ATLAS Offline Software
LuminosityCondAlgConfig.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
2 #
3 # File: LumiBlockComps/python/LuminosityCondAlgConfig.py
4 # Created: May 2019, sss, from existing LuminosityToolDefault.
5 # Purpose: Configure LuminosityCondAlg.
6 #
7 
8 from AthenaConfiguration.ComponentFactory import CompFactory
9 from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
10 from AthenaConfiguration.Enums import BeamType
11 from IOVDbSvc.IOVDbSvcConfig import addFolders
12 from AthenaCommon.Logging import logging
13 from AthenaConfiguration.AccumulatorCache import AccumulatorCache
14 from AthenaConfiguration.Enums import ProductionStep
15 
16 @AccumulatorCache
17 def LuminosityCondAlgCfg (flags, useOnlineLumi=None, suffix=None):
18  # This function, without the useOnlineLumi and suffix arguments, will set up a default configuration
19  # appropriate to the job; the conditions object will be called LuminosityCondData
20  # Can override whether it sets up the online lumi (but then you are strongly urged to use the suffix
21  # argument!)
22  # Suffix will allow you to make an object with a different name, e.g. LuminosityCondDataOnline
23  log = logging.getLogger ('LuminosityCondAlgCfg')
24  name = 'LuminosityCondAlg'
25  result = ComponentAccumulator()
26 
27  if suffix is None: suffix = ''
28  if useOnlineLumi is not None and suffix is None:
29  log.warning('useOnlineLumi argument is provided but not a suffix for the lumi object name. Is this really intended?')
30 
31  if flags.Input.isMC:
32  kwargs = luminosityCondAlgMCCfg (flags, name, result)
33  elif ((useOnlineLumi is None and flags.Common.useOnlineLumi)
34  or (useOnlineLumi is not None and useOnlineLumi)):
35  kwargs = luminosityCondAlgOnlineCfg (flags, name, result)
36  elif flags.IOVDb.DatabaseInstance == 'COMP200':
37  kwargs = luminosityCondAlgRun1Cfg (flags, name, result)
38  elif flags.IOVDb.DatabaseInstance == 'CONDBR2':
39  kwargs = luminosityCondAlgRun2Cfg (flags, name, result)
40 
41  else:
42  log.warning ("LuminosityCondAlgCfg can't resolve database instance = %s, assume Run2!" % flags.IOVDb.DatabaseInstance)
43  kwargs = luminosityCondAlgRun2Cfg (flags, name, result)
44 
45  if flags.Common.ProductionStep is ProductionStep.PileUpPretracking:
46  kwargs.setdefault("EventInfoKey", flags.Overlay.BkgPrefix + "EventInfo")
47  kwargs.setdefault("actualMuKey", flags.Overlay.BkgPrefix + "EventInfo.actualInteractionsPerCrossing")
48  kwargs.setdefault("averageMuKey", flags.Overlay.BkgPrefix + "EventInfo.averageInteractionsPerCrossing")
49 
50  LuminosityCondAlg=CompFactory.LuminosityCondAlg
51 
52  alg = LuminosityCondAlg (name,
53  LuminosityOutputKey = 'LuminosityCondData' + suffix,
54  **kwargs)
55 
56  result.addCondAlgo (alg)
57  return result
58 
59 
60 def luminosityCondAlgMCCfg (flags, name, result):
61  from DigitizationConfig.DigitizationParametersConfig import readDigitizationParameters
62  result.merge(readDigitizationParameters(flags))
63  return { 'LuminosityFolderInputKey' : '',
64  'DigitizationFolderInputKey' : '/Digitization/Parameters',
65  'OnlineLumiCalibrationInputKey' : '',
66  'BunchLumisInputKey' : '',
67  'BunchGroupInputKey' : '',
68  'FillParamsInputKey' : '',
69  'IsMC' : True }
70 
71 
72 # Configuration for offline default luminosity used in Run2
73 def luminosityCondAlgRun2Cfg (flags, name, result):
74  log = logging.getLogger(name)
75 
76  kwargs = {}
77 
78  # Check if this is express stream or bulk
79  if flags.Common.doExpressProcessing:
80  lumiFolder = "/TRIGGER/LUMI/OnlPrefLumi"
81  result.merge (addFolders (flags, lumiFolder, 'TRIGGER_ONL',
82  className = 'CondAttrListCollection'))
83 
84  else:
85  lumiFolder = "/TRIGGER/OFLLUMI/OflPrefLumi"
86  result.merge (addFolders (flags, lumiFolder, 'TRIGGER_OFL',
87  className = 'CondAttrListCollection'))
88 
89  log.info ("luminosityCondAlgRun2Config requested %s", lumiFolder)
90  kwargs['LuminosityFolderInputKey'] = lumiFolder
91 
92  log.info ("Created Run2 %s using folder %s" % (name, lumiFolder))
93 
94  # Need the calibration just to get the proper MuToLumi value
95  from CoolLumiUtilities.OnlineLumiCalibrationCondAlgConfig \
96  import OnlineLumiCalibrationCondAlgCfg
97  result.merge (OnlineLumiCalibrationCondAlgCfg(flags))
98  olalg = result.getCondAlgo ('OnlineLumiCalibrationCondAlg')
99  kwargs['OnlineLumiCalibrationInputKey'] = olalg.LumiCalibOutputKey
100 
101  # Other folder names should be blank.
102  kwargs['BunchLumisInputKey'] = ''
103  kwargs['BunchGroupInputKey'] = ''
104  kwargs['FillParamsInputKey'] = ''
105 
106  # if cosmics, suppress warnings.
107  if flags.Beam.Type is BeamType.Cosmics:
108  kwargs['ExpectInvalid'] = True
109 
110  return kwargs
111 
112 
113 # Configuration for offline default luminosity used in Run1
114 def luminosityCondAlgRun1Cfg (flags, name, result):
115  log = logging.getLogger(name)
116 
117  kwargs = {}
118 
119  # Check if this is express stream or bulk
120  if flags.Common.doExpressProcessing:
121  lumiFolder = "/TRIGGER/LUMI/LBLESTONL"
122  result.merge (addFolders (flags, lumiFolder, 'TRIGGER_ONL',
123  className = 'CondAttrListCollection'))
124 
125  else:
126  lumiFolder = "/TRIGGER/OFLLUMI/LBLESTOFL"
127  result.merge (addFolders (flags, lumiFolder, 'TRIGGER_OFL',
128  className = 'CondAttrListCollection'))
129 
130  log.info ("configureLuminosityCondAlgRun1 requested %s", lumiFolder)
131  kwargs['LuminosityFolderInputKey'] = lumiFolder
132 
133  # Configure input conditions data.
134  from CoolLumiUtilities.FillParamsCondAlgConfig \
135  import FillParamsCondAlgCfg
136  result.merge (FillParamsCondAlgCfg (flags))
137  fpalg = result.getCondAlgo ('FillParamsCondAlg')
138  kwargs['FillParamsInputKey'] = fpalg.FillParamsOutputKey
139 
140  from CoolLumiUtilities.BunchLumisCondAlgConfig \
141  import BunchLumisCondAlgCfg
142  result.merge (BunchLumisCondAlgCfg (flags))
143  blalg = result.getCondAlgo ('BunchLumisCondAlg')
144  kwargs['BunchLumisInputKey'] = blalg.BunchLumisOutputKey
145 
146  from CoolLumiUtilities.BunchGroupCondAlgConfig \
147  import BunchGroupCondAlgCfg
148  result.merge (BunchGroupCondAlgCfg (flags))
149  bgalg = result.getCondAlgo ('BunchGroupCondAlg')
150  kwargs['BunchGroupInputKey'] = bgalg.BunchGroupOutputKey
151 
152  from CoolLumiUtilities.OnlineLumiCalibrationCondAlgConfig \
153  import OnlineLumiCalibrationCondAlgCfg
154  result.merge (OnlineLumiCalibrationCondAlgCfg (flags))
155  olalg = result.getCondAlgo ('OnlineLumiCalibrationCondAlg')
156  kwargs['OnlineLumiCalibrationInputKey'] = olalg.LumiCalibOutputKey
157 
158  return kwargs
159 
160 
161 
162 # Configuration for online luminosity.
163 def luminosityCondAlgOnlineCfg (flags, name, result):
164  log = logging.getLogger(name)
165 
166  kwargs = {}
167 
168  # Keep values for invalid data
169  kwargs['SkipInvalid'] = False
170 
171  if flags.IOVDb.DatabaseInstance == 'COMP200': # Run1
172  folder = "/TRIGGER/LUMI/LBLESTONL"
173  result.merge (addFolders (flags, folder, 'TRIGGER_ONL',
174  className = 'CondAttrListCollection'))
175 
176  else: # Run 2+
177  if flags.IOVDb.DatabaseInstance != 'CONDBR2':
178  log.warning("LuminosityCondAlgOnlineCfg can't resolve DatabaseInstance = %s, assuming CONDBR2!", flags.IOVDb.DatabaseInstance)
179 
180  folder = "/TRIGGER/LUMI/HLTPrefLumi"
181  result.merge (addFolders (flags, folder, 'TRIGGER_ONL',
182  className = 'CondAttrListCollection',
183  extensible = flags.Trigger.doHLT and flags.Trigger.Online.isPartition))
184 
185  kwargs['LuminosityFolderInputKey'] = folder
186  log.info ("Created online %s using folder %s" % (name, folder))
187 
188  # Need the calibration just to get the proper MuToLumi value
189  from CoolLumiUtilities.OnlineLumiCalibrationCondAlgConfig \
190  import OnlineLumiCalibrationCondAlgCfg
191  result.merge (OnlineLumiCalibrationCondAlgCfg(flags))
192  olalg = result.getCondAlgo ('OnlineLumiCalibrationCondAlg')
193  kwargs['OnlineLumiCalibrationInputKey'] = olalg.LumiCalibOutputKey
194 
195  # Other folder names should be blank.
196  kwargs['BunchLumisInputKey'] = ''
197  kwargs['BunchGroupInputKey'] = ''
198  kwargs['FillParamsInputKey'] = ''
199 
200  return kwargs
201 
202 
203 if __name__ == "__main__":
204  from AthenaConfiguration.AllConfigFlags import initConfigFlags
205  from AthenaConfiguration.TestDefaults import defaultTestFiles
206 
207  print ('--- run2')
208  flags1 = initConfigFlags()
209  flags1.Input.Files = defaultTestFiles.RAW_RUN2
210  flags1.lock()
211  acc1 = LuminosityCondAlgCfg (flags1)
212  acc1.printCondAlgs(summariseProps=True)
213  print ('IOVDbSvc:', acc1.getService('IOVDbSvc').Folders)
214  acc1.wasMerged()
215 
216  print ('--- run2/express')
217  flags2 = initConfigFlags()
218  flags2.Input.Files = defaultTestFiles.RAW_RUN2
219  flags2.Common.doExpressProcessing = True
220  flags2.lock()
221  acc2 = LuminosityCondAlgCfg (flags2)
222  acc2.printCondAlgs(summariseProps=True)
223  print ('IOVDbSvc:', acc2.getService('IOVDbSvc').Folders)
224  acc2.wasMerged()
225 
226  print ('--- run1')
227  flags3 = initConfigFlags()
228  flags3.Input.Files = defaultTestFiles.RAW_RUN2
229  flags3.Input.ProjectName = 'data12_8TeV'
230  flags3.lock()
231  acc3 = LuminosityCondAlgCfg (flags3)
232  acc3.printCondAlgs(summariseProps=True)
233  print ('IOVDbSvc:', acc3.getService('IOVDbSvc').Folders)
234  acc3.wasMerged()
235 
236  print ('--- run1/express')
237  flags4 = initConfigFlags()
238  flags4.Input.Files = defaultTestFiles.RAW_RUN2
239  flags4.Input.ProjectName = 'data12_8TeV'
240  flags4.Common.doExpressProcessing = True
241  flags4.lock()
242  acc4 = LuminosityCondAlgCfg (flags4)
243  acc4.printCondAlgs(summariseProps=True)
244  print ('IOVDbSvc:', acc4.getService('IOVDbSvc').Folders)
245  acc4.wasMerged()
246 
247  print ('--- mc')
248  flags5 = initConfigFlags()
249  flags5.Input.Files = defaultTestFiles.ESD
250  flags5.lock()
251  acc5 = LuminosityCondAlgCfg (flags5)
252  acc5.printCondAlgs(summariseProps=True)
253  acc5.wasMerged()
254 
255  print ('--- online')
256  flags6 = initConfigFlags()
257  flags6.Input.Files = defaultTestFiles.RAW_RUN2
258  flags6.Common.useOnlineLumi = True
259  flags6.lock()
260  acc6 = LuminosityCondAlgCfg (flags6)
261  acc6.printCondAlgs(summariseProps=True)
262  acc6.wasMerged()
263 
264  print ('--- forced online')
265  flags7 = initConfigFlags()
266  flags7.Input.Files = defaultTestFiles.RAW_RUN2
267  flags7.lock()
268  acc7 = LuminosityCondAlgCfg (flags7, useOnlineLumi=True, suffix='Online')
269  acc7.printCondAlgs(summariseProps=True)
270  acc7.wasMerged()
python.DigitizationParametersConfig.readDigitizationParameters
def readDigitizationParameters(flags)
Definition: DigitizationParametersConfig.py:85
python.LuminosityCondAlgConfig.luminosityCondAlgMCCfg
def luminosityCondAlgMCCfg(flags, name, result)
Definition: LuminosityCondAlgConfig.py:60
python.LuminosityCondAlgConfig.LuminosityCondAlgCfg
def LuminosityCondAlgCfg(flags, useOnlineLumi=None, suffix=None)
Definition: LuminosityCondAlgConfig.py:17
python.JetAnalysisCommon.ComponentAccumulator
ComponentAccumulator
Definition: JetAnalysisCommon.py:302
python.LuminosityCondAlgConfig.luminosityCondAlgOnlineCfg
def luminosityCondAlgOnlineCfg(flags, name, result)
Definition: LuminosityCondAlgConfig.py:163
python.OnlineLumiCalibrationCondAlgConfig.OnlineLumiCalibrationCondAlgCfg
def OnlineLumiCalibrationCondAlgCfg(flags)
Definition: OnlineLumiCalibrationCondAlgConfig.py:13
python.LuminosityCondAlgConfig.luminosityCondAlgRun1Cfg
def luminosityCondAlgRun1Cfg(flags, name, result)
Definition: LuminosityCondAlgConfig.py:114
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
python.LuminosityCondAlgConfig.luminosityCondAlgRun2Cfg
def luminosityCondAlgRun2Cfg(flags, name, result)
Definition: LuminosityCondAlgConfig.py:73