CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes
BareRootProductGetter Class Reference

#include <FWCore/FWLite/interface/BareRootProductGetter.h>

Inheritance diagram for BareRootProductGetter:
edm::EDProductGetter

Classes

struct  Buffer
 

Public Member Functions

 BareRootProductGetter ()
 
 BareRootProductGetter (BareRootProductGetter const &)=delete
 
edm::WrapperBase const * getIt (edm::ProductID const &) const override
 
edm::OptionalThinnedKey getThinnedKeyFrom (edm::ProductID const &parent, unsigned int key, edm::ProductID const &thinned) const override
 
std::optional< std::tuple< edm::WrapperBase const *, unsigned int > > getThinnedProduct (edm::ProductID const &, unsigned int key) const override
 
void getThinnedProducts (edm::ProductID const &, std::vector< edm::WrapperBase const *> &foundContainers, std::vector< unsigned int > &keys) const override
 
BareRootProductGetter const & operator= (BareRootProductGetter const &)=delete
 
 ~BareRootProductGetter () override
 
- Public Member Functions inherited from edm::EDProductGetter
 EDProductGetter ()
 
 EDProductGetter (EDProductGetter const &)=delete
 
EDProductGetter const & operator= (EDProductGetter const &)=delete
 
unsigned int transitionIndex () const
 
virtual ~EDProductGetter ()
 

Private Types

typedef std::map< edm::BranchID, BufferIdToBuffers
 

Private Member Functions

BuffercreateNewBuffer (edm::BranchID const &) const
 
edm::WrapperBase const * getIt (edm::BranchID const &, Long_t eventEntry) const
 
edm::ThinnedAssociation const * getThinnedAssociation (edm::BranchID const &branchID, Long_t eventEntry) const
 
unsigned int transitionIndex_ () const override
 

Private Attributes

fwlite::BranchMapReader branchMap_
 
IdToBuffers idToBuffers_
 

Additional Inherited Members

- Static Public Member Functions inherited from edm::EDProductGetter
static void assignEDProductGetter (EDProductGetter const *&)
 
static EDProductGetter const * switchProductGetter (EDProductGetter const *)
 These can only be used internally by the framework. More...
 

Detailed Description

Description: <one line="" class="" summary>="">

Usage: <usage>

Definition at line 43 of file BareRootProductGetter.h.

Member Typedef Documentation

◆ IdToBuffers

Definition at line 113 of file BareRootProductGetter.h.

Constructor & Destructor Documentation

◆ BareRootProductGetter() [1/2]

BareRootProductGetter::BareRootProductGetter ( )

Definition at line 45 of file BareRootProductGetter.cc.

45 {}

◆ ~BareRootProductGetter()

BareRootProductGetter::~BareRootProductGetter ( )
override

Definition at line 51 of file BareRootProductGetter.cc.

51 {}

◆ BareRootProductGetter() [2/2]

BareRootProductGetter::BareRootProductGetter ( BareRootProductGetter const &  )
delete

Member Function Documentation

◆ createNewBuffer()

BareRootProductGetter::Buffer * BareRootProductGetter::createNewBuffer ( edm::BranchID const &  branchID) const
private

Definition at line 221 of file BareRootProductGetter.cc.

References b, MicroEventContent_cff::branch, fwlite::BranchMapReader::branchIDToBranch(), branchMap_, edm::BranchDescription::branchName(), edm::TypeWithDict::byName(), edm::BranchDescription::className(), runTheMatrix::const, Exception, newFWLiteAna::fullName, fwlite::BranchMapReader::getEventTree(), idToBuffers_, eostools::move(), dumpMFGeometry_cfg::prod, AlCaHLTBitMon_QueryRunRegistry::string, and edm::wrappedClassName().

Referenced by getIt().

