ATLAS Offline Software
Loading...
Searching...
No Matches
AthenaCommonFlags.py
Go to the documentation of this file.
1# Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
2
3
7
8""" AthenaCommonFlags
9 Python module to hold common flags to configure JobOptions.
10
11 From the python prompt:
12 >>> from AthenaCommon.AthenaCommonFlags import athenaCommonFlags
13 >>> print athenaCommonFlags.EvtMax()
14 >>> athenaCommonFlags.EvtMax = 50
15 >>> assert( athenaCommonFlags.EvtMax() == 50 )
16 >>> athenaCommonFlags.print_JobProperties('tree&value')
17
18"""
19
20__author__ = "S.Binet, M.Gallas"
21__version__= "$Revision: 1.11 $"
22__doc__ = "AthenaCommonFlags"
23
24__all__ = [ "athenaCommonFlags" ]
25
26
28
29from AthenaCommon.JobProperties import JobProperty, JobPropertyContainer
30from AthenaCommon.JobProperties import jobproperties
31
32
34
35class EvtMax(JobProperty):
36 """Number of events to process or generate"""
37 statusOn = False
38 allowedTypes = ['int']
39 StoredValue = 5
40
41class SkipEvents(JobProperty):
42 """Number of events to skip when reading an input POOL file. This should
43 be given to the EventSelector service.
44 """
45 statusOn = False
46 allowedTypes = ['int']
47 StoredValue = 0
48
49class FilesInput(JobProperty):
50 """The list of input data files (if not empty override all the specific XYZInput) """
51 statusOn = True
52 allowedTypes = ['list']
53 StoredValue = []
54
55 def _do_action( self, *args, **kwds ):
56 #first remove any blanks
57 if "" in self.StoredValue:
58 self.StoredValue = list(filter(None,self.StoredValue))
59 from AthenaCommon import AppMgr
60 if hasattr(AppMgr.ServiceMgr,"EventSelector") and hasattr(AppMgr.ServiceMgr.EventSelector,"InputCollections"):
61 AppMgr.ServiceMgr.EventSelector.InputCollections = self.StoredValue
62
63 pass
64
65class TreeName(JobProperty):
66 """The name of the ttree in the input file"""
67 statusOn = True
68 allowedType = "str"
69 StoredValue = "CollectionTree"
70
71 def _do_action( self, *args, **kwds ):
72 from AthenaCommon import AppMgr
73 if not hasattr(AppMgr.ServiceMgr,"EventSelector"):
74 #assume the TreeAccess mode then ..
75 jobproperties.AthenaCommonFlags.AccessMode="TreeAccess"
76
77 if not hasattr(AppMgr.ServiceMgr.EventSelector,"TupleName"):
78 if self.StoredValue != "CollectionTree":
79 raise ValueError("TreeName can only be CollectionTree if you are not using AccessMode=TreeAccess")
80 else:
81 AppMgr.ServiceMgr.EventSelector.TupleName = self.StoredValue
82
83
84class AccessMode(JobProperty):
85 """The type of read mechanism to use in this athena job"""
86 statusOn = True
87 allowedType = "str"
88 allowedValues = ["TreeAccess","TreeAccessWithEventInfo","BranchAccess","ClassAccess","AthenaAccess","POOLAccess"]
89 StoredValue = "ClassAccess"
90
91 def _do_action( self, *args, **kwds ):
92 from AthenaCommon import AppMgr
93
94 if self.StoredValue in ["ClassAccess","AthenaAccess","BranchAccess"]:
95 if hasattr(AppMgr.ServiceMgr,"EventSelector"):
96 if AppMgr.ServiceMgr.EventSelector.getType()!="Athena::xAODEventSelector":
97 raise ValueError("Cannot switch to %s mode with existing EventSelector of type %s" % (self.StoredValue,AppMgr.ServiceMgr.EventSelector.getType()) )
98 else:
99 import AthenaRootComps.ReadAthenaxAODHybrid # noqa: F401
100 if self.StoredValue=="ClassAccess": AppMgr.ServiceMgr.EventSelector.AccessMode = 1
101 elif self.StoredValue=="BranchAccess": AppMgr.ServiceMgr.EventSelector.AccessMode = 0
102 elif self.StoredValue=="AthenaAccess": AppMgr.ServiceMgr.EventSelector.AccessMode = 2
103 elif self.StoredValue=="POOLAccess":
104 if hasattr(AppMgr.ServiceMgr,"EventSelector"):
105 if AppMgr.ServiceMgr.EventSelector.getType()!="EventSelectorAthenaPool":
106 raise ValueError("Cannot switch to %s mode with existing EventSelector of type %s" % (self.StoredValue,AppMgr.ServiceMgr.EventSelector.getType()) )
107 else:
108 import AthenaPoolCnvSvc.ReadAthenaPool # noqa: F401
109 elif self.StoredValue=="TreeAccess" or self.StoredValue=="TreeAccessWithEventInfo":
110 if hasattr(AppMgr.ServiceMgr,"EventSelector"):
111 if AppMgr.ServiceMgr.EventSelector.getType()!="Athena::RootNtupleEventSelector":
112 raise ValueError("Cannot switch to %s mode with existing EventSelector of type %s" % (self.StoredValue,AppMgr.ServiceMgr.EventSelector.getType()) )
113 else:
114 import AthenaRootComps.ReadAthenaRoot # noqa: F401
115 AppMgr.ServiceMgr.EventSelector.TupleName = jobproperties.AthenaCommonFlags.TreeName()
116 if self.StoredValue=="TreeAccessWithEventInfo":
117 AppMgr.ServiceMgr.EventSelector.CreateEventInfo = True
118 AppMgr.ServiceMgr.AthenaEventLoopMgr.DoLiteLoop = False
119
120
121class HistOutputs(JobProperty):
122 """A list of outputs to be produced by THistSvc in the format <streamName>:<fileName>"""
123 statusOn = True
124 allowedTypes = ['list']
125 StoredValue = []
126
127 def _do_action( self, *args, **kwds ):
128 from AthenaCommon import CfgMgr
129 from AthenaCommon import AppMgr
130 if not hasattr(AppMgr.ServiceMgr,"THistSvc"):
131 AppMgr.ServiceMgr += CfgMgr.THistSvc()
132
133 for output in self.StoredValue:
134 if ":" not in output:
135 self.StoredValue.remove(output)
136 raise ValueError("HistOutputs: %s must be in format '<streamName>:<fileName>'" % output)
137
138 streamName = output.split(":",1)[0]
139 fileName = output.split(":",1)[1]
140
141 #check the THistSvc has the stream, if not we create it
142 outputs = AppMgr.ServiceMgr.THistSvc.Output
143 foundStream=False
144 for hsOutput in outputs:
145 hsStreamName = hsOutput.split(" ",1)[0]
146 if hsStreamName==streamName:
147 foundStream=True
148 break
149 if not foundStream:
150 AppMgr.ServiceMgr.THistSvc.Output += ["%s DATAFILE='%s' OPT='RECREATE'" % (streamName,fileName)]
151
152
153class AllowIgnoreConfigError(JobProperty):
154 """Allow an algorithm to ignore return error code from upstream algorithm
155 and tools.
156 """
157 statusOn = True
158 allowedTypes = ['bool']
159 StoredValue = True
160
161class isOnline(JobProperty):
162 """ Set to True when running online
163 """
164 statusOn = True
165 allowedTypes = ['bool']
166 StoredValue = False
167
168
169
172class AthenaCommonFlags(JobPropertyContainer):
173 """Container for the common flags
174 """
175 pass
176
177
180jobproperties.add_Container(AthenaCommonFlags)
181
182
185jobproperties.AthenaCommonFlags.add_JobProperty(EvtMax)
186jobproperties.AthenaCommonFlags.add_JobProperty(SkipEvents)
187jobproperties.AthenaCommonFlags.add_JobProperty(FilesInput )
188jobproperties.AthenaCommonFlags.add_JobProperty(TreeName)
189jobproperties.AthenaCommonFlags.add_JobProperty(AccessMode)
190jobproperties.AthenaCommonFlags.add_JobProperty(HistOutputs)
191jobproperties.AthenaCommonFlags.add_JobProperty(AllowIgnoreConfigError)
192jobproperties.AthenaCommonFlags.add_JobProperty(isOnline)
193
194
201athenaCommonFlags = jobproperties.AthenaCommonFlags