Logo ROOT   6.12/07
Reference Guide
sqlfilldb.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_sql
3 /// Fill run catalog with nfiles entries
4 ///
5 /// \macro_code
6 ///
7 /// \author Sergey Linev
8 
9 void sqlfilldb(int nfiles = 1000)
10 {
11  const char *ins = "INSERT INTO runcatalog VALUES ('%s', %d,"
12  " %d, %d, %d, %10.2f, '%s', '%s', '1997-01-15 20:16:28',"
13  " '1999-01-15 20:16:28', '%s', '%s')";
14 
15  char sql[4096];
16  char dataset[32];
17  char rawfile[128];
18  int tag, evt = 0;
19 
20  // open connection to MySQL server on localhost
21  TSQLServer *db = TSQLServer::Connect("mysql://localhost/test", "nobody", "");
22  TSQLResult *res;
23 
24  // first clean table of old entries
25  res = db->Query("DELETE FROM runcatalog");
26  delete res;
27 
28  // start timer
29  TStopwatch timer;
30  timer.Start();
31 
32  // fill run catalog
33  for (int i = 0; i < nfiles; i++) {
34  sprintf(dataset, "testrun_%d", i);
35  sprintf(rawfile, "/v1/data/lead/test/run_%d.root", i);
36  tag = int(gRandom->Rndm()*10.);
37  sprintf(sql, ins, dataset, i, evt, evt+10000, tag, 25.5, "test", "lead",
38  rawfile, "test run dummy data");
39  evt += 10000;
40  res = db->Query(sql);
41  delete res;
42  //printf("%s\n", sql);
43  }
44 
45  delete db;
46 
47  // stop timer and print results
48  timer.Stop();
49  Double_t rtime = timer.RealTime();
50  Double_t ctime = timer.CpuTime();
51 
52  printf("\n%d files in run catalog\n", nfiles);
53  printf("RealTime=%f seconds, CpuTime=%f seconds\n", rtime, ctime);
54 }
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
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.
Definition: TSQLServer.cxx:61
virtual TSQLResult * Query(const char *sql)=0
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
virtual Double_t Rndm()
Machine independent random number generator.
Definition: TRandom.cxx:533
R__EXTERN TRandom * gRandom
Definition: TRandom.h:62
double Double_t
Definition: RtypesCore.h:55
Stopwatch class.
Definition: TStopwatch.h:28