5 '''@file RunTileMonitoring.py
6 @brief Script to run Tile Reconstrcution/Monitoring with new-style configuration
9 from AthenaConfiguration.ComponentFactory
import CompFactory
10 from AthenaConfiguration.Enums
import BeamType, Format, LHCPeriod
11 from TileConfiguration.TileConfigFlags
import TileRunType
15 Configure the following flags from partition in online: run number, beam type, and project
18 from ipc
import IPCPartition
19 from ispy
import ISObject
20 ipcPartition = IPCPartition(partition)
21 if not ipcPartition.isValid():
22 log.error(
'Partition: ' + ipcPartition.name() +
' is not valid' )
25 runParams = ISObject(ipcPartition,
'RunParams.SOR_RunParams',
'RunParams')
29 projectName =
'data20_calib'
30 log.warning(
"No Run Parameters in IS => Set defaults: partition: %s, beam type: %i, run number: %i, project tag: %s",
31 partition, beamType, runNumber, projectName)
34 beamType = runParams.beam_type
35 beamEnergy = runParams.beam_energy
36 runNumber = runParams.run_number
37 projectName = runParams.T0_project_tag
38 runType = runParams.run_type
39 log.info(
"RUN CONFIG: partition: %s, run type: %s, beam type: %i, beam energy: %i, run number: %i, project tag: %s",
40 partition, runType, beamType, beamEnergy, runNumber, projectName)
42 if any([projectName.endswith(_)
for _
in (
"cos",
"test",
"calib")]):
44 elif projectName.endswith(
'1beam'):
45 beamType =
'singlebeam'
47 beamType =
'collisions'
51 if partition ==
'Tile':
52 flags.Tile.NoiseFilter = 0
54 flags.Tile.RunType = TileRunType.MONOCIS
if 'mono' in runType
else TileRunType.CIS
55 elif 'Laser' in runType:
56 flags.Tile.RunType = TileRunType.LAS
57 elif 'Pedestals' in runType:
58 flags.Tile.RunType = TileRunType.PED
61 flags.Input.ProjectName = projectName
62 flags.Input.RunNumbers = [runNumber]
65 if __name__==
'__main__':
69 group = parser.add_mutually_exclusive_group()
70 destination = dest
if dest
else argument
71 group.add_argument(
'--' + argument, dest=destination, action=
'store_true', help=
"Switch on " + help)
72 group.add_argument(
'--no-' + argument, dest=destination, action=
'store_false', help=
"Switch off " + help)
74 from AthenaConfiguration.AllConfigFlags
import initConfigFlags
76 parser = flags.getArgumentParser()
77 parser.add_argument(
'--preExec', help=
'Code to execute before locking configs')
78 parser.add_argument(
'--postExec', help=
'Code to execute after setup')
79 parser.add_argument(
'--printDetailedConfig', action=
'store_true', help=
'Print detailed Athena configuration')
80 parser.add_argument(
'--dumpArguments', action=
'store_true', help=
'Print arguments and exit')
86 _addBoolArgument(parser,
'towers', help=
'Tile Calorimeter Towers monitoring')
87 _addBoolArgument(parser,
'clusters', help=
'Tile Calorimeter Clusters monitoring')
89 _addBoolArgument(parser,
'muonfit', help=
'Tile Calorimeter MuonFit monitoring')
92 _addBoolArgument(parser,
'digi-noise',dest=
'digiNoise', help=
'Tile digi noise monitoring')
93 _addBoolArgument(parser,
'raw-chan-noise',dest=
'rawChanNoise', help=
'Tile raw channel noise monitoring')
95 _addBoolArgument(parser,
'tmdb-digits', dest=
'tmdbDigits', help=
'TMDB digits monitoring')
96 _addBoolArgument(parser,
'tmdb-raw-channels', dest=
'tmdbRawChannels', help=
'TMDB raw channels monitoring')
99 parser.add_argument(
'--no-mon', action=
'store_false', dest=
'mon', help=
'Do not run Tile monitoring algorithms')
100 parser.add_argument(
'--cosmics', action=
'store_true', help=
'Use cosmics streams for online Tile monitoring')
101 parser.add_argument(
'--jivexml', action=
'store_true', help=
'Create Jive XML output')
102 parser.add_argument(
'--stateless', action=
"store_true", help=
'Run Online Tile monitoring in partition')
103 parser.add_argument(
'--use-mbts-trigger', action=
"store_true", dest=
'useMbtsTrigger', help=
'Use L1 MBTS triggers')
104 parser.add_argument(
'--partition', default=
"", help=
'EMON, Partition name, default taken from $TDAQ_PARTITION if not set')
105 parser.add_argument(
'--key', type=str, default=
"",
106 help=
'EMON, Selection key, e.g.: SFI, default: dcm (ATLAS), CompleteEvent (TileMon), ReadoutApplication (Tile)')
107 parser.add_argument(
'--keyValue', default=[],
108 help=
'EMON, Key values, e.g. [SFI-1, SFI-2]; if empty all SFIs; default: "" (*), TileREB-ROS (Tile)')
109 parser.add_argument(
'--keyCount', type=int, default=50,
110 help=
'EMON, key count, e.g. 5 to get five random SFIs, default: 50 (physics), 1000 (laser:CIS)')
111 parser.add_argument(
'--publishName', default=
'TilePT-stateless-10', help=
'EMON, Name under which to publish histograms')
112 parser.add_argument(
'--include', default=
"", help=
'EMON, Regular expression to select histograms to publish')
113 parser.add_argument(
'--lvl1Items', default=[], help=
'EMON, A list of L1 bit numbers, default []')
114 parser.add_argument(
'--lvl1Names', default=[], help=
'EMON, A list of L1 bit names, default []')
115 parser.add_argument(
'--lvl1Logic', default=
'Ignore', choices=[
'And',
'Or',
'Ignore'], help=
'EMON, default: Ignore')
116 parser.add_argument(
'--lvl1Origin', default=
'TAV', choices=[
'TBP',
'TAP',
'TAV'], help=
'EMON, default: TAV')
117 parser.add_argument(
'--streamType', default=
'physics', help=
'EMON, HLT stream type (e.g. physics or calibration)')
118 parser.add_argument(
'--streamNames', default=[
'express',
'Main',
'Standby',
'L1Calo',
'ZeroBias',
'Background',
'MinBias'], help=
'EMON, List of HLT stream names')
119 parser.add_argument(
'--streamLogic', default=
'Or', choices=[
'And',
'Or',
'Ignore'], help=
'EMON, default: Or')
120 parser.add_argument(
'--triggerType', type=int, default=256, help=
'EMON, LVL1 8 bit trigger type, default: 256')
121 parser.add_argument(
'--groupName', default=
"TilePhysMon", help=
'EMON, Name of the monitoring group')
122 parser.add_argument(
'--postProcessingInterval', type=int, default=10000000,
123 help=
'Number of events between postprocessing steps (<0: disabled, >evtMax: during finalization)')
125 update_group = parser.add_mutually_exclusive_group()
126 update_group.add_argument(
'--frequency', type=int, default=0, help=
'EMON, Frequency (in number of events) of publishing histograms')
127 update_group.add_argument(
'--updatePeriod', type=int, default=60, help=
'EMON, Frequency (in seconds) of publishing histograms')
129 args, _ = parser.parse_known_args()
133 parser.set_defaults(cells=
False, towers=
False, clusters=
False, muid=
False, muonfit=
False, mbts=
False,
134 rod=
False, tmdb=
False, tmdbDigits=
False, tmdbRawChannels=
False)
135 elif not any([args.laser, args.cis, args.noise, args.mbts]):
136 mbts =
False if (args.stateless
and args.useMbtsTrigger)
else True
137 parser.set_defaults(cells=
True, towers=
True, clusters=
True, muid=
True, muonfit=
True, mbts=mbts,
138 rod=
True, tmdb=
True, tmdbDigits=
True, tmdbRawChannels=
True)
140 parser.set_defaults(digiNoise=
True, rawChanNoise=
True)
143 parser.set_defaults(online=
True)
144 partition = args.partition
if args.partition
else os.getenv(
'TDAQ_PARTITION',
'ATLAS')
146 keys = {
'ATLAS' :
'dcm',
'TileMon' :
'CompleteEvent',
'Tile' :
'ReadoutApplication'}
147 key = args.key
if args.key
else keys.get(partition,
'dcm')
149 keyValues = {
'Tile': [
'TileREB-ROS']}
150 keyValue = args.keyValue
if args.keyValue
else keyValues.get(partition, [])
153 updatePeriod = 0
if args.frequency > 0
else args.updatePeriod
154 parser.set_defaults(partition=partition, key=key, keyValue=keyValue, updatePeriod=updatePeriod)
156 if any([args.laser, args.cis]):
157 calibGroupName =
'TileLasMon' if args.laser
else 'TileCisMon'
158 parser.set_defaults(streamType=
'calibration', streamNames=[
'Tile'], streamLogic=
'And', keyCount=1000, groupName=calibGroupName)
160 publishInclude =
".*Summary.*|.*DMUErrors.*|.*DigiNoise.*"
161 parser.set_defaults(streamType=
'physics', streamNames=[
'CosmicCalo'], streamLogic=
'And', include=publishInclude,
162 triggerType=0x82, frequency=300, updatePeriod=0, keyCount=100, groupName=
'TileNoiseMon', postProcessingInterval=299)
166 _l1Names = [
'L1_MBTS_1',
'L1_MBTS_1_EMPTY',
'L1_MBTS_1_1_EMPTY']
167 _l1Names += [
'L1_MBTSA' +
str(counter)
for counter
in range(0, 16)]
168 _l1Names += [
'L1_MBTSC' +
str(counter)
for counter
in range(0, 16)]
169 parser.set_defaults(lvl1Logic=
'Or', lvl1Origin=
'TBP', lvl1Items=_l1Items, lvl1Names=_l1Names,
170 keyCount=100, groupName=
'TileMBTSMon', useMbtsTrigger =
True)
172 parser.set_defaults(postProcessingInterval=100, groupName=
'TileCosmicsMon', streamNames=[
'CosmicCalo',
'CosmicMuons',
'IDCosmic'])
174 parser.set_defaults(postProcessingInterval=100)
176 args, _ = parser.parse_known_args()
179 from AthenaCommon.Logging
import log
183 if args.dumpArguments:
184 log.info(
'=====>>> FINAL ARGUMENTS FOLLOW')
185 print(
'{:40} : {}'.
format(
'Argument Name',
'Value'))
186 for a,v
in (vars(args)).
items():
187 print(f
'{a:40} : {v}')
191 flags.DQ.useTrigger =
False
192 flags.DQ.enableLumiAccess =
False
193 flags.Tile.RunType = TileRunType.PHY
195 if args.mbts
and args.useMbtsTrigger:
196 flags.Trigger.triggerConfig =
'DB'
198 flags.Input.Files = []
201 flags.Input.isMC =
False
202 flags.Input.Format = Format.BS
203 flags.GeoModel.Run = LHCPeriod.Run3
204 if args.mbts
and args.useMbtsTrigger:
205 if args.partition
in [
'TileMon']:
206 flags.Trigger.triggerConfig =
'DB:{:s}:{:d},{:d},{:d},{:d}'.
format(
'TRIGGERDB_RUN3', 3185, 4357, 4219, 2543)
208 beamType = flags.Beam.Type
209 from AthenaConfiguration.AutoConfigOnlineRecoFlags
import autoConfigOnlineRecoFlags
211 flags.Beam.Type = beamType
215 flags.fillFromArgs(parser=parser)
216 if not (args.filesInput
or flags.Input.Files):
218 inputDirectory =
"/cvmfs/atlas-nightlies.cern.ch/repo/data/data-art/TileByteStream/TileByteStream-02-00-00"
219 inputFile =
"data18_tilecomm.00363899.calibration_tile.daq.RAW._lb0000._TileREB-ROS._0005-200ev.data"
220 flags.Input.Files = [os.path.join(inputDirectory, inputFile)]
221 flags.Input.RunNumbers = [363899]
223 inputDirectory =
"/cvmfs/atlas-nightlies.cern.ch/repo/data/data-art/TileByteStream/TileByteStream-02-00-00"
224 inputFile =
"data18_tilecomm.00363899.calibration_tile.daq.RAW._lb0000._TileREB-ROS._0005-200ev.data"
225 flags.Input.Files = [os.path.join(inputDirectory, inputFile)]
226 flags.Input.RunNumbers = [363899]
228 inputDirectory =
'root://eosatlas.cern.ch//eos/atlas/atlascerngroupdisk/det-tile/test'
229 inputFile =
'data12_8TeV.00201555.physics_ZeroBiasOverlay.merge.RAW._lb0150._SFO-ALL._0001.1'
230 flags.Input.Files = [os.path.join(inputDirectory, inputFile)]
232 from AthenaConfiguration.TestDefaults
import defaultTestFiles
233 flags.Input.Files = defaultTestFiles.RAW_RUN2
235 if any([args.cis, args.laser]):
236 flags.Input.ProjectName = flags.Input.Files[0].
split(os.path.sep)[-1].
split(
'.')[0]
238 runNumber = flags.Input.RunNumbers[0]
239 if not flags.Input.isMC:
240 from AthenaConfiguration.TestDefaults
import defaultGeometryTags
241 flags.GeoModel.AtlasVersion = defaultGeometryTags.autoconfigure(flags)
243 if not flags.Output.HISTFileName:
244 flags.Output.HISTFileName =
'tilemon_{}.root'.
format(runNumber)
247 flags.Common.isOnline =
True
248 if flags.Common.isOnline:
249 flags.IOVDb.GlobalTag =
'CONDBR2-HLTP-2023-01' if runNumber > 232498
else 'COMCOND-HLTP-004-02'
250 flags.DQ.Environment =
'online'
251 flags.DQ.FileKey =
''
253 flags.IOVDb.GlobalTag =
'CONDBR2-BLKPA-2023-01' if runNumber > 232498
else 'COMCOND-BLKPA-RUN1-06'
255 if any([args.laser, args.cis]):
257 flags.Tile.RunType = TileRunType.GAPLAS
259 flags.Tile.RunType = TileRunType.GAPCIS
260 flags.Tile.doFit =
True
261 flags.Tile.correctTime =
True
262 flags.Tile.doOverflowFit =
False
263 flags.Tile.BestPhaseFromCOOL =
True
264 flags.Tile.NoiseFilter = 1
267 flags.Output.doJiveXML =
True
270 flags.fillFromArgs(parser=parser)
273 log.info(
'Executing preExec: %s', args.preExec)
276 log.info(
'=====>>> FINAL CONFIG FLAGS SETTINGS FOLLOW')
277 flags.dump(pattern=
'Tile.*|Input.*|Exec.*|IOVDb.[D|G].*', evaluate=
True)
282 from AthenaConfiguration.MainServicesConfig
import MainServicesCfg
285 typeNames = [
'CTP_RDO/CTP_RDO']
if args.mbts
and args.useMbtsTrigger
else []
287 from TileByteStream.TileByteStreamConfig
import TileRawDataReadingCfg
289 readMuRcvDigits=any([args.tmdbDigits, args.tmdb]),
290 readMuRcvRawCh=any([args.tmdbRawChannels, args.tmdb]),
292 stateless=args.stateless,
293 type_names=typeNames) )
296 bsEmonInputSvc = cfg.getService(
"ByteStreamInputSvc" )
297 bsEmonInputSvc.Partition = args.partition
298 bsEmonInputSvc.Key = args.key
299 bsEmonInputSvc.KeyValue = args.keyValue
300 bsEmonInputSvc.KeyCount = args.keyCount
301 bsEmonInputSvc.PublishName = args.publishName
302 bsEmonInputSvc.ISServer =
'Histogramming'
303 bsEmonInputSvc.Include = args.include
304 bsEmonInputSvc.UpdatePeriod = args.updatePeriod
305 bsEmonInputSvc.Frequency = args.frequency
306 bsEmonInputSvc.LVL1Items = args.lvl1Items
307 bsEmonInputSvc.LVL1Names = args.lvl1Names
308 bsEmonInputSvc.LVL1Logic = args.lvl1Logic
309 bsEmonInputSvc.LVL1Origin = args.lvl1Origin
310 bsEmonInputSvc.StreamType =
'express' if flags.Beam.Type
is BeamType.SingleBeam
else args.streamType
311 bsEmonInputSvc.StreamNames = args.streamNames
312 bsEmonInputSvc.StreamLogic = args.streamLogic
313 bsEmonInputSvc.GroupName = args.groupName
314 bsEmonInputSvc.ProcessCorruptedEvents =
True
315 bsEmonInputSvc.BufferSize = 200
317 cfg.addPublicTool( CompFactory.TileROD_Decoder(fullTileMode = runNumber) )
319 from TileRecUtils.TileRawChannelMakerConfig
import TileRawChannelMakerCfg
321 if args.threads
and (args.threads > 1):
322 rawChMaker = cfg.getEventAlgo(
'TileRChMaker')
323 rawChMaker.Cardinality = args.threads
325 l1Triggers = [
'bit0_RNDM',
'bit1_ZeroBias',
'bit2_L1Cal',
'bit3_Muon',
326 'bit4_RPC',
'bit5_FTK',
'bit6_CTP',
'bit7_Calib',
'AnyPhysTrig']
328 if any([args.laser, args.cis]):
329 triggerTypes = [0x34]
if args.laser
else [0x32]
330 from TileMonitoring.TileRawChannelTimeMonitorAlgorithm
import TileRawChannelTimeMonitoringConfig
334 from TileMonitoring.TileRODMonitorAlgorithm
import TileRODMonitoringConfig
338 from TileMonitoring.TileTMDBDigitsMonitorAlgorithm
import TileTMDBDigitsMonitoringConfig
341 if args.tmdbRawChannels:
342 from TileMonitoring.TileTMDBRawChannelMonitorAlgorithm
import TileTMDBRawChannelMonitoringConfig
346 from TileMonitoring.TileTMDBMonitorAlgorithm
import TileTMDBMonitoringConfig
349 if any([args.cells, args.towers, args.clusters, args.mbts, args.muid, args.muonfit, flags.Output.doJiveXML]):
350 from TileRecUtils.TileCellMakerConfig
import TileCellMakerCfg
354 from TileMonitoring.TileCellMonitorAlgorithm
import TileCellMonitoringConfig
358 from TileMonitoring.TileTowerMonitorAlgorithm
import TileTowerMonitoringConfig
362 from TileMonitoring.TileClusterMonitorAlgorithm
import TileClusterMonitoringConfig
366 from TileMonitoring.TileMBTSMonitorAlgorithm
import TileMBTSMonitoringConfig
370 from TileMuId.TileMuIdConfig
import TileLookForMuAlgCfg
373 from TileMonitoring.TileMuIdMonitorAlgorithm
import TileMuIdMonitoringConfig
377 from TileCosmicAlgs.TileMuonFitterConfig
import TileMuonFitterCfg
380 from TileMonitoring.TileMuonFitMonitorAlgorithm
import TileMuonFitMonitoringConfig
384 from TileMonitoring.TileDigiNoiseMonitorAlgorithm
import TileDigiNoiseMonitoringConfig
387 if args.rawChanNoise:
388 from TileMonitoring.TileRawChannelNoiseMonitorAlgorithm
import TileRawChannelNoiseMonitoringConfig
391 from TileMonitoring.TileDQFragMonitorAlgorithm
import TileDQFragMonitoringConfig
394 if any([args.digiNoise, args.rawChanNoise, args.tmdbDigits, args.tmdb])
and args.postProcessingInterval > 0:
395 from AthenaCommon.Utils.unixtools
import find_datafile
398 if any([args.tmdbDigits, args.tmdb]):
399 configurations += [os.path.join(dataPath,
'TileTMDBPostProc.yaml')]
401 configurations += [os.path.join(dataPath,
'TileDigiNoisePostProc.yaml')]
402 if args.rawChanNoise:
403 configurations += [os.path.join(dataPath,
'TileRawChanNoisePostProc.yaml')]
405 from DataQualityUtils.DQPostProcessingAlg
import DQPostProcessingAlg
408 if hasattr(self,
'OutputLevel'):
410 return super(TileMonPostProcessingAlg, self).
initialize()
413 ppa.OutputLevel = flags.Exec.OutputLevel
414 ppa.ExtraInputs = {(
'xAOD::EventInfo' ,
'StoreGateSvc+EventInfo' )}
415 ppa.Interval = args.postProcessingInterval
416 ppa.ConfigFiles = configurations
418 if flags.Common.isOnline:
419 fileKey = flags.DQ.FileKey
420 ppa.FileKey = (fileKey +
'/')
if not fileKey.endswith(
'/')
else fileKey
422 ppa.FileKey = f
'/{flags.DQ.FileKey}/run_{runNumber}/'
424 cfg.addEventAlgo(ppa, sequenceName=
'AthEndSeq')
426 if flags.Output.doJiveXML:
427 from TileMonitoring.TileJiveXMLConfig
import TileAlgoJiveXMLCfg
433 log.info(
'Executing postExec: %s', args.postExec)
436 if flags.Common.isOnline:
437 cfg.getService(
"THistSvc").Output=[
"Tile DATAFILE='%s' OPT='RECREATE'" % (flags.Output.HISTFileName)]
438 cfg.getService(
"TileCablingSvc").CablingType=6
440 if args.stateless
and args.cis:
441 cfg.getEventAlgo(
'TileDQstatusAlg').TileBeamElemContainer=
""
443 cfg.printConfig(withDetails=args.printDetailedConfig)
446 sys.exit(0
if sc.isSuccess()
else 1)