CMS 3D CMS Logo

List of all members | Public Member Functions | Private Types | Private Member Functions | Private Attributes
fwlite::DataGetterHelper Class Reference

#include <DataGetterHelper.h>

Public Member Functions

 DataGetterHelper (TTree *tree, std::shared_ptr< HistoryGetterBase > historyGetter, std::shared_ptr< BranchMapReader > branchMap=std::shared_ptr< BranchMapReader >(), std::shared_ptr< edm::EDProductGetter > getter=std::shared_ptr< edm::EDProductGetter >(), bool useCache=false, std::function< void(TBranch const &)> baFunc=[](TBranch const &){})
 
virtual std::string const getBranchNameFor (std::type_info const &, char const *, char const *, char const *) const
 
virtual bool getByLabel (std::type_info const &, char const *, char const *, char const *, void *, Long_t) const
 
edm::WrapperBase const * getByProductID (edm::ProductID const &pid, Long_t eventEntry) const
 
edm::EDProductGetter const * getter () const
 
edm::WrapperBase const * getThinnedProduct (edm::ProductID const &pid, unsigned int &key, Long_t eventEntry) const
 
void getThinnedProducts (edm::ProductID const &pid, std::vector< edm::WrapperBase const * > &foundContainers, std::vector< unsigned int > &keys, Long_t eventEntry) const
 
void setGetter (std::shared_ptr< edm::EDProductGetter const > getter)
 
virtual ~DataGetterHelper ()
 

Private Types

typedef std::map< internal::DataKey, std::shared_ptr< internal::Data > > KeyToDataMap
 

Private Member Functions

 DataGetterHelper (const DataGetterHelper &)=delete
 
void getBranchData (edm::EDProductGetter const *, Long64_t, internal::Data &) const
 
internal::DatagetBranchDataFor (std::type_info const &, char const *, char const *, char const *) const
 
bool getByBranchDescription (edm::BranchDescription const &, Long_t eventEntry, KeyToDataMap::iterator &) const
 
edm::WrapperBase const * getByBranchID (edm::BranchID const &bid, Long_t eventEntry) const
 
edm::ThinnedAssociation const * getThinnedAssociation (edm::BranchID const &branchID, Long_t eventEntry) const
 
const edm::ProcessHistoryhistory () const
 
const DataGetterHelperoperator= (const DataGetterHelper &)=delete
 
edm::WrapperBase const * wrapperBasePtr (edm::ObjectWithDict const &) const
 

Private Attributes

std::map< edm::BranchID, std::shared_ptr< internal::Data > > bidToData_
 
std::function< void(TBranch const &)> branchAccessFunc_
 
std::shared_ptr< BranchMapReaderbranchMap_
 
KeyToDataMap data_
 
std::shared_ptr< edm::EDProductGetter const > getter_
 
edm::propagate_const< std::shared_ptr< fwlite::HistoryGetterBase > > historyGetter_
 
std::map< std::pair< edm::ProductID, edm::BranchListIndex >, std::shared_ptr< internal::Data > > idToData_
 
std::vector< char const * > labels_
 
bool tcTrained_
 
const bool tcUse_
 Use internal TTreeCache. More...
 
TTree * tree_
 

Detailed Description

Definition at line 53 of file DataGetterHelper.h.

Member Typedef Documentation

typedef std::map<internal::DataKey, std::shared_ptr<internal::Data> > fwlite::DataGetterHelper::KeyToDataMap
private

Definition at line 97 of file DataGetterHelper.h.

Constructor & Destructor Documentation

DataGetterHelper::DataGetterHelper ( TTree *  tree,
std::shared_ptr< HistoryGetterBase historyGetter,
std::shared_ptr< BranchMapReader branchMap = std::shared_ptr<BranchMapReader>(),
std::shared_ptr< edm::EDProductGetter getter = std::shared_ptr<edm::EDProductGetter>(),
bool  useCache = false,
std::function< void(TBranch const &)>  baFunc = [](TBranch const&){} 
)

Definition at line 52 of file DataGetterHelper.cc.

References Exception, tcUse_, compare::tree, and tree_.

