21 #include "TTreeCache.h" 53 std::shared_ptr<HistoryGetterBase> historyGetter,
54 std::shared_ptr<BranchMapReader> branchMap,
55 std::shared_ptr<edm::EDProductGetter> getter,
57 branchMap_(branchMap),
58 historyGetter_(historyGetter),
62 branchAccessFunc_(baFunc)
65 throw cms::Exception(
"NoTree")<<
"The TTree pointer passed to the constructor was null";
69 tree_->SetCacheSize();
110 branchName+=iProcess;
113 return iTree->GetBranch(branchName.c_str());
138 TTreeCache* tcache =
dynamic_cast<TTreeCache*
> (
branchMap_->getFile()->GetCacheRead());
140 if (
nullptr != tcache) {
142 tcache->SetLearnEntries(100);
143 tcache->SetEntryRange(0,
tree_->GetEntries());
146 tree_->LoadTree(eventEntry);
150 iData.
branch_->GetEntry(eventEntry);
157 char const* iModuleLabel,
158 char const* iProductInstanceLabel,
159 char const* iProcessLabel)
const 164 KeyToDataMap::iterator itFind =
data_.find(key);
165 if(itFind ==
data_.end()) {
175 TBranch*
branch =
nullptr;
176 std::shared_ptr<internal::Data> theData;
178 if (
nullptr == iProcessLabel || iProcessLabel == key.
kEmpty() ||
179 strlen(iProcessLabel)==0) {
187 lastLabel = &(iproc->processName());
189 if(
nullptr != branch) {
193 if(
nullptr == branch) {
197 if(
nullptr != lastLabel) {
198 internal::DataKey fullKey(type,iModuleLabel,iProductInstanceLabel,lastLabel->c_str());
199 itFind =
data_.find(fullKey);
200 if(itFind !=
data_.end()) {
202 theData = itFind->second;
205 foundProcessLabel = *lastLabel;
211 if(
nullptr == branch){
217 size_t moduleLabelLen = strlen(iModuleLabel)+1;
218 char* newModule =
new char[moduleLabelLen];
219 std::strncpy(newModule,iModuleLabel,moduleLabelLen);
224 size_t newProductLen = strlen(key.
product())+1;
225 newProduct =
new char[newProductLen];
226 std::strncpy(newProduct,key.
product(),newProductLen);
231 size_t newProcessLen = strlen(key.
process())+1;
232 newProcess =
new char[newProcessLen];
233 std::strncpy(newProcess,key.
process(),newProcessLen);
238 if(
nullptr == theData.get()) {
244 throw cms::Exception(
"UnknownType") <<
"No dictionary exists for type " << iInfo.name();
250 throw cms::Exception(
"ConstructionFailed") <<
"failed to construct an instance of " << type.
name();
252 auto newData = std::make_shared<internal::Data>();
253 newData->branch_ =
branch;
255 newData->lastProduct_ = -1;
256 newData->pObj_ = obj.
address();
257 newData->pProd_ =
nullptr;
258 branch->SetAddress(&(newData->pObj_));
261 itFind =
data_.insert(std::make_pair(newKey, theData)).first;
263 if(!foundProcessLabel.empty()) {
265 newProcess =
new char[foundProcessLabel.size()+1];
266 std::strcpy(newProcess,foundProcessLabel.c_str());
270 data_.insert(std::make_pair(newKey,theData));
273 return *(itFind->second);
278 char const* iModuleLabel,
279 char const* iProductInstanceLabel,
280 char const* iProcessLabel)
const 285 if (
nullptr != theData.
branch_) {
293 char const* iModuleLabel,
294 char const* iProductInstanceLabel,
295 char const* iProcessLabel,
296 void* oData, Long_t eventEntry)
const 299 void** pOData =
reinterpret_cast<void**
>(oData);
305 if (
nullptr != theData.
branch_) {
313 if (
nullptr == *pOData)
return false;
320 KeyToDataMap::iterator& itData)
const {
342 if(
data_.end() == itData) {
350 if(
nullptr == dummy) {
354 assert(itData !=
data_.end());
355 assert(dummy == itData->second->obj_.address());
363 typedef std::pair<edm::ProductID,edm::BranchListIndex> IDPair;
365 std::map<IDPair,std::shared_ptr<internal::Data> >::const_iterator itFound =
idToData_.find(theID);
369 KeyToDataMap::iterator itData;
374 itFound =
idToData_.insert(std::make_pair(theID,itData->second)).first;
376 if(eventEntry != itFound->second->lastProduct_) {
380 if(
nullptr == itFound->second->pProd_) {
382 if(
nullptr == itFound->second->pProd_) {
386 return itFound->second->pProd_;
396 KeyToDataMap::iterator itData;
401 itFound =
bidToData_.insert(std::make_pair(bid,itData->second)).first;
403 if(eventEntry != itFound->second->lastProduct_) {
407 if(
nullptr == itFound->second->pProd_) {
409 if(
nullptr == itFound->second->pProd_) {
413 return itFound->second->pProd_;
421 objectWithDict.
typeOf()));
428 if(!parent.
isValid())
return nullptr;
432 for(
auto associatedBranches = thinnedAssociationsHelper.
parentBegin(parent),
433 iEnd = thinnedAssociationsHelper.
parentEnd(parent);
434 associatedBranches != iEnd; ++associatedBranches) {
438 if(thinnedAssociation ==
nullptr)
continue;
444 unsigned int thinnedIndex = 0;
454 if(thinnedCollection ==
nullptr) {
458 if(thinnedFromRecursiveCall !=
nullptr) {
460 return thinnedFromRecursiveCall;
466 return thinnedCollection;
472 std::vector<edm::WrapperBase const*>& foundContainers,
473 std::vector<unsigned int>&
keys,
474 Long_t eventEntry)
const {
481 for(
auto associatedBranches = thinnedAssociationsHelper.
parentBegin(parent),
482 iEnd = thinnedAssociationsHelper.
parentEnd(parent);
483 associatedBranches != iEnd; ++associatedBranches) {
487 if(thinnedAssociation ==
nullptr)
continue;
493 unsigned int nKeys = keys.size();
495 std::vector<unsigned int> thinnedIndexes(nKeys, doNotLookForThisIndex);
497 for(
unsigned k = 0;
k < nKeys; ++
k) {
499 if(foundContainers[
k] !=
nullptr)
continue;
501 if(keys[
k] == doNotLookForThisIndex )
continue;
517 if(thinnedCollection ==
nullptr) {
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];
527 for(
unsigned k = 0;
k < nKeys; ++
k) {
528 if(thinnedIndexes[
k] == doNotLookForThisIndex)
continue;
529 keys[
k] = thinnedIndexes[
k];
530 foundContainers[
k] = thinnedCollection;
540 if(wrapperBase ==
nullptr) {
542 <<
"DataGetterHelper::getThinnedAssociation, product ThinnedAssociation not found.\n";
546 <<
"DataGetterHelper::getThinnedAssociation, product has wrong type, not a ThinnedAssociation.\n";
552 return thinnedAssociation;
const_reverse_iterator rbegin() const
static TBranch * findBranch(TTree *iTree, std::string const &iMainLabels, std::string const &iProcess)
static ObjectWithDict byType(TypeWithDict const &)
edm::WrapperBase const * getByBranchID(edm::BranchID const &bid, Long_t eventEntry) const
edm::propagate_const< std::shared_ptr< fwlite::HistoryGetterBase > > historyGetter_
edm::ThinnedAssociation const * getThinnedAssociation(edm::BranchID const &branchID, Long_t eventEntry) const
edm::propagate_const< TBranch * > branch_
std::vector< char const * > labels_
std::map< edm::BranchID, std::shared_ptr< internal::Data > > bidToData_
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
std::type_info const & dynamicTypeInfo() const
collection_type::const_reverse_iterator const_reverse_iterator
void const * pointerToBaseType(void const *ptr, TypeWithDict const &derivedType) const
virtual std::string const getBranchNameFor(std::type_info const &, char const *, char const *, char const *) const
std::map< std::pair< edm::ProductID, edm::BranchListIndex >, std::shared_ptr< internal::Data > > idToData_
std::string const & processName() const
char const * product() const
void getThinnedProducts(edm::ProductID const &pid, std::vector< edm::WrapperBase const * > &foundContainers, std::vector< unsigned int > &keys, Long_t eventEntry) const
bool getByBranchDescription(edm::BranchDescription const &, Long_t eventEntry, KeyToDataMap::iterator &) const
std::function< void(TBranch const &)> branchAccessFunc_
static TypeWithDict byName(std::string const &name)
char const * kEmpty() const
TypeWithDict typeOf() const
std::vector< ThinnedAssociationBranches >::const_iterator parentEnd(BranchID const &) const
const bool tcUse_
Use internal TTreeCache.
char const * module() const
const edm::ProcessHistory & history() const
edm::WrapperBase const * getByProductID(edm::ProductID const &pid, Long_t eventEntry) const
const_reverse_iterator rend() const
std::string const & moduleLabel() const
std::string const & productInstanceName() const
static internal::Data branchNotFound
static char kEmptyString[1]
BranchID const & branchID() const
virtual ~DataGetterHelper()
ProductID const & thinnedCollectionID() const
void getBranchData(edm::EDProductGetter const *, Long64_t, internal::Data &) const
std::string const & fullClassName() const
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 &){})
std::shared_ptr< BranchMapReader > branchMap_
std::string wrappedClassName(std::string const &iFullName)
char const * process() const
std::vector< ThinnedAssociationBranches >::const_iterator parentBegin(BranchID const &) const
internal::Data & getBranchDataFor(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 * getThinnedProduct(edm::ProductID const &pid, unsigned int &key, Long_t eventEntry) const
edm::WrapperBase const * wrapperBasePtr(edm::ObjectWithDict const &) const
ProductID const & parentCollectionID() const
bool hasParentIndex(unsigned int parentIndex, unsigned int &thinnedIndex) const
std::shared_ptr< edm::EDProductGetter const > getter_
ProcessIndex processIndex() const
static HepMC::HEPEVT_Wrapper wrapper
std::string friendlyClassName() const