Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 }