56  :
57  branchMap_(branchMap),
58  historyGetter_(historyGetter),
59  getter_(getter),
60  tcTrained_(false),
61  tcUse_(useCache),
62  branchAccessFunc_(baFunc)
63  {
64  if(nullptr == tree) {
65  throw cms::Exception("NoTree")<<"The TTree pointer passed to the constructor was null";
66  }
67  tree_ = tree;
68  if (tcUse_) {
69  tree_->SetCacheSize();
70  }
71  }
edm::propagate_const< std::shared_ptr< fwlite::HistoryGetterBase > > historyGetter_
std::function< void(TBranch const &)> branchAccessFunc_
const bool tcUse_
Use internal TTreeCache.
std::shared_ptr< BranchMapReader > branchMap_
edm::EDProductGetter const * getter() const
Definition: tree.py:1
std::shared_ptr< edm::EDProductGetter const > getter_
DataGetterHelper::~DataGetterHelper ( )
virtual

Definition at line 78 of file DataGetterHelper.cc.

78 {}
fwlite::DataGetterHelper::DataGetterHelper ( const DataGetterHelper )
privatedelete

Member Function Documentation

void DataGetterHelper::getBranchData ( edm::EDProductGetter const *  iGetter,
Long64_t  eventEntry,
internal::Data iData 
) const
private

Definition at line 117 of file DataGetterHelper.cc.

References fwlite::internal::Data::branch_, branchAccessFunc_, branchMap_, fwlite::internal::Data::lastProduct_, tcTrained_, tcUse_, and tree_.

Referenced by getByBranchID(), getByLabel(), and getByProductID().

120  {
121  GetterOperate op(iGetter);
122 
126  //edm::ObjectWithDict obj = iData.obj_;
127  //iData.obj_ = iData.obj_.construct();
128  //iData.pObj_ = iData.obj_.address();
129  //iData.branch_->SetAddress(&(iData.pObj_));
131  //if(nullptr != iData.pProd_) {
132  // iData.pProd_ = iData.obj_.address();
133  //}
134  //obj.destruct();
136 
137  if (tcUse_) {
138  TTreeCache* tcache = dynamic_cast<TTreeCache*> (branchMap_->getFile()->GetCacheRead());
139 
140  if (nullptr != tcache) {
141  if (!tcTrained_) {
142  tcache->SetLearnEntries(100);
143  tcache->SetEntryRange(0, tree_->GetEntries());
144  tcTrained_ = true;
145  }
146  tree_->LoadTree(eventEntry);
147  }
148  }
149  branchAccessFunc_(*iData.branch_);
150  iData.branch_->GetEntry(eventEntry);
151 
152  iData.lastProduct_=eventEntry;
153  }
std::function< void(TBranch const &)> branchAccessFunc_
const bool tcUse_
Use internal TTreeCache.
std::shared_ptr< BranchMapReader > branchMap_
internal::Data & DataGetterHelper::getBranchDataFor ( std::type_info const &  iInfo,
char const *  iModuleLabel,
char const *  iProductInstanceLabel,
char const *  iProcessLabel 
) const
private

Definition at line 156 of file DataGetterHelper.cc.

References edm::ObjectWithDict::address(), MicroEventContent_cff::branch, fwlite::branchNotFound, edm::ObjectWithDict::byType(), data_, Exception, fwlite::findBranch(), edm::TypeID::friendlyClassName(), h, history(), fwlite::internal::DataKey::kEmpty(), fwlite::kEmptyString, crabWrapper::key, labels_, fwlite::internal::DataKey::module(), dataset::name, edm::TypeWithDict::name(), haddnano::obj, fwlite::internal::DataKey::process(), fwlite::internal::DataKey::product(), edm::ProcessHistory::rbegin(), edm::ProcessHistory::rend(), AlCaHLTBitMon_QueryRunRegistry::string, and tree_.

Referenced by getBranchNameFor(), and getByLabel().

