CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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)
 
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::EDProductGettergetter ()
 
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 > getter)
 
virtual ~DataGetterHelper ()
 

Private Types

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

Private Member Functions

 DataGetterHelper (const DataGetterHelper &)
 
void getBranchData (edm::EDProductGetter *, 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 &)
 
edm::WrapperBase const * wrapperBasePtr (edm::ObjectWithDict const &) const
 

Private Attributes

std::map< edm::BranchID,
std::shared_ptr
< internal::Data > > 
bidToData_
 
std::shared_ptr< BranchMapReaderbranchMap_
 
KeyToDataMap data_
 
std::shared_ptr
< edm::EDProductGetter
getter_
 
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_
 
TTree * tree_
 

Detailed Description

Definition at line 52 of file DataGetterHelper.h.

Member Typedef Documentation

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

Definition at line 96 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 
)

Definition at line 51 of file DataGetterHelper.cc.

References Exception, MainPageGenerator::tree, and tree_.

55  :
56  branchMap_(branchMap),
57  historyGetter_(historyGetter),
58  getter_(getter),
59  tcTrained_(false)
60  {
61  if(0==tree) {
62  throw cms::Exception("NoTree")<<"The TTree pointer passed to the constructor was null";
63  }
64  tree_ = tree;
65  if (useCache) {
66  tree_->SetCacheSize();
67  }
68  }
edm::EDProductGetter * getter()
std::shared_ptr< edm::EDProductGetter > getter_
std::shared_ptr< fwlite::HistoryGetterBase > historyGetter_
std::shared_ptr< BranchMapReader > branchMap_
DataGetterHelper::~DataGetterHelper ( )
virtual

Definition at line 75 of file DataGetterHelper.cc.

75 {}
fwlite::DataGetterHelper::DataGetterHelper ( const DataGetterHelper )
private

Member Function Documentation

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

Definition at line 114 of file DataGetterHelper.cc.

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

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

117  {
118  GetterOperate op(iGetter);
119 
123  //edm::ObjectWithDict obj = iData.obj_;
124  //iData.obj_ = iData.obj_.construct();
125  //iData.pObj_ = iData.obj_.address();
126  //iData.branch_->SetAddress(&(iData.pObj_));
128  //if(0!=iData.pProd_) {
129  // iData.pProd_ = iData.obj_.address();
130  //}
131  //obj.destruct();
133 
134  TTreeCache* tcache = dynamic_cast<TTreeCache*> (branchMap_->getFile()->GetCacheRead());
135 
136  if (0 == tcache) {
137  iData.branch_->GetEntry(eventEntry);
138  } else {
139  if (!tcTrained_) {
140  tcache->SetLearnEntries(100);
141  tcache->SetEntryRange(0, tree_->GetEntries());
142  tcTrained_ = true;
143  }
144  tree_->LoadTree(eventEntry);
145  iData.branch_->GetEntry(eventEntry);
146  }
147  iData.lastProduct_=eventEntry;
148  }
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 151 of file DataGetterHelper.cc.

References edm::ObjectWithDict::address(), fwlite::branchNotFound, edm::ObjectWithDict::byType(), data_, Exception, fwlite::findBranch(), edm::TypeID::friendlyClassName(), h, history(), fwlite::internal::DataKey::kEmpty(), relval_steps::key, labels_, fwlite::internal::DataKey::module(), mergeVDriftHistosByStation::name, edm::TypeWithDict::name(), getGTfromDQMFile::obj, fwlite::internal::DataKey::process(), fwlite::internal::DataKey::product(), edm::ProcessHistory::rbegin(), edm::ProcessHistory::rend(), cmsHarvester::sep, AlCaHLTBitMon_QueryRunRegistry::string, and tree_.

Referenced by getBranchNameFor(), and getByLabel().

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

Definition at line 272 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().

276  {
277  internal::Data& theData =
278  DataGetterHelper::getBranchDataFor(iInfo, iModuleLabel, iProductInstanceLabel, iProcessLabel);
279 
280  if (0 != theData.branch_) {
281  return std::string(theData.branch_->GetName());
282  }
283  return std::string("");
284  }
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 313 of file DataGetterHelper.cc.

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

Referenced by getByBranchID(), and getByProductID().

