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.PoolSvc.DefaultContainerType = '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 cfg.addService (CompFactory.DataModelCompatSvc (), create = True)
82
83 if flags.Input.Files == ['_ATHENA_GENERIC_INPUTFILE_NAME_']:
84 # No input file --- configure like an event generator,
85 # and make an xAODEventInfo.
86 from McEventSelector.McEventSelectorConfig import McEventSelectorCfg
87 mckw = {}
88 if EventsPerLB is not None:
89 mckw['EventsPerLB'] = EventsPerLB
90 if TimeStampInterval is not None:
91 mckw['TimeStampInterval'] = TimeStampInterval
92 cfg.merge (McEventSelectorCfg (flags, **mckw))
93
94 from xAODEventInfoCnv.xAODEventInfoCnvConfig import EventInfoCnvAlgCfg
95 cfg.merge (EventInfoCnvAlgCfg (flags, disableBeamSpot = True))
96 elif not flags.Input.Files[0].endswith ('.bs'):
97 # Configure reading.
98 from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
99 cfg.merge (PoolReadCfg (flags))
100
101 # Load dictionaries if requested.
102 if loadWriteDicts:
103 cfg.merge (LoadWriteDictsCfg (flags))
104 if loadReadDicts:
105 cfg.merge (LoadReadDictsCfg (flags))
106
107 # Prevent races when we run tests in parallel in the same directory.
108 if 'ROOTRNTUPLE' in flags.PoolSvc.DefaultContainerType:
109 testName = testName + '_rntup'
110 fileCatalog = testName + '_catalog.xml'
111 from AthenaPoolCnvSvc.PoolCommonConfig import PoolSvcCfg
112 kw = {'WriteCatalog' : 'file:' + fileCatalog}
113 if readCatalog:
114 kw['ReadCatalog'] = ['file:' + readCatalog]
115 cfg.merge (PoolSvcCfg (flags, **kw))
116 import os
117 try:
118 os.remove (fileCatalog)
119 except OSError:
120 pass
121
122
123 return cfg
124
125
126#
127# Configure an output stream.
128#
129def TestOutputCfg (flags, stream, itemList, typeNames = [], metaItemList = []):
130 from OutputStreamAthenaPool.OutputStreamConfig import OutputStreamCfg, outputStreamName
131 acc = ComponentAccumulator()
132 itemList = ['xAOD::EventInfo#EventInfo',
133 'xAOD::EventAuxInfo#EventInfoAux.'] + itemList
134 helperTools = []
135 metaItemList = ["IOVMetaDataContainer#*"]
136 if typeNames:
137 helperTools = [ CompFactory.xAODMaker.EventFormatStreamHelperTool(
138 f'{stream}_EventFormatStreamHelperTool',
139 Key = f'EventFormat{stream}',
140 TypeNames = typeNames,
141 DataHeaderKey = f'Stream{stream}') ]
142 metaItemList = [ f'xAOD::EventFormat#EventFormat{stream}' ] + metaItemList
143 acc.merge (OutputStreamCfg (flags, stream,
144 ItemList = itemList,
145 HelperTools = helperTools,
146 MetadataItemList = metaItemList))
147 if typeNames:
148 alg = acc.getEventAlgo (outputStreamName(stream))
149 alg.WritingTool.SubLevelBranchName = '<key>'
150 acc.getService ('AthenaPoolCnvSvc').PoolAttributes += ["DEFAULT_SPLITLEVEL='1'"]
151 return acc
152
153
154
155
156# Arrange to get dictionaries loaded for write tests.
157# Do this as an algorithm so we can defer it to initialize().
158# In some cases, loading DSOs during initial python processing
159# can cause component loading to fail.
160class LoadWriteDicts (Alg):
161 def __init__ (self, name = 'LoadWriteDicts', **kw):
162 super(LoadWriteDicts, self).__init__ (name=name, **kw)
163 def initialize (self):
164 import ROOT
165 ROOT.gROOT.SetBatch(True)
166 import cppyy
167 cppyy.load_library("libDataModelTestDataCommonDict")
168 cppyy.load_library("libDataModelTestDataWriteDict")
169 cppyy.load_library("libDataModelTestDataWriteCnvDict")
170 ROOT.DMTest.B
171 ROOT.DMTest.setConverterLibrary ('libDataModelTestDataWriteCnvPoolCnv.so')
172 ROOT.DMTest.setTrigConverterLibrary ('libDataModelTestDataWriteSerCnv.so')
173 return StatusCode.Success
174
175
177 acc = ComponentAccumulator()
178 acc.addEventAlgo (LoadWriteDicts())
179 return acc
180
181
182# Arrange to get dictionaries loaded for read tests.
183# Do this as an algorithm so we can defer it to initialize().
184# In some cases, loading DSOs during initial python processing
185# can cause component loading to fail.
186class LoadReadDicts (Alg):
187 def __init__ (self, name = 'LoadReadDicts', **kw):
188 super(LoadReadDicts, self).__init__ (name=name, **kw)
189 def initialize (self):
190 import ROOT
191 ROOT.gROOT.SetBatch(True)
192 import cppyy
193 cppyy.load_library("libDataModelTestDataCommonDict")
194 cppyy.load_library("libDataModelTestDataReadDict")
195 ROOT.DMTest.B
196 ROOT.gROOT.GetClass('DMTest::HAuxContainer_v1')
197 ROOT.gROOT.GetClass('DataVector<DMTest::H_v1>')
198 ROOT.gROOT.GetClass('DMTest::HView_v1')
199 ROOT.DMTest.setConverterLibrary ('libDataModelTestDataReadCnvPoolCnv.so')
200 ROOT.DMTest.setTrigConverterLibrary ('libDataModelTestDataReadSerCnv.so')
201 return StatusCode.Success
202
204 acc = ComponentAccumulator()
205 acc.addEventAlgo (LoadReadDicts())
206 return acc
207
208
209def rnt (flags):
210 is_rntuple = 'ROOTRNTUPLE' in flags.PoolSvc.DefaultContainerType
211 if is_rntuple:
212 return True, lambda k: ''
213 return False, lambda k:k
214
__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()