221  {
222  //find the branch
223  edm::BranchDescription const& bdesc = branchMap_.branchIDToBranch(branchID);
224 
225  TBranch* branch = branchMap_.getEventTree()->GetBranch(bdesc.branchName().c_str());
226  if (nullptr == branch) {
227  //we do not thrown on missing branches since 'getIt' should not throw under that condition
228  return nullptr;
229  }
230  //find the class type
233  if (!bool(classType)) {
234  throw cms::Exception("MissingDictionary") << "could not find dictionary for type '" << fullName << "'"
235  << "\n Please make sure all the necessary libraries are available.";
236  return nullptr;
237  }
238 
239  TClass* rootClassType = TClass::GetClass(classType.typeInfo());
240  if (nullptr == rootClassType) {
241  throw cms::Exception("MissingRootDictionary") << "could not find a ROOT dictionary for type '" << fullName << "'"
242  << "\n Please make sure all the necessary libraries are available.";
243  return nullptr;
244  }
245  void* address = rootClassType->New();
246 
247  static TClass const* edproductTClass = TClass::GetClass(typeid(edm::WrapperBase));
248  edm::WrapperBase const* prod =
249  static_cast<edm::WrapperBase const*>(rootClassType->DynamicCast(edproductTClass, address, true));
250  if (nullptr == prod) {
251  throw cms::Exception("FailedConversion") << "failed to convert a '" << fullName << "' to a edm::WrapperBase."
252  << "Please contact developers since something is very wrong.";
253  }
254 
255  //connect the instance to the branch
256  //void* address = wrapperObj.Address();
257  Buffer b(prod, branch, address, rootClassType);
258  idToBuffers_[branchID] = std::move(b);
259 
260  //As of 5.13 ROOT expects the memory address held by the pointer passed to
261  // SetAddress to be valid forever
262  address = &(idToBuffers_[branchID].address_);
263  branch->SetAddress(address);
264 
265  return &(idToBuffers_[branchID]);
266 }
TTree const * getEventTree() const
static TypeWithDict byName(std::string const &name)
Definition: TypeWithDict.cc:74
std::string const & className() const
std::string const & branchName() const
const edm::BranchDescription & branchIDToBranch(const edm::BranchID &bid) const
std::string wrappedClassName(std::string const &iFullName)
double b
Definition: hdecay.h:118
fwlite::BranchMapReader branchMap_
def move(src, dest)
Definition: eostools.py:511

◆ getIt() [1/2]

edm::WrapperBase const * BareRootProductGetter::getIt ( edm::ProductID const &  pid) const
overridevirtual

Implements edm::EDProductGetter.

Definition at line 71 of file BareRootProductGetter.cc.

References branchMap_, edm::poolNames::eventTreeName(), Exception, fwlite::BranchMapReader::getEventTree(), fwlite::BranchMapReader::getFile(), idToBuffers_, fwlite::BranchMapReader::productToBranchID(), fwlite::BranchMapReader::updateEvent(), and fwlite::BranchMapReader::updateFile().

Referenced by getThinnedAssociation(), getThinnedProduct(), and getThinnedProducts().

71  {
72  // std::cout << "getIt called " << pid << std::endl;
73  TFile* currentFile = dynamic_cast<TFile*>(gROOT->GetListOfFiles()->Last());
74  if (nullptr == currentFile) {
75  throw cms::Exception("FileNotFound") << "unable to find the TFile '" << gROOT->GetListOfFiles()->Last() << "'\n"
76  << "retrieved by calling 'gROOT->GetListOfFiles()->Last()'\n"
77  << "Please check the list of files.";
78  }
79  if (branchMap_.updateFile(currentFile)) {
80  idToBuffers_.clear();
81  }
82  TTree* eventTree = branchMap_.getEventTree();
83  // std::cout << "eventTree " << eventTree << std::endl;
84  if (nullptr == eventTree) {
85  throw cms::Exception("NoEventsTree")
86  << "unable to find the TTree '" << edm::poolNames::eventTreeName() << "' in the last open file, \n"
87  << "file: '" << branchMap_.getFile()->GetName()
88  << "'\n Please check that the file is a standard CMS ROOT format.\n"
89  << "If the above is not the file you expect then please open your data file after all other files.";
90  }
91  Long_t eventEntry = eventTree->GetReadEntry();
92  // std::cout << "eventEntry " << eventEntry << std::endl;
93  branchMap_.updateEvent(eventEntry);
94  if (eventEntry < 0) {
95  throw cms::Exception("GetEntryNotCalled")
96  << "please call GetEntry for the 'Events' TTree for each event in order to make edm::Ref's work."
97  << "\n Also be sure to call 'SetAddress' for all Branches after calling the GetEntry.";
98  }
99 
101 
102  return getIt(branchID, eventEntry);
103 }
bool updateEvent(Long_t eventEntry)
bool updateFile(TFile *file)
TTree const * getEventTree() const
edm::WrapperBase const * getIt(edm::ProductID const &) const override
TFile const * getFile() const
std::string const & eventTreeName()
Definition: BranchType.cc:220
fwlite::BranchMapReader branchMap_
edm::BranchID productToBranchID(const edm::ProductID &pid)