315  {
316  if (!bDesc.branchID().isValid()) {
317  return false;
318  }
319 
320  //Calculate the key from the branch description
321  edm::TypeWithDict typeWD(edm::TypeWithDict::byName(edm::wrappedClassName(bDesc.fullClassName())));
322  edm::TypeID type(typeWD.typeInfo());
323  assert(bool(type));
324 
325  //Only the product instance label may be empty
326  char const* pIL = bDesc.productInstanceName().c_str();
327  if(pIL[0] == 0) {
328  pIL = 0;
329  }
330  internal::DataKey k(type,
331  bDesc.moduleLabel().c_str(),
332  pIL,
333  bDesc.processName().c_str());
334 
335  //has this already been gotten?
336  itData = data_.find(k);
337  if(data_.end() == itData) {
338  //ask for the data
339  edm::WrapperBase const* dummy = nullptr;
340  getByLabel(type.typeInfo(),
341  k.module(),
342  k.product(),
343  k.process(),
344  &dummy, eventEntry);
345  if(nullptr == dummy) {
346  return false;
347  }
348  itData = data_.find(k);
349  assert(itData != data_.end());
350  assert(dummy == itData->second->obj_.address());
351  }
352  return true;
353  }
type
Definition: HCALResponse.h:21
assert(m_qm.get())
static TypeWithDict byName(std::string const &name)
Definition: TypeWithDict.cc:60
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 385 of file DataGetterHelper.cc.

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

Referenced by getThinnedAssociation().

386  {
387  auto itFound = bidToData_.find(bid);
388 
389  if(itFound == bidToData_.end()) {
390  edm::BranchDescription const& bDesc = branchMap_->branchIDToBranch(bid);
391  KeyToDataMap::iterator itData;
392 
393  if(!getByBranchDescription(bDesc, eventEntry, itData)) {
394  return nullptr;
395  }
396  itFound = bidToData_.insert(std::make_pair(bid,itData->second)).first;
397  }
398  if(eventEntry != itFound->second->lastProduct_) {
399  //haven't gotten the data for this event
400  getBranchData(getter_.get(), eventEntry, *(itFound->second));
401  }
402  if(nullptr == itFound->second->pProd_) {
403  itFound->second->pProd_ = wrapperBasePtr(itFound->second->obj_);
404  if(nullptr == itFound->second->pProd_) {
405  return nullptr;
406  }
407  }
408  return itFound->second->pProd_;
409  }
std::map< edm::BranchID, std::shared_ptr< internal::Data > > bidToData_
std::shared_ptr< edm::EDProductGetter > getter_
bool getByBranchDescription(edm::BranchDescription const &, Long_t eventEntry, KeyToDataMap::iterator &) const
std::shared_ptr< BranchMapReader > branchMap_
void getBranchData(edm::EDProductGetter *, Long64_t, internal::Data &) const
edm::WrapperBase const * wrapperBasePtr(edm::ObjectWithDict const &) const
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 287 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().

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

Definition at line 356 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().

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

Definition at line 87 of file DataGetterHelper.h.

References getter_.

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

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

Definition at line 532 of file DataGetterHelper.cc.

References compareJSON::const, edm::WrapperBase::dynamicTypeInfo(), Exception, getByBranchID(), edm::errors::LogicError, edm::Wrapper< T >::product(), and wrapper.

Referenced by getThinnedProduct(), and getThinnedProducts().

532  {
533 
534  edm::WrapperBase const* wrapperBase = getByBranchID(branchID, eventEntry);
535  if(wrapperBase == nullptr) {
537  << "DataGetterHelper::getThinnedAssociation, product ThinnedAssociation not found.\n";
538  }
539  if(!(typeid(edm::ThinnedAssociation) == wrapperBase->dynamicTypeInfo())) {
541  << "DataGetterHelper::getThinnedAssociation, product has wrong type, not a ThinnedAssociation.\n";
542  }
544  static_cast<edm::Wrapper<edm::ThinnedAssociation> const*>(wrapperBase);
545 
546  edm::ThinnedAssociation const* thinnedAssociation = wrapper->product();
547  return thinnedAssociation;
548  }
edm::WrapperBase const * getByBranchID(edm::BranchID const &bid, Long_t eventEntry) const
std::type_info const & dynamicTypeInfo() const
Definition: WrapperBase.h:38
T const * product() const
Definition: Wrapper.h:34
string const
Definition: compareJSON.py:14
static HepMC::HEPEVT_Wrapper wrapper
edm::WrapperBase const * DataGetterHelper::getThinnedProduct ( edm::ProductID const &  pid,
unsigned int &  key,
Long_t  eventEntry 
) const

Definition at line 420 of file DataGetterHelper.cc.

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

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

