ATLAS Offline Software
Loading...
Searching...
No Matches
python.DQPostProcessingAlg.AthOutputModule Class Reference
Inheritance diagram for python.DQPostProcessingAlg.AthOutputModule:
Collaboration diagram for python.DQPostProcessingAlg.AthOutputModule:

Public Member Functions

 __init__ (self)
None configure (self, Mapping[str, Any] options)
None publish (self, Union[HistObject, Iterable[HistObject]] obj)
None finalize (self)

Public Attributes

 target = None
 overwrite = bool(options.get('overwrite', True))
 prefix = options.get('prefix', '/')
 delay = bool(options.get('delay', True))
dict queue = {}

Protected Member Functions

None _write (self)

Protected Attributes

dict _hsvc_funcs

Detailed Description

Definition at line 226 of file DQPostProcessingAlg.py.

Constructor & Destructor Documentation

◆ __init__()

python.DQPostProcessingAlg.AthOutputModule.__init__ ( self)

Definition at line 227 of file DQPostProcessingAlg.py.

227 def __init__(self):
228 self.target = None
229

Member Function Documentation

◆ _write()

None python.DQPostProcessingAlg.AthOutputModule._write ( self)
protected
write obj to THistSvc 

Definition at line 274 of file DQPostProcessingAlg.py.

274 def _write(self) -> None:
275 """ write obj to THistSvc """
276 import ROOT
277 import os.path
278 if not self.queue:
279 return # Nothing to do
280 log = self.target.msg
281 hsvc = self.target.hsvc
282 for _, o in self.queue.items():
283 fulltargetname = os.path.join(self.prefix, o.name) % { 'run': self.target._run }
284 log.debug(f"Attempt to publish {fulltargetname} of type {type(o.hist)}")
285 # it would be perverse if the type of the postprocessing output changed
286 # between invocations and we will not consider it
287 if isinstance(o.hist, ROOT.TH1):
288 funcs = self._hsvc_funcs['hist']
289 parenttype = ROOT.TH1
290 elif isinstance(o.hist, ROOT.TGraph):
291 funcs = self._hsvc_funcs['graph']
292 parenttype = ROOT.TGraph
293 elif isinstance(o.hist, ROOT.TEfficiency):
294 funcs = self._hsvc_funcs['eff']
295 parenttype = ROOT.TEfficiency
296 else:
297 log.warning(f'Do not know how to handle object {fulltargetname} of type {type(o.hist)}; skipping')
298 continue
299 o.hist.SetName(os.path.basename(fulltargetname))
300 if funcs['exists'](fulltargetname):
301 # following kind of silly procedure is necessary to avoid memory leaks
302 hptr = ROOT.MakeNullPointer(parenttype)
303 if funcs['get'](fulltargetname, hptr).isSuccess():
304 hsvc.deReg(hptr)
305 ROOT.SetOwnership(hptr, True) # clean up the histogram from our side
306 if not funcs['reg'](fulltargetname, o.hist).isSuccess():
307 log.error(f"Unable to register {fulltargetname}")
308 else:
309 ROOT.SetOwnership(o.hist, False)
310 log.debug("Published")
311 self.queue.clear()
312

◆ configure()

None python.DQPostProcessingAlg.AthOutputModule.configure ( self,
Mapping[str, Any] options )
Configure this module. Potential elements of "options":
target: should be a ROOT-openable filename or URL which
    can be opened for writing.
prefix: directory path to place results under.
overwrite: boolean to indicate whether results should overwrite
    existing histograms in the file.
delay: only write histograms in finalize() (not during publish()).

Definition at line 230 of file DQPostProcessingAlg.py.

