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

Public Member Functions

 __init__ (self)
None configure (self, Mapping[str, Any] options)
None setSelectors (self, Collection[Pattern] selectors)
Generator[HistObject, None, Noneiterate (self, dryrun)
Iterator[HistObject] __iter__ (self)
Iterable[HistObject] warmup (self)

Public Attributes

 source = None
 classwarnings = set()
 selectors = None
dict entries = {}
 prefix = options.get('prefix', '/')
 cachednames = set()
dict matchednames = {}

Protected Member Functions

 _getklass (self, k)

Detailed Description

Definition at line 135 of file DQPostProcessingAlg.py.

Constructor & Destructor Documentation

◆ __init__()

python.DQPostProcessingAlg.AthInputModule.__init__ ( self)

Definition at line 136 of file DQPostProcessingAlg.py.

136 def __init__(self):
137 self.source = None
138 self.classwarnings = set()
139 self.selectors = None
140 self.entries = {}
141
STL class.

Member Function Documentation

◆ __iter__()

Iterator[HistObject] python.DQPostProcessingAlg.AthInputModule.__iter__ ( self)

Definition at line 220 of file DQPostProcessingAlg.py.

220 def __iter__(self) -> Iterator[HistObject]:
221 return self.iterate(dryrun=False)
222

◆ _getklass()

python.DQPostProcessingAlg.AthInputModule._getklass ( self,
k )
protected

Definition at line 161 of file DQPostProcessingAlg.py.

161 def _getklass(self, k):
162 import ROOT
163 hsvc = self.source.hsvc
164 if hsvc.existsHist(k):
165 hptr = ROOT.MakeNullPointer(ROOT.TH1)
166 if hsvc.getHist(k, hptr).isSuccess():
167 klass = getattr(ROOT, hptr.ClassName())
168 return klass
169 return None
170

◆ configure()

None python.DQPostProcessingAlg.AthInputModule.configure ( self,
Mapping[str, Any] options )
Configure this module. Potential elements of "options":
source: should be a ROOT-openable filename or URL.
prefix: directory path to search under. Returned histogram names
    will not include this.

Definition at line 142 of file DQPostProcessingAlg.py.

142 def configure(self, options: Mapping[str, Any]) -> None:
143 """
144 Configure this module. Potential elements of "options":
145 source: should be a ROOT-openable filename or URL.
146 prefix: directory path to search under. Returned histogram names
147 will not include this.
148 """
149 if 'source' not in options:
150 raise ValueError("Must specify 'source' as an "
151 "option to AthInputModule")
152 self.source = options['source']
153 self.prefix = options.get('prefix', '/')
154 self.cachednames = set()
155 self.matchednames = {}
156
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)

◆ iterate()

Generator[HistObject, None, None] python.DQPostProcessingAlg.AthInputModule.iterate ( self,
dryrun )
Iterate over all histograms in THistSvc 

Definition at line 171 of file DQPostProcessingAlg.py.

171 def iterate(self, dryrun) -> Generator[HistObject, None, None]:
172 """ Iterate over all histograms in THistSvc """
173 import ROOT
174 log = self.source.msg
175 specprefix = self.prefix % { 'run': self.source._run }
176 log.debug(f'Would like to match {specprefix}')
177 hsvc = self.source.hsvc
178
179 # check if we have new histograms; if so, check against selectors to see if we're interested
180 # weirdly unpythonic code to avoid memory leak in iterators pre-ROOT 6.26
181 histnames = hsvc.getHists()
182 currenthists = set(str(histnames[_]) for _ in range(len(histnames)))
183 for k in currenthists - self.cachednames:
184 # log.info(f'We have ... ? {k}')
185 if not k.startswith(specprefix):
186 continue
187 shortk = k.replace(specprefix, '', 1)
188 if self.selectors is not None:
189 if not any(_.match(shortk) for _ in self.selectors):
190 continue
191 self.matchednames[k] = None
192 self.cachednames.update(currenthists)
193 log.debug(f'We now have {len(self.cachednames)} entries in our cache, of {len(currenthists)} total plots')
194 log.debug(f'There are {len(self.matchednames)} matches to be considered')
195
196 # postprocess only matched histograms
197 for k, klass in self.matchednames.items():
198 if dryrun:
199 yield HistObject(k.replace(specprefix, '', 1), None)
200
201 log.debug(f'THistSvc input trying to read {k}')
202 if klass is None:
203 klass = self._getklass(k)
204 self.matchednames[k] = klass
205 hptr = ROOT.MakeNullPointer(klass)
206 if hsvc.getHist(k, hptr).isSuccess():
207 log.debug(f'THistSvc input read {k} as {type(hptr)}')
208 obj = hptr
209 ROOT.SetOwnership(obj, False) # no NOT attempt to GC histograms read from THistSvc
210 if k in self.entries:
211 if obj.GetEntries() == self.entries[k]:
212 continue
213 self.entries[k] = obj.GetEntries()
214 yield HistObject(k.replace(specprefix, '', 1), obj)
215 else:
216 log.error(f'Cannot read {k}')
217
218 log.debug('Done on input side')
219

◆ setSelectors()

None python.DQPostProcessingAlg.AthInputModule.setSelectors ( self,
Collection[Pattern] selectors )
Do more later 

Definition at line 157 of file DQPostProcessingAlg.py.

157 def setSelectors(self, selectors: Collection[Pattern]) -> None:
158 """ Do more later """
159 self.selectors = selectors
160

◆ warmup()

Iterable[HistObject] python.DQPostProcessingAlg.AthInputModule.warmup ( self)

Definition at line 223 of file DQPostProcessingAlg.py.

223 def warmup(self) -> Iterable[HistObject]:
224 return self.iterate(dryrun=True)
225

Member Data Documentation

◆ cachednames

python.DQPostProcessingAlg.AthInputModule.cachednames = set()

Definition at line 154 of file DQPostProcessingAlg.py.

◆ classwarnings

python.DQPostProcessingAlg.AthInputModule.classwarnings = set()

Definition at line 138 of file DQPostProcessingAlg.py.

◆ entries

dict python.DQPostProcessingAlg.AthInputModule.entries = {}

Definition at line 140 of file DQPostProcessingAlg.py.

◆ matchednames

dict python.DQPostProcessingAlg.AthInputModule.matchednames = {}

Definition at line 155 of file DQPostProcessingAlg.py.

◆ prefix

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

Definition at line 153 of file DQPostProcessingAlg.py.

◆ selectors

python.DQPostProcessingAlg.AthInputModule.selectors = None

Definition at line 139 of file DQPostProcessingAlg.py.

◆ source

python.DQPostProcessingAlg.AthInputModule.source = None

Definition at line 137 of file DQPostProcessingAlg.py.


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