9 from PyCool
import cool
10 from optparse
import OptionParser
16 self.
coolIdPath=ROOT.PathResolver.find_calib_file(
"TrigT1Calo/COOLIdDump_v1.txt")
21 for line
in input.readlines():
22 parts = line.split(
' ')
23 emCool = parts[4].rstrip()
24 hadCool = parts[5].rstrip()
36 dbSvc = cool.DatabaseSvcFactory.databaseService()
38 dbString =
'oracle://ATLAS_COOLPROD;schema=ATLAS_COOLONL_TRIGGER;dbname=CONDBR2'
40 db = dbSvc.openDatabase(dbString,
False)
41 except Exception
as e:
42 print (
'Error: Problem opening database', e)
45 folder_name =
"/TRIGGER/Receivers/RxPpmIdMap"
46 folder=db.getFolder(folder_name)
48 startUtime =
int(time.time())
49 endUtime =
int(time.time())
52 chsel = cool.ChannelSelection(0,sys.maxsize)
55 itr=folder.browseObjects(startValKey, endValKey, chsel)
56 except Exception
as e:
61 ReceiverId = hex(
int(row.channelId()))
62 payload = row.payload()
63 PPMId = hex(
int(payload[
'ppmid']))
82 if strategy_string
is None:
83 print (
" Warning! in getReceiverfromPPM no runtype give, using default!")
84 return ReceiverChannels[0]
88 if strategy_string ==
"GainOneOvEmbFcalHighEta":
89 for channel
in ReceiverChannels:
92 if strategy_string ==
"GainOneOvEmecFcalLowEta":
93 for channel
in ReceiverChannels:
99 if strategy_string ==
"GainOneOvEmbFcalHighEta":
100 for channel
in ReceiverChannels:
103 if strategy_string ==
"GainOneOvEmecFcalLowEta":
104 for channel
in ReceiverChannels:
109 return ReceiverChannels[0]
139 return int(channel[0][0])
142 return int(channel[0][0])
149 return int(channel[0][1])
152 return int(channel[0][1])
159 return missing_channels
164 recI=
int(ReceiverId,16)
167 recI = recI - crate*1024
170 recI = recI - module*64
173 recI = recI - conn*16
177 return [crate,module,conn,pair]
183 if eta_bin >= 32
or eta_bin <= -36:
192 if self.
isCoolEm(CoolId)
is True and (eta_bin == 14
or eta_bin == -15):
207 elif cabling[2] == 0:
209 elif cabling[2] == 2:
212 print (
"Error in GetOverlapLayer, can't determine layer!")
223 RecCoolInt =
int(RecCoolId,16)
224 if RecCoolInt%2 == 1:
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) )
306 dbSvc = cool.DatabaseSvcFactory.databaseService()
308 dbString=
'sqlite://;schema='+name+
';dbname=L1CALO'
310 db = dbSvc.openDatabase(dbString,
False)
311 except Exception
as e:
312 print (
'Error: Problem opening database', e)
315 folder_name =
'/TRIGGER/L1Calo/V1/Results/EnergyScanResults'
316 folder=db.getFolder(folder_name)
318 startUtime =
int(time.time())
319 endUtime =
int(time.time())
320 startValKey = startUtime * self.
UNIX2COOL
322 chsel = cool.ChannelSelection(0,sys.maxsize)
325 itr=folder.browseObjects(startValKey, endValKey, chsel)
326 except Exception
as e:
331 CoolId = hex(
int(row.channelId()))
332 payload = row.payload()
340 folder_gen_name =
'/TRIGGER/L1Calo/V1/Results/EnergyScanRunInfo'
341 folder_gen=db.getFolder(folder_gen_name)
344 itr=folder_gen.browseObjects(startValKey, endValKey, chsel)
345 except Exception
as e:
350 payload = row.payload()
351 self.
run_nr = payload[
'RunNumber']
352 self.
strategy = payload[
'GainStrategy']
375 print (
"GainsFromSqlite::getGoodGains have rejected channel ", i)
387 dbSvc = cool.DatabaseSvcFactory.databaseService()
389 dbString =
'oracle://ATLAS_COOLPROD;schema=ATLAS_COOLONL_TRIGGER;dbname=CONDBR2'
391 db = dbSvc.openDatabase(dbString,
False)
392 except Exception
as e:
393 print (
'Error: Problem opening database', e)
396 folder_name =
"/TRIGGER/Receivers/Factors/CalibGains"
397 folder=db.getFolder(folder_name)
399 startUtime =
int(time.time())
400 endUtime =
int(time.time())
401 startValKey = startUtime * self.
UNIX2COOL
403 chsel = cool.ChannelSelection(0,sys.maxsize)
406 itr=folder.browseObjects(startValKey, endValKey, chsel)
407 except Exception
as e:
412 ReceiverId = hex(
int(row.channelId()))
413 payload = row.payload()
414 gain = payload[
'factor']
421 def 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" )
533 if __name__ ==
"__main__":
535 print (
"Starting mergeEnergyRamps")
537 parser = OptionParser()
539 parser.add_option(
"-1",
"--FirstFile" ,action=
"store",type=
"string",dest=
"input_file1",help=
"Name of input file")
540 parser.add_option(
"-2",
"--SecondFile" ,action=
"store",type=
"string",dest=
"input_file2",help=
"Name of input file")
541 parser.add_option(
"-3",
"--ThirdFile" ,action=
"store",type=
"string",dest=
"input_file3",help=
"Name of input file")
542 parser.add_option(
"-f",
"--ForcedChannels",action=
"store",type=
"string",dest=
"forced_file",help=
"Name of input file")
543 parser.add_option(
"-o",
"--OutputFile" ,action=
"store",type=
"string",dest=
"output_file",help=
"Name of input file")
544 parser.add_option(
"-A",
"--WriteAllChannels",action=
"store_true",dest=
"writeAllChannels",help=
"Writes all channels to .sqlite file")
546 (options, args) = parser.parse_args()
549 geometry_convertor.LoadReceiverPPMMap()
551 print (
"Processing inputs")
553 if options.input_file1
is not None:
558 if options.input_file2
is not None:
563 if options.input_file3
is not None:
568 print (
"Reading reference")
571 print (
"Merging gains")
572 if options.writeAllChannels:
573 print (
"Will write out gains for all channels")
575 print (
"Will write out gains only for updated channels" )
577 gains_to_load =
merge_gains(gains_1,gains_2,gains_3,gains_reference,options.forced_file,geometry_convertor,options.writeAllChannels)
579 if options.output_file
is not None:
580 output_file_name = options.output_file
582 output_file_name =
"MergedGains.sqlite"
584 print (
"Writing output file ",output_file_name ,
" this may take some time ... :-( " )