160  {
161  edm::TypeID type(iInfo);
162  internal::DataKey key(type, iModuleLabel, iProductInstanceLabel, iProcessLabel);
163 
164  KeyToDataMap::iterator itFind = data_.find(key);
165  if(itFind == data_.end()) {
166  //see if such a branch actually exists
167  std::string const sep("_");
168  //CHANGE: If this fails, need to lookup the the friendly name which was used to write the file
169  std::string name(type.friendlyClassName());
170  name +=sep+std::string(key.module());
171  name +=sep+std::string(key.product())+sep;
172 
173  //if we have to lookup the process label, remember it and register the product again
174  std::string foundProcessLabel;
175  TBranch* branch = nullptr;
176  std::shared_ptr<internal::Data> theData;
177 
178  if (nullptr == iProcessLabel || iProcessLabel == key.kEmpty() ||
179  strlen(iProcessLabel)==0) {
180  std::string const* lastLabel = nullptr;
181  //have to search in reverse order since newest are on the bottom
183  for (edm::ProcessHistory::const_reverse_iterator iproc = h.rbegin(), eproc = h.rend();
184  iproc != eproc;
185  ++iproc) {
186 
187  lastLabel = &(iproc->processName());
188  branch=findBranch(tree_,name,iproc->processName());
189  if(nullptr != branch) {
190  break;
191  }
192  }
193  if(nullptr == branch) {
194  return branchNotFound;
195  }
196  //do we already have this one?
197  if(nullptr != lastLabel) {
198  internal::DataKey fullKey(type,iModuleLabel,iProductInstanceLabel,lastLabel->c_str());
199  itFind = data_.find(fullKey);
200  if(itFind != data_.end()) {
201  //remember the data we've found
202  theData = itFind->second;
203  } else {
204  //only set this if we don't already have it since it this string is not empty we re-register
205  foundProcessLabel = *lastLabel;
206  }
207  }
208  } else {
209  //we have all the pieces
210  branch = findBranch(tree_,name,key.process());
211  if(nullptr == branch){
212  return branchNotFound;
213  }
214  }
215 
216  //cache the info
217  size_t moduleLabelLen = strlen(iModuleLabel)+1;
218  char* newModule = new char[moduleLabelLen];
219  std::strncpy(newModule,iModuleLabel,moduleLabelLen);
220  labels_.push_back(newModule);
221 
222  char* newProduct = kEmptyString;
223  if(key.product()[0] != 0) {
224  size_t newProductLen = strlen(key.product())+1;
225  newProduct = new char[newProductLen];
226  std::strncpy(newProduct,key.product(),newProductLen);
227  labels_.push_back(newProduct);
228  }
229  char* newProcess = kEmptyString;
230  if(key.process()[0]!=0) {
231  size_t newProcessLen = strlen(key.process())+1;
232  newProcess = new char[newProcessLen];
233  std::strncpy(newProcess,key.process(),newProcessLen);
234  labels_.push_back(newProcess);
235  }
236  internal::DataKey newKey(edm::TypeID(iInfo),newModule,newProduct,newProcess);
237 
238  if(nullptr == theData.get()) {
239  //We do not already have this data as another key
240 
241  //create an instance of the object to be used as a buffer
242  edm::TypeWithDict type(iInfo);
243  if(!bool(type)) {
244  throw cms::Exception("UnknownType") << "No dictionary exists for type " << iInfo.name();
245  }
246 
248 
249  if(obj.address() == nullptr) {
250  throw cms::Exception("ConstructionFailed") << "failed to construct an instance of " << type.name();
251  }
252  auto newData = std::make_shared<internal::Data>();
253  newData->branch_ = branch;
254  newData->obj_ = obj;
255  newData->lastProduct_ = -1;
256  newData->pObj_ = obj.address();
257  newData->pProd_ = nullptr;
258  branch->SetAddress(&(newData->pObj_));
259  theData = newData;
260  }
261  itFind = data_.insert(std::make_pair(newKey, theData)).first;
262 
263  if(!foundProcessLabel.empty()) {
264  //also remember it with the process label
265  newProcess = new char[foundProcessLabel.size()+1];
266  std::strcpy(newProcess,foundProcessLabel.c_str());
267  labels_.push_back(newProcess);
268  internal::DataKey newKey(edm::TypeID(iInfo),newModule,newProduct,newProcess);
269 
270  data_.insert(std::make_pair(newKey,theData));
271  }
272  }
273  return *(itFind->second);
274  }
const_reverse_iterator rbegin() const
static TBranch * findBranch(TTree *iTree, std::string const &iMainLabels, std::string const &iProcess)
type
Definition: HCALResponse.h:21
static ObjectWithDict byType(TypeWithDict const &)
std::vector< char const * > labels_
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
collection_type::const_reverse_iterator const_reverse_iterator
void * address() const
const edm::ProcessHistory & history() const
const_reverse_iterator rend() const
static internal::Data branchNotFound
static char kEmptyString[1]
std::string const DataGetterHelper::getBranchNameFor ( std::type_info const &  iInfo,
char const *  iModuleLabel,
char const *  iProductInstanceLabel,
char const *  iProcessLabel 
) const
virtual

Definition at line 277 of file DataGetterHelper.cc.

References fwlite::internal::Data::branch_, getBranchDataFor(), and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by fwlite::Run::getBranchNameFor(), fwlite::LuminosityBlock::getBranchNameFor(), and fwlite::Event::getBranchNameFor().