◆ getIt() [2/2]

edm::WrapperBase const * BareRootProductGetter::getIt ( edm::BranchID const &  branchID,
Long_t  eventEntry 
) const
private

Definition at line 105 of file BareRootProductGetter.cc.

References edmScanValgrind::buffer, runTheMatrix::const, createNewBuffer(), Exception, idToBuffers_, and dumpMFGeometry_cfg::prod.

105  {
106  Buffer* buffer = nullptr;
107  IdToBuffers::iterator itBuffer = idToBuffers_.find(branchID);
108 
109  // std::cout << "Buffers" << std::endl;
110  if (itBuffer == idToBuffers_.end()) {
111  buffer = createNewBuffer(branchID);
112  // std::cout << "buffer " << buffer << std::endl;
113  if (nullptr == buffer) {
114  return nullptr;
115  }
116  } else {
117  buffer = &(itBuffer->second);
118  }
119  if (nullptr == buffer) {
120  throw cms::Exception("NullBuffer") << "Found a null buffer which is supposed to hold the data item."
121  << "\n Please contact developers since this message should not happen.";
122  }
123  if (nullptr == buffer->branch_) {
124  throw cms::Exception("NullBranch") << "The TBranch which should hold the data item is null."
125  << "\n Please contact the developers since this message should not happen.";
126  }
127  if (buffer->eventEntry_ != eventEntry) {
128  //NOTE: Need to reset address because user could have set the address themselves
129  //std::cout << "new event" << std::endl;
130 
131  //ROOT WORKAROUND: Create new objects so any internal data cache will get cleared
132  void* address = buffer->class_->New();
133 
134  static TClass const* edproductTClass = TClass::GetClass(typeid(edm::WrapperBase));
135  edm::WrapperBase const* prod =
136  static_cast<edm::WrapperBase const*>(buffer->class_->DynamicCast(edproductTClass, address, true));
137 
138  if (nullptr == prod) {
139  cms::Exception("FailedConversion") << "failed to convert a '" << buffer->class_->GetName()
140  << "' to a edm::WrapperBase."
141  << "Please contact developers since something is very wrong.";
142  }
143  buffer->address_ = address;
144  buffer->product_ = std::shared_ptr<edm::WrapperBase const>(prod);
145  //END WORKAROUND
146 
147  address = &(buffer->address_);
148  buffer->branch_->SetAddress(address);
149 
150  buffer->branch_->GetEntry(eventEntry);
151  buffer->eventEntry_ = eventEntry;
152  }
153  if (!buffer->product_) {
154  throw cms::Exception("BranchGetEntryFailed")
155  << "Calling GetEntry with index " << eventEntry << "for branch " << buffer->branch_->GetName() << " failed.";
156  }
157 
158  return buffer->product_.get();
159 }
Buffer * createNewBuffer(edm::BranchID const &) const

◆ getThinnedAssociation()

edm::ThinnedAssociation const * BareRootProductGetter::getThinnedAssociation ( edm::BranchID const &  branchID,
Long_t  eventEntry 
) const
private

Definition at line 268 of file BareRootProductGetter.cc.

References runTheMatrix::const, edm::WrapperBase::dynamicTypeInfo(), Exception, getIt(), edm::errors::LogicError, and wrapper.

