Logo ROOT  
Reference Guide
sqlfilldb.py
Go to the documentation of this file.
1## \file
2## \ingroup tutorial_sql
3## \notebook -nodraw
4## Fill run catalog with nfiles entries
5##
6## Based on sqlfill.C by Sergey Linev
7##
8## \macro_code
9##
10## \author Juan Fernando Jaramillo Botero
11
12from ROOT import TSQLServer, TSQLResult, TStopwatch, gRandom
13
14
15nfiles = 1000
16
17ins = "INSERT INTO runcatalog VALUES ('%s', %d," \
18 " %d, %d, %d, %10.2f, '%s', '%s', '1997-01-15 20:16:28'," \
19 " '1999-01-15 20:16:28', '%s', '%s')"
20
21tag = evt = 0
22
23# open connection to MySQL server on localhost
24db = TSQLServer.Connect("mysql://localhost/test", "nobody", "")
25
26# first clean table of old entries
27res = db.Query("DELETE FROM runcatalog")
28
29# start timer
30timer = TStopwatch()
31timer.Start()
32
33# fill run catalog
34for i in range(nfiles):
35 dataset = "testrun_%d" % i
36 rawfile = "/v1/data/lead/test/run_%d.root" % i
37 tag = int(gRandom.Rndm() * 10.)
38 sql = ins % (dataset, i, evt, evt + 10000, tag, 25.5, "test", "lead",
39 rawfile, "test run dummy data")
40 evt += 10000
41 res = db.Query(sql)
42 # print("%s" % sql)
43
44
45# stop timer and print results
46timer.Stop()
47rtime = timer.RealTime()
48ctime = timer.CpuTime()
49
50print("")
51print("%d files in run catalog" % nfiles)
52print("RealTime=%f seconds, CpuTime=%f seconds" % (rtime, ctime))
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
Stopwatch class.
Definition: TStopwatch.h:28