281  {
282  internal::Data& theData =
283  DataGetterHelper::getBranchDataFor(iInfo, iModuleLabel, iProductInstanceLabel, iProcessLabel);
284 
285  if (nullptr != theData.branch_) {
286  return std::string(theData.branch_->GetName());
287  }
288  return std::string("");
289  }
internal::Data & getBranchDataFor(std::type_info const &, char const *, char const *, char const *) const
bool DataGetterHelper::getByBranchDescription ( edm::BranchDescription const &  bDesc,
Long_t  eventEntry,
KeyToDataMap::iterator &  itData 
) const
private

Definition at line 318 of file DataGetterHelper.cc.

References edm::BranchDescription::branchID(), edm::TypeWithDict::byName(), data_, edm::BranchDescription::fullClassName(), getByLabel(), edm::BranchID::isValid(), gen::k, edm::BranchDescription::moduleLabel(), edm::BranchDescription::processName(), edm::BranchDescription::productInstanceName(), and edm::wrappedClassName().

Referenced by getByBranchID(), and getByProductID().

320  {
321  if (!bDesc.branchID().isValid()) {
322  return false;
323  }
324 
325  //Calculate the key from the branch description
326  edm::TypeWithDict typeWD(edm::TypeWithDict::byName(edm::wrappedClassName(bDesc.fullClassName())));
327  edm::TypeID type(typeWD.typeInfo());
328  assert(bool(type));
329 
330  //Only the product instance label may be empty
331  char const* pIL = bDesc.productInstanceName().c_str();
332  if(pIL[0] == 0) {
333  pIL = nullptr;
334  }
335  internal::DataKey k(type,
336  bDesc.moduleLabel().c_str(),
337  pIL,
338  bDesc.processName().c_str());
339 
340  //has this already been gotten?
341  itData = data_.find(k);
342  if(data_.end() == itData) {
343  //ask for the data
344  edm::WrapperBase const* dummy = nullptr;
345  getByLabel(type.typeInfo(),
346  k.module(),
347  k.product(),
348  k.process(),
349  &dummy, eventEntry);
350  if(nullptr == dummy) {
351  return false;
352  }
353  itData = data_.find(k);
354  assert(itData != data_.end());
355  assert(dummy == itData->second->obj_.address());
356  }
357  return true;
358  }
type
Definition: HCALResponse.h:21
static TypeWithDict byName(std::string const &name)
Definition: TypeWithDict.cc:74
int k[5][pyjets_maxn]
std::string wrappedClassName(std::string const &iFullName)
virtual bool getByLabel(std::type_info const &, char const *, char const *, char const *, void *, Long_t) const
edm::WrapperBase const * DataGetterHelper::getByBranchID ( edm::BranchID const &  bid,
Long_t  eventEntry 
) const
private

Definition at line 390 of file DataGetterHelper.cc.

References bidToData_, branchMap_, getBranchData(), getByBranchDescription(), getter_, and wrapperBasePtr().

Referenced by getThinnedAssociation().

391  {
392  auto itFound = bidToData_.find(bid);
393 
394  if(itFound == bidToData_.end()) {
395  edm::BranchDescription const& bDesc = branchMap_->branchIDToBranch(bid);
396  KeyToDataMap::iterator itData;
397 
398  if(!getByBranchDescription(bDesc, eventEntry, itData)) {
399  return nullptr;
400  }
401  itFound = bidToData_.insert(std::make_pair(bid,itData->second)).first;
402  }
403  if(eventEntry != itFound->second->lastProduct_) {
404  //haven't gotten the data for this event
405  getBranchData(getter_.get(), eventEntry, *(itFound->second));
406  }
407  if(nullptr == itFound->second->pProd_) {
408  itFound->second->pProd_ = wrapperBasePtr(itFound->second->obj_);
409  if(nullptr == itFound->second->pProd_) {
410  return nullptr;
411  }
412  }
413  return itFound->second->pProd_;
414  }
std::map< edm::BranchID, std::shared_ptr< internal::Data > > bidToData_
bool getByBranchDescription(edm::BranchDescription const &, Long_t eventEntry, KeyToDataMap::iterator &) const
void getBranchData(edm::EDProductGetter const *, Long64_t, internal::Data &) const
std::shared_ptr< BranchMapReader > branchMap_
edm::WrapperBase const * wrapperBasePtr(edm::ObjectWithDict const &) const
std::shared_ptr< edm::EDProductGetter const > getter_
bool DataGetterHelper::getByLabel ( std::type_info const &  iInfo,
char const *  iModuleLabel,
char const *  iProductInstanceLabel,
char const *  iProcessLabel,
void *  oData,
Long_t  eventEntry 
) const
virtual

