ATLAS Offline Software
dummyLHCFillDB.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2 from PyCool import cool
3 import ROOT
4 # Work around pyroot issue with long long --- see ATEAM-997.
5 ROOT.gInterpreter
6 import os
7 from AthenaCommon.Logging import logging
8 msg = logging.getLogger( 'dummyLHCFillDB' )
9 
10 
11 
12 def createSqlite(sqliteName,folderName="/TDAQ/OLC/LHC/FILLPARAMS"):
13 
14  dbSvc = cool.DatabaseSvcFactory.databaseService()
15 
16  if os.access(sqliteName,os.R_OK):
17  msg.debug("UPDATING existing sqlite file %s" , sqliteName)
18  db=dbSvc.openDatabase("sqlite://;schema="+sqliteName+";dbname=CONDBR2",False)
19  else:
20  msg.debug("Creating new sqlite file %s" , sqliteName)
21  db=dbSvc.createDatabase("sqlite://;schema="+sqliteName+";dbname=CONDBR2")
22  pass
23 
24  spec = cool.RecordSpecification()
25  spec.extend("Beam1Bunches",cool.StorageType.UInt32)
26  spec.extend("Beam2Bunches",cool.StorageType.UInt32)
27  spec.extend("LuminousBunches",cool.StorageType.UInt32)
28  spec.extend("BCIDmasks",cool.StorageType.Blob64k)
29 
30  descr='<timeStamp>time</timeStamp><addrHeader><address_header service_type="71" clid="40774348" /></addrHeader><typeName>AthenaAttributeList</typeName>'
31  if db.existsFolder(folderName):
32  folder=db.getFolder(folderName)
33  else:
34  msg.debug("Creating COOL folder/tag %s" , (folderName))
35  folderSpec = cool.FolderSpecification(cool.FolderVersioning.MULTI_VERSION, spec)
36  folder = db.createFolder(folderName, folderSpec, descr, True)
37  pass
38 
39  return db,folder
40 
41 
42 
43 def createSqliteForAvg(sqliteName,folderName="/TDAQ/OLC/LHC/LBDATA3"):
44 
45  dbSvc = cool.DatabaseSvcFactory.databaseService()
46 
47  if os.access(sqliteName,os.R_OK):
48  msg.debug("UPDATING existing sqlite file %s" , sqliteName)
49  db=dbSvc.openDatabase("sqlite://;schema="+sqliteName+";dbname=CONDBR2",False)
50  else:
51  msg.debug("Creating new sqlite file %s" , sqliteName)
52  db=dbSvc.createDatabase("sqlite://;schema="+sqliteName+";dbname=CONDBR2")
53  pass
54 
55 
56 
57  spec = cool.RecordSpecification()
58  spec.extend("Beam1Intensity",cool.StorageType.Float)
59  spec.extend("Beam2Intensity",cool.StorageType.Float)
60 
61  spec.extend("Beam1IntensityAll",cool.StorageType.Float)
62  spec.extend("Beam2IntensityAll",cool.StorageType.Float)
63  spec.extend("Beam1IntensityStd",cool.StorageType.Float)
64  spec.extend("Beam2IntensityStd",cool.StorageType.Float)
65  spec.extend("Beam1IntensityAllStd",cool.StorageType.Float)
66  spec.extend("Beam2IntensityAllStd",cool.StorageType.Float)
67 
68  spec.extend("RunLB",cool.StorageType.UInt63)
69  spec.extend("Valid",cool.StorageType.UInt32)
70 
71  # clid=40774348 -> AthenaAttributeList
72  # clid=120132775 -> BunchCrossingAverageData
73  descr='<timeStamp>time</timeStamp><addrHeader><address_header service_type="71" clid="1238547719" /></addrHeader><typeName>CondAttrListCollection</typeName>'
74 
75  if db.existsFolder(folderName):
76  msg.debug("folder exist")
77  folder=db.getFolder(folderName)
78  else:
79  msg.debug("Creating COOL folder/tag %s" , (folderName))
80  folderSpec = cool.FolderSpecification(cool.FolderVersioning.MULTI_VERSION, spec)
81  folder = db.createFolder(folderName, folderSpec, descr, True)
82  pass
83 
84  return db,folder
85 
86 
87 
88 def createSqliteForInt(sqliteName,folderName="/TDAQ/OLC/LHC/BUNCHDATA"):
89 
90  dbSvc = cool.DatabaseSvcFactory.databaseService()
91 
92  if os.access(sqliteName,os.R_OK):
93  msg.debug("UPDATING existing sqlite file %s" , sqliteName)
94  db=dbSvc.openDatabase("sqlite://;schema="+sqliteName+";dbname=CONDBR2",False)
95  else:
96  msg.debug("Creating new sqlite file %s" , sqliteName)
97  db=dbSvc.createDatabase("sqlite://;schema="+sqliteName+";dbname=CONDBR2")
98  pass
99 
100 
101 
102  spec = cool.RecordSpecification()
103  spec.extend("RunLB",cool.StorageType.UInt63)
104  spec.extend("B1BunchAverage",cool.StorageType.Float)
105  spec.extend("B2BunchAverage",cool.StorageType.Float)
106 
107  spec.extend("B1BunchIntensities",cool.StorageType.Blob64k)
108  spec.extend("B2BunchIntensities",cool.StorageType.Blob64k)
109 
110  spec.extend("Valid",cool.StorageType.UInt32)
111 
112  # clid=40774348 -> AthenaAttributeList
113  # clid=120132775 -> BunchCrossingAverageData
114  descr='<timeStamp>time</timeStamp><addrHeader><address_header service_type="71" clid="1238547719" /></addrHeader><typeName>CondAttrListCollection</typeName>'
115 
116  if db.existsFolder(folderName):
117  msg.debug("folder exist")
118  folder=db.getFolder(folderName)
119  else:
120  msg.debug("Creating COOL folder/tag %s" , (folderName))
121  folderSpec = cool.FolderSpecification(cool.FolderVersioning.MULTI_VERSION, spec)
122  folder = db.createFolder(folderName, folderSpec, descr, True)
123  pass
124 
125  return db,folder
126 
127 
128 def fillFolder(folder,data=[],iovMin=cool.ValidityKeyMin,iovMax=cool.ValidityKeyMax):
129 
130  nB1=0
131  nB2=0
132  nColl=0
133 
134  for bcid in data:
135  if (bcid & 0x1): nB1+=1
136  if (bcid & 0x2): nB2+=1
137  if (bcid & 0x3 == 0x3): nColl+=1
138  pass
139 
140 
141  payload=cool.Record(folder.payloadSpecification())
142  payload['Beam1Bunches']=nB1
143  payload['Beam2Bunches']=nB2
144  payload['LuminousBunches']=nColl
145  btype=getattr(ROOT,"coral::Blob")
146 
147  bcmask=btype()
148  bcmask.resize(3564)
149 
150  for i,d in enumerate(data):
151  bcmask[i]=d
152 
153 
154  payload['BCIDmasks']=bcmask
155 
156 
157  msg.debug("Storing FILLPARAMS object")
158  folder.storeObject(iovMin, iovMax, payload, cool.ChannelId(0))
159 
160  return
161 
162 
163 
164 def fillFolderForAvg(folder,data=[],iovMin=cool.ValidityKeyMin,iovMax=cool.ValidityKeyMax):
165 
166  nB1=0
167  nB2=0
168  nColl=0
169 
170  for bcid in data:
171  if (bcid & 0x1): nB1+=1
172  if (bcid & 0x2): nB2+=1
173  if (bcid & 0x3 == 0x3): nColl+=1
174  pass
175 
176  for chanNum in range(0,4):
177  payload=cool.Record(folder.payloadSpecification())
178 
179  payload['Beam1Intensity']=1.5+1.5*chanNum
180  payload['Beam2Intensity']=1.5+1.5*chanNum
181  payload['Beam1IntensityAll']=1.5+1.5*chanNum
182  payload['Beam2IntensityAll']=1.5+1.5*chanNum
183  payload['Beam1IntensityStd']=1.5+1.5*chanNum
184  payload['Beam2IntensityStd']=1.5+1.5*chanNum
185  payload['Beam1IntensityAllStd']=1.5+1.5*chanNum
186  payload['Beam2IntensityAllStd']=1.5+1.5*chanNum
187  payload['RunLB']=430897
188  payload['Valid']=1
189 
190 
191  channelId = cool.ChannelId(chanNum)
192  folder.storeObject(iovMin, iovMax, payload, channelId)
193  msg.debug("Storing LBDATA3 object")
194 
195 
196  return
197 
198 
199 
200 
201 def fillFolderForInt(folder,data=[],iovMin=cool.ValidityKeyMin,iovMax=cool.ValidityKeyMax):
202 
203  for chanNum in range(0,2):
204  payload=cool.Record(folder.payloadSpecification())
205  # payload['Channel']=0
206  payload['RunLB']=430897
207  payload['B1BunchAverage']=1.5+1.5*chanNum
208  payload['B2BunchAverage']=1.5+1.5*chanNum
209 
210 
211  btype=getattr(ROOT,"coral::Blob")
212 
213  bcmask_1=btype()
214  bcmask_1.resize(3564)
215 
216  bcmask_2=btype()
217  bcmask_2.resize(3564)
218 
219  for i,d in enumerate(data):
220  bcmask_1[i]=d
221 
222  for i,d in enumerate(data):
223  bcmask_2[i]=d
224 
225  payload['B1BunchIntensities']=bcmask_1
226  payload['B2BunchIntensities']=bcmask_2
227  payload['Valid']=1
228 
229  channelId = cool.ChannelId(chanNum)
230  folder.storeObject(iovMin, iovMax, payload, channelId)
231 
232  msg.debug("Storing BUNCHDATA object")
233 
234  return
235 
236 
237 
239  mask=[]
240  #pre-fill with zero
241  for i in range(0,3564):
242  mask.append(0x0)
243 
244  #A train across the wrap-around:
245  for i in range (0,25):
246  mask[i]=0x3
247 
248  for i in range (3550,3564):
249  mask[i]=0x3
250 
251  #A short sequence of bunches that doesn't qualify as train
252  for i in range (1000,1030):
253 
254  mask[i]=0x3
255  return mask
256 
257 
259  mask=[]
260  #pre-fill with zero
261  for i in range(0,3564):
262  mask.append(0x0)
263 
264  t8b4e=[0x3,0x3,0x3,0x3, 0x3,0x3,0x3,0x3, 0x0,0x0,0x0,0x0]
265 
266  for i in range(0,20):
267  #create a train of 20 8be4 groups start
268  mask[100+i*12:100+(i+1)*12]=t8b4e
269 
270  return mask
271 
272 
273 
274 
275 if __name__=="__main__":
276 
277 
278  db,folder=createSqlite("test.db")
279 
282 
283  fillFolder(folder,d1,iovMin=cool.ValidityKey(1e6),iovMax=cool.ValidityKey(2e6))
284  fillFolder(folder,d2,iovMin=cool.ValidityKey(2e6),iovMax=cool.ValidityKey(3e6))
285 
286 
287  db.closeDatabase()
288 
289 
python.dummyLHCFillDB.createSqlite
def createSqlite(sqliteName, folderName="/TDAQ/OLC/LHC/FILLPARAMS")
Definition: dummyLHCFillDB.py:12
python.dummyLHCFillDB.createBCMask1
def createBCMask1()
Definition: dummyLHCFillDB.py:238
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
python.dummyLHCFillDB.fillFolderForAvg
def fillFolderForAvg(folder, data=[], iovMin=cool.ValidityKeyMin, iovMax=cool.ValidityKeyMax)
Definition: dummyLHCFillDB.py:164
python.dummyLHCFillDB.createSqliteForAvg
def createSqliteForAvg(sqliteName, folderName="/TDAQ/OLC/LHC/LBDATA3")
Definition: dummyLHCFillDB.py:43
python.dummyLHCFillDB.fillFolderForInt
def fillFolderForInt(folder, data=[], iovMin=cool.ValidityKeyMin, iovMax=cool.ValidityKeyMax)
Definition: dummyLHCFillDB.py:201
python.dummyLHCFillDB.createSqliteForInt
def createSqliteForInt(sqliteName, folderName="/TDAQ/OLC/LHC/BUNCHDATA")
Definition: dummyLHCFillDB.py:88
python.dummyLHCFillDB.fillFolder
def fillFolder(folder, data=[], iovMin=cool.ValidityKeyMin, iovMax=cool.ValidityKeyMax)
Definition: dummyLHCFillDB.py:128
python.dummyLHCFillDB.createBCMask2
def createBCMask2()
Definition: dummyLHCFillDB.py:258