ATLAS Offline Software
Loading...
Searching...
No Matches
TileRawDataReadTestConfig.py
Go to the documentation of this file.
1# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2
3from AthenaConfiguration.ComponentFactory import CompFactory
4from AthenaCommon.Utils.unixtools import find_datafile
5from AthenaPython.PyAthenaComps import Alg, StatusCode
6from TileConfiguration.TileConfigFlags import TileRunType
7
8import os
9import sys
10import glob
11
12
13def findAbsPath(path):
14 refPaths = [os.environ.get('ATLAS_REFERENCE_DATA', None),
15 '/cvmfs/atlas-nightlies.cern.ch/repo/data/data-art']
16 for refPath in refPaths:
17 if refPath:
18 absPath = os.path.join(refPath, path)
19 if os.path.exists(absPath):
20 return absPath
21
22 from AthenaCommon.Logging import logging
23 msg = logging.getLogger('findAbsPath')
24 msg.error(f'Cannot find abs path: {path}')
25
26 return None
27
28
29def getRefPath(directory):
30 """ Find reference directory."""
31 referenceTag = os.environ.get('ATLAS_REFERENCE_TAG', 'TileByteStream-02-00-00')
32 directoryPath = find_datafile(os.path.join('TileByteStream', referenceTag))
33 refDirectory = None
34 if directoryPath:
35 refDirectory = os.path.join(directoryPath, directory)
36 if not refDirectory or not os.path.exists(refDirectory):
37 refDirectory = findAbsPath(os.path.join('TileByteStream', referenceTag, directory))
38 return refDirectory
39
40
41def getRefAndDumpDirectories(flags, directory):
42 refDirectory = getRefPath(f'{directory}')
43 dumpDirectory = f'{directory}-{flags.Concurrency.NumThreads}'
44 return refDirectory, dumpDirectory
45
46
47def getInputFile(fileName):
48 """ Find input file. """
49 filePath = os.environ.get('ATLAS_REFERENCE_DATA',
50 '/cvmfs/atlas-nightlies.cern.ch/repo/data/data-art/Tier0ChainTests')
51 inputFile = os.path.join(filePath, fileName)
52 if not os.path.exists(inputFile):
53 inputFile = getRefPath(fileName)
54 return inputFile
55
56
57class Finalizer(Alg):
58 def __init__(self, name=None, **kw):
59 self.refDirectory = ""
60 self.dumpDirectory = ""
61 super(Finalizer, self).__init__(name, **kw)
62
63 def finalize(self):
64 self.msg.info(f'Reference directory: {self.refDirectory}')
65 self.msg.info(f'Dump directory: {self.dumpDirectory}')
66 dumps = glob.glob(os.path.join(self.refDirectory, '*.dump'))
67 for refDump in dumps:
68 localDump = os.path.join(self.dumpDirectory, os.path.basename(refDump))
69 os.system(f'diff -u {refDump} {localDump}')
70 self.msg.info(f'Finalize: compared {len(dumps)} dumps')
71 sys.stdout.flush()
72 return StatusCode.Success
73
74
75def TileDigitsReadTestCfg(flags, refDirectory, dumpDirectory, **kwargs):
76 """ Configure test of reading the Tile digits container from BS """
77
78 from TileByteStream.TileByteStreamConfig import TileRawDataReadingCfg
79 cfg = TileRawDataReadingCfg(flags, readDigits=True, readRawChannel=False, readMuRcv=False, readMuRcvDigits=True)
80
81 TileDigitsDumper = CompFactory.TileDigitsDumper
82 cfg.addEventAlgo(TileDigitsDumper('TileDigitsCntDumper',
83 TileDigitsContainer='TileDigitsCnt',
84 Prefix=f'{dumpDirectory}/'))
85
86 cfg.addEventAlgo(TileDigitsDumper('MuRcvDigitsCntDumper',
87 TileDigitsContainer='MuRcvDigitsCnt',
88 Prefix=f'{dumpDirectory}/'))
89
90 cfg.addEventAlgo(Finalizer('TileDigitsCompareAlg', refDirectory=refDirectory, dumpDirectory=dumpDirectory))
91 return cfg
92
93
94def TileRawChannelReadTestCfg(flags, refDirectory, dumpDirectory, **kwargs):
95 """ Configure test of reading the Tile raw channel container from BS """
96
97 from TileByteStream.TileByteStreamConfig import TileRawDataReadingCfg
98 cfg = TileRawDataReadingCfg(flags, readDigits=False, readRawChannel=True, readMuRcv=False, readMuRcvRawCh=True)
99
100 TileRawChannelDumper = CompFactory.TileRawChannelDumper
101 cfg.addEventAlgo(TileRawChannelDumper('TileRawChannelCntDumper',
102 TileRawChannelContainer='TileRawChannelCnt',
103 Prefix=f'{dumpDirectory}/'))
104
105 cfg.addEventAlgo(TileRawChannelDumper('MuRcvRawChannelCntDumper',
106 TileRawChannelContainer='MuRcvRawChCnt',
107 Prefix=f'{dumpDirectory}/'))
108
109 cfg.addEventAlgo(Finalizer('TileRawChannelCompareAlg', refDirectory=refDirectory, dumpDirectory=dumpDirectory))
110 return cfg
111
112
113def TileLaserObjectReadTestCfg(flags, refDirectory, dumpDirectory, **kwargs):
114 """ Configure test of reading the Tile laser object from BS """
115
116 from TileByteStream.TileByteStreamConfig import TileRawDataReadingCfg
117 cfg = TileRawDataReadingCfg(flags, readDigits=False, readRawChannel=False, readMuRcv=False, readLaserObj=True)
118
119 TileLaserObjectDumper = CompFactory.TileLaserObjectDumper
120 cfg.addEventAlgo(TileLaserObjectDumper('TileLaserObjectDumper',
121 TileLaserObject='TileLaserObj',
122 Prefix=f'{dumpDirectory}/'))
123
124 cfg.addEventAlgo(Finalizer('TileLaserObjCompareAlg', refDirectory=refDirectory, dumpDirectory=dumpDirectory))
125 return cfg
126
127
128def TileL2ReadTestCfg(flags, refDirectory, dumpDirectory, **kwargs):
129 """ Configure test of reading the Tile L2 container from BS """
130
131 from TileByteStream.TileByteStreamConfig import TileRawDataReadingCfg
132 cfg = TileRawDataReadingCfg(flags, readDigits=False, readRawChannel=False, readMuRcv=False, readL2=True)
133
134 TileL2Dumper = CompFactory.TileL2Dumper
135 cfg.addEventAlgo(TileL2Dumper('TileL2CntDumper',
136 TileL2Container='TileL2Cnt',
137 Prefix=f'{dumpDirectory}/'))
138
139 cfg.addEventAlgo(Finalizer('TileL2CompareAlg', refDirectory=refDirectory, dumpDirectory=dumpDirectory))
140 return cfg
141
142
143def TileBeamElemReadTestCfg(flags, refDirectory, dumpDirectory, **kwargs):
144 """ Configure test of reading the Tile beam elements container from BS """
145
146 from TileByteStream.TileByteStreamConfig import TileRawDataReadingCfg
147 cfg = TileRawDataReadingCfg(flags, readDigits=False, readRawChannel=False, readMuRcv=False, readBeamElem=True)
148
149 TileBeamElemDumper = CompFactory.TileBeamElemDumper
150 cfg.addEventAlgo(TileBeamElemDumper('TileBeamElemCntDumper',
151 TileBeamElemContainer='TileBeamElemCnt',
152 Prefix=f'{dumpDirectory}/'))
153
154 cfg.addEventAlgo(Finalizer('TileBeamElemCompareAlg', refDirectory=refDirectory, dumpDirectory=dumpDirectory))
155 return cfg
156
157
158def TileMuRcvReadTestCfg(flags, refDirectory, dumpDirectory, **kwargs):
159 """ Configure test of reading the Tile muon receiver container from BS """
160
161 from TileByteStream.TileByteStreamConfig import TileRawDataReadingCfg
162 cfg = TileRawDataReadingCfg(flags, readDigits=False, readRawChannel=False, readMuRcv=True)
163
164 TileMuonReceiverDumper = CompFactory.TileMuonReceiverDumper
165 cfg.addEventAlgo(TileMuonReceiverDumper('TileMuonReceiverDumper',
166 TileMuonReceiverContainer='TileMuRcvCnt',
167 Prefix=f'{dumpDirectory}/'))
168
169 cfg.addEventAlgo(Finalizer('TileMuRcvCompareAlg', refDirectory=refDirectory, dumpDirectory=dumpDirectory))
170 return cfg
171
172
173if __name__ == "__main__":
174
175 from AthenaConfiguration.AllConfigFlags import initConfigFlags
176 from AthenaConfiguration.TestDefaults import defaultGeometryTags
177 from AthenaCommon.Logging import log
178 from AthenaCommon.Constants import INFO
179
180 # Test setup
181 log.setLevel(INFO)
182
183 flags = initConfigFlags()
184 parser = flags.getArgumentParser()
185 tests_group = parser.add_argument_group('Test of reading Tile raw data from BS')
186 tests = tests_group.add_mutually_exclusive_group()
187 tests.add_argument('--digits', action='store_true', help='Test of reading Tile digits container from BS')
188 tests.add_argument('--murcv', action='store_true', help='Test of reading Tile muon receiver container from BS')
189 tests.add_argument('--level2', action='store_true', help='Test of reading Tile L2 container from BS')
190 tests.add_argument('--raw-channels', dest='rawChannels', action='store_true', help='Test of reading Tile raw channel container from BS')
191 tests.add_argument('--laser-object', dest='laserObject', action='store_true', help='Test of reading Tile laser object from BS')
192 tests.add_argument('--beam-elements', dest='beamElements', action='store_true', help='Test of reading Tile beam elements container from BS')
193 args, _ = parser.parse_known_args()
194
195 if not any([args.digits, args.rawChannels, args.murcv, args.laserObject, args.beamElements, args.level2]):
196 log.info('No tests are requested. Exiting ...')
197 sys.exit(0)
198
199 if any([args.murcv, args.laserObject]):
200 flags.Input.Files = [getInputFile('data18_tilecomm.00363899.calibration_tile.daq.RAW._lb0000._TileREB-ROS._0005-200ev.data')]
201 flags.GeoModel.AtlasVersion = defaultGeometryTags.RUN2
202 else:
203 flags.Input.Files = [getInputFile('data12_8TeV.00204073.physics_JetTauEtmiss.merge.RAW._lb0144._SFO-5._0001.1')]
204 flags.GeoModel.AtlasVersion = defaultGeometryTags.RUN1_2012
205
206 flags.Exec.MaxEvents = 100
207 flags.Tile.RunType = TileRunType.PHY
208 flags.IOVDb.DatabaseInstance = 'CONDBR2'
209 flags.fillFromArgs(parser=parser)
210 flags.lock()
211
212 # Initialize configuration object, add accumulator, merge, and run.
213 from AthenaConfiguration.MainServicesConfig import MainServicesCfg
214 cfg = MainServicesCfg(flags)
215
216 dumpDirectory = None
217 if args.digits:
218 refDirectory, dumpDirectory = getRefAndDumpDirectories(flags, 'TileDigitDumps')
219 cfg.merge( TileDigitsReadTestCfg(flags, refDirectory, dumpDirectory) )
220 elif args.rawChannels:
221 refDirectory, dumpDirectory = getRefAndDumpDirectories(flags, 'TileRawChannelDumps')
222 cfg.merge( TileRawChannelReadTestCfg(flags, refDirectory, dumpDirectory) )
223 elif args.laserObject:
224 refDirectory, dumpDirectory = getRefAndDumpDirectories(flags, 'TileLaserDumps')
225 cfg.merge( TileLaserObjectReadTestCfg(flags, refDirectory, dumpDirectory) )
226 elif args.level2:
227 refDirectory, dumpDirectory = getRefAndDumpDirectories(flags, 'TileL2Dumps')
228 cfg.merge( TileL2ReadTestCfg(flags, refDirectory, dumpDirectory) )
229 elif args.beamElements:
230 refDirectory, dumpDirectory = getRefAndDumpDirectories(flags, 'TileBeamElemDumps')
231 cfg.merge( TileBeamElemReadTestCfg(flags, refDirectory, dumpDirectory) )
232 elif args.murcv:
233 refDirectory, dumpDirectory = getRefAndDumpDirectories(flags, 'TileMuRcvDumps')
234 cfg.merge( TileMuRcvReadTestCfg(flags, refDirectory, dumpDirectory) )
235
236 cfg.printConfig(withDetails=True)
237
238 if dumpDirectory:
239 os.system(f'rm -rf {dumpDirectory}')
240 os.system(f'mkdir -p {dumpDirectory}')
241
242 sc = cfg.run()
243
244 import sys
245 # Success should be 0
246 sys.exit(not sc.isSuccess())
Dump a TileBeamElemContainer to a text file.
Dump a TileDigitsContainer to a text file.
Dump a TileL2Container to a text file.
Dump a TileLaserObject to a text file.
Dump a TileMuonReceiverContainer to a text file.
Dump a TileRawChannelContainer to a text file.
TileRawChannelReadTestCfg(flags, refDirectory, dumpDirectory, **kwargs)
TileMuRcvReadTestCfg(flags, refDirectory, dumpDirectory, **kwargs)
TileL2ReadTestCfg(flags, refDirectory, dumpDirectory, **kwargs)
TileDigitsReadTestCfg(flags, refDirectory, dumpDirectory, **kwargs)
TileBeamElemReadTestCfg(flags, refDirectory, dumpDirectory, **kwargs)
TileLaserObjectReadTestCfg(flags, refDirectory, dumpDirectory, **kwargs)