6 @file RunTileTBMonitoring.py
7 @brief Script to run Tile TestBeam Reconstrcution/Monitoring
10 from AthenaConfiguration.ComponentAccumulator
import ComponentAccumulator
11 from AthenaConfiguration.Enums
import Format, BeamType
12 from AthenaConfiguration.AutoConfigFlags
import GetFileMD
13 from TileConfiguration.TileConfigFlags
import TileRunType
22 Configure the flags and args from partition in online
24 Configure the following flags from partition in online:
25 run type, run number, beam type, beam energy, project
27 Configure the following args from partition in online: args.nsamples
30 from ipc
import IPCPartition
31 from ispy
import ISObject
32 ipcPartition = IPCPartition(partition)
33 if not ipcPartition.isValid():
34 log.error(
'Partition: ' + ipcPartition.name() +
' is not valid')
39 beamType =
'collisions'
40 beamEnergy = 200 * GeV
45 runParams = ISObject(ipcPartition,
'RunParams.SOR_RunParams',
'RunParams')
47 log.warning(f
'No Run Parameters in IS => Set defaults: partition: {partition}, beam type: {beamType}'
48 + f
', beam energy: {beamEnergy}, run number: {runNumber}, project tag: {project}')
51 beamType = runParams.beam_type
52 beamEnergy = runParams.beam_energy * GeV
53 runNumber = runParams.run_number
54 project = runParams.T0_project_tag
55 runType = runParams.run_type
56 log.info(f
'RUN CONFIGURATION: run type: {runType}, beam type: {beamType}'
57 + f
', beam energy: {beamEnergy}, run number: {runNumber}, project: {project}')
60 cisParams = ISObject(ipcPartition,
'TileParams.cispar',
'TileCISparameters')
62 log.info(
'Could not find Tile Parameters in IS')
67 log.info(
"Could not get Tile Parameters from IS")
69 log.info(f
'TILE CONFIGURATION: CISPAR size: {len(cisParams.data)}')
70 cispar =
'TILE CONFIGURATION: CISPAR: '
71 for d
in cisParams.data:
72 cispar +=
' ' +
str(d)
75 if len(cisParams.data) == 16:
84 runType = runType
if 'mono' in runType
else 'CIS'
86 log.info(f
'TILE CONFIGURATION: RunType: {runType}, Mode: {data[0]}, Samples: {data[1]}, Pipeline: {data[2]}'
87 + f
', I3Delay: {data[3]}, Event: {data[4]}, Phase: {data[5]}, DAC: {data[6]}, Capacity: {data[7]}')
92 dspConfig = ISObject(ipcPartition,
'TileParams.TileCal_DSPConfig',
'TileCal_IS_DSPConfig')
94 log.info(f
"Could not find Tile DSP Config in IS => set default number of samples to {nSamples}")
99 log.info(f
"Could not get Tile DSP Config from IS => set default number of samples to {nSamples}")
101 nSamples = dspConfig.samples
102 log.info(f
"Set number of samples from DSP Config in IS: {nSamples}")
104 if 'Physics' in runType:
105 flags.Tile.RunType = TileRunType.PHY
106 elif 'CIS' in runType:
107 flags.Tile.RunType = TileRunType.MONOCIS
if 'mono' in runType
else TileRunType.CIS
108 elif 'Laser' in runType:
109 flags.Tile.RunType = TileRunType.LAS
110 elif 'Pedestals' in runType:
111 flags.Tile.RunType = TileRunType.PED
113 if beamType
in [
'collisions',
'singlebeam',
'cosmics',
'testbeam']:
114 flags.Beam.Type =
BeamType(beamType)
116 flags.Beam.Energy = beamEnergy
if beamEnergy > 1 * GeV
else 200 * GeV
117 flags.Input.ProjectName = project
118 flags.Input.RunNumbers = [runNumber]
119 args.nsamples = nSamples
124 ''' Function to configure Tile TestBeam monitoring.'''
128 caloCells =
'AllCaloHG' if flags.Tile.RunType.isBiGain()
else 'AllCalo'
130 from TileMonitoring.TileTBBeamMonitorAlgorithm
import TileTBBeamMonitoringConfig
133 from TileMonitoring.TileTBMonitorAlgorithm
import TileTBMonitoringConfig
136 from TileMonitoring.TileTBPulseMonitorAlgorithm
import TileTBPulseMonitoringConfig
139 from TileMonitoring.TileTBCellMonitorAlgorithm
import TileTBCellMonitoringConfig
143 from TileMonitoring.TileTBCellMonitorAlgorithm
import TileTBCellMonitoringConfig
146 from TileMonitoring.TileTBPulseMonitorAlgorithm
import TileTBPulseMonitoringConfig
149 from TileMonitoring.TileDigitsFlxMonitorAlgorithm
import TileDigitsFlxMonitoringConfig
152 from TileMonitoring.TileRawChannelFlxMonitorAlgorithm
import TileRawChannelFlxMonitoringConfig
158 if __name__ ==
'__main__':
161 from AthenaCommon.Logging
import log
166 from AthenaConfiguration.AllConfigFlags
import initConfigFlags
167 from AthenaConfiguration.TestDefaults
import defaultTestFiles
170 parser = flags.getArgumentParser()
171 parser.add_argument(
'--preExec', help=
'Code to execute before locking configs')
172 parser.add_argument(
'--postExec', help=
'Code to execute after setup')
173 parser.add_argument(
'--printConfig', action=
'store_true', help=
'Print detailed Athena configuration')
174 parser.add_argument(
'--dumpArguments', action=
'store_true', help=
'Print arguments and exit')
175 parser.add_argument(
'--frag-ids', dest=
'fragIDs', nargs=
"*", default=[
'0x100',
'0x101',
'0x200',
'0x201',
'0x402'],
176 help=
'Tile Frag IDs of modules to be monitored. Empty=ALL')
177 parser.add_argument(
'--demo-cabling', dest=
'demoCabling', type=int, default=2018, help=
'Time Demonatrator cabling to be used')
178 parser.add_argument(
'--nsamples', type=int, default=15, help=
'Number of samples')
179 parser.add_argument(
'--use-sqlite', dest=
'useSqlite', default=
'/afs/cern.ch/user/t/tiledemo/public/efmon/condb/tileSqlite.db',
180 help=
'Providing local SQlite file, conditions constants will be used from it')
182 parser.add_argument(
'--stateless', action=
"store_true", help=
'Run Online Tile TB monitoring in partition')
183 parser.add_argument(
'--partition', default=
"", help=
'EMON, Partition name, default taken from $TDAQ_PARTITION if not set')
184 parser.add_argument(
'--key', type=str, default=
'ReadoutApplication', help=
'EMON, Selection key, e.g.: ReadoutApplication (TileTB)')
185 parser.add_argument(
'--keyValue', default=[
'TileREB-ROS'], help=
'EMON, Key values, e.g.: TileREB-ROS (TileTB)')
186 parser.add_argument(
'--keyCount', type=int, default=0, help=
'EMON, key count, e.g. 5 to get five random SFIs')
187 parser.add_argument(
'--publishName', default=
'TilePT-stateless-tb', help=
'EMON, Name under which to publish histograms')
188 parser.add_argument(
'--include', default=
"", help=
'EMON, Regular expression to select histograms to publish')
189 parser.add_argument(
'--lvl1Items', default=[], help=
'EMON, A list of L1 bit numbers, default []')
190 parser.add_argument(
'--lvl1Names', default=[], help=
'EMON, A list of L1 bit names, default []')
191 parser.add_argument(
'--lvl1Logic', default=
'Ignore', choices=[
'And',
'Or',
'Ignore'], help=
'EMON, default: Ignore')
192 parser.add_argument(
'--lvl1Origin', default=
'TAV', choices=[
'TBP',
'TAP',
'TAV'], help=
'EMON, default: TAV')
193 parser.add_argument(
'--streamType', default=
'physics', help=
'EMON, HLT stream type (e.g. physics or calibration)')
194 parser.add_argument(
'--streamNames', default=[
'tile'], help=
'EMON, List of HLT stream names')
195 parser.add_argument(
'--streamLogic', default=
'Ignore', choices=[
'And',
'Or',
'Ignore'], help=
'EMON, default: Ignore')
196 parser.add_argument(
'--triggerType', type=int, default=256, help=
'EMON, LVL1 8 bit trigger type, default: 256')
197 parser.add_argument(
'--groupName', default=
"TileTBMon", help=
'EMON, Name of the monitoring group')
199 update_group = parser.add_mutually_exclusive_group()
200 update_group.add_argument(
'--frequency', type=int, default=0, help=
'EMON, Frequency (in number of events) of publishing histograms')
201 update_group.add_argument(
'--updatePeriod', type=int, default=30, help=
'EMON, Frequency (in seconds) of publishing histograms')
203 args, _ = parser.parse_known_args()
205 if args.dumpArguments:
206 log.info(
'=====>>> FINAL ARGUMENTS FOLLOW')
207 print(
'{:40} : {}'.
format(
'Argument Name',
'Value'))
208 for a,v
in (vars(args)).
items():
209 print(f
'{a:40} : {v}')
212 fragIDs = [
int(fragID, base=16)
for fragID
in args.fragIDs]
215 flags.Input.Files = []
218 flags.fillFromArgs(parser=parser)
221 flags.DQ.useTrigger =
False
222 flags.DQ.enableLumiAccess =
False
223 flags.DQ.FileKey =
'Tile'
224 flags.Common.isOnline =
True
225 from AthenaConfiguration.TestDefaults
import defaultConditionsTags, defaultGeometryTags
226 flags.GeoModel.AtlasVersion = defaultGeometryTags.RUN2
227 flags.IOVDb.GlobalTag = defaultConditionsTags.RUN2_DATA
229 flags.Tile.doFit =
True
230 flags.Tile.useDCS =
False
231 flags.Tile.NoiseFilter = 0
232 flags.Tile.correctTime =
False
233 flags.Tile.correctTimeJumps =
False
234 flags.Tile.BestPhaseFromCOOL =
False
235 flags.Tile.doOverflowFit =
False
237 flags.Exec.PrintAlgsSequence =
True
240 flags.Input.isMC =
False
241 flags.Input.Format = Format.BS
242 partition = args.partition
if args.partition
else os.getenv(
'TDAQ_PARTITION',
'TileTB')
245 flags.Tile.RunType = TileRunType.PHY
246 flags.Beam.Type = BeamType.Collisions
249 flags.Beam.Energy = beamEnergy * GeV
251 if not (args.filesInput
or flags.Input.Files):
252 flags.Input.Files = defaultTestFiles.RAW_RUN2
255 flags.fillFromArgs(parser=parser)
257 if not flags.Output.HISTFileName:
258 runNumber = flags.Input.RunNumbers[0]
259 flags.Output.HISTFileName = f
'tiletbmon_{runNumber}.root'
262 log.info(
'Executing preExec: %s', args.preExec)
267 log.info(
'=====>>> FINAL CONFIG FLAGS SETTINGS FOLLOW:')
268 flags.dump(pattern=
'Tile.*|Beam.*|Input.*|Exec.*|IOVDb.[D|G].*', evaluate=
True)
271 from AthenaConfiguration.MainServicesConfig
import MainServicesCfg
275 from TileByteStream.TileByteStreamConfig
import TileRawDataReadingCfg
281 stateless=args.stateless) )
284 bsEmonInputSvc = cfg.getService(
'ByteStreamInputSvc')
285 bsEmonInputSvc.Partition = args.partition
286 bsEmonInputSvc.Key = args.key
287 bsEmonInputSvc.KeyValue = args.keyValue
288 bsEmonInputSvc.KeyCount = args.keyCount
289 bsEmonInputSvc.PublishName = args.publishName
290 bsEmonInputSvc.ISServer =
'Histogramming'
291 bsEmonInputSvc.UpdatePeriod = args.updatePeriod
292 bsEmonInputSvc.Frequency = args.frequency
293 bsEmonInputSvc.LVL1Items = args.lvl1Items
294 bsEmonInputSvc.LVL1Names = args.lvl1Names
295 bsEmonInputSvc.LVL1Logic = args.lvl1Logic
296 bsEmonInputSvc.LVL1Origin = args.lvl1Origin
297 bsEmonInputSvc.StreamType = args.streamType
298 bsEmonInputSvc.StreamNames = args.streamNames
299 bsEmonInputSvc.StreamLogic = args.streamLogic
300 bsEmonInputSvc.GroupName = args.groupName
301 bsEmonInputSvc.ProcessCorruptedEvents =
True
302 bsEmonInputSvc.BufferSize = 2000
305 from TileTBRec.TileTestBeamRecoConfig
import TileTestBeamRecoCfg
310 cfg.getService(
'IOVDbSvc').overrideTags += [
311 f
'<prefix>/TILE</prefix> <db>sqlite://;schema={args.useSqlite};dbname={flags.IOVDb.DatabaseInstance}</db>',
313 f
'<prefix>/TILE/ONL01/STATUS/ROD</prefix> <db>COOLONL_TILE/{flags.IOVDb.DatabaseInstance}</db>'
321 cfg.getCondAlgo(
'TileHid2RESrcIDCondAlg').RODStatusProxy =
None
325 log.info(
'Executing postExec: %s', args.postExec)
329 cfg.printConfig(withDetails=
True, summariseProps=
True, printDefaults=
True)
332 cfg.store(
open(
'TileTestBeamMonitoring.pkl',
'wb'))
336 sys.exit(
not sc.isSuccess())