ATLAS Offline Software
createLinkMaskingSQLiteFile.py
Go to the documentation of this file.
1 #!/bin/env python
2 
3 from __future__ import print_function
4 
5 # Taken from InnerDetector/InDetRecTools/TRT_ElectronPidTools/DatabaseTools/WritePyCoolAll.py
6 # https://twiki.cern.ch/twiki/bin/view/Atlas/ConditionsSimpleExample
7 # Usage: python ../athena/InnerDetector/InDetConditions/SCT_ConditionsTools/python/createLinkMaskingSQLiteFile.py
8 
9 import sys
10 from PyCool import cool
11 
12 def main():
13  dbFile = "LinkMasking.db"
14  dbName = "CONDBR2"
15  folderName ="/purple/pants"
16 
17  fieldNames = ["lastProbedState"]
18  fieldTypes = [cool.StorageType.Bool]
19 
20  # remove the old db file so that we can write the new one
21  try:
22  import os
23  os.remove(dbFile)
24  except:
25  pass
26 
27  # get database service and open database
28  dbSvc = cool.DatabaseSvcFactory.databaseService()
29 
30  # database accessed via physical name
31  dbString = "sqlite://;schema=%s;dbname=%s" % (dbFile, dbName)
32  try:
33  db = dbSvc.createDatabase(dbString)
34  except Exception:
35  import traceback
36  traceback.print_exc()
37  sys.exit(-1)
38  print ("Created database", dbString)
39 
40  # setup folder
41  spec = cool.RecordSpecification()
42  spec.extend(fieldNames[0], fieldTypes[0])
43 
44  # folder meta-data - note for Athena this has a special meaning
45  desc = '<timeStamp>run-lumi</timeStamp><addrHeader><address_header service_type="71" clid="1238547719" /></addrHeader><typeName>CondAttrListCollection</typeName>'
46 
47  # create the folder - single version
48  # last argument is createParents - if true, automatically creates parent folders if needed
49  # note this will not work if the database already exists - delete mycool.db first
50  folderSpec = cool.FolderSpecification(cool.FolderVersioning.SINGLE_VERSION, spec)
51  folder = db.createFolder(folderName, folderSpec, desc, True)
52 
53  # now fill in some data - create a record and fill it
54  data = cool.Record(spec)
55 
56  dataDict = {167772160:False, # barrel_ec 0 layer_disk 0 eta_module -6 phi_module 0 side 0
57  167773184:True, # barrel_ec 0 layer_disk 0 eta_module -6 phi_module 0 side 1
58  167774208:True, # barrel_ec 0 layer_disk 0 eta_module -5 phi_module 0 side 0
59  167775232:True, # barrel_ec 0 layer_disk 0 eta_module -5 phi_module 0 side 1
60  167776256:False, # barrel_ec 0 layer_disk 0 eta_module -4 phi_module 0 side 0
61  }
62 
63  for waferID, lastProbedState in dataDict.items():
64  print ("\nChannel", waferID)
65  print ("lastProbedState is", lastProbedState)
66  data[fieldNames[0]] = lastProbedState
67  print ("Will store this object for channel", waferID, data)
68  folder.storeObject(0, cool.ValidityKeyMax, data, waferID)
69 
70  print ("\nClose database")
71  db.closeDatabase()
72 
73 if __name__=="__main__":
74  main()
createLinkMaskingSQLiteFile.main
def main()
Definition: createLinkMaskingSQLiteFile.py:12