Referenced by getThinnedKeyFrom(), getThinnedProduct(), and getThinnedProducts().

269  {
270  edm::WrapperBase const* wrapperBase = getIt(branchID, eventEntry);
271  if (wrapperBase == nullptr) {
273  << "BareRootProductGetter::getThinnedAssociation, product ThinnedAssociation not found.\n";
274  }
275  if (!(typeid(edm::ThinnedAssociation) == wrapperBase->dynamicTypeInfo())) {
277  << "BareRootProductGetter::getThinnedAssociation, product has wrong type, not a ThinnedAssociation.\n";
278  }
280  static_cast<edm::Wrapper<edm::ThinnedAssociation> const*>(wrapperBase);
281 
282  edm::ThinnedAssociation const* thinnedAssociation = wrapper->product();
283  return thinnedAssociation;
284 }
std::type_info const & dynamicTypeInfo() const
Definition: WrapperBase.h:42
edm::WrapperBase const * getIt(edm::ProductID const &) const override
static HepMC::HEPEVT_Wrapper wrapper

◆ getThinnedKeyFrom()

edm::OptionalThinnedKey BareRootProductGetter::getThinnedKeyFrom ( edm::ProductID const &  parent,
unsigned int  key,
edm::ProductID const &  thinned 
) const
overridevirtual

Implements edm::EDProductGetter.

Definition at line 187 of file BareRootProductGetter.cc.

References cms::Exception::addContext(), branchMap_, EcalMonitorTask_cff::func, fwlite::BranchMapReader::getEventTree(), getThinnedAssociation(), edm::detail::getThinnedKeyFrom_implementation(), edm::BranchID::isValid(), crabWrapper::key, class-composition::parent, fwlite::BranchMapReader::productToBranchID(), runTheMatrix::ret, and fwlite::BranchMapReader::thinnedAssociationsHelper().

189  {
190  Long_t eventEntry = branchMap_.getEventTree()->GetReadEntry();
192  if (!parent.isValid())
193  return std::monostate{};
194  edm::BranchID thinned = branchMap_.productToBranchID(thinnedID);
195  if (!thinned.isValid())
196  return std::monostate{};
197  try {
199  parentID,
200  parent,
201  key,
202  thinnedID,
203  thinned,
205  [this, eventEntry](edm::BranchID const& branchID) { return getThinnedAssociation(branchID, eventEntry); });
206  if (auto factory = std::get_if<edm::detail::GetThinnedKeyFromExceptionFactory>(&ret)) {
207  return [func = *factory]() {
208  auto ex = func();
209  ex.addContext("Calling BareRootProductGetter::getThinnedKeyFrom()");
210  return ex;
211  };
212  } else {
213  return ret;
214  }
215  } catch (edm::Exception& ex) {
216  ex.addContext("Calling BareRootProductGetter::getThinnedKeyFrom()");
217  throw ex;
218  }
219 }
ret
prodAgent to be discontinued
std::variant< unsigned int, GetThinnedKeyFromExceptionFactory, std::monostate > getThinnedKeyFrom_implementation(ProductID const &parentID, BranchID const &parent, unsigned int key, ProductID const &thinnedID, BranchID thinned, ThinnedAssociationsHelper const &thinnedAssociationsHelper, F &&getThinnedAssociation)
TTree const * getEventTree() const
const edm::ThinnedAssociationsHelper & thinnedAssociationsHelper() const
bool isValid() const
Definition: BranchID.h:22
void addContext(std::string const &context)
Definition: Exception.cc:169
edm::ThinnedAssociation const * getThinnedAssociation(edm::BranchID const &branchID, Long_t eventEntry) const
fwlite::BranchMapReader branchMap_
edm::BranchID productToBranchID(const edm::ProductID &pid)

◆ getThinnedProduct()

std::optional< std::tuple< edm::WrapperBase const *, unsigned int > > BareRootProductGetter::getThinnedProduct ( edm::ProductID const &  pid,
unsigned int  key 
) const
overridevirtual

Implements edm::EDProductGetter.

Definition at line 161 of file BareRootProductGetter.cc.

