4 from AthenaConfiguration.ComponentAccumulator
import ComponentAccumulator
5 from AthenaConfiguration.ComponentFactory
import CompFactory
6 from IOVDbSvc.IOVDbSvcConfig
import addFolders
9 return "sqlite://;schema="+sqlitefile+
";dbname=CONDBR2"
11 def mergeDBCfg(flags, InputKeys=[], InputSQLiteFiles=[]):
14 print(
"mergeDBCfg",len(InputSQLiteFiles),
" SQLite files: ",InputSQLiteFiles)
15 print(len(InputKeys),
" InputKeys: ",InputKeys)
18 if not flags.LArCalib.isSC: GroupingType =
"ExtendedSubDetector"
19 else: GroupingType =
"SuperCells"
21 if ( flags.LArCalib.Output.POOLFile ):
22 if os.path.exists(flags.LArCalib.Output.POOLFile):
23 os.remove(flags.LArCalib.Output.POOLFile)
27 print(
"Working for: ",key)
31 if 'Pedestal' == key
or 'PhysWave' == key
or 'MphysOverMcal' == key
or 'Ramp' == key
or 'Params' in key:
33 if 'Pedestal' == key
or 'PhysWave' == key
or 'CaliWave' or 'MphysOverMcal' == key
or 'Ramp' == key
or 'Params' in key:
38 KeyInput=
'LArAutoCorr'
47 ofcphyskeytmp = key.split(
"OFCPhys")[1]
48 if 'Mu' in ofcphyskeytmp:
49 ofcphyskey=ofcphyskeytmp.replace(
"Mu",
"")
51 ofcphyskey=ofcphyskeytmp
56 shapekey = key.split(
"Shape")[1]
62 if [i
for i
in flags._flagdict.keys()
if FlagInput
in i]:
64 Folder = flags._get(
'LArCalib.'+FlagInput+
'.Folder')
65 except Exception
as e:
67 print(flags._flagdict)
70 print(
'No folder in flags for '+FlagInput)
71 print(flags._flagdict.keys())
74 if shapekey
is not None:
75 if Folder.endswith(
"/"):
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(
"/"):
87 Folder+=
"/"+ofcphyskey
89 if "OFCPhys" in FlagInput:
90 print(
"Folder: ",Folder)
92 from PyCool
import cool
93 dbSvc=cool.DatabaseSvcFactory.databaseService()
96 db=dbSvc.openDatabase(db_string)
97 except Exception
as e:
98 print (
'Problem opening database',e)
101 cool_folder=db.getFolder(Folder)
102 tags = [ x
for x
in cool_folder.listTags() ]
104 TagSpec =
str(tags[0])
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]
109 TagSpec = [
str(tag)
for tag
in tags
if "-mu-" not in str(tag)][0]
111 from LArCalibProcessing.utils
import FolderTagResolver
as FolderTagResover
112 FolderTagResover._globalTag=flags.IOVDb.GlobalTag
116 FolderTag = rs.getFolderTagSuffix(Folder)
119 from LArCalibProcessing.LArCalibConfigFlags
import LArCalibFolderTag
123 if 'Wave' in KeyInput:
124 OutputObjectSpec = KeyInput+
"Container#"+KeyOutput+
"#"+Folder
126 OutputObjectSpec = KeyInput+
"Complete#"+KeyOutput+
"#"+Folder
127 OutputObjectSpecTag = TagSpec
129 print(
"**",KeyInput,FlagInput,
"folder **",Folder)
130 print(
"** TagSpec: ",TagSpec)
131 print(
"** keyOutput: ",KeyOutput)
137 for sqf
in InputSQLiteFiles:
138 thiskey = KeyInput+
str(InputSQLiteFiles.index(sqf))
140 if 'PhysAutoCorr' in key: thiskey=
'Phys'+thiskey
142 if 'OFC' in key
and 'Mu' in key:
144 if 'OFC' in key
and 'Cali' in key:
147 inkeys.append(thiskey)
148 if 'Wave' in KeyInput:
149 inobjs.append(KeyInput+
"Container#"+thiskey)
151 inobjs.append(KeyInput+
"Complete#"+thiskey)
153 if 'Wave' in KeyInput
or 'Params' in KeyInput:
154 result.merge(
addFolders(flags,Folder,tag=TagSpec,detDb=sqf,modifiers=
"<key>"+thiskey+
"</key>"))
156 result.merge(
addFolders(flags,Folder,tag=TagSpec,detDb=sqf,modifiers=
"<key>"+thiskey+
"</key>", className=KeyInput+
"Complete"))
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))
170 result.addCondAlgo(CompFactory.getComp(
'LArConditionsMergerAlg<'+KeyInput+
'Complete, LArPhysWaveContainer>')(key+
"Merger",
171 GroupingType = GroupingType, WriteKey = KeyOutput, ReadKeys = inkeys))
173 if ( flags.LArCalib.Output.POOLFile ):
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))
181 result.addService(CompFactory.IOVRegistrationSvc(RecreateFolders =
True))
184 from McEventSelector.McEventSelectorConfig
import McEventSelectorCfg
186 RunNumber = flags.LArCalib.Input.RunNumbers[0],
189 InitialTimeStamp = 0,
190 TimeStampInterval = 1))
192 result.printConfig(withDetails=
True, printDefaults=
True)
196 if __name__==
"__main__":
200 return arg.split(
',')
203 parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
204 parser.add_argument(
'-r',
'--run', dest=
'run', default=
str(0x7FFFFFFF), help=
'Run number to query input DB', type=str)
205 parser.add_argument(
'-i',
'--insqlite', dest=
'insql', default=
"", help=
'List of input sqlite files, comma separated, if empty all *.db files in current dir.', type=list_of_strings)
206 parser.add_argument(
'-k',
'--inkeys', dest=
'inkeys', default=[
"LArPedestal"], help=
'List of input keys to process', type=list_of_strings)
207 parser.add_argument(
'-o',
'--outsqlite', dest=
'outsql', default=
"freshConstants_merged.db", help=
'Output sqlite file', type=str)
208 parser.add_argument(
'-p',
'--poolfile', dest=
'poolfile', default=
"freshConstants_pp.pool.root", help=
'Output pool file', type=str)
209 parser.add_argument(
'-d',
'--dbname', dest=
'dbname', default=
"COOLOFL_LAR/CONDBR2", help=
'DB to query for tags', type=str)
210 parser.add_argument(
'--iovstart',dest=
"iovstart", default=0, help=
"IOV start (run-number)", type=int)
211 parser.add_argument(
'--isSC', dest=
'supercells', default=
False, help=
'is SC data ?', action=
'store_true')
212 parser.add_argument(
'-c',
'--poolcat', dest=
'poolcat', default=
"freshConstants.xml", help=
'Catalog of POOL files', type=str)
213 parser.add_argument(
'--Ncoll',dest=
'Ncoll', default=60, help=
'Number of MinBias collision assumed for OFCs folder', type=int)
214 args = parser.parse_args()
215 if help
in args
and args.help
is not None and args.help:
219 if len(args.insql)==0:
220 InputSQLiteFiles = [ db
for db
in os.listdir(
".")
if db.endswith(
".db") ]
222 InputSQLiteFiles = args.insql
224 if len(InputSQLiteFiles) == 1:
226 shutil.copyfile(InputSQLiteFiles[0],args.outsql)
229 from AthenaConfiguration.AllConfigFlags
import initConfigFlags
230 from LArCalibProcessing.LArCalibConfigFlags
import addLArCalibFlags
235 flags.LArCalib.Input.RunNumbers = [
int(args.run),]
236 flags.LArCalib.Input.Database = args.insql
237 flags.LArCalib.Input.Database2 = args.dbname
239 flags.LArCalib.Output.POOLFile = args.poolfile
244 flags.IOVDb.GlobalTag =
"LARCALIB-RUN2-00"
247 flags.LArCalib.Input.Files = [ ]
248 flags.LArCalib.OFC.Ncoll = args.Ncoll
249 flags.LArCalib.IOVStart = args.iovstart
251 flags.LAr.doAlign=
False
252 flags.Input.RunNumbers=flags.LArCalib.Input.RunNumbers
254 from AthenaConfiguration.TestDefaults
import defaultGeometryTags
255 flags.GeoModel.AtlasVersion=defaultGeometryTags.RUN3
257 flags.Debug.DumpDetStore=
True
258 flags.Debug.DumpCondStore=
True
263 from AthenaConfiguration.MainServicesConfig
import MainServicesCfg
265 from LArGeoAlgsNV.LArGMConfig
import LArGMCfg
269 from AthenaPoolCnvSvc.PoolCommonConfig
import PoolSvcCfg
272 cfg.merge(
mergeDBCfg(flags,args.inkeys, InputSQLiteFiles))
274 cfg.getService(
"PoolSvc").ReadCatalog+=[
"xmlcatalog_file:%s"%args.poolcat,]
275 cfg.getService(
"PoolSvc").WriteCatalog=
"xmlcatalog_file:%s"%args.poolcat
276 cfg.getService(
"IOVDbSvc").DBInstance=
""
278 cfg.printConfig(withDetails=
True, summariseProps=
True, printDefaults=
True)