Definition at line 292 of file DataGetterHelper.cc.

References edm::ObjectWithDict::address(), fwlite::internal::Data::branch_, getBranchData(), getBranchDataFor(), getter_, fwlite::internal::Data::lastProduct_, and fwlite::internal::Data::obj_.

Referenced by getByBranchDescription(), fwlite::Run::getByLabel(), fwlite::LuminosityBlock::getByLabel(), and fwlite::Event::getByLabel().

297  {
298  // Maintain atEnd() check in parent classes
299  void** pOData = reinterpret_cast<void**>(oData);
300  *pOData = nullptr;
301 
302  internal::Data& theData =
303  DataGetterHelper::getBranchDataFor(iInfo, iModuleLabel, iProductInstanceLabel, iProcessLabel);
304 
305  if (nullptr != theData.branch_) {
306  if(eventEntry != theData.lastProduct_) {
307  //haven't gotten the data for this event
308  getBranchData(getter_.get(), eventEntry, theData);
309  }
310  *pOData = theData.obj_.address();
311  }
312 
313  if (nullptr == *pOData) return false;
314  else return true;
315  }
void getBranchData(edm::EDProductGetter const *, Long64_t, internal::Data &) const
internal::Data & getBranchDataFor(std::type_info const &, char const *, char const *, char const *) const
std::shared_ptr< edm::EDProductGetter const > getter_
edm::WrapperBase const * DataGetterHelper::getByProductID ( edm::ProductID const &  pid,
Long_t  eventEntry 
) const

Definition at line 361 of file DataGetterHelper.cc.

References branchMap_, getBranchData(), getByBranchDescription(), getter_, idToData_, edm::ProductID::processIndex(), and wrapperBasePtr().

Referenced by fwlite::Run::getByProductID(), fwlite::LuminosityBlock::getByProductID(), fwlite::Event::getByProductID(), getThinnedProduct(), and getThinnedProducts().

362  {
363  typedef std::pair<edm::ProductID,edm::BranchListIndex> IDPair;
364  IDPair theID = std::make_pair(iID, branchMap_->branchListIndexes()[iID.processIndex()-1]);
365  std::map<IDPair,std::shared_ptr<internal::Data> >::const_iterator itFound = idToData_.find(theID);
366 
367  if(itFound == idToData_.end()) {
368  edm::BranchDescription const& bDesc = branchMap_->productToBranch(iID);
369  KeyToDataMap::iterator itData;
370 
371  if(!getByBranchDescription(bDesc, eventEntry, itData)) {
372  return nullptr;
373  }
374  itFound = idToData_.insert(std::make_pair(theID,itData->second)).first;
375  }
376  if(eventEntry != itFound->second->lastProduct_) {
377  //haven't gotten the data for this event
378  getBranchData(getter_.get(), eventEntry, *(itFound->second));
379  }
380  if(nullptr == itFound->second->pProd_) {
381  itFound->second->pProd_ = wrapperBasePtr(itFound->second->obj_);
382  if(nullptr == itFound->second->pProd_) {
383  return nullptr;
384  }
385  }
386  return itFound->second->pProd_;
387  }
std::map< std::pair< edm::ProductID, edm::BranchListIndex >, std::shared_ptr< internal::Data > > idToData_
bool getByBranchDescription(edm::BranchDescription const &, Long_t eventEntry, KeyToDataMap::iterator &) const
void getBranchData(edm::EDProductGetter const *, Long64_t, internal::Data &) const
std::shared_ptr< BranchMapReader > branchMap_
edm::WrapperBase const * wrapperBasePtr(edm::ObjectWithDict const &) const
std::shared_ptr< edm::EDProductGetter const > getter_
edm::EDProductGetter const* fwlite::DataGetterHelper::getter ( ) const
inline

Definition at line 88 of file DataGetterHelper.h.

Referenced by fwlite::Event::draw(), and fwlite::Event::scan().

88  {
89  return getter_.get();
90  }
std::shared_ptr< edm::EDProductGetter const > getter_
edm::ThinnedAssociation const * DataGetterHelper::getThinnedAssociation ( edm::BranchID const &  branchID,
Long_t  eventEntry 
) const
private

Definition at line 537 of file DataGetterHelper.cc.

