ATLAS Offline Software
Loading...
Searching...
No Matches
DataModelTestConfig.py
Go to the documentation of this file.
2# Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration.
3#
4#
5# File: DataModelRunTests/python/DataModelTestConfig.py
6# Author: snyder@bnl.gov
7# Date: Nov 2023
8# Purpose: Helpers for configuration tests.
9#
10
11from AthenaConfiguration.ComponentAccumulator import ComponentAccumulator
12from AthenaConfiguration.AllConfigFlags import initConfigFlags
13from AthenaConfiguration.ComponentFactory import CompFactory
14from AthenaPython.PyAthenaComps import Alg, StatusCode
15from AthenaCommon.Constants import INFO
16
17
18#
19# Common configuration flag settings.
20# Takes an optional input file name and event count.
21# Remaining keyword argument names are interpreted as stream names. Example:
22# flags = DataModelTestFlags (infile = 'SimplePoolFile.root',
23# Stream1 = 'SimplePoolFile2.root')
24#
25def DataModelTestFlags (infile = None, evtMax = 20, **kw):
26 flags = initConfigFlags()
27 flags.addFlag('rntuple', False)
28 flags.Exec.MaxEvents = evtMax
29 flags.Exec.OutputLevel = INFO
30 flags.Common.MsgSourceLength = 18
31
32 # Disable FPE auditing.
33 flags.Exec.FPE = -2
34
35 # Set input/output files.
36 if infile:
37 flags.Input.Files = [infile]
38 for stream, outfile in kw.items():
39 flags.addFlag (f'Output.{stream}FileName', outfile)
40
41 # Block input file peeking.
42 from Campaigns.Utils import Campaign
43 flags.Input.RunNumbers = [0]
44 flags.Input.TimeStamps = [0]
45 flags.Input.ProcessingTags = []
46 flags.Input.TypedCollections = []
47 flags.Input.isMC = True
48 flags.IOVDb.GlobalTag = ''
49 flags.Input.MCCampaign = Campaign.Unknown
50 flags.fillFromArgs()
51
52 if flags.rntuple:
53 flags.Output.StorageTechnology.EventData = {'*' : 'ROOTRNTUPLE'}
54 def to_rntup (s):
55 return s.replace ('.root', '.rntup.root')
56 flags.Input.Files = [to_rntup(f) for f in flags.Input.Files]
57 for stream, outfile in kw.items():
58 setattr (flags.Output, stream+'FileName', to_rntup (outfile))
59
60 return flags
61
62
63#
64# Common configuration for tests.
65#
66def DataModelTestCfg (flags, testName,
67 loadReadDicts = False,
68 loadWriteDicts = False,
69 EventsPerLB = None,
70 TimeStampInterval = None,
71 readCatalog = None):
72 from AthenaConfiguration.MainServicesConfig import \
73 MainServicesCfg, MessageSvcCfg
74 cfg = MainServicesCfg (flags)
75 cfg.merge (MessageSvcCfg (flags))
76 cfg.getService("MessageSvc").debugLimit = 10000
77 cfg.addService (CompFactory.ClassIDSvc (OutputLevel = INFO))
78 cfg.addService (CompFactory.ChronoStatSvc (ChronoPrintOutTable = False,
79 PrintUserTime = False,
80 StatPrintOutTable = False))
81
82 if flags.Input.Files == ['_ATHENA_GENERIC_INPUTFILE_NAME_']:
83 # No input file --- configure like an event generator,
84 # and make an xAODEventInfo.
85 from McEventSelector.McEventSelectorConfig import McEventSelectorCfg
86 mckw = {}
87 if EventsPerLB is not None:
88 mckw['EventsPerLB'] = EventsPerLB
89 if TimeStampInterval is not None:
90 mckw['TimeStampInterval'] = TimeStampInterval
91 cfg.merge (McEventSelectorCfg (flags, **mckw))
92
93 from xAODEventInfoCnv.xAODEventInfoCnvConfig import EventInfoCnvAlgCfg
94 cfg.merge (EventInfoCnvAlgCfg (flags, disableBeamSpot = True))
95 elif not flags.Input.Files[0].endswith ('.bs'):
96 # Configure reading.
97 from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
98 cfg.merge (PoolReadCfg (flags))
99
100 # Load dictionaries if requested.
101 if loadWriteDicts:
102 cfg.merge (LoadWriteDictsCfg (flags))
103 if loadReadDicts:
104 cfg.merge (LoadReadDictsCfg (flags))
105
106 # Prevent races when we run tests in parallel in the same directory.
107 if 'ROOTRNTUPLE' in flags.Output.StorageTechnology.EventData.values():
108 testName = testName + '_rntup'
109 fileCatalog = testName + '_catalog.xml'
110 from AthenaPoolCnvSvc.PoolCommonConfig import PoolSvcCfg
111 kw = {'WriteCatalog' : 'file:' + fileCatalog}
112 if readCatalog:
113 kw['ReadCatalog'] = ['file:' + readCatalog]
114 cfg.merge (PoolSvcCfg (flags, **kw))
115 import os
116 try:
117 os.remove (fileCatalog)
118 except OSError:
119 pass
120
121
122 return cfg
123
124
125#
126# Configure an output stream.
127#
128def TestOutputCfg (flags, stream, itemList, typeNames = [], metaItemList = []):
129 from OutputStreamAthenaPool.OutputStreamConfig import OutputStreamCfg, outputStreamName
130 acc = ComponentAccumulator()
131 itemList = ['xAOD::EventInfo#EventInfo',
132 'xAOD::EventAuxInfo#EventInfoAux.'] + itemList
133 helperTools = []
134 metaItemList = ["IOVMetaDataContainer#*"]
135 if typeNames:
136 helperTools = [ CompFactory.xAODMaker.EventFormatStreamHelperTool(
137 f'{stream}_EventFormatStreamHelperTool',
138 Key = f'EventFormat{stream}',
139 TypeNames = typeNames,
140 DataHeaderKey = f'Stream{stream}') ]
141 metaItemList = [ f'xAOD::EventFormat#EventFormat{stream}' ] + metaItemList
142 acc.merge (OutputStreamCfg (flags, stream,
143 ItemList = itemList,
144 HelperTools = helperTools,
145 MetadataItemList = metaItemList))
146 if typeNames:
147 alg = acc.getEventAlgo (outputStreamName(stream))
148 alg.WritingTool.SubLevelBranchName = '<key>'
149 acc.getService ('AthenaPoolCnvSvc').PoolAttributes += ["DEFAULT_SPLITLEVEL='1'"]
150 return acc
151
152
153
154
155# Arrange to get dictionaries loaded for write tests.
156# Do this as an algorithm so we can defer it to initialize().
157# In some cases, loading DSOs during initial python processing
158# can cause component loading to fail.
159class LoadWriteDicts (Alg):
160 def __init__ (self, name = 'LoadWriteDicts', **kw):
161 super(LoadWriteDicts, self).__init__ (name=name, **kw)
162 def initialize (self):
163 import ROOT
164 ROOT.gROOT.SetBatch(True)
165 import cppyy
166 cppyy.load_library("libDataModelTestDataCommonDict")
167 cppyy.load_library("libDataModelTestDataWriteDict")
168 cppyy.load_library("libDataModelTestDataWriteCnvDict")
169 ROOT.DMTest.B
170 ROOT.DMTest.setConverterLibrary ('libDataModelTestDataWriteCnvPoolCnv.so')
171 ROOT.DMTest.setTrigConverterLibrary ('libDataModelTestDataWriteSerCnv.so')
172 return StatusCode.Success
173
174
176 acc = ComponentAccumulator()
177 acc.addEventAlgo (LoadWriteDicts())
178 return acc
179
180
181# Arrange to get dictionaries loaded for read tests.
182# Do this as an algorithm so we can defer it to initialize().
183# In some cases, loading DSOs during initial python processing
184# can cause component loading to fail.
185class LoadReadDicts (Alg):
186 def __init__ (self, name = 'LoadReadDicts', **kw):
187 super(LoadReadDicts, self).__init__ (name=name, **kw)
188 def initialize (self):
189 import ROOT
190 ROOT.gROOT.SetBatch(True)
191 import cppyy
192 cppyy.load_library("libDataModelTestDataCommonDict")
193 cppyy.load_library("libDataModelTestDataReadDict")
194 ROOT.DMTest.B
195 ROOT.gROOT.GetClass('DMTest::HAuxContainer_v1')
196 ROOT.gROOT.GetClass('DataVector<DMTest::H_v1>')
197 ROOT.gROOT.GetClass('DMTest::HView_v1')
198 ROOT.DMTest.setConverterLibrary ('libDataModelTestDataReadCnvPoolCnv.so')
199 ROOT.DMTest.setTrigConverterLibrary ('libDataModelTestDataReadSerCnv.so')
200 return StatusCode.Success
201
203 acc = ComponentAccumulator()
204 acc.addEventAlgo (LoadReadDicts())
205 return acc
206
207
208def rnt (flags):
209 is_rntuple = 'ROOTRNTUPLE' in flags.Output.StorageTechnology.EventData.values()
210 if is_rntuple:
211 return True, lambda k: ''
212 return False, lambda k:k
213
__init__(self, name='LoadReadDicts', **kw)
__init__(self, name='LoadWriteDicts', **kw)
TestOutputCfg(flags, stream, itemList, typeNames=[], metaItemList=[])
DataModelTestFlags(infile=None, evtMax=20, **kw)
DataModelTestCfg(flags, testName, loadReadDicts=False, loadWriteDicts=False, EventsPerLB=None, TimeStampInterval=None, readCatalog=None)
void initialize()