ATLAS Offline Software
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 
29 from AthenaCommon.JobProperties import JobProperty, JobPropertyContainer
30 from AthenaCommon.JobProperties import jobproperties
31 
32 
34 
35 class EvtMax(JobProperty):
36  """Number of events to process or generate"""
37  statusOn = False
38  allowedTypes = ['int']
39  StoredValue = 5
40 
41 class 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 
49 class 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 
65 class 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 
84 class 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 
121 class 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 
153 class 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 
161 class isOnline(JobProperty):
162  """ Set to True when running online
163  """
164  statusOn = True
165  allowedTypes = ['bool']
166  StoredValue = False
167 
168 
169 
172 class AthenaCommonFlags(JobPropertyContainer):
173  """Container for the common flags
174  """
175  pass
176 
177 
180 jobproperties.add_Container(AthenaCommonFlags)
181 
182 
185 jobproperties.AthenaCommonFlags.add_JobProperty(EvtMax)
186 jobproperties.AthenaCommonFlags.add_JobProperty(SkipEvents)
187 jobproperties.AthenaCommonFlags.add_JobProperty(FilesInput )
188 jobproperties.AthenaCommonFlags.add_JobProperty(TreeName)
189 jobproperties.AthenaCommonFlags.add_JobProperty(AccessMode)
190 jobproperties.AthenaCommonFlags.add_JobProperty(HistOutputs)
191 jobproperties.AthenaCommonFlags.add_JobProperty(AllowIgnoreConfigError)
192 jobproperties.AthenaCommonFlags.add_JobProperty(isOnline)
193 
194 
201 athenaCommonFlags = jobproperties.AthenaCommonFlags
python.AthenaCommonFlags.FilesInput
Definition: AthenaCommonFlags.py:49
python.AthenaCommonFlags.TreeName
Definition: AthenaCommonFlags.py:65
python.AthenaCommonFlags.FilesInput.StoredValue
list StoredValue
Definition: AthenaCommonFlags.py:53
python.AthenaCommonFlags.FilesInput._do_action
def _do_action(self, *args, **kwds)
Definition: AthenaCommonFlags.py:55
python.AthenaCommonFlags.HistOutputs._do_action
def _do_action(self, *args, **kwds)
Definition: AthenaCommonFlags.py:127
python.AthenaCommonFlags.TreeName._do_action
def _do_action(self, *args, **kwds)
Definition: AthenaCommonFlags.py:71
covarianceTool.filter
filter
Definition: covarianceTool.py:514
PixelModuleFeMask_create_db.remove
string remove
Definition: PixelModuleFeMask_create_db.py:83
python.AthenaCommonFlags.AthenaCommonFlags
Definition: AthenaCommonFlags.py:172
python.AthenaCommonFlags.HistOutputs
Definition: AthenaCommonFlags.py:121
python.AthenaCommonFlags.EvtMax
Definition: AthenaCommonFlags.py:35
python.AthenaCommonFlags.isOnline
Definition: AthenaCommonFlags.py:161
python.AthenaCommonFlags.SkipEvents
Definition: AthenaCommonFlags.py:41
histSizes.list
def list(name, path='/')
Definition: histSizes.py:38
python.AthenaCommonFlags.AccessMode._do_action
def _do_action(self, *args, **kwds)
Definition: AthenaCommonFlags.py:91
python.AthenaCommonFlags.AccessMode.StoredValue
string StoredValue
Definition: AthenaCommonFlags.py:89
python.AthenaCommonFlags.HistOutputs.StoredValue
list StoredValue
Definition: AthenaCommonFlags.py:125
python.AthenaCommonFlags.TreeName.StoredValue
string StoredValue
Definition: AthenaCommonFlags.py:69
python.AthenaCommonFlags.AllowIgnoreConfigError
Definition: AthenaCommonFlags.py:153
python.AthenaCommonFlags.AccessMode
Definition: AthenaCommonFlags.py:84