243 UNIX2COOL = 1000000000
245 dbSvc = cool.DatabaseSvcFactory.databaseService()
246 connectString =
'sqlite://;schema='+name+
';dbname=L1CALO'
250 print (
'\nrecreating database file:',name)
251 dbSvc.dropDatabase( connectString )
252 db = dbSvc.createDatabase( connectString )
254 spec = cool.RecordSpecification()
255 spec.extend(
"factor", cool.StorageType.Float)
256 spec.extend(
"status", cool.StorageType.UInt32 )
257 folderSpec = cool.FolderSpecification(cool.FolderVersioning.SINGLE_VERSION, spec)
259 now = int(time.time())
261 since = now*UNIX2COOL
262 until = cool.ValidityKeyMax
263 db.createFolderSet(
'/TRIGGER')
264 db.createFolderSet(
'/TRIGGER/Receivers')
265 db.createFolderSet(
'/TRIGGER/Receivers/Factors')
267 folder_description =
'<timeStamp>time</timeStamp><addrHeader><address_header service_type="71" clid="1238547719"/></addrHeader><typeName>CondAttrListCollection</typeName>'
268 f = db.createFolder(
"/TRIGGER/Receivers/Factors/CalibGains", folderSpec, folder_description)
270 print (
" Now creating sqlite file for ", len(input_dict.keys()),
" channels")
271 for i
in input_dict.keys():
272 data = cool.Record( spec )
273 data[
'factor'] = input_dict[i][0]
274 data[
'status'] = input_dict[i][1]
275 f.storeObject(since,until, data, int(i,16) )
421def merge_gains(gains1,gains2,gains3,reference_gains,forced_list,geometry_map,writeAllChannels):
426 n_files_LowEta_EMEC = 0
427 n_files_HighEta_EMB = 0
431 if gains3
is not None:
432 good_gains=gains3.getGoodGains()
433 print (
" Using run ", gains3.run_nr,
" run strategy= ", gains3.strategy )
435 if gains3.strategy ==
"GainOne":
436 n_files_Tile = n_files_Tile + 1
437 if gains3.strategy ==
"GainOneOvEmecFcalLowEta":
438 n_files_LowEta_EMEC = n_files_LowEta_EMEC + 1
439 if gains3.strategy ==
"GainOneOvEmbFcalHighEta":
440 n_files_HighEta_EMB = n_files_HighEta_EMB + 1
443 for ppm_channel
in good_gains.keys():
444 gain = good_gains[ppm_channel][0]
445 error_code = good_gains[ppm_channel][1]
446 rec_chan = geometry_map.getReceiverfromPPM(ppm_channel,gains3.strategy)
447 output_gains[rec_chan]=[gain,error_code]
449 print (
"Ignoring File 3, probably not specified" )
453 if gains2
is not None:
454 good_gains=gains2.getGoodGains()
455 print (
" Using run ", gains2.run_nr,
" run strategy= ", gains2.strategy )
457 if gains2.strategy ==
"GainOne":
458 n_files_Tile = n_files_Tile + 1
459 if gains2.strategy ==
"GainOneOvEmecFcalLowEta":
460 n_files_LowEta_EMEC = n_files_LowEta_EMEC + 1
461 if gains2.strategy ==
"GainOneOvEmbFcalHighEta":
462 n_files_HighEta_EMB = n_files_HighEta_EMB + 1
464 for ppm_channel
in good_gains.keys():
465 gain = good_gains[ppm_channel][0]
466 error_code = good_gains[ppm_channel][1]
467 rec_chan = geometry_map.getReceiverfromPPM(ppm_channel,gains2.strategy)
468 output_gains[rec_chan]=[gain,error_code]
470 print (
"Ignoring File 2, probably not specified" )
475 if gains1
is not None:
476 good_gains=gains1.getGoodGains()
477 print (
" Using run ", gains1.run_nr,
" run strategy= ", gains1.strategy )
479 if gains1.strategy ==
"GainOne":
480 n_files_Tile = n_files_Tile + 1
481 if gains1.strategy ==
"GainOneOvEmecFcalLowEta":
482 n_files_LowEta_EMEC = n_files_LowEta_EMEC + 1
483 if gains1.strategy ==
"GainOneOvEmbFcalHighEta":
484 n_files_HighEta_EMB = n_files_HighEta_EMB + 1
486 for ppm_channel
in good_gains.keys():
487 gain = good_gains[ppm_channel][0]
488 error_code = good_gains[ppm_channel][1]
489 rec_chan = geometry_map.getReceiverfromPPM(ppm_channel,gains1.strategy)
490 output_gains[rec_chan]=[gain,error_code]
492 print (
"Ignoring File 1, probably not specified" )
497 if forced_list
is not None:
498 myfile = open(forced_list,
'r')
499 for line
in myfile.readlines():
502 line_cont = line.split(
' ')
503 line_cont = [iii
for iii
in line_cont
if not iii ==
'']
504 rec_chan = line_cont[0]
505 gain = float(line_cont[1])
507 output_gains[rec_chan]=[gain,error_code]
508 print (
"forcing channel ", rec_chan,
" to value ", gain )
510 print (
"Ignoring forced channel list")
516 print (
"Adding gains for missing channels from Oracle" )
517 missing_channels = geometry_convertor.getMissingReceiverChannels(output_gains.keys())
518 default_gains = reference_gains.getGoodGains()
519 for channel
in missing_channels:
520 gain = default_gains[channel]
522 output_gains[channel]=[gain,error_code]
526 if (
not n_files_Tile == 1)
or (
not n_files_LowEta_EMEC == 1)
or (
not n_files_HighEta_EMB == 1):
527 print (
"WARNING! input files do not allow to calibrate all partitions, using defaults where needed" )
577 gains_to_load =
merge_gains(gains_1,gains_2,gains_3,gains_reference,options.forced_file,geometry_convertor,options.writeAllChannels)