11def mergeDBCfg(flags, InputKeys=[], InputSQLiteFiles=[]):
12 result=ComponentAccumulator()
13
14 print(
"mergeDBCfg",len(InputSQLiteFiles),
" SQLite files: ",InputSQLiteFiles)
15 print(len(InputKeys),
" InputKeys: ",InputKeys)
16
17
18 if not flags.LArCalib.isSC: GroupingType = "ExtendedSubDetector"
19 else: GroupingType = "SuperCells"
20
21 if ( flags.LArCalib.Output.POOLFile ):
22 if os.path.exists(flags.LArCalib.Output.POOLFile):
23 os.remove(flags.LArCalib.Output.POOLFile)
24
25 for key in InputKeys:
26
27 print(
"Working for: ",key)
28 KeyOutput = key
29 FlagInput = key
30
31 if 'Pedestal' == key or 'PhysWave' == key or 'MphysOverMcal' == key or 'Ramp' == key or 'Params' in key:
32 KeyInput="LAr"+key
33 if 'Pedestal' == key or 'PhysWave' == key or 'CaliWave' or 'MphysOverMcal' == key or 'Ramp' == key or 'Params' in key:
34 KeyInput="LAr"+key
35 KeyOutput="LAr"+key
36
37 if 'AutoCorr' in key:
38 KeyInput='LArAutoCorr'
39
40 ofcphyskey=None
41 if "OFC" in key:
42 KeyInput = "LArOFC"
43 if "Cali" in key:
44 FlagInput = "OFCCali"
45
46 if "Phys" in key:
47 ofcphyskeytmp = key.split("OFCPhys")[1]
48 if 'Mu' in ofcphyskeytmp:
49 ofcphyskey=ofcphyskeytmp.replace("Mu","")
50 else:
51 ofcphyskey=ofcphyskeytmp
52 FlagInput = "OFCPhys"
53
54 shapekey=None
55 if "Shape" in key:
56 shapekey = key.split("Shape")[1]
57 FlagInput = "Shape"
58 KeyInput = "LArShape"
59
60
61
62 if [i for i in flags._flagdict.keys() if FlagInput in i]:
63 try:
64 Folder = flags._get('LArCalib.'+FlagInput+'.Folder')
65 except Exception as e:
67 print(flags._flagdict)
68 sys.exit(-1)
69 else:
70 print(
'No folder in flags for '+FlagInput)
71 print(flags._flagdict.keys())
72 sys.exit(-2)
73
74 if shapekey is not None:
75 if Folder.endswith("/"):
76 Folder+=shapekey
77 else:
78 Folder+="/"+shapekey
79
80 if ofcphyskey is not None and ofcphyskey != "":
81 print(
"Folder: ",Folder,
" ofcphyskey: ",ofcphyskey)
82 if "4samples" in Folder:
83 Folder = Folder.replace("4samples", ofcphyskey)
84 elif Folder.endswith("/"):
85 Folder+=ofcphyskey
86 else:
87 Folder+="/"+ofcphyskey
88
89 if "OFCPhys" in FlagInput:
90 print(
"Folder: ",Folder)
91
92 from PyCool import cool
93 dbSvc=cool.DatabaseSvcFactory.databaseService()
94 db_string=DBConnectionFile(InputSQLiteFiles[0])
95 try:
96 db=dbSvc.openDatabase(db_string)
97 except Exception as e:
98 print ('Problem opening database',e)
100 sys.exit(-3)
101 cool_folder=db.getFolder(Folder)
102 tags = [ x for x in cool_folder.listTags() ]
103 if len(tags) == 1:
104 TagSpec = str(tags[0])
105 else:
106 if flags.LArCalib.OFC.Ncoll > 0 or 'Mu' in key:
107 TagSpec = [ str(tag) for tag in tags if "-mu-" in str(tag)][0]
108 else:
109 TagSpec = [ str(tag) for tag in tags if "-mu-" not in str(tag)][0]
110 else:
111 from LArCalibProcessing.utils import FolderTagResolver as FolderTagResover
112 FolderTagResover._globalTag=flags.IOVDb.GlobalTag
113
114
115 rs=FolderTagResover(DBConnectionFile(InputSQLiteFiles[0]))
116 FolderTag = rs.getFolderTagSuffix(Folder)
117 del rs
118
119 from LArCalibProcessing.LArCalibConfigFlags import LArCalibFolderTag
120 TagSpec = LArCalibFolderTag(Folder,FolderTag)
121
122
123 if 'Wave' in KeyInput:
124 OutputObjectSpec = KeyInput+"Container#"+KeyOutput+"#"+Folder
125 else:
126 OutputObjectSpec = KeyInput+"Complete#"+KeyOutput+"#"+Folder
127 OutputObjectSpecTag = TagSpec
128
129 print(
"**",KeyInput,FlagInput,
"folder **",Folder)
130 print(
"** TagSpec: ",TagSpec)
131 print(
"** keyOutput: ",KeyOutput)
132
133
134 inkeys=[]
135 inobjs=[]
136
137 for sqf in InputSQLiteFiles:
138 thiskey = KeyInput+str(InputSQLiteFiles.index(sqf))
139
140 if 'PhysAutoCorr' in key: thiskey='Phys'+thiskey
141
142 if 'OFC' in key and 'Mu' in key:
143 thiskey+="Mu"
144 if 'OFC' in key and 'Cali' in key:
145 thiskey+="Cali"
146
147 inkeys.append(thiskey)
148 if 'Wave' in KeyInput:
149 inobjs.append(KeyInput+"Container#"+thiskey)
150 else:
151 inobjs.append(KeyInput+"Complete#"+thiskey)
152
153 if 'Wave' in KeyInput or 'Params' in KeyInput:
154 result.merge(addFolders(flags,Folder,tag=TagSpec,detDb=sqf,modifiers="<key>"+thiskey+"</key>"))
155 else:
156 result.merge(addFolders(flags,Folder,tag=TagSpec,detDb=sqf,modifiers="<key>"+thiskey+"</key>", className=KeyInput+"Complete"))
157 pass
158
159 pass
160
161 if 'Wave' in KeyInput:
162 result.addCondAlgo(CompFactory.getComp('ForceLoadCondObj')(KeyOutput,ObjectList=inobjs))
163 result.addCondAlgo(CompFactory.getComp('LArConditionsMergerAlg<LArDAC2uAComplete,'+KeyInput+'Container>')(key+"Merger",
164 GroupingType = GroupingType, WriteKey = KeyOutput, DetStoreReadKeys = inkeys))
165 elif 'Params' in KeyInput:
166 result.addCondAlgo(CompFactory.getComp('ForceLoadCondObj')(KeyOutput,ObjectList=inobjs))
167 result.addCondAlgo(CompFactory.getComp('LArConditionsMergerAlg<LArDAC2uAComplete,'+KeyInput+'Complete>')(key+"Merger",
168 GroupingType = GroupingType, WriteKey = KeyOutput, DetStoreReadKeys = inkeys))
169 else:
170 result.addCondAlgo(CompFactory.getComp('LArConditionsMergerAlg<'+KeyInput+'Complete, LArPhysWaveContainer>')(key+"Merger",
171 GroupingType = GroupingType, WriteKey = KeyOutput, ReadKeys = inkeys))
172
173 if ( flags.LArCalib.Output.POOLFile ):
174
175 from RegistrationServices.OutputConditionsAlgConfig import OutputConditionsAlgCfg
176 result.merge(OutputConditionsAlgCfg(flags,name="OutputConditionsAlg"+KeyInput, outputFile=flags.LArCalib.Output.POOLFile,
177 ObjectList=[OutputObjectSpec], IOVTagList=[OutputObjectSpecTag],
178 Run1 = flags.LArCalib.IOVStart, Run2= flags.LArCalib.IOVEnd, WriteIOV=True))
179 pass
180
181 result.addService(CompFactory.IOVRegistrationSvc(RecreateFolders = False))
182
183
184 from McEventSelector.McEventSelectorConfig import McEventSelectorCfg
185 result.merge(McEventSelectorCfg(flags,
186 RunNumber = flags.LArCalib.Input.RunNumbers[0],
187 EventsPerRun = 1,
188 FirstEvent = 1,
189 InitialTimeStamp = 0,
190 TimeStampInterval = 1))
191
192 result.printConfig(withDetails=True, printDefaults=True)
193 return result
194
195
void print(char *figname, TCanvas *c1)