Logo ROOT  
Reference Guide
sqlfilldb.C File Reference

Detailed Description

Fill run catalog with nfiles entries.

void sqlfilldb(int nfiles = 1000)
const char *ins = "INSERT INTO runcatalog VALUES ('%s', %d,"
" %d, %d, %d, %10.2f, '%s', '%s', '1997-01-15 20:16:28',"
" '1999-01-15 20:16:28', '%s', '%s')";
char sql[4096];
char dataset[32];
char rawfile[128];
int tag, evt = 0;
// open connection to MySQL server on localhost
TSQLServer *db = TSQLServer::Connect("mysql://localhost/test", "nobody", "");
TSQLResult *res;
// first clean table of old entries
res = db->Query("DELETE FROM runcatalog");
delete res;
// start timer
TStopwatch timer;
// fill run catalog
for (int i = 0; i < nfiles; i++) {
sprintf(dataset, "testrun_%d", i);
sprintf(rawfile, "/v1/data/lead/test/run_%d.root", i);
tag = int(gRandom->Rndm()*10.);
sprintf(sql, ins, dataset, i, evt, evt+10000, tag, 25.5, "test", "lead",
rawfile, "test run dummy data");
evt += 10000;
res = db->Query(sql);
delete res;
//printf("%s\n", sql);
delete db;
// stop timer and print results
Double_t rtime = timer.RealTime();
Double_t ctime = timer.CpuTime();
printf("\n%d files in run catalog\n", nfiles);
printf("RealTime=%f seconds, CpuTime=%f seconds\n", rtime, ctime);
double Double_t
Definition: RtypesCore.h:59
R__EXTERN TRandom * gRandom
Definition: TRandom.h:62
Double_t Rndm() override
Machine independent random number generator.
Definition: TRandom.cxx:552
virtual TSQLResult * Query(const char *sql)=0
static TSQLServer * Connect(const char *db, const char *uid, const char *pw)
The db should be of the form: <dbms>://<host>[:<port>][/<database>], e.g.: mysql://pcroot....
Definition: TSQLServer.cxx:61
Stopwatch class.
Definition: TStopwatch.h:28
Double_t RealTime()
Stop the stopwatch (if it is running) and return the realtime (in seconds) passed between the start a...
Definition: TStopwatch.cxx:110
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
Definition: TStopwatch.cxx:58
Double_t CpuTime()
Stop the stopwatch (if it is running) and return the cputime (in seconds) passed between the start an...
Definition: TStopwatch.cxx:125
void Stop()
Stop the stopwatch.
Definition: TStopwatch.cxx:77
Sergey Linev

Definition in file sqlfilldb.C.