ATLAS Offline Software
RunTileTBMonitoring.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #
3 # Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
4 #
5 '''
6 @file RunTileTBMonitoring.py
7 @brief Script to run Tile TestBeam Reconstrcution/Monitoring
8 '''
9 
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
14 from AthenaCommon.SystemOfUnits import GeV
15 
16 import os
17 import sys
18 
19 
20 def configureFlagsAndArgsFromPartition(flags, args, partition, log):
21  """
22  Configure the flags and args from partition in online
23 
24  Configure the following flags from partition in online:
25  run type, run number, beam type, beam energy, project
26 
27  Configure the following args from partition in online: args.nsamples
28  """
29 
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')
35  sys.exit(1)
36 
37  # Set up default values
38  runType = 'Physics'
39  beamType = 'collisions'
40  beamEnergy = 200 * GeV
41  runNumber = 2400000
42  project = 'data_H8'
43 
44  try:
45  runParams = ISObject(ipcPartition, 'RunParams.SOR_RunParams', 'RunParams')
46  except Exception:
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}')
49  else:
50  runParams.checkout()
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}')
58 
59  try:
60  cisParams = ISObject(ipcPartition, 'TileParams.cispar', 'TileCISparameters')
61  except Exception:
62  log.info('Could not find Tile Parameters in IS')
63  else:
64  try:
65  cisParams.checkout()
66  except Exception:
67  log.info("Could not get Tile Parameters from IS")
68  else:
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)
73  log.info(cispar)
74 
75  if len(cisParams.data) == 16:
76  data = cisParams.data
77  if data[12] == 1:
78  runType = 'Physics'
79  elif data[12] == 2:
80  runType = 'Laser'
81  elif data[12] == 4:
82  runType = 'Pedestals'
83  elif data[12] == 8:
84  runType = runType if 'mono' in runType else 'CIS'
85 
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]}')
88 
89  # Try to get number of samples from partition
90  nSamples = 15 # Default number of samples
91  try:
92  dspConfig = ISObject(ipcPartition, 'TileParams.TileCal_DSPConfig', 'TileCal_IS_DSPConfig')
93  except Exception:
94  log.info(f"Could not find Tile DSP Config in IS => set default number of samples to {nSamples}")
95  else:
96  try:
97  dspConfig.checkout()
98  except Exception:
99  log.info(f"Could not get Tile DSP Config from IS => set default number of samples to {nSamples}")
100  else:
101  nSamples = dspConfig.samples
102  log.info(f"Set number of samples from DSP Config in IS: {nSamples}")
103 
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
112 
113  if beamType in ['collisions', 'singlebeam', 'cosmics', 'testbeam']:
114  flags.Beam.Type = BeamType(beamType)
115 
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
120 
121 
122 def TileTestBeamMonitoringCfg(flags, fragIDs=[0x100, 0x101, 0x200, 0x201, 0x402], useFELIX=False, **kwargs):
123 
124  ''' Function to configure Tile TestBeam monitoring.'''
125 
126  acc = ComponentAccumulator()
127 
128  caloCells = 'AllCaloHG' if flags.Tile.RunType.isBiGain() else 'AllCalo'
129 
130  from TileMonitoring.TileTBBeamMonitorAlgorithm import TileTBBeamMonitoringConfig
131  acc.merge(TileTBBeamMonitoringConfig(flags, fragIDs=fragIDs, CaloCellContainer=caloCells))
132 
133  from TileMonitoring.TileTBMonitorAlgorithm import TileTBMonitoringConfig
134  acc.merge(TileTBMonitoringConfig(flags, fragIDs=fragIDs, CaloCellContainer=caloCells))
135 
136  from TileMonitoring.TileTBPulseMonitorAlgorithm import TileTBPulseMonitoringConfig
137  acc.merge(TileTBPulseMonitoringConfig(flags, timeRange=[-200, 200], fragIDs=fragIDs))
138 
139  from TileMonitoring.TileTBCellMonitorAlgorithm import TileTBCellMonitoringConfig
140  acc.merge(TileTBCellMonitoringConfig(flags, timeRange=[-200, 200], fragIDs=fragIDs))
141 
142  if useFELIX:
143  from TileMonitoring.TileTBCellMonitorAlgorithm import TileTBCellMonitoringConfig
144  acc.merge(TileTBCellMonitoringConfig(flags, timeRange=[-200, 200], fragIDs=fragIDs, useFELIX=True))
145 
146  from TileMonitoring.TileTBPulseMonitorAlgorithm import TileTBPulseMonitoringConfig
147  acc.merge(TileTBPulseMonitoringConfig(flags, timeRange=[-200, 200], fragIDs=fragIDs, useFELIX=True))
148 
149  from TileMonitoring.TileDigitsFlxMonitorAlgorithm import TileDigitsFlxMonitoringConfig
150  acc.merge(TileDigitsFlxMonitoringConfig(flags))
151 
152  from TileMonitoring.TileRawChannelFlxMonitorAlgorithm import TileRawChannelFlxMonitoringConfig
153  acc.merge(TileRawChannelFlxMonitoringConfig(flags))
154 
155  return acc
156 
157 
158 if __name__ == '__main__':
159 
160  # Setup logs
161  from AthenaCommon.Logging import log
162  from AthenaCommon.Constants import INFO
163  log.setLevel(INFO)
164 
165  # Set the Athena configuration flags
166  from AthenaConfiguration.AllConfigFlags import initConfigFlags
167  from AthenaConfiguration.TestDefaults import defaultTestFiles
168 
169  flags = initConfigFlags()
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')
181 
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')
198 
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')
202 
203  args, _ = parser.parse_known_args()
204 
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}')
210  sys.exit(0)
211 
212  fragIDs = [int(fragID, base=16) for fragID in args.fragIDs]
213 
214  # Initially the following flags are not set up (they must be provided)
215  flags.Input.Files = []
216 
217  # Initial configuration flags from command line arguments (to be used to set up defaults)
218  flags.fillFromArgs(parser=parser)
219 
220  # =======>>> Set the Athena configuration flags to defaults (can be overriden via comand line)
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
228 
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
236 
237  flags.Exec.PrintAlgsSequence = True
238 
239  if args.stateless:
240  flags.Input.isMC = False
241  flags.Input.Format = Format.BS
242  partition = args.partition if args.partition else os.getenv('TDAQ_PARTITION', 'TileTB')
243  configureFlagsAndArgsFromPartition(flags, args, partition, log)
244  else:
245  flags.Tile.RunType = TileRunType.PHY
246  flags.Beam.Type = BeamType.Collisions
247  # Get beam energy from meta data (Tile TB setup: [GeV])
248  beamEnergy = GetFileMD(flags.Input.Files).get("beam_energy", 100)
249  flags.Beam.Energy = beamEnergy * GeV
250 
251  if not (args.filesInput or flags.Input.Files):
252  flags.Input.Files = defaultTestFiles.RAW_RUN2
253 
254  # =======>>> Override default configuration flags from command line arguments
255  flags.fillFromArgs(parser=parser)
256 
257  if not flags.Output.HISTFileName:
258  runNumber = flags.Input.RunNumbers[0]
259  flags.Output.HISTFileName = f'tiletbmon_{runNumber}.root'
260 
261  if args.preExec:
262  log.info('Executing preExec: %s', args.preExec)
263  exec(args.preExec)
264 
265  flags.lock()
266 
267  log.info('=====>>> FINAL CONFIG FLAGS SETTINGS FOLLOW:')
268  flags.dump(pattern='Tile.*|Beam.*|Input.*|Exec.*|IOVDb.[D|G].*', evaluate=True)
269 
270  # =======>>> Initialize configuration object, add accumulator, merge, and run
271  from AthenaConfiguration.MainServicesConfig import MainServicesCfg
272  cfg = MainServicesCfg(flags)
273 
274  # =======>>> Configure Tile raw data (digits) reading
275  from TileByteStream.TileByteStreamConfig import TileRawDataReadingCfg
276  cfg.merge( TileRawDataReadingCfg(flags, readMuRcv=False,
277  readDigits=True,
278  readRawChannel=True,
279  readDigitsFlx=True,
280  readBeamElem=True,
281  stateless=args.stateless) )
282 
283  if 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
303 
304  # =======>>> Configure reconstruction of Tile TestBeam data
305  from TileTBRec.TileTestBeamRecoConfig import TileTestBeamRecoCfg
306  cfg.merge( TileTestBeamRecoCfg(flags, useDemoCabling=args.demoCabling, nsamples=args.nsamples) )
307  cfg.merge( TileTestBeamRecoCfg(flags, useDemoCabling=args.demoCabling, nsamples=16, useFELIX=True) )
308 
309  if args.useSqlite:
310  cfg.getService('IOVDbSvc').overrideTags += [
311  f'<prefix>/TILE</prefix> <db>sqlite://;schema={args.useSqlite};dbname={flags.IOVDb.DatabaseInstance}</db>',
312  # ROD folder does not exist in Sqlite file at the moment (should be added)
313  f'<prefix>/TILE/ONL01/STATUS/ROD</prefix> <db>COOLONL_TILE/{flags.IOVDb.DatabaseInstance}</db>'
314  ]
315 
316  # =======>>> Configure Tile TestBeam monitoring
317  cfg.merge(TileTestBeamMonitoringCfg(flags, fragIDs=fragIDs, useFELIX=True))
318 
319  # =======>>> Configure ROD to ROB mapping
320  # Scan first event for all fragments to create proper ROD to ROB map
321  cfg.getCondAlgo('TileHid2RESrcIDCondAlg').RODStatusProxy = None
322 
323  # =======>>> Any last things to do?
324  if args.postExec:
325  log.info('Executing postExec: %s', args.postExec)
326  exec(args.postExec)
327 
328  if args.printConfig:
329  cfg.printConfig(withDetails=True, summariseProps=True, printDefaults=True)
330 
331  if args.config_only:
332  cfg.store(open('TileTestBeamMonitoring.pkl', 'wb'))
333  else:
334  sc = cfg.run()
335  # Success should be 0
336  sys.exit(not sc.isSuccess())
python.AutoConfigFlags.GetFileMD
def GetFileMD(filenames, allowEmpty=True, maxLevel='peeker')
Definition: AutoConfigFlags.py:65
TileDigitsFlxMonitorAlgorithm.TileDigitsFlxMonitoringConfig
def TileDigitsFlxMonitoringConfig(flags, fragIDs=[0x201, 0x402], topPath='TestBeam', **kwargs)
Definition: TileDigitsFlxMonitorAlgorithm.py:10
SystemOfUnits
TileRawChannelFlxMonitorAlgorithm.TileRawChannelFlxMonitoringConfig
def TileRawChannelFlxMonitoringConfig(flags, fragIDs=[0x201, 0x402], topPath='TestBeam', **kwargs)
Definition: TileRawChannelFlxMonitorAlgorithm.py:10
python.JetAnalysisCommon.ComponentAccumulator
ComponentAccumulator
Definition: JetAnalysisCommon.py:302
vtune_athena.format
format
Definition: vtune_athena.py:14
RunTileTBMonitoring.TileTestBeamMonitoringCfg
def TileTestBeamMonitoringCfg(flags, fragIDs=[0x100, 0x101, 0x200, 0x201, 0x402], useFELIX=False, **kwargs)
Definition: RunTileTBMonitoring.py:122
RunTileTBMonitoring.int
int
Definition: RunTileTBMonitoring.py:177
RunTileTBMonitoring.configureFlagsAndArgsFromPartition
def configureFlagsAndArgsFromPartition(flags, args, partition, log)
Definition: RunTileTBMonitoring.py:20
TileTBBeamMonitorAlgorithm.TileTBBeamMonitoringConfig
def TileTBBeamMonitoringConfig(flags, fragIDs=[0x100, 0x101, 0x200, 0x201, 0x402], **kwargs)
Definition: TileTBBeamMonitorAlgorithm.py:12
CBNT_TBInfo.BeamType
BeamType
Definition: CBNT_TBInfo.py:29
TileTBMonitorAlgorithm.TileTBMonitoringConfig
def TileTBMonitoringConfig(flags, fragIDs=[0x100, 0x101, 0x200, 0x201, 0x402], **kwargs)
Definition: TileTBMonitorAlgorithm.py:12
LArG4FSStartPointFilter.exec
exec
Definition: LArG4FSStartPointFilter.py:103
python.MainServicesConfig.MainServicesCfg
def MainServicesCfg(flags, LoopMgr='AthenaEventLoopMgr')
Definition: MainServicesConfig.py:260
Constants
some useful constants -------------------------------------------------—
print
void print(char *figname, TCanvas *c1)
Definition: TRTCalib_StrawStatusPlots.cxx:25
TrigJetMonitorAlgorithm.items
items
Definition: TrigJetMonitorAlgorithm.py:79
Trk::open
@ open
Definition: BinningType.h:40
python.AllConfigFlags.initConfigFlags
def initConfigFlags()
Definition: AllConfigFlags.py:19
TileByteStreamConfig.TileRawDataReadingCfg
def TileRawDataReadingCfg(flags, readDigits=True, readRawChannel=True, readMuRcv=None, readMuRcvDigits=False, readMuRcvRawCh=False, readBeamElem=None, readLaserObj=None, readDigitsFlx=False, readL2=False, stateless=False, **kwargs)
Definition: TileByteStreamConfig.py:87
get
T * get(TKey *tobj)
get a TObject* from a TKey* (why can't a TObject be a TKey?)
Definition: hcg.cxx:127
TileTestBeamRecoConfig.TileTestBeamRecoCfg
def TileTestBeamRecoCfg(flags, useDemoCabling, nsamples, useFELIX=False, filterDigits=False, filterChannels=True)
Definition: TileTestBeamRecoConfig.py:45
str
Definition: BTagTrackIpAccessor.cxx:11
TileTBCellMonitorAlgorithm.TileTBCellMonitoringConfig
def TileTBCellMonitoringConfig(flags, timeRange=[-100, 100], fragIDs=[0x100, 0x101, 0x200, 0x201, 0x402], useDemoCabling=2018, useFELIX=False, **kwargs)
Definition: TileTBCellMonitorAlgorithm.py:12
TileTBPulseMonitorAlgorithm.TileTBPulseMonitoringConfig
def TileTBPulseMonitoringConfig(flags, timeRange=[-100, 100], fragIDs=[0x100, 0x101, 0x200, 0x201, 0x402], useDemoCabling=2018, useFELIX=False, **kwargs)
Definition: TileTBPulseMonitorAlgorithm.py:42