ATLAS Offline Software
AFPDBBase.py
Go to the documentation of this file.
1 #!/bin/env python
2 # Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 
4 from __future__ import print_function
5 
6 from PyCool import cool
7 
9  def serialiseValues (self):
10  output = "["
11  for quantity in dir(self): # loop over all elements in class
12  if not callable(getattr(self, quantity)) and not quantity.startswith("__"): # select only user variables
13  # print ("Moj " + quantity + " wynosi: " + str(getattr(self, quantity)))
14  output += str(getattr(self, quantity)) + ", "
15 
16  output = output[:-2] # remove the last comma and space ", "
17  output += "]" # close bracket
18 
19  return output
20 
21  def serialiseTypes (self):
22  output = '"folder_payloadspec": "'
23  for quantity in dir(self): # loop over all elements in class
24  if not callable(getattr(self, quantity)) and not quantity.startswith('__'): # select only user variables
25  output += quantity + ': ' + self.translateType(type(getattr(self, quantity))) + ', ' # append variable name and type
26 
27  output = output[:-2] # remove the last comma and space ", "
28  output += '"' # close parenthisis
29 
30  return output
31 
32  def translateType (self, typeName):
33  if (typeName == int):
34  return "Int32"
35  elif (typeName == float):
36  return "Float"
37  elif (typeName == str):
38  return "String"
39  else:
40  raise ValueError ("Unknown type of field, typeName is %s. Need to update method translateType in AFPDBBase.py" % typeName)
41 
42 
44  def __init__ (self):
45  self.records = []
46  self.iovStartRun = 0
48  self.iovEndRun = 0
49  self.iovEndLumiBlock = 0
50 
51  self.tag = "AFPTest-00-00-00"
52  self.folderName = "/FWD/AFP/TEST"
53  self.spec = cool.RecordSpecification()
54 # self.spec.extend("data", cool.StorageType.Blob64k)
55  self.spec.extend("data", cool.StorageType.String16M)
56 # self.desc = '<timeStamp>run-lumi</timeStamp><addrHeader><address_header service_type="71" clid="1238547719" /></addrHeader><typeName>CondAttrListCollection</typeName>'
57  self.desc = '<timeStamp>run-lumi</timeStamp><addrHeader><address_header service_type="71" clid="40774348" /></addrHeader><typeName>AthenaAttributeList</typeName>'
58  self.data = cool.Record(self.spec)
59  self.folderSpec = cool.FolderSpecification(cool.FolderVersioning.MULTI_VERSION, self.spec)
60 
61 
62 
63  def serialiseHeader (self):
64  output = '"node_description": '
65 # output += '"<timeStamp>run-lumi</timeStamp><addrHeader><address_header service_type="71" clid="1238547719" /></addrHeader<typeName>CondAttrListCollection</typeName>"'
66  output += '"<timeStamp>run-lumi</timeStamp><addrHeader><address_header service_type=\\"71\\" clid=\\"40774348\\" /></addrHeader><typeName>AthenaAttributeList</typeName> "'
67 
68  return output
69 
70  def serialiseRecords (self):
71  output = '"data_array": ['
72  if (len(self.records) > 0):
73  channelID = 1
74 
75  for entry in self.records:
76  output += '{'
77  output += '"' + str(channelID) + '" : '
78  output += entry.serialiseValues()
79  output += '}, '
80  channelID += 1
81 
82  # remove the last comma and space ", "
83  output = output[:-2]
84  # close bracket
85  output += ']'
86 
87  return output
88 
89  def serialiseTable (self):
90  if (len(self.records) < 1):
91  raise ValueError ("Empty records list. Please, fill records before serialising table.")
92 
93  output = '{'
94  output += self.serialiseHeader() + ', '
95  output += self.records[0].serialiseTypes() + ', '
96  output += self.serialiseRecords()
97  output += '}'
98 
99  return output
100 
101  def saveToDB (self):
102  self.data['data'] = self.serialiseTable()
103  iovStart=(self.iovStartRun<<32) + self.iovStartLumiBlock
104  print ("before self.iovEndRun=" + str(self.iovEndRun))
105  iovEnd=(self.iovEndRun<<32) + self.iovEndLumiBlock
106  print ("after self.iovEndRun=" + str(self.iovEndRun))
107 
108  self.folder.storeObject(iovStart, iovEnd, self.data, 0, self.tag)
109 
110  def createOrGetFolder (self, db):
111  print (self.folderSpec)
112  if(db.existsFolder(self.folderName)):
113  self.folder=db.getFolder(self.folderName)
114  else:
115  self.folder=db.createFolder(self.folderName, self.folderSpec, self.desc, True)
116 
117 
AFPDBBase.AFPDBTableBase.records
records
Definition: AFPDBBase.py:45
AFPDBBase.AFPDBTableBase.iovEndRun
iovEndRun
Definition: AFPDBBase.py:48
AFPDBBase.AFPDBTableBase.iovStartRun
iovStartRun
Definition: AFPDBBase.py:46
AFPDBBase.AFPDBTableBase.tag
tag
Definition: AFPDBBase.py:51
AFPDBBase.AFPDBTableBase.saveToDB
def saveToDB(self)
Definition: AFPDBBase.py:101
AFPDBBase.AFPDBTableBase.serialiseRecords
def serialiseRecords(self)
Definition: AFPDBBase.py:70
AFPDBBase.AFPDBTableBase.folderSpec
folderSpec
Definition: AFPDBBase.py:59
AFPDBBase.AFPDBTableBase
Definition: AFPDBBase.py:43
AFPDBBase.AFPDBTableBase.serialiseHeader
def serialiseHeader(self)
Definition: AFPDBBase.py:63
AFPDBBase.AFPDBTableBase.folder
folder
Definition: AFPDBBase.py:113
AFPDBBase.AFPDBRecordBase.serialiseTypes
def serialiseTypes(self)
Definition: AFPDBBase.py:21
AFPDBBase.AFPDBTableBase.iovStartLumiBlock
iovStartLumiBlock
Definition: AFPDBBase.py:47
AFPDBBase.AFPDBRecordBase.translateType
def translateType(self, typeName)
Definition: AFPDBBase.py:32
AFPDBBase.AFPDBRecordBase.serialiseValues
def serialiseValues(self)
Definition: AFPDBBase.py:9
beamspotman.dir
string dir
Definition: beamspotman.py:623
AFPDBBase.AFPDBTableBase.data
data
Definition: AFPDBBase.py:58
AFPDBBase.AFPDBTableBase.createOrGetFolder
def createOrGetFolder(self, db)
Definition: AFPDBBase.py:110
AFPDBBase.AFPDBTableBase.folderName
folderName
Definition: AFPDBBase.py:52
AFPDBBase.AFPDBTableBase.__init__
def __init__(self)
Definition: AFPDBBase.py:44
AFPDBBase.AFPDBTableBase.iovEndLumiBlock
iovEndLumiBlock
Definition: AFPDBBase.py:49
AFPDBBase.AFPDBTableBase.desc
desc
Definition: AFPDBBase.py:57
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
AFPDBBase.AFPDBTableBase.spec
spec
Definition: AFPDBBase.py:53
if
if(febId1==febId2)
Definition: LArRodBlockPhysicsV0.cxx:569
pickleTool.object
object
Definition: pickleTool.py:30
str
Definition: BTagTrackIpAccessor.cxx:11
AFPDBBase.AFPDBTableBase.serialiseTable
def serialiseTable(self)
Definition: AFPDBBase.py:89
AFPDBBase.AFPDBRecordBase
Definition: AFPDBBase.py:8