References edm::WrapperBase::dynamicTypeInfo(), Exception, getByBranchID(), edm::errors::LogicError, and wrapper.

Referenced by getThinnedProduct(), and getThinnedProducts().

537  {
538 
539  edm::WrapperBase const* wrapperBase = getByBranchID(branchID, eventEntry);
540  if(wrapperBase == nullptr) {
542  << "DataGetterHelper::getThinnedAssociation, product ThinnedAssociation not found.\n";
543  }
544  if(!(typeid(edm::ThinnedAssociation) == wrapperBase->dynamicTypeInfo())) {
546  << "DataGetterHelper::getThinnedAssociation, product has wrong type, not a ThinnedAssociation.\n";
547  }
549  static_cast<edm::Wrapper<edm::ThinnedAssociation> const*>(wrapperBase);
550 
551  edm::ThinnedAssociation const* thinnedAssociation = wrapper->product();
552  return thinnedAssociation;
553  }
edm::WrapperBase const * getByBranchID(edm::BranchID const &bid, Long_t eventEntry) const
std::type_info const & dynamicTypeInfo() const
Definition: WrapperBase.h:46
static HepMC::HEPEVT_Wrapper wrapper
edm::WrapperBase const * DataGetterHelper::getThinnedProduct ( edm::ProductID const &  pid,
unsigned int &  key,
Long_t  eventEntry 
) const

Definition at line 425 of file DataGetterHelper.cc.

References branchMap_, getByProductID(), getThinnedAssociation(), edm::ThinnedAssociation::hasParentIndex(), edm::BranchID::isValid(), class-composition::parent, edm::ThinnedAssociationsHelper::parentBegin(), edm::ThinnedAssociation::parentCollectionID(), edm::ThinnedAssociationsHelper::parentEnd(), and edm::ThinnedAssociation::thinnedCollectionID().

Referenced by fwlite::Event::getThinnedProduct().

425  {
426 
427  edm::BranchID parent = branchMap_->productToBranchID(pid);
428  if(!parent.isValid()) return nullptr;
429  edm::ThinnedAssociationsHelper const& thinnedAssociationsHelper = branchMap_->thinnedAssociationsHelper();
430 
431  // Loop over thinned containers which were made by selecting elements from the parent container
432  for(auto associatedBranches = thinnedAssociationsHelper.parentBegin(parent),
433  iEnd = thinnedAssociationsHelper.parentEnd(parent);
434  associatedBranches != iEnd; ++associatedBranches) {
435 
436  edm::ThinnedAssociation const* thinnedAssociation =
437  getThinnedAssociation(associatedBranches->association(), eventEntry);
438  if(thinnedAssociation == nullptr) continue;
439 
440  if(associatedBranches->parent() != branchMap_->productToBranchID(thinnedAssociation->parentCollectionID())) {
441  continue;
442  }
443 
444  unsigned int thinnedIndex = 0;
445  // Does this thinned container have the element referenced by key?
446  // If yes, thinnedIndex is set to point to it in the thinned container
447  if(!thinnedAssociation->hasParentIndex(key, thinnedIndex)) {
448  continue;
449  }
450  // Get the thinned container and return a pointer if we can find it
451  edm::ProductID const& thinnedCollectionPID = thinnedAssociation->thinnedCollectionID();
452  edm::WrapperBase const* thinnedCollection = getByProductID(thinnedCollectionPID, eventEntry);
453 
454  if(thinnedCollection == nullptr) {
455  // Thinned container is not found, try looking recursively in thinned containers
456  // which were made by selecting elements from this thinned container.
457  edm::WrapperBase const* thinnedFromRecursiveCall = getThinnedProduct(thinnedCollectionPID, thinnedIndex, eventEntry);
458  if(thinnedFromRecursiveCall != nullptr) {
459  key = thinnedIndex;
460  return thinnedFromRecursiveCall;
461  } else {
462  continue;
463  }
464  }
465  key = thinnedIndex;
466  return thinnedCollection;
467  }
468  return nullptr;
469  }
edm::ThinnedAssociation const * getThinnedAssociation(edm::BranchID const &branchID, Long_t eventEntry) const
bool isValid() const
Definition: BranchID.h:24
std::vector< ThinnedAssociationBranches >::const_iterator parentEnd(BranchID const &) const
edm::WrapperBase const * getByProductID(edm::ProductID const &pid, Long_t eventEntry) const
ProductID const & thinnedCollectionID() const
std::shared_ptr< BranchMapReader > branchMap_
std::vector< ThinnedAssociationBranches >::const_iterator parentBegin(BranchID const &) const
edm::WrapperBase const * getThinnedProduct(edm::ProductID const &pid, unsigned int &key, Long_t eventEntry) const
ProductID const & parentCollectionID() const
bool hasParentIndex(unsigned int parentIndex, unsigned int &thinnedIndex) const
void DataGetterHelper::getThinnedProducts ( edm::ProductID const &  pid,
std::vector< edm::WrapperBase const * > &  foundContainers,
std::vector< unsigned int > &  keys,
Long_t  eventEntry 
) const

