Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
9void 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 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:559
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....
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...
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
Double_t CpuTime()
Stop the stopwatch (if it is running) and return the cputime (in seconds) passed between the start an...
void Stop()
Stop the stopwatch.