8 from __future__
import print_function
10 __version__ =
"$Id: ParameterDbFiller.py,v 1.3 2008-11-13 12:25:23 schaffer Exp $"
11 __author__ =
"RD Schaffer <R.D.Schaffer@cern.ch>"
17 from PyCool
import cool
28 A simple class used to fill SQLite db file with parameters for simulation
65 if dbFileName
is None:
67 dbFileName =
"SimParams.db"
70 self.
genDb(dbFileName,
'SIMPARAM', self.
simParams,
'/Simulation/Parameters')
75 if dbFileName
is None:
77 dbFileName =
"DigitParams.db"
83 def genDb(self, dbFileName, dbName, params, folderPath, params64 = {}):
87 raise ParameterDbFillerError (
'Must set begin run number before generating db')
89 raise ParameterDbFillerError (
'Must set end run number before generating db')
91 raise ParameterDbFillerError (
'No parameters for db ' + dbName)
96 print (
"ParameterDbFiller.genDb: Removed db", dbFileName)
101 dbSvc=cool.DatabaseSvcFactory.databaseService()
104 dbstring=
"sqlite://;schema=" + dbFileName +
";dbname=" + dbName
106 db=dbSvc.createDatabase(dbstring)
107 except Exception
as e:
108 print (
'ParameterDbFiller.genDb: Problem creating database',e)
110 print (
"ParameterDbFiller.genDb: Created database",dbstring)
113 spec=cool.RecordSpecification()
115 spec.extend(key, cool.StorageType.String4k)
119 spec.extend(key, cool.StorageType.String64k)
122 desc =
'<timeStamp>run-event</timeStamp><addrHeader><address_header service_type="71" clid="40774348" /></addrHeader><typeName>AthenaAttributeList</typeName>'
128 folderSpec = cool.FolderSpecification(cool.FolderVersioning.SINGLE_VERSION, spec)
129 myfolder = db.createFolder(folderPath, folderSpec, desc,
True)
132 data = cool.Record(spec)
133 for k, v
in six.iteritems(params):
135 for k, v
in six.iteritems(params64):
138 print (
"ParameterDbFiller.genDb: Recording parameters", data)
142 print (
"ParameterDbFiller.genDb: Stored object")
152 print (
"ParameterDbFiller.dumpDb: Dumping database:", dbstring)
154 dbSvc = cool.DatabaseSvcFactory.databaseService()
157 db = dbSvc.openDatabase(dbstring,
False)
158 except Exception
as e:
159 print (
'ParameterDbFiller.dumpDb: Problem opening database',e)
163 folders = db.listAllNodes()
166 if (
not db.existsFolder(ff)):
170 print (
"ParameterDbFiller.dumpDb: Dumping folder " +
str(ff))
182 nobjs = f.countObjects( cool.ValidityKeyMin,
184 cool.ChannelSelection.all())
186 print (
"ParameterDbFiller.dumpDb: number of IOV payloads", nobjs)
188 objs = f.browseObjects( cool.ValidityKeyMin,
190 cool.ChannelSelection.all())
192 while objs.goToNext():
193 obj = objs.currentRef()
194 print (
"ParameterDbFiller.dumpDb: Payload", i, end=
'')
195 print (
"since [r,l]: [", obj.since() >> 32,
',',obj.since()%0x100000000,
']', end=
'')
196 print (
"until [r,l]: [", obj.until() >> 32,
',',obj.until()%0x100000000,
']', end=
'')
197 print (
"payload", obj.payload(), end=
'')
198 print (
"chan",obj.channelId() )