16 #include "canvas_root_io/Streamers/AssnsStreamer.h" 17 #include "canvas_root_io/Streamers/BranchDescriptionStreamer.h" 18 #include "canvas_root_io/Streamers/CacheStreamers.h" 19 #include "canvas_root_io/Streamers/ProductIDStreamer.h" 20 #include "canvas_root_io/Streamers/RefCoreStreamer.h" 21 #include "canvas_root_io/Streamers/TransientStreamer.h" 22 #include "canvas_root_io/Streamers/setPtrVectorBaseStreamer.h" 32 constexpr
char underscore{
'_'};
33 constexpr
char period{
'.'};
38 art::setCacheStreamers();
39 art::setProvenanceTransientStreamers();
40 art::detail::setBranchDescriptionStreamer();
41 art::detail::setPtrVectorBaseStreamer();
42 art::configureProductIDStreamer();
43 art::configureRefCoreStreamer();
51 unsigned int const branchNameSize =
52 branchName.size() + info.
label().size() + info.
instance().size() +
53 processName.size() + 4;
54 branchName.reserve(branchNameSize);
55 branchName += underscore;
56 branchName += info.
label();
57 branchName += underscore;
59 branchName += underscore;
60 branchName += processName;
71 std::shared_ptr<EventHistoryGetter> historyGetter)
74 initializeStreamers();
88 if (inputTag.
process().empty()) {
97 return std::make_pair(edProduct, *reverseIter);
103 unsigned int const processIndex = itProcess->second;
108 auto product = branchData->uniqueProduct_(
type);
109 return std::make_pair(product, pd->productID());
116 std::vector<art::BranchDescription const*>
120 std::vector<art::BranchDescription const*>
result;
126 auto const& pd = pr.second;
127 if (pd.friendlyClassName() != fcn) {
131 result.push_back(&pd);
136 std::vector<art::InputTag>
139 std::vector<art::InputTag>
result;
142 result.push_back(pd->inputTag());
147 std::vector<ProductWithID>
150 std::vector<ProductWithID>
result;
159 type, pd->moduleLabel(), pd->productInstanceName());
161 unsigned int const processIndex = itProcess->second;
167 if (
auto product = branchData->uniqueProduct_(
type)) {
168 result.emplace_back(product, pd->productID());
177 bool const initializeTheCache)
180 art::configureProductIDStreamer();
183 if (initializeTheCache) {
184 tree_->SetCacheSize();
188 std::vector<IndexProductIDPair> old;
191 for (
unsigned int processIndex{}; processIndex <
processNames_.size();
201 if (productID.isValid()) {
203 auto branch =
tree_->GetBranch(branchData.branchName().c_str());
207 branchData.updateFile(branch);
214 if (info.
isAssns() && branch !=
nullptr) {
215 TClass* tClass =
getTClass(info, processName);
217 art::TypeID const typeIDInDescription{tClass->GetTypeInfo()};
219 branchData.tClass()->GetTypeInfo()};
220 if (typeIDInDescription != typeIDInBranchData) {
223 std::make_unique<AssnsBranchData>(typeIDInDescription,
235 if (initializeTheCache && branch) {
236 tree_->AddBranchToCache(branch, kTRUE);
241 bd->branchName(), processIndex,
info, initializeTheCache);
246 if (initializeTheCache) {
247 tree_->StopCacheLearningPhase();
258 tree_->SetCacheSize();
262 auto const productID = i.second;
264 if (
auto branch = branchData.branch()) {
265 tree_->AddBranchToCache(branch, kTRUE);
269 tree_->StopCacheLearningPhase();
293 for (
auto i = processHistory.
begin(), iEnd = processHistory.
end();
296 if (i->processName() != *iPrevious) {
308 for (
auto const& processConfig : processHistory) {
309 std::string const& processName = processConfig.processName();
341 unsigned int const processIndex,
343 bool const initializeTheCache)
const 345 auto branch =
tree_->GetBranch(branchName.c_str());
346 if (branch ==
nullptr) {
352 auto const productID = pd->productID();
355 auto tClass =
getTClass(info, processName);
357 art::TypeID const typeIDInDescription{tClass->GetTypeInfo()};
359 std::make_unique<AssnsBranchData>(typeIDInDescription,
369 std::make_unique<BranchData>(info.
type(),
377 if (initializeTheCache && branch) {
378 tree_->AddBranchToCache(branch, kTRUE);
389 "DataGetterHelper::getTClass: "}
390 <<
"TBranch exists but no BranchDescription in ProductRegistry.\n" 391 <<
"This shouldn't be possible. For type " << info.
type().
className()
395 art::detail::AssnsStreamer::init_streamer(bd->producedClassName());
396 auto tClass = TClass::GetClass(bd->wrappedName().c_str());
397 if (tClass ==
nullptr) {
399 "DataGetterHelper::getTClass: "}
400 <<
"Missing dictionary for wrapped Assns class.\n" 401 << bd->wrappedName() <<
"\n";
414 <<
"getValidHandle was passed an empty module label. Not allowed.\n";
440 unsigned int processIndex{};
442 std::string branchName{buildBranchName(info, processName)};
456 unsigned int const infoIndex)
const 467 return branchData->uniqueProduct_(type);
472 std::vector<IndexProductIDPair>
const& processIndexToProductID,
473 unsigned int const processIndex)
const 475 auto itBranchDataIndex = lower_bound(
476 processIndexToProductID.cbegin(),
477 processIndexToProductID.cend(),
479 [](
auto const&
l,
auto const&
r) {
return l.
first <
r.first; });
480 if (itBranchDataIndex != processIndexToProductID.cend() &&
481 itBranchDataIndex->first == processIndex) {
482 return itBranchDataIndex->second;
489 unsigned int const processIndex)
const 506 auto const& orderedProcessName =
processNames_[processIndex];
512 if (branchData && branchData->branch() !=
nullptr) {
524 TClass* tClass = TClass::GetClass(desc.
wrappedName().c_str());
525 if (tClass ==
nullptr) {
527 "DataGetterHelper::getBranchData: ")
528 <<
"Missing dictionary for wrapped class.\n" 532 auto const& typeInfoOfWrapper = *tClass->GetTypeInfo();
538 unsigned int const processIndex = itProcess->second;
540 if (branchData && branchData->branch() !=
nullptr) {
553 "DataGetterHelper::getProductDescription: "}
554 <<
"No product description could be found for ProductID " << productID
565 return itFind->second.get();
578 if (branchData ==
nullptr) {
art::EDProductGetter const * getEDProductGetter_(art::ProductID const &) const override
std::map< art::ProductID, std::unique_ptr< BranchData > > branchDataMap_
const_iterator end() const
std::set< art::ProductID > branchDataMissingSet_
decltype(auto) constexpr cend(T &&obj)
ADL-aware version of std::cend.
art::BranchDescription const * productDescription(InfoForTypeLabelInstance const &info, std::string const &process) const
std::vector< art::BranchDescription const * > getProductDescriptions(art::TypeID const &typeIDOfWrapper) const
void updateFile(TFile *iFile, TTree *iTree, bool initializeTheCache)
std::string friendlyClassName() const
std::string const & wrappedName() const noexcept
void addTypeLabelInstance(art::TypeID const &type, std::string const &label, std::string const &instance) const
void addBranchData(std::string branchName, unsigned int processIndex, InfoForTypeLabelInstance const &info, bool initializeTheCache=false) const
const_iterator begin() const
const std::string instance
void initializeForProcessHistory() const
void insertIntoInfoMap(art::TypeID const &type, std::string const &label, std::string const &instance, unsigned int infoIndex) const
ProductWithID getByLabel(std::type_info const &typeInfoOfWrapper, art::InputTag const &inputTag) const
InfoForTypeLabelInstance & getInfoForTypeLabelInstance(art::TypeID const &type, std::string const &label, std::string const &instance) const
void addProcess(std::string const &processName) const
art::ProductID getMaybeValidProductID(std::vector< IndexProductIDPair > const &processIndexToProductID, unsigned int processIndex) const
std::string const & processName() const noexcept
TBranch * eventAuxiliaryBranch() const
std::vector< std::string > previousProcessHistoryNames_
TClass * tClass() const noexcept
std::string uniform_type_name(std::type_info const &tid)
std::map< art::ProductID, art::BranchDescription > const & productDescriptions() const
void updateFile(TFile *tFile)
art::ProcessHistoryID previousProcessHistoryID_
std::string const & instance() const noexcept
void updateBranchDataIndexOrderedByHistory(InfoForTypeLabelInstance const &info) const
std::vector< art::ProductID > & productIDsOrderedByHistory() const noexcept
std::vector< art::InputTag > getInputTags(std::type_info const &typeInfoOfWrapper) const
BranchData const * getBranchData(InfoForTypeLabelInstance const &info, unsigned int processIndex) const
art::BranchDescription const & getProductDescription(art::ProductID) const
std::vector< IndexProductIDPair > & processIndexToProductID() const noexcept
art::TypeID const & partnerType() const noexcept
std::string className() const
std::map< std::string, unsigned int > processNameToProcessIndex_
bool branchInRegistryOfAnyOpenedFile(art::ProductID const &) const
EventNavigator const * eventNavigator_
std::map< TypeLabelInstanceKey, unsigned int > infoMap_
std::string const & moduleLabel() const noexcept
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
BranchMapReader branchMapReader_
std::string const & label() const noexcept
std::vector< ProductWithID > getManyByType(std::type_info const &typeInfoOfWrapper) const
bool initializedForProcessHistory_
art::TypeID const & type() const noexcept
BranchData invalidBranchData_
std::pair< art::EDProduct const *, art::ProductID > ProductWithID
std::string const & productInstanceName() const noexcept
std::shared_ptr< EventHistoryGetter > historyGetter_
std::vector< InfoForTypeLabelInstance > infoVector_
static constexpr ProductID invalid() noexcept
std::vector< unsigned int > orderedProcessIndexes_
art::EDProduct const * readProduct(art::ProductID const productID, art::TypeID const &type) const
bool isAssns() const noexcept
TClass * getTClass(InfoForTypeLabelInstance const &info, std::string const &processName) const
cet::exempt_ptr< art::BranchIDLists const > branchIDLists() const
std::vector< std::string > processNames_
void initializeTTreeCache()
std::type_info const & typeInfo() const
DataGetterHelper(EventNavigator const *eventNavigator, std::shared_ptr< EventHistoryGetter > historyGetter)
art::root::DictionaryChecker dictChecker_