43 print (
" Loading reference HV file", ref_file_name)
45 dbSvc = cool.DatabaseSvcFactory.databaseService()
47 dbString=
'sqlite://;schema='+ref_file_name+
';dbname=L1CALO'
49 db = dbSvc.openDatabase(dbString,
False)
50 except Exception
as e:
51 print (
'Error: Problem opening database', e)
54 folder_name =
'/TRIGGER/L1Calo/V1/Results/HVCorrections'
55 folder=db.getFolder(folder_name)
57 startUtime = int(time.time())
58 endUtime = int(time.time())
61 chsel = cool.ChannelSelection(0,sys.maxint)
64 itr=folder.browseObjects(startValKey, endValKey, chsel)
65 except Exception
as e:
71 Affected_cells = 4*[0]
73 CoolId = hex(int(row.channelId()))
74 payload = row.payload()
76 HV_corrections[0] = payload[
'LayerMean1']
77 HV_corrections[1] = payload[
'LayerMean2']
78 HV_corrections[2] = payload[
'LayerMean3']
79 HV_corrections[3] = payload[
'LayerMean4']
81 Affected_cells[0] = struct.unpack(
'B',payload[
'AffectedCells1'])[0]
82 Affected_cells[1] = struct.unpack(
'B',payload[
'AffectedCells2'])[0]
83 Affected_cells[2] = struct.unpack(
'B',payload[
'AffectedCells3'])[0]
84 Affected_cells[3] = struct.unpack(
'B',payload[
'AffectedCells4'])[0]
102 print (
" Reading HV geometry from file", ref_file_name)
104 dbSvc = cool.DatabaseSvcFactory.databaseService()
106 dbString=
'sqlite://;schema='+ref_file_name+
';dbname=L1CALO'
108 db = dbSvc.openDatabase(dbString,
False)
109 except Exception
as e:
110 print (
'Error: Problem opening database', e)
113 folder_name =
'/TRIGGER/L1Calo/V1/Results/RxLayers'
114 folder=db.getFolder(folder_name)
116 startUtime = int(time.time())
117 endUtime = int(time.time())
118 startValKey = startUtime * self.
UNIX2COOL
120 chsel = cool.ChannelSelection(0,sys.maxint)
123 itr=folder.browseObjects(startValKey, endValKey, chsel)
124 except Exception
as e:
132 CoolId = hex(int(row.channelId()))
133 payload = row.payload()
135 self.
NLayers[CoolId] = struct.unpack(
'B',payload[
'NLayers'])[0]
137 HV_layer_names[0] = struct.unpack(
'B',payload[
'Name1'])[0]
138 HV_layer_names[1] = struct.unpack(
'B',payload[
'Name2'])[0]
139 HV_layer_names[2] = struct.unpack(
'B',payload[
'Name3'])[0]
140 HV_layer_names[3] = struct.unpack(
'B',payload[
'Name4'])[0]
142 HV_Ncells[0] = struct.unpack(
'B',payload[
'NCells1'])[0]
143 HV_Ncells[1] = struct.unpack(
'B',payload[
'NCells2'])[0]
144 HV_Ncells[2] = struct.unpack(
'B',payload[
'NCells3'])[0]
145 HV_Ncells[3] = struct.unpack(
'B',payload[
'NCells4'])[0]
148 self.
NCells[CoolId] = HV_Ncells
193 print (
" Writing geometry to file " , new_file_name)
195 dbSvc = cool.DatabaseSvcFactory.databaseService()
196 connectString =
'sqlite://;schema='+new_file_name+
';dbname=L1CALO'
199 print (
'Writing into database file',new_file_name)
200 db = dbSvc.openDatabase(connectString,
False)
202 spec = cool.RecordSpecification()
203 spec.extend(
'NLayers',cool.StorageType.UChar)
205 spec.extend(
'Name1', cool.StorageType.UChar)
206 spec.extend(
'Name2', cool.StorageType.UChar)
207 spec.extend(
'Name3', cool.StorageType.UChar)
208 spec.extend(
'Name4', cool.StorageType.UChar)
210 spec.extend(
'NCells1',cool.StorageType.UChar)
211 spec.extend(
'NCells2',cool.StorageType.UChar)
212 spec.extend(
'NCells3',cool.StorageType.UChar)
213 spec.extend(
'NCells4',cool.StorageType.UChar)
215 now = int(time.time())
218 until = cool.ValidityKeyMax
220 folder_description =
"<timeStamp>time</timeStamp><addrHeader><address_header service_type=\"71\" clid=\"1238547719\"/></addrHeader><typeName>CondAttrListCollection</typeName>"
221 f = db.createFolder(
"/TRIGGER/L1Calo/V1/Results/RxLayers" , spec,folder_description)
225 data = cool.Record( spec )
227 data[
'NLayers'] = struct.pack(
'B',self.
NLayers[i])
228 data[
'Name1'] = struct.pack(
'B',self.
LayerName[i][0])
229 data[
'Name2'] = struct.pack(
'B',self.
LayerName[i][1])
230 data[
'Name3'] = struct.pack(
'B',self.
LayerName[i][2])
231 data[
'Name4'] = struct.pack(
'B',self.
LayerName[i][3])
233 data[
'NCells1'] = struct.pack(
'B',self.
NCells[i][0])
234 data[
'NCells2'] = struct.pack(
'B',self.
NCells[i][1])
235 data[
'NCells3'] = struct.pack(
'B',self.
NCells[i][2])
236 data[
'NCells4'] = struct.pack(
'B',self.
NCells[i][3])
238 f.storeObject(since,until, data, int(i,16) )
247 print (
" Writing output to file " , new_file_name)
249 dbSvc = cool.DatabaseSvcFactory.databaseService()
250 connectString =
'sqlite://;schema='+new_file_name+
';dbname=L1CALO'
252 print (
'recreating database file',new_file_name)
253 dbSvc.dropDatabase( connectString )
254 db = dbSvc.createDatabase( connectString )
256 spec = cool.RecordSpecification()
257 spec.extend(
'RxMean',cool.StorageType.Float)
259 spec.extend(
'AffectedCells1', cool.StorageType.UChar)
260 spec.extend(
'AffectedCells2', cool.StorageType.UChar)
261 spec.extend(
'AffectedCells3', cool.StorageType.UChar)
262 spec.extend(
'AffectedCells4', cool.StorageType.UChar)
264 spec.extend(
'LayerMean1',cool.StorageType.Float)
265 spec.extend(
'LayerMean2',cool.StorageType.Float)
266 spec.extend(
'LayerMean3',cool.StorageType.Float)
267 spec.extend(
'LayerMean4',cool.StorageType.Float)
269 now = int(time.time())
272 until = cool.ValidityKeyMax
273 db.createFolderSet(
'/TRIGGER')
274 db.createFolderSet(
'/TRIGGER/L1Calo')
275 db.createFolderSet(
'/TRIGGER/L1Calo/V1')
276 db.createFolderSet(
'/TRIGGER/L1Calo/V1/Results')
279 folder_description =
"<timeStamp>time</timeStamp><addrHeader><address_header service_type=\"71\" clid=\"1238547719\"/></addrHeader><typeName>CondAttrListCollection</typeName>"
280 f = db.createFolder(
"/TRIGGER/L1Calo/V1/Results/HVCorrections" , spec,folder_description)
285 data = cool.Record( spec )
290 for ilayer
in range(4):
291 if self.
NCells[i][ilayer]>0:
293 TotalNrCells += self.
NCells[i][ilayer]
295 MeanHV /= TotalNrCells
298 data[
'RxMean'] = MeanHV
310 f.storeObject(since,until, data, int(i,16) )