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.

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 }

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

Referenced by getIt().

◆ getIt() [1/2]

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

Definition at line 105 of file BareRootProductGetter.cc.

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 }

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

◆ getIt() [2/2]

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

Implements edm::EDProductGetter.

Definition at line 71 of file BareRootProductGetter.cc.

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 }

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().

◆ getThinnedAssociation()

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

Definition at line 268 of file BareRootProductGetter.cc.

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 }

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

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

◆ 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.

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 }

References cms::Exception::addContext(), branchMap_, TrackCollections2monitor_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().

◆ 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.

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 }

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

◆ 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.

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 }

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

◆ 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().

edm::detail::getThinnedProduct
std::optional< std::tuple< WrapperBase const *, unsigned int > > getThinnedProduct(ProductID const &pid, unsigned int key, ThinnedAssociationsHelper const &thinnedAssociationsHelper, F1 pidToBid, F2 getThinnedAssociation, F3 getByProductID)
Definition: getThinned_implementation.h:287
runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:543
edm::TypeWithDict::byName
static TypeWithDict byName(std::string const &name)
Definition: TypeWithDict.cc:74
edm::poolNames::eventTreeName
std::string const & eventTreeName()
Definition: BranchType.cc:220
cms::Exception::addContext
void addContext(std::string const &context)
Definition: Exception.cc:165
edm::errors::LogicError
Definition: EDMException.h:37
MicroEventContent_cff.branch
branch
Definition: MicroEventContent_cff.py:174
edm::ThinnedAssociation
Definition: ThinnedAssociation.h:15
fwlite::BranchMapReader::branchIDToBranch
const edm::BranchDescription & branchIDToBranch(const edm::BranchID &bid) const
Definition: BranchMapReader.h:86
relativeConstraints.keys
keys
Definition: relativeConstraints.py:89
wrapper
static HepMC::HEPEVT_Wrapper wrapper
Definition: BeamHaloProducer.cc:47
BareRootProductGetter::idToBuffers_
IdToBuffers idToBuffers_
Definition: BareRootProductGetter.h:114
fwlite::BranchMapReader::productToBranchID
edm::BranchID productToBranchID(const edm::ProductID &pid)
Definition: BranchMapReader.h:84
fwlite::BranchMapReader::getEventTree
TTree const * getEventTree() const
Definition: BranchMapReader.h:94
watchdog.const
const
Definition: watchdog.py:83
edm::Wrapper
Definition: Product.h:10
fwlite::BranchMapReader::updateEvent
bool updateEvent(Long_t eventEntry)
Definition: BranchMapReader.cc:604
edm::Exception
Definition: EDMException.h:77
edmScanValgrind.buffer
buffer
Definition: edmScanValgrind.py:171
fwlite::BranchMapReader::updateFile
bool updateFile(TFile *file)
Definition: BranchMapReader.cc:610
edm::detail::getThinnedKeyFrom_implementation
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)
Definition: getThinned_implementation.h:394
edm::BranchID
Definition: BranchID.h:14
dumpMFGeometry_cfg.prod
prod
Definition: dumpMFGeometry_cfg.py:24
BareRootProductGetter::getThinnedAssociation
edm::ThinnedAssociation const * getThinnedAssociation(edm::BranchID const &branchID, Long_t eventEntry) const
Definition: BareRootProductGetter.cc:268
BareRootProductGetter::branchMap_
fwlite::BranchMapReader branchMap_
Definition: BareRootProductGetter.h:115
fwlite::BranchMapReader::thinnedAssociationsHelper
const edm::ThinnedAssociationsHelper & thinnedAssociationsHelper() const
Definition: BranchMapReader.h:109
b
double b
Definition: hdecay.h:118
newFWLiteAna.fullName
fullName
Definition: newFWLiteAna.py:122
edm::WrapperBase::dynamicTypeInfo
std::type_info const & dynamicTypeInfo() const
Definition: WrapperBase.h:42
edm::TypeWithDict
Definition: TypeWithDict.h:38
BareRootProductGetter::getIt
edm::WrapperBase const * getIt(edm::ProductID const &) const override
Definition: BareRootProductGetter.cc:71
AlCaHLTBitMon_ParallelJobs.p
def p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
BareRootProductGetter::createNewBuffer
Buffer * createNewBuffer(edm::BranchID const &) const
Definition: BareRootProductGetter.cc:221
edm::WrapperBase
Definition: WrapperBase.h:23
edm::BranchDescription::branchName
std::string const & branchName() const
Definition: BranchDescription.h:120
edm::wrappedClassName
std::string wrappedClassName(std::string const &iFullName)
Definition: WrappedClassName.cc:4
TrackCollections2monitor_cff.func
func
Definition: TrackCollections2monitor_cff.py:359
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
fwlite::BranchMapReader::getFile
TFile const * getFile() const
Definition: BranchMapReader.h:92
eostools.move
def move(src, dest)
Definition: eostools.py:511
Exception
Definition: hltDiff.cc:245
edm::BranchID::isValid
bool isValid() const
Definition: BranchID.h:22
edm::BranchDescription
Definition: BranchDescription.h:32
edm::BranchDescription::className
std::string const & className() const
Definition: BranchDescription.h:79
edm::detail::getThinnedProducts
void getThinnedProducts(ProductID const &pid, ThinnedAssociationsHelper const &thinnedAssociationsHelper, F1 pidToBid, F2 getThinnedAssociation, F3 getByProductID, std::vector< WrapperBase const * > &foundContainers, std::vector< unsigned int > &keys)
Definition: getThinned_implementation.h:334
crabWrapper.key
key
Definition: crabWrapper.py:19
class-composition.parent
parent
Definition: class-composition.py:98
edm::ProductID
Definition: ProductID.h:27