Definition at line 471 of file DataGetterHelper.cc.

References branchMap_, getByProductID(), getThinnedAssociation(), edm::ThinnedAssociation::hasParentIndex(), edm::BranchID::isValid(), gen::k, SiStripPI::max, class-composition::parent, edm::ThinnedAssociationsHelper::parentBegin(), edm::ThinnedAssociation::parentCollectionID(), edm::ThinnedAssociationsHelper::parentEnd(), and edm::ThinnedAssociation::thinnedCollectionID().

Referenced by fwlite::Event::getThinnedProducts().

474  {
475 
476  edm::BranchID parent = branchMap_->productToBranchID(pid);
477  if(!parent.isValid()) return;
478  edm::ThinnedAssociationsHelper const& thinnedAssociationsHelper = branchMap_->thinnedAssociationsHelper();
479 
480  // Loop over thinned containers which were made by selecting elements from the parent container
481  for(auto associatedBranches = thinnedAssociationsHelper.parentBegin(parent),
482  iEnd = thinnedAssociationsHelper.parentEnd(parent);
483  associatedBranches != iEnd; ++associatedBranches) {
484 
485  edm::ThinnedAssociation const* thinnedAssociation =
486  getThinnedAssociation(associatedBranches->association(), eventEntry);
487  if(thinnedAssociation == nullptr) continue;
488 
489  if(associatedBranches->parent() != branchMap_->productToBranchID(thinnedAssociation->parentCollectionID())) {
490  continue;
491  }
492 
493  unsigned int nKeys = keys.size();
494  unsigned int doNotLookForThisIndex = std::numeric_limits<unsigned int>::max();
495  std::vector<unsigned int> thinnedIndexes(nKeys, doNotLookForThisIndex);
496  bool hasAny = false;
497  for(unsigned k = 0; k < nKeys; ++k) {
498  // Already found this one
499  if(foundContainers[k] != nullptr) continue;
500  // Already know this one is not in this thinned container
501  if(keys[k] == doNotLookForThisIndex ) continue;
502  // Does the thinned container hold the entry of interest?
503  // Modifies thinnedIndexes[k] only if it returns true and
504  // sets it to the index in the thinned collection.
505  if(thinnedAssociation->hasParentIndex(keys[k], thinnedIndexes[k])) {
506  hasAny = true;
507  }
508  }
509  if(!hasAny) {
510  continue;
511  }
512  // Get the thinned container and set the pointers and indexes into
513  // it (if we can find it)
514  edm::ProductID thinnedCollectionPID = thinnedAssociation->thinnedCollectionID();
515  edm::WrapperBase const* thinnedCollection = getByProductID(thinnedCollectionPID, eventEntry);
516 
517  if(thinnedCollection == nullptr) {
518  // Thinned container is not found, try looking recursively in thinned containers
519  // which were made by selecting elements from this thinned container.
520  getThinnedProducts(thinnedCollectionPID, foundContainers, thinnedIndexes, eventEntry);
521  for(unsigned k = 0; k < nKeys; ++k) {
522  if(foundContainers[k] == nullptr) continue;
523  if(thinnedIndexes[k] == doNotLookForThisIndex) continue;
524  keys[k] = thinnedIndexes[k];
525  }
526  } else {
527  for(unsigned k = 0; k < nKeys; ++k) {
528  if(thinnedIndexes[k] == doNotLookForThisIndex) continue;
529  keys[k] = thinnedIndexes[k];
530  foundContainers[k] = thinnedCollection;
531  }
532  }
533  }
534  }
edm::ThinnedAssociation const * getThinnedAssociation(edm::BranchID const &branchID, Long_t eventEntry) const
bool isValid() const
Definition: BranchID.h:24
void getThinnedProducts(edm::ProductID const &pid, std::vector< edm::WrapperBase const * > &foundContainers, std::vector< unsigned int > &keys, Long_t eventEntry) const
std::vector< ThinnedAssociationBranches >::const_iterator parentEnd(BranchID const &) const
edm::WrapperBase const * getByProductID(edm::ProductID const &pid, Long_t eventEntry) const
ProductID const & thinnedCollectionID() const
int k[5][pyjets_maxn]
std::shared_ptr< BranchMapReader > branchMap_
std::vector< ThinnedAssociationBranches >::const_iterator parentBegin(BranchID const &) const
ProductID const & parentCollectionID() const
bool hasParentIndex(unsigned int parentIndex, unsigned int &thinnedIndex) const
const edm::ProcessHistory & DataGetterHelper::history ( ) const
private