230 def configure(self, options: Mapping[str, Any]) -> None:
231 """
232 Configure this module. Potential elements of "options":
233 target: should be a ROOT-openable filename or URL which
234 can be opened for writing.
235 prefix: directory path to place results under.
236 overwrite: boolean to indicate whether results should overwrite
237 existing histograms in the file.
238 delay: only write histograms in finalize() (not during publish()).
239 """
240 if 'target' not in options:
241 raise ValueError("Must specify 'target' as an option "
242 "to AthInputModule")
243 self.target = options['target']
244 self.overwrite = bool(options.get('overwrite', True))
245 self.prefix = options.get('prefix', '/')
246 self.delay = bool(options.get('delay', True))
247 self.queue: Optional[Dict[str, HistObject]] = {}
248 self._hsvc_funcs = {'hist': { 'exists': self.target.hsvc.existsHist,
249 'get': self.target.hsvc.getHist,
250 'reg': self.target.hsvc._cpp_regHist },
251 'graph': { 'exists': self.target.hsvc.existsGraph,
252 'get': self.target.hsvc.getGraph,
253 'reg': self.target.hsvc._cpp_regGraph },
254 'eff': { 'exists': self.target.hsvc.existsEfficiency,
255 'get': self.target.hsvc.getEfficiency,
256 'reg': self.target.hsvc._cpp_regEfficiency },
257 }
258
bool configure(asg::AnaToolHandle< ITrigGlobalEfficiencyCorrectionTool > &tool, ToolHandleArray< IAsgElectronEfficiencyCorrectionTool > &electronEffToolsHandles, ToolHandleArray< IAsgElectronEfficiencyCorrectionTool > &electronSFToolsHandles, ToolHandleArray< CP::IMuonTriggerScaleFactors > &muonToolsHandles, ToolHandleArray< IAsgPhotonEfficiencyCorrectionTool > &photonEffToolsHandles, ToolHandleArray< IAsgPhotonEfficiencyCorrectionTool > &photonSFToolsHandles, const std::string &triggers, const std::map< std::string, std::string > &legsPerTool, unsigned long nToys, bool debug)

◆ finalize()

None python.DQPostProcessingAlg.AthOutputModule.finalize ( self)
Outputs outstanding HistObjects 

Definition at line 313 of file DQPostProcessingAlg.py.

313 def finalize(self) -> None:
314 """ Outputs outstanding HistObjects """
315 self._write()

◆ publish()

None python.DQPostProcessingAlg.AthOutputModule.publish ( self,
Union[HistObject, Iterable[HistObject]] obj )
Accepts a HistObject containing a ROOT object to write to file 

Definition at line 259 of file DQPostProcessingAlg.py.

259 def publish(self, obj: Union[HistObject, Iterable[HistObject]]) -> None:
260 """ Accepts a HistObject containing a ROOT object to write to file """
261 if isinstance(obj, HistObject):
262 obj = [obj]
263 d_obj = { _.name: _ for _ in obj }
264 if self.delay:
265 if not self.queue:
266 self.queue = d_obj
267 else:
268 self.queue.update(d_obj)
269 else:
270 self.queue = d_obj
271 self._write()
272 self.queue = None
273

Member Data Documentation

◆ _hsvc_funcs

dict python.DQPostProcessingAlg.AthOutputModule._hsvc_funcs
protected
Initial value:
= {'hist': { 'exists': self.target.hsvc.existsHist,
'get': self.target.hsvc.getHist,
'reg': self.target.hsvc._cpp_regHist },
'graph': { 'exists': self.target.hsvc.existsGraph,
'get': self.target.hsvc.getGraph,
'reg': self.target.hsvc._cpp_regGraph },
'eff': { 'exists': self.target.hsvc.existsEfficiency,
'get': self.target.hsvc.getEfficiency,
'reg': self.target.hsvc._cpp_regEfficiency },
}

Definition at line 248 of file DQPostProcessingAlg.py.

◆ delay

python.DQPostProcessingAlg.AthOutputModule.delay = bool(options.get('delay', True))

Definition at line 246 of file DQPostProcessingAlg.py.

◆ overwrite

python.DQPostProcessingAlg.AthOutputModule.overwrite = bool(options.get('overwrite', True))

Definition at line 244 of file DQPostProcessingAlg.py.

◆ prefix

python.DQPostProcessingAlg.AthOutputModule.prefix = options.get('prefix', '/')

Definition at line 245 of file DQPostProcessingAlg.py.

◆ queue

dict python.DQPostProcessingAlg.AthOutputModule.queue = {}

Definition at line 247 of file DQPostProcessingAlg.py.

◆ target

python.DQPostProcessingAlg.AthOutputModule.target = None

Definition at line 228 of file DQPostProcessingAlg.py.


The documentation for this class was generated from the following file: