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