Definition at line 555 of file DataGetterHelper.cc.

References historyGetter_.

Referenced by getBranchDataFor().

555  {
556  return historyGetter_->history();
557  }
edm::propagate_const< std::shared_ptr< fwlite::HistoryGetterBase > > historyGetter_
const DataGetterHelper& fwlite::DataGetterHelper::operator= ( const DataGetterHelper )
privatedelete
void fwlite::DataGetterHelper::setGetter ( std::shared_ptr< edm::EDProductGetter const >  getter)
inline

Definition at line 84 of file DataGetterHelper.h.

84  {
85  getter_ = getter;
86  }
edm::EDProductGetter const * getter() const
std::shared_ptr< edm::EDProductGetter const > getter_
edm::WrapperBase const * DataGetterHelper::wrapperBasePtr ( edm::ObjectWithDict const &  objectWithDict) const
private

Definition at line 417 of file DataGetterHelper.cc.

References edm::ObjectWithDict::address(), edm::TypeWithDict::pointerToBaseType(), and edm::ObjectWithDict::typeOf().

Referenced by getByBranchID(), and getByProductID().

417  {
418  // This converts a void* that points at a Wrapper<T>* into a WrapperBase*
419  edm::TypeWithDict wrapperBaseTypeWithDict(typeid(edm::WrapperBase));
420  return static_cast<edm::WrapperBase const*>(wrapperBaseTypeWithDict.pointerToBaseType(objectWithDict.address(),
421  objectWithDict.typeOf()));
422  }

Member Data Documentation

std::map<edm::BranchID, std::shared_ptr<internal::Data> > fwlite::DataGetterHelper::bidToData_
mutableprivate

Definition at line 114 of file DataGetterHelper.h.

Referenced by getByBranchID().

std::function<void (TBranch const&)> fwlite::DataGetterHelper::branchAccessFunc_
private

Branch-access-function gets called whenever a branch data is accessed. This can be used for management of TTreeCache on the user side.

Definition at line 122 of file DataGetterHelper.h.

Referenced by getBranchData().

std::shared_ptr<BranchMapReader> fwlite::DataGetterHelper::branchMap_
mutableprivate
KeyToDataMap fwlite::DataGetterHelper::data_
mutableprivate

Definition at line 109 of file DataGetterHelper.h.

Referenced by getBranchDataFor(), and getByBranchDescription().

std::shared_ptr<edm::EDProductGetter const> fwlite::DataGetterHelper::getter_
private

Definition at line 116 of file DataGetterHelper.h.

Referenced by getByBranchID(), getByLabel(), and getByProductID().

edm::propagate_const<std::shared_ptr<fwlite::HistoryGetterBase> > fwlite::DataGetterHelper::historyGetter_
private

Definition at line 115 of file DataGetterHelper.h.

Referenced by history().

std::map<std::pair<edm::ProductID, edm::BranchListIndex>,std::shared_ptr<internal::Data> > fwlite::DataGetterHelper::idToData_
mutableprivate

Definition at line 113 of file DataGetterHelper.h.

Referenced by getByProductID().

std::vector<char const*> fwlite::DataGetterHelper::labels_
mutableprivate

Definition at line 110 of file DataGetterHelper.h.

Referenced by getBranchDataFor().

bool fwlite::DataGetterHelper::tcTrained_
mutableprivate

Definition at line 117 of file DataGetterHelper.h.

Referenced by getBranchData().

const bool fwlite::DataGetterHelper::tcUse_
private

Use internal TTreeCache.

Definition at line 119 of file DataGetterHelper.h.

Referenced by DataGetterHelper(), and getBranchData().

TTree* fwlite::DataGetterHelper::tree_
private

Definition at line 107 of file DataGetterHelper.h.

Referenced by DataGetterHelper(), getBranchData(), and getBranchDataFor().