420  {
421 
422  edm::BranchID parent = branchMap_->productToBranchID(pid);
423  if(!parent.isValid()) return nullptr;
424  edm::ThinnedAssociationsHelper const& thinnedAssociationsHelper = branchMap_->thinnedAssociationsHelper();
425 
426  // Loop over thinned containers which were made by selecting elements from the parent container
427  for(auto associatedBranches = thinnedAssociationsHelper.parentBegin(parent),
428  iEnd = thinnedAssociationsHelper.parentEnd(parent);
429  associatedBranches != iEnd; ++associatedBranches) {
430 
431  edm::ThinnedAssociation const* thinnedAssociation =
432  getThinnedAssociation(associatedBranches->association(), eventEntry);
433  if(thinnedAssociation == nullptr) continue;
434 
435  if(associatedBranches->parent() != branchMap_->productToBranchID(thinnedAssociation->parentCollectionID())) {
436  continue;
437  }
438 
439  unsigned int thinnedIndex = 0;
440  // Does this thinned container have the element referenced by key?
441  // If yes, thinnedIndex is set to point to it in the thinned container
442  if(!thinnedAssociation->hasParentIndex(key, thinnedIndex)) {
443  continue;
444  }
445  // Get the thinned container and return a pointer if we can find it
446  edm::ProductID const& thinnedCollectionPID = thinnedAssociation->thinnedCollectionID();
447  edm::WrapperBase const* thinnedCollection = getByProductID(thinnedCollectionPID, eventEntry);
448 
449  if(thinnedCollection == nullptr) {
450  // Thinned container is not found, try looking recursively in thinned containers
451  // which were made by selecting elements from this thinned container.
452  edm::WrapperBase const* thinnedFromRecursiveCall = getThinnedProduct(thinnedCollectionPID, thinnedIndex, eventEntry);
453  if(thinnedFromRecursiveCall != nullptr) {
454  key = thinnedIndex;
455  return thinnedFromRecursiveCall;
456  } else {
457  continue;
458  }
459  }
460  key = thinnedIndex;
461  return thinnedCollection;
462  }
463  return nullptr;
464  }
edm::ThinnedAssociation const * getThinnedAssociation(edm::BranchID const &branchID, Long_t eventEntry) const
list parent
Definition: dbtoconf.py:74
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
string key
FastSim: produces sample of signal events, overlayed with premixed minbias events.
std::shared_ptr< BranchMapReader > branchMap_
tuple pid
Definition: sysUtil.py:22
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 466 of file DataGetterHelper.cc.

References branchMap_, getByProductID(), getThinnedAssociation(), edm::ThinnedAssociation::hasParentIndex(), edm::BranchID::isValid(), relval_steps::k, bookConverter::max, dbtoconf::parent, edm::ThinnedAssociationsHelper::parentBegin(), edm::ThinnedAssociation::parentCollectionID(), edm::ThinnedAssociationsHelper::parentEnd(), and edm::ThinnedAssociation::thinnedCollectionID().

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

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

References historyGetter_.

Referenced by getBranchDataFor().

550  {
551  return historyGetter_->history();
552  }
std::shared_ptr< fwlite::HistoryGetterBase > historyGetter_
const DataGetterHelper& fwlite::DataGetterHelper::operator= ( const DataGetterHelper )
private
void fwlite::DataGetterHelper::setGetter ( std::shared_ptr< edm::EDProductGetter getter)
inline

Definition at line 83 of file DataGetterHelper.h.

References getter(), and getter_.

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

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

Definition at line 412 of file DataGetterHelper.cc.

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

Referenced by getByBranchID(), and getByProductID().

412  {
413  // This converts a void* that points at a Wrapper<T>* into a WrapperBase*
414  edm::TypeWithDict wrapperBaseTypeWithDict(typeid(edm::WrapperBase));
415  return static_cast<edm::WrapperBase const*>(wrapperBaseTypeWithDict.pointerToBaseType(objectWithDict.address(),
416  objectWithDict.typeOf()));
417  }
string const
Definition: compareJSON.py:14

Member Data Documentation

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

Definition at line 113 of file DataGetterHelper.h.

Referenced by getByBranchID().

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

Definition at line 108 of file DataGetterHelper.h.

Referenced by getBranchDataFor(), and getByBranchDescription().

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

Definition at line 115 of file DataGetterHelper.h.

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

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

Definition at line 114 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 112 of file DataGetterHelper.h.

Referenced by getByProductID().

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

Definition at line 109 of file DataGetterHelper.h.

Referenced by getBranchDataFor().

bool fwlite::DataGetterHelper::tcTrained_
mutableprivate

Definition at line 116 of file DataGetterHelper.h.

Referenced by getBranchData().

TTree* fwlite::DataGetterHelper::tree_
private

Definition at line 106 of file DataGetterHelper.h.

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