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