ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
sqlfilldb.C
Go to the documentation of this file.
1 void sqlfilldb(int nfiles = 1000)
2 {
3  // Fill run catalog with nfiles entries
4 
5  const char *ins = "INSERT INTO runcatalog VALUES ('%s', %d,"
6  " %d, %d, %d, %10.2f, '%s', '%s', '1997-01-15 20:16:28',"
7  " '1999-01-15 20:16:28', '%s', '%s')";
8 
9  char sql[4096];
10  char dataset[32];
11  char rawfile[128];
12  int tag, evt = 0;
13 
14  // open connection to MySQL server on localhost
15  TSQLServer *db = TSQLServer::Connect("mysql://localhost/test", "nobody", "");
16  TSQLResult *res;
17 
18  // first clean table of old entries
19  res = db->Query("DELETE FROM runcatalog");
20  delete res;
21 
22  // start timer
24  timer.Start();
25 
26  // fill run catalog
27  for (int i = 0; i < nfiles; i++) {
28  sprintf(dataset, "testrun_%d", i);
29  sprintf(rawfile, "/v1/data/lead/test/run_%d.root", i);
30  tag = int(gRandom->Rndm()*10.);
31  sprintf(sql, ins, dataset, i, evt, evt+10000, tag, 25.5, "test", "lead",
32  rawfile, "test run dummy data");
33  evt += 10000;
34  res = db->Query(sql);
35  delete res;
36  //printf("%s\n", sql);
37  }
38 
39  delete db;
40 
41  // stop timer and print results
42  timer.Stop();
43  Double_t rtime = timer.RealTime();
44  Double_t ctime = timer.CpuTime();
45 
46  printf("\n%d files in run catalog\n", nfiles);
47  printf("RealTime=%f seconds, CpuTime=%f seconds\n", rtime, ctime);
48 }
Double_t RealTime()
Stop the stopwatch (if it is running) and return the realtime (in seconds) passed between the start a...
Definition: TStopwatch.cxx:108
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
Definition: TStopwatch.cxx:56
virtual Double_t Rndm(Int_t i=0)
Machine independent random number generator.
Definition: TRandom.cxx:512
virtual TSQLResult * Query(const char *sql)=0
static TSQLServer * Connect(const char *db, const char *uid, const char *pw)
Double_t CpuTime()
Stop the stopwatch (if it is running) and return the cputime (in seconds) passed between the start an...
Definition: TStopwatch.cxx:123
void sqlfilldb(int nfiles=1000)
Definition: sqlfilldb.C:1
TStopwatch timer
Definition: pirndm.C:37
void Stop()
Stop the stopwatch.
Definition: TStopwatch.cxx:75
R__EXTERN TRandom * gRandom
Definition: TRandom.h:62
double Double_t
Definition: RtypesCore.h:55
ClassImp(TMCParticle) void TMCParticle printf(": p=(%7.3f,%7.3f,%9.3f) ;", fPx, fPy, fPz)
Stopwatch class.
Definition: TStopwatch.h:30