References b, branchMap_, fwlite::BranchMapReader::getEventTree(), getIt(), getThinnedAssociation(), edm::detail::getThinnedProduct(), crabWrapper::key, AlCaHLTBitMon_ParallelJobs::p, fwlite::BranchMapReader::productToBranchID(), and fwlite::BranchMapReader::thinnedAssociationsHelper().

162  {
163  Long_t eventEntry = branchMap_.getEventTree()->GetReadEntry();
165  pid,
166  key,
168  [this](edm::ProductID const& p) { return branchMap_.productToBranchID(p); },
169  [this, eventEntry](edm::BranchID const& b) { return getThinnedAssociation(b, eventEntry); },
170  [this](edm::ProductID const& p) { return getIt(p); });
171 }
std::optional< std::tuple< WrapperBase const *, unsigned int > > getThinnedProduct(ProductID const &pid, unsigned int key, ThinnedAssociationsHelper const &thinnedAssociationsHelper, F1 pidToBid, F2 getThinnedAssociation, F3 getByProductID)
TTree const * getEventTree() const
const edm::ThinnedAssociationsHelper & thinnedAssociationsHelper() const
edm::WrapperBase const * getIt(edm::ProductID const &) const override
double b
Definition: hdecay.h:118
edm::ThinnedAssociation const * getThinnedAssociation(edm::BranchID const &branchID, Long_t eventEntry) const
fwlite::BranchMapReader branchMap_
edm::BranchID productToBranchID(const edm::ProductID &pid)

◆ getThinnedProducts()

void BareRootProductGetter::getThinnedProducts ( edm::ProductID const &  pid,
std::vector< edm::WrapperBase const *> &  foundContainers,
std::vector< unsigned int > &  keys 
) const
overridevirtual

Implements edm::EDProductGetter.

Definition at line 173 of file BareRootProductGetter.cc.

References b, branchMap_, fwlite::BranchMapReader::getEventTree(), getIt(), getThinnedAssociation(), edm::detail::getThinnedProducts(), relativeConstraints::keys, AlCaHLTBitMon_ParallelJobs::p, fwlite::BranchMapReader::productToBranchID(), and fwlite::BranchMapReader::thinnedAssociationsHelper().

175  {
176  Long_t eventEntry = branchMap_.getEventTree()->GetReadEntry();
178  pid,
180  [this](edm::ProductID const& p) { return branchMap_.productToBranchID(p); },
181  [this, eventEntry](edm::BranchID const& b) { return getThinnedAssociation(b, eventEntry); },
182  [this](edm::ProductID const& p) { return getIt(p); },
183  foundContainers,
184  keys);
185 }
TTree const * getEventTree() const
const edm::ThinnedAssociationsHelper & thinnedAssociationsHelper() const
void getThinnedProducts(ProductID const &pid, ThinnedAssociationsHelper const &thinnedAssociationsHelper, F1 pidToBid, F2 getThinnedAssociation, F3 getByProductID, std::vector< WrapperBase const *> &foundContainers, std::vector< unsigned int > &keys)
edm::WrapperBase const * getIt(edm::ProductID const &) const override
double b
Definition: hdecay.h:118
edm::ThinnedAssociation const * getThinnedAssociation(edm::BranchID const &branchID, Long_t eventEntry) const
fwlite::BranchMapReader branchMap_
edm::BranchID productToBranchID(const edm::ProductID &pid)

◆ operator=()

BareRootProductGetter const& BareRootProductGetter::operator= ( BareRootProductGetter const &  )
delete

◆ transitionIndex_()

unsigned int BareRootProductGetter::transitionIndex_ ( ) const
inlineoverrideprivatevirtual

Implements edm::EDProductGetter.

Definition at line 92 of file BareRootProductGetter.h.

92 { return 0u; }

Member Data Documentation

◆ branchMap_

fwlite::BranchMapReader BareRootProductGetter::branchMap_
mutableprivate

◆ idToBuffers_

IdToBuffers BareRootProductGetter::idToBuffers_
mutableprivate

Definition at line 114 of file BareRootProductGetter.h.

Referenced by createNewBuffer(), and getIt().