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
180
181 histnames = hsvc.getHists()
182 currenthists =
set(str(histnames[_])
for _
in range(len(histnames)))
183 for k in currenthists - self.cachednames:
184
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
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)
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