ATLAS Offline Software
Loading...
Searching...
No Matches
ForwardDetectors
AFP
AFP_DBTools
python
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
7
class
AFPDBRecordBase
(
object
):
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
42
class
AFPDBTableBase
(
object
):
43
def
__init__
(self):
44
self.
records
= []
45
self.
iovStartRun
= 0
46
self.
iovStartLumiBlock
= 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
if
if(febId1==febId2)
Definition
LArRodBlockPhysicsV0.cxx:567
AFPDBBase.AFPDBRecordBase
Definition
AFPDBBase.py:7
AFPDBBase.AFPDBRecordBase.serialiseValues
serialiseValues(self)
Definition
AFPDBBase.py:8
AFPDBBase.AFPDBRecordBase.serialiseTypes
serialiseTypes(self)
Definition
AFPDBBase.py:20
AFPDBBase.AFPDBRecordBase.translateType
translateType(self, typeName)
Definition
AFPDBBase.py:31
AFPDBBase.AFPDBTableBase
Definition
AFPDBBase.py:42
AFPDBBase.AFPDBTableBase.iovStartLumiBlock
int iovStartLumiBlock
Definition
AFPDBBase.py:46
AFPDBBase.AFPDBTableBase.createOrGetFolder
createOrGetFolder(self, db)
Definition
AFPDBBase.py:109
AFPDBBase.AFPDBTableBase.serialiseRecords
serialiseRecords(self)
Definition
AFPDBBase.py:69
AFPDBBase.AFPDBTableBase.folder
folder
Definition
AFPDBBase.py:112
AFPDBBase.AFPDBTableBase.folderSpec
folderSpec
Definition
AFPDBBase.py:58
AFPDBBase.AFPDBTableBase.iovStartRun
int iovStartRun
Definition
AFPDBBase.py:45
AFPDBBase.AFPDBTableBase.data
data
Definition
AFPDBBase.py:57
AFPDBBase.AFPDBTableBase.__init__
__init__(self)
Definition
AFPDBBase.py:43
AFPDBBase.AFPDBTableBase.iovEndRun
int iovEndRun
Definition
AFPDBBase.py:47
AFPDBBase.AFPDBTableBase.iovEndLumiBlock
int iovEndLumiBlock
Definition
AFPDBBase.py:48
AFPDBBase.AFPDBTableBase.records
list records
Definition
AFPDBBase.py:44
AFPDBBase.AFPDBTableBase.spec
spec
Definition
AFPDBBase.py:52
AFPDBBase.AFPDBTableBase.tag
str tag
Definition
AFPDBBase.py:50
AFPDBBase.AFPDBTableBase.saveToDB
saveToDB(self)
Definition
AFPDBBase.py:100
AFPDBBase.AFPDBTableBase.serialiseHeader
serialiseHeader(self)
Definition
AFPDBBase.py:62
AFPDBBase.AFPDBTableBase.folderName
str folderName
Definition
AFPDBBase.py:51
AFPDBBase.AFPDBTableBase.desc
str desc
Definition
AFPDBBase.py:56
AFPDBBase.AFPDBTableBase.serialiseTable
serialiseTable(self)
Definition
AFPDBBase.py:88
type
object
Generated on
for ATLAS Offline Software by
1.14.0