42 #include "canvas_root_io/Streamers/ProductIDStreamer.h" 43 #include "canvas_root_io/Utilities/DictionaryChecker.h" 73 have_table(sqlite3* db,
string const& table,
string const&
filename)
76 sqlite3_stmt* stmt =
nullptr;
78 "select 1 from sqlite_master where type='table' and name='" + table +
80 auto rc = sqlite3_prepare_v2(db, ddl.c_str(), -1, &stmt,
nullptr);
81 if (
rc == SQLITE_OK) {
82 switch (
rc = sqlite3_step(stmt)) {
93 rc = sqlite3_finalize(stmt);
94 if (
rc != SQLITE_OK) {
96 <<
"Unexpected status (" <<
rc 97 <<
") when interrogating SQLite3 DB in file " << filename <<
":\n" 98 << sqlite3_errmsg(db) <<
'\n';
125 RootInputFile::RootInputTree::~RootInputTree() {}
127 RootInputFile::RootInputTree::RootInputTree(
132 bool const missingOK )
135 tree_ =
static_cast<TTree*
>(
137 metaTree_ =
static_cast<TTree*
>(
143 entries_ = tree_->GetEntries();
146 productProvenanceBranch_ =
149 if (!missingOK && !isValid()) {
152 <<
" could not be initialized correctly from input file.\n";
157 RootInputFile::RootInputTree::auxBranch()
const 163 RootInputFile::RootInputTree::entries()
const 175 RootInputFile::RootInputTree::metaTree()
const 181 RootInputFile::RootInputTree::branches()
const 187 RootInputFile::RootInputTree::productProvenanceBranch()
const 189 return productProvenanceBranch_;
193 RootInputFile::RootInputTree::isValid()
const 195 if ((metaTree_ ==
nullptr) || (metaTree_->GetNbranches() == 0)) {
196 return tree_ && auxBranch_ && (tree_->GetNbranches() == 1);
198 return tree_ && auxBranch_ && metaTree_ && productProvenanceBranch_;
205 TBranch* branch = tree_->GetBranch(bd.
branchName().c_str());
206 assert(bd.
present() == (branch !=
nullptr));
207 assert(bd.
dropped() == (branch ==
nullptr));
213 RootInputFile::RootInputTree::dropBranch(
string const& branchName)
215 TBranch* branch = tree_->GetBranch(branchName.c_str());
216 if (branch ==
nullptr) {
219 TObjArray* leaves = tree_->GetListOfLeaves();
220 if (leaves ==
nullptr) {
223 int entries = leaves->GetEntries();
224 for (
int i = 0;
i < entries; ++
i) {
225 TLeaf* leaf =
reinterpret_cast<TLeaf*
>((*leaves)[
i]);
226 if (leaf ==
nullptr) {
229 TBranch* br = leaf->GetBranch();
233 if (br->GetMother() == branch) {
234 leaves->Remove(leaf);
238 tree_->GetListOfBranches()->Remove(branch);
239 tree_->GetListOfBranches()->Compress();
244 RootInputFile::~RootInputFile() {}
246 RootInputFile::RootInputFile(
string const& fileName,
247 string const& catalogName,
249 string const& logicalFileName,
250 unique_ptr<TFile>&& filePtr,
252 unsigned int eventsToSkip,
253 bool const compactSubRunRanges,
255 unsigned int treeCacheSize,
257 int64_t saveMemoryObjectThreshold,
258 bool delayedReadEventProducts,
259 bool delayedReadSubRunProducts,
260 bool delayedReadRunProducts,
265 shared_ptr<DuplicateChecker> duplicateChecker,
266 bool dropDescendants,
267 bool const readIncomingParameterSets,
269 vector<string>
const& secondaryFileNames,
272 : fileName_{fileName}
273 , catalog_{catalogName}
274 , processConfiguration_{processConfiguration}
275 , logicalFileName_{logicalFileName}
276 , filePtr_{move(filePtr)}
277 , origEventID_{origEventID}
278 , eventsToSkip_{eventsToSkip}
279 , compactSubRunRanges_{compactSubRunRanges}
280 , treePointers_{{make_unique<RootInputTree>(filePtr_.get(),
282 saveMemoryObjectThreshold,
285 make_unique<RootInputTree>(filePtr_.get(),
287 saveMemoryObjectThreshold,
290 make_unique<RootInputTree>(filePtr_.get(),
292 saveMemoryObjectThreshold,
295 make_unique<RootInputTree>(filePtr_.get(),
297 saveMemoryObjectThreshold,
300 , delayedReadEventProducts_{delayedReadEventProducts}
301 , delayedReadSubRunProducts_{delayedReadSubRunProducts}
302 , delayedReadRunProducts_{delayedReadRunProducts}
303 , processingMode_{processingMode}
304 , forcedRunOffset_{forcedRunOffset}
305 , noEventSort_{noEventSort}
306 , duplicateChecker_{duplicateChecker}
307 , primaryFile_{primaryFile ? primaryFile :
this}
308 , secondaryFileNames_{secondaryFileNames}
309 , rifSequence_{rifSequence}
310 , saveMemoryObjectThreshold_{saveMemoryObjectThreshold}
312 secondaryFiles_.resize(secondaryFileNames_.size());
313 if (treeMaxVirtualSize >= 0) {
314 eventTree().tree()->SetMaxVirtualSize(
315 static_cast<Long64_t>(treeMaxVirtualSize));
317 if (treeMaxVirtualSize >= 0) {
318 subRunTree().tree()->SetMaxVirtualSize(
319 static_cast<Long64_t>(treeMaxVirtualSize));
321 if (treeMaxVirtualSize >= 0) {
322 runTree().tree()->SetMaxVirtualSize(
323 static_cast<Long64_t>(treeMaxVirtualSize));
325 eventTree().tree()->SetCacheSize(static_cast<Long64_t>(treeCacheSize));
326 subRunTree().tree()->SetCacheSize(static_cast<Long64_t>(treeCacheSize));
327 runTree().tree()->SetCacheSize(static_cast<Long64_t>(treeCacheSize));
328 if (resultsTree().isValid()) {
329 if (treeMaxVirtualSize >= 0) {
330 resultsTree().tree()->SetMaxVirtualSize(
331 static_cast<Long64_t>(treeMaxVirtualSize));
333 resultsTree().tree()->SetCacheSize(static_cast<Long64_t>(treeCacheSize));
342 metaDataTree->SetCacheSize(static_cast<Long64_t>(treeCacheSize));
344 fileFormatVersion_ = detail::readMetadata<FileFormatVersion>(metaDataTree);
346 auto findexPtr = &fileIndex_;
351 branchIDLists_ = make_unique<BranchIDLists>(move(branchIDLists));
352 configureProductIDStreamer(branchIDLists_.get());
357 if (readIncomingParameterSets &&
360 for (
auto const& psEntry : psetMap) {
372 auto pHistMap = detail::readMetadata<ProcessHistoryMap>(metaDataTree);
373 ProcessHistoryRegistry::put(pHistMap);
382 if (fileFormatVersion_.era_ != expected_era) {
384 <<
"Can only read files written during the \"" << expected_era
387 <<
"\"" << fileName_ <<
"\" was " 388 << (fileFormatVersion_.era_.empty() ?
390 (
"set to \"" + fileFormatVersion_.era_ +
"\" "))
394 if (fileFormatVersion_.value_ >= 5) {
397 "RootFileDB", filePtr_.get()));
398 if (readIncomingParameterSets &&
399 have_table(*sqliteDB_,
"ParameterSets", fileName_)) {
402 if (ServiceRegistry::isAvailable<art::FileCatalogMetadata>() &&
403 have_table(*sqliteDB_,
"FileCatalog_metadata", fileName_)) {
404 sqlite3_stmt* stmt{
nullptr};
405 sqlite3_prepare_v2(*sqliteDB_,
406 "SELECT Name, Value from FileCatalog_metadata;",
410 vector<pair<string, string>>
md;
411 while (sqlite3_step(stmt) == SQLITE_ROW) {
413 reinterpret_cast<char const*
>(sqlite3_column_text(stmt, 0))};
415 reinterpret_cast<char const*
>(sqlite3_column_text(stmt, 1))};
418 int const finalize_status = sqlite3_finalize(stmt);
419 if (finalize_status != SQLITE_OK) {
421 <<
"Unexpected status (" << finalize_status
422 <<
") from DB status cleanup:\n" 423 << sqlite3_errmsg(*sqliteDB_) <<
'\n';
426 ->setMetadataFromInput(md);
432 readParentageTree(treeCacheSize);
433 initializeDuplicateChecker();
435 fileIndex_.sortBy_Run_SubRun_EventEntry();
437 fiIter_ = fileIndex_.begin();
438 fiBegin_ = fileIndex_.begin();
439 fiEnd_ = fileIndex_.end();
440 readEventHistoryTree(treeCacheSize);
448 detail::readMetadata<ProductRegistry>(metaDataTree,
false).productList_;
453 dropOnInput(groupSelectorRules, dropDescendants, presentProducts_);
462 auto set_validity_then_add_branch = [
this](
BranchType const bt) {
463 for (
auto& prod : presentProducts_.get(bt).descriptions) {
464 auto& pd = prod.second;
465 if (treePointers_[bt]->
tree()->GetBranch(pd.branchName().c_str()) ==
467 pd.setValidity(BranchDescription::Transients::Dropped);
469 treePointers_[bt]->addBranch(pd);
476 outputCallbacks.
invoke(presentProducts_);
479 fastClonable_ = setIfFastClonable(fcip);
483 root::DictionaryChecker checker{};
488 checker.reportMissingDictionaries();
491 configureProductIDStreamer();
495 RootInputFile::setEntry_Event(
EventID const&
id,
bool exact )
497 fiIter_ = fileIndex_.findPosition(
id, exact);
498 if (fiIter_ == fiEnd_) {
505 RootInputFile::setEntry_SubRun(
SubRunID const&
id,
bool exact )
507 fiIter_ = fileIndex_.findPosition(
id, exact);
508 if (fiIter_ == fiEnd_) {
515 RootInputFile::setEntry_Run(
RunID const&
id,
bool exact )
517 fiIter_ = fileIndex_.findPosition(
id, exact);
518 if (fiIter_ == fiEnd_) {
525 RootInputFile::eventTree()
const 527 return *treePointers_[
InEvent];
531 RootInputFile::subRunTree()
const 537 RootInputFile::runTree()
const 539 return *treePointers_[
InRun];
543 RootInputFile::resultsTree()
const 549 RootInputFile::eventTree()
551 return *treePointers_[
InEvent];
555 RootInputFile::subRunTree()
561 RootInputFile::runTree()
563 return *treePointers_[
InRun];
567 RootInputFile::resultsTree()
576 auto pAux = &eventAux_;
577 auxbr->SetAddress(&pAux);
584 auto auxbr = treePointers_[
InSubRun]->auxBranch();
585 auto pAux = &subRunAux_;
586 auxbr->SetAddress(&pAux);
593 auto auxbr = treePointers_[
InRun]->auxBranch();
594 auto pAux = &runAux_;
595 auxbr->SetAddress(&pAux);
602 auto auxbr = treePointers_[
InResults]->auxBranch();
603 auto pAux = &resultsAux_;
604 auxbr->SetAddress(&pAux);
608 unique_ptr<RangeSetHandler>
613 auto auxbr = treePointers_[
InSubRun]->auxBranch();
614 auto pAux = &auxResult;
615 auxbr->SetAddress(&pAux);
618 if (fileFormatVersion_.value_ < 9) {
619 swap(subRunAux_, auxResult);
620 return make_unique<OpenRangeSetHandler>(subRunAux_.run());
622 auto resolve_info = [
this](
auto const id) {
625 SubRunAuxiliary::branch_type,
627 compactSubRunRanges_);
629 auto rangeSetInfo = resolve_info(auxResult.rangeSetID());
630 for (
auto i = entries.cbegin() + 1,
e = entries.cend();
i !=
e; ++
i) {
633 auto auxbr = treePointers_[
InSubRun]->auxBranch();
635 auxbr->SetAddress(&pAux);
639 rangeSetInfo.update(resolve_info(tmpAux.rangeSetID()),
640 compactSubRunRanges_);
642 auxResult.setRangeSetID(-1u);
643 swap(subRunAux_, auxResult);
644 return make_unique<ClosedRangeSetHandler>(
resolveRangeSet(rangeSetInfo));
647 unique_ptr<RangeSetHandler>
652 auto auxbr = treePointers_[
InRun]->auxBranch();
653 auto pAux = &auxResult;
654 auxbr->SetAddress(&pAux);
657 if (fileFormatVersion_.value_ < 9) {
658 swap(runAux_, auxResult);
659 return make_unique<OpenRangeSetHandler>(runAux_.run());
661 auto resolve_info = [
this](
auto const id) {
664 RunAuxiliary::branch_type,
666 compactSubRunRanges_);
668 auto rangeSetInfo = resolve_info(auxResult.rangeSetID());
669 for (
auto i = entries.cbegin() + 1,
e = entries.cend();
i !=
e; ++
i) {
672 auto auxbr = treePointers_[
InRun]->auxBranch();
674 auxbr->SetAddress(&pAux);
678 rangeSetInfo.update(resolve_info(tmpAux.rangeSetID()),
679 compactSubRunRanges_);
681 auxResult.setRangeSetID(-1u);
682 swap(runAux_, auxResult);
683 return make_unique<ClosedRangeSetHandler>(
resolveRangeSet(rangeSetInfo));
687 RootInputFile::fileName()
const 693 RootInputFile::treePointers()
695 return treePointers_;
699 RootInputFile::fileFormatVersion()
const 701 return fileFormatVersion_;
705 RootInputFile::fastClonable()
const 707 return fastClonable_;
711 RootInputFile::rewind()
722 RootInputFile::setToLastEntry()
728 RootInputFile::nextEntry()
734 RootInputFile::previousEntry()
740 RootInputFile::advanceEntry(
size_t n)
748 RootInputFile::eventsToSkip()
const 750 return eventsToSkip_;
753 shared_ptr<FileIndex>
754 RootInputFile::fileIndexSharedPtr()
const 756 return fileIndexSharedPtr_;
759 vector<string>
const&
760 RootInputFile::secondaryFileNames()
const 762 return secondaryFileNames_;
765 vector<unique_ptr<RootInputFile>>
const&
766 RootInputFile::secondaryFiles()
const 768 return secondaryFiles_;
772 RootInputFile::readParentageTree(
unsigned int const treeCacheSize)
777 auto parentageTree =
static_cast<TTree*
>(
779 if (!parentageTree) {
783 parentageTree->SetCacheSize(static_cast<Long64_t>(treeCacheSize));
784 auto idBuffer = root::getObjectRequireDict<ParentageID>();
785 auto pidBuffer = &idBuffer;
789 auto parentageBuffer = root::getObjectRequireDict<Parentage>();
790 auto pParentageBuffer = &parentageBuffer;
795 for (
EntryNumber i = 0, numEntries = parentageTree->GetEntries();
799 if (idBuffer != parentageBuffer.id()) {
801 <<
"Corruption of Parentage tree detected.\n";
803 ParentageRegistry::emplace(parentageBuffer.id(), parentageBuffer);
813 RootInputFile::eventIDForFileIndexPosition()
const 815 if (fiIter_ == fiEnd_) {
818 return fiIter_->eventID_;
827 if (secondaryFileNames_.size() != 0) {
830 if (!fileIndex_.allEventsInEntryOrder()) {
833 if (eventsToSkip_ != 0) {
844 if (processingMode_ != InputSource::RunsSubRunsAndEvents) {
847 if (forcedRunOffset_ != 0) {
852 while ((it != fiEnd_) && (it->getEntryType() != FileIndex::kEvent)) {
858 if (it->eventID_ < origEventID_) {
865 RootInputFile::setForcedRunOffset(
RunNumber_t const& forcedRunNumber)
867 if (fiBegin_ == fiEnd_) {
870 forcedRunOffset_ = 0;
871 if (!
RunID(forcedRunNumber).isValid()) {
874 forcedRunOffset_ = forcedRunNumber - fiBegin_->eventID_.
run();
875 if (forcedRunOffset_ != 0) {
876 fastClonable_ =
false;
878 return forcedRunOffset_;
881 unique_ptr<FileBlock>
882 RootInputFile::createFileBlock()
884 return std::make_unique<RootFileBlock>(
893 RootInputFile::getEntryType()
const 895 if (fiIter_ == fiEnd_) {
896 return FileIndex::kEnd;
898 return fiIter_->getEntryType();
902 RootInputFile::getNextEntryTypeWanted()
904 auto entryType = getEntryType();
905 if (entryType == FileIndex::kEnd) {
906 return FileIndex::kEnd;
908 RunID currentRun(fiIter_->eventID_.runID());
909 if (!currentRun.isValid()) {
910 return FileIndex::kEnd;
912 if (entryType == FileIndex::kRun) {
914 if (currentRun < origEventID_.runID()) {
915 fiIter_ = fileIndex_.findPosition(origEventID_.runID(),
false);
916 return getNextEntryTypeWanted();
918 return FileIndex::kRun;
920 if (processingMode_ == InputSource::Runs) {
921 fiIter_ = fileIndex_.findPosition(
922 currentRun.isValid() ? currentRun.next() : currentRun,
false);
923 return getNextEntryTypeWanted();
925 SubRunID const& currentSubRun = fiIter_->eventID_.subRunID();
926 if (entryType == FileIndex::kSubRun) {
928 if ((currentRun == origEventID_.runID()) &&
929 (currentSubRun < origEventID_.subRunID())) {
930 fiIter_ = fileIndex_.findSubRunOrRunPosition(origEventID_.subRunID());
931 return getNextEntryTypeWanted();
933 return FileIndex::kSubRun;
935 if (processingMode_ == InputSource::RunsAndSubRuns) {
936 fiIter_ = fileIndex_.findSubRunOrRunPosition(currentSubRun.
next());
937 return getNextEntryTypeWanted();
939 assert(entryType == FileIndex::kEvent);
941 if (fiIter_->eventID_ < origEventID_) {
942 fiIter_ = fileIndex_.findPosition(origEventID_);
943 return getNextEntryTypeWanted();
945 if (duplicateChecker_.get() && duplicateChecker_->isDuplicateAndCheckActive(
946 fiIter_->eventID_, fileName_)) {
948 return getNextEntryTypeWanted();
950 if (eventsToSkip_ == 0) {
951 return FileIndex::kEvent;
956 while ((eventsToSkip_ != 0) && (fiIter_ != fiEnd_) &&
957 (getEntryType() == FileIndex::kEvent)) {
960 while ((eventsToSkip_ != 0) && (fiIter_ != fiEnd_) &&
961 (fiIter_->getEntryType() == FileIndex::kEvent) &&
962 duplicateChecker_.get() &&
963 duplicateChecker_->isDuplicateAndCheckActive(fiIter_->eventID_,
968 return getNextEntryTypeWanted();
972 RootInputFile::validateFile()
974 if (!fileFormatVersion_.isValid()) {
975 fileFormatVersion_.value_ = 0;
977 if (!eventTree().isValid()) {
979 <<
"'Events' tree is corrupted or not present\n" 980 <<
"in the input file.\n";
982 if (fileIndex_.empty()) {
984 <<
"FileIndex information is missing for the input file.\n";
989 RootInputFile::reportOpened()
993 RootInputFile::close(
bool reallyClose)
999 for (
auto const& sf : secondaryFiles_) {
1003 sf->filePtr_->Close();
1013 auto pHistory = &history;
1014 auto eventHistoryBranch =
1016 if (!eventHistoryBranch) {
1018 <<
"Failed to find history branch in event history tree.\n";
1020 eventHistoryBranch->SetAddress(&pHistory);
1027 while ((offset > 0) && (fiIter_ != fiEnd_)) {
1028 if (fiIter_->getEntryType() == FileIndex::kEvent) {
1033 while ((offset < 0) && (fiIter_ != fiBegin_)) {
1035 if (fiIter_->getEntryType() == FileIndex::kEvent) {
1039 while ((fiIter_ != fiEnd_) &&
1040 (fiIter_->getEntryType() != FileIndex::kEvent)) {
1059 unique_ptr<EventPrincipal>
1060 RootInputFile::readEvent()
1062 assert(fiIter_ != fiEnd_);
1063 assert(fiIter_->getEntryType() == FileIndex::kEvent);
1064 assert(fiIter_->eventID_.runID().isValid());
1065 auto const& entryNumbers = getEntryNumbers(
InEvent);
1066 auto ep = readCurrentEvent(entryNumbers);
1068 assert(eventAux_.run() == fiIter_->eventID_.run() + forcedRunOffset_);
1069 assert(eventAux_.subRunID() == fiIter_->eventID_.subRunID());
1076 unique_ptr<EventPrincipal>
1077 RootInputFile::readCurrentEvent(pair<EntryNumbers, bool>
const& entryNumbers)
1079 assert(entryNumbers.first.size() == 1ull);
1080 fillAuxiliary_Event(entryNumbers.first.front());
1081 assert(eventAux_.eventID() == fiIter_->eventID_);
1082 unique_ptr<History> history = make_unique<History>();
1083 fillHistory(entryNumbers.first.front(), *history);
1084 overrideRunNumber(const_cast<EventID&>(eventAux_.eventID()),
1085 eventAux_.isRealData());
1086 auto ep = make_unique<EventPrincipal>(
1088 processConfiguration_,
1089 &presentProducts_.get(
InEvent),
1091 make_unique<RootDelayedReader>(fileFormatVersion_,
1094 &eventTree().branches(),
1095 eventTree().productProvenanceBranch(),
1096 saveMemoryObjectThreshold_,
1098 branchIDLists_.get(),
1100 eventAux_.eventID(),
1101 compactSubRunRanges_),
1102 entryNumbers.second);
1103 if (!delayedReadEventProducts_) {
1104 ep->readImmediate();
1111 RootInputFile::readEventForSecondaryFile(
EventID eID)
1116 if (!setEntry_Event(eID,
true)) {
1120 auto const& entryNumbers = getEntryNumbers(
InEvent);
1121 assert(entryNumbers.first.size() == 1ull);
1122 fillAuxiliary_Event(entryNumbers.first.front());
1123 unique_ptr<History> history = make_unique<History>();
1124 fillHistory(entryNumbers.first.front(), *history);
1125 overrideRunNumber(const_cast<EventID&>(eventAux_.eventID()),
1126 eventAux_.isRealData());
1127 auto ep = make_unique<EventPrincipal>(
1129 processConfiguration_,
1130 &presentProducts_.get(
InEvent),
1132 make_unique<RootDelayedReader>(fileFormatVersion_,
1135 &eventTree().branches(),
1136 eventTree().productProvenanceBranch(),
1137 saveMemoryObjectThreshold_,
1139 branchIDLists_.get(),
1141 eventAux_.eventID(),
1142 compactSubRunRanges_),
1143 entryNumbers.second);
1144 primaryFile_->primaryEP_->addSecondaryPrincipal(move(ep));
1148 unique_ptr<RangeSetHandler>
1149 RootInputFile::runRangeSetHandler()
1151 return move(runRangeSetHandler_);
1154 unique_ptr<RunPrincipal>
1155 RootInputFile::readRun()
1157 assert(fiIter_ != fiEnd_);
1158 assert(fiIter_->getEntryType() == FileIndex::kRun);
1159 assert(fiIter_->eventID_.runID().isValid());
1160 auto const& entryNumbers = getEntryNumbers(
InRun).first;
1161 auto rp = readCurrentRun(entryNumbers);
1162 advanceEntry(entryNumbers.size());
1166 unique_ptr<RunPrincipal>
1169 runRangeSetHandler_ = fillAuxiliary_Run(entryNumbers);
1170 assert(runAux_.runID() == fiIter_->eventID_.runID());
1171 overrideRunNumber(runAux_);
1172 if (runAux_.beginTime() == Timestamp::invalidTimestamp()) {
1173 runAux_.beginTime(eventAux_.time());
1174 runAux_.endTime(Timestamp::invalidTimestamp());
1176 auto rp = make_unique<RunPrincipal>(
1178 processConfiguration_,
1179 &presentProducts_.get(
InRun),
1180 make_unique<RootDelayedReader>(fileFormatVersion_,
1183 &runTree().branches(),
1184 runTree().productProvenanceBranch(),
1185 saveMemoryObjectThreshold_,
1190 compactSubRunRanges_));
1191 if (!delayedReadRunProducts_) {
1192 rp->readImmediate();
1199 RootInputFile::readRunForSecondaryFile(
RunID rID)
1204 if (!setEntry_Run(rID)) {
1208 auto const& entryNumbers = getEntryNumbers(
InRun).first;
1209 assert(fiIter_ != fiEnd_);
1210 assert(fiIter_->getEntryType() == FileIndex::kRun);
1211 assert(fiIter_->eventID_.runID().isValid());
1212 runRangeSetHandler_ = fillAuxiliary_Run(entryNumbers);
1213 assert(runAux_.runID() == fiIter_->eventID_.runID());
1214 overrideRunNumber(runAux_);
1215 if (runAux_.beginTime() == Timestamp::invalidTimestamp()) {
1216 runAux_.beginTime(eventAux_.time());
1217 runAux_.endTime(Timestamp::invalidTimestamp());
1219 auto rp = make_unique<RunPrincipal>(
1221 processConfiguration_,
1222 &presentProducts_.get(
InRun),
1223 make_unique<RootDelayedReader>(fileFormatVersion_,
1226 &runTree().branches(),
1227 runTree().productProvenanceBranch(),
1228 saveMemoryObjectThreshold_,
1233 compactSubRunRanges_));
1234 if (!delayedReadRunProducts_) {
1235 rp->readImmediate();
1237 primaryFile_->primaryRP_->addSecondaryPrincipal(move(rp));
1241 unique_ptr<RangeSetHandler>
1242 RootInputFile::subRunRangeSetHandler()
1244 return move(subRunRangeSetHandler_);
1247 unique_ptr<SubRunPrincipal>
1250 assert(fiIter_ != fiEnd_);
1251 assert(fiIter_->getEntryType() == FileIndex::kSubRun);
1252 auto const& entryNumbers = getEntryNumbers(
InSubRun).first;
1253 auto srp = readCurrentSubRun(entryNumbers, rp);
1254 advanceEntry(entryNumbers.size());
1258 unique_ptr<SubRunPrincipal>
1259 RootInputFile::readCurrentSubRun(
1263 subRunRangeSetHandler_ = fillAuxiliary_SubRun(entryNumbers);
1264 assert(subRunAux_.subRunID() == fiIter_->eventID_.subRunID());
1265 overrideRunNumber(subRunAux_.id_);
1266 assert(subRunAux_.runID() == rp->runID());
1267 if (subRunAux_.beginTime() == Timestamp::invalidTimestamp()) {
1268 subRunAux_.beginTime_ = eventAux_.time();
1269 subRunAux_.endTime_ = Timestamp::invalidTimestamp();
1271 auto srp = make_unique<SubRunPrincipal>(
1273 processConfiguration_,
1275 make_unique<RootDelayedReader>(fileFormatVersion_,
1278 &subRunTree().branches(),
1279 subRunTree().productProvenanceBranch(),
1280 saveMemoryObjectThreshold_,
1285 compactSubRunRanges_));
1286 if (!delayedReadSubRunProducts_) {
1287 srp->readImmediate();
1294 RootInputFile::readSubRunForSecondaryFile(
SubRunID srID)
1299 if (!setEntry_SubRun(srID)) {
1303 auto const& entryNumbers = getEntryNumbers(
InSubRun).first;
1304 assert(fiIter_ != fiEnd_);
1305 assert(fiIter_->getEntryType() == FileIndex::kSubRun);
1306 subRunRangeSetHandler_ = fillAuxiliary_SubRun(entryNumbers);
1307 assert(subRunAux_.subRunID() == fiIter_->eventID_.subRunID());
1308 overrideRunNumber(subRunAux_.id_);
1309 if (subRunAux_.beginTime() == Timestamp::invalidTimestamp()) {
1310 subRunAux_.beginTime_ = eventAux_.time();
1311 subRunAux_.endTime_ = Timestamp::invalidTimestamp();
1313 auto srp = make_unique<SubRunPrincipal>(
1315 processConfiguration_,
1317 make_unique<RootDelayedReader>(fileFormatVersion_,
1320 &subRunTree().branches(),
1321 subRunTree().productProvenanceBranch(),
1322 saveMemoryObjectThreshold_,
1327 compactSubRunRanges_));
1328 if (!delayedReadSubRunProducts_) {
1329 srp->readImmediate();
1331 primaryFile_->primarySRP_->addSecondaryPrincipal(move(srp));
1338 if (forcedRunOffset_ != 0) {
1341 if (aux.
runID() < RunID::firstRun()) {
1342 aux.
runID(RunID::firstRun());
1349 if (forcedRunOffset_ != 0) {
1350 id =
SubRunID(
id.
run() + forcedRunOffset_,
id.subRun());
1355 RootInputFile::overrideRunNumber(
EventID&
id,
bool isRealData)
1357 if (forcedRunOffset_ == 0) {
1362 "RootInputFile::overrideRunNumber()"}
1363 <<
"The 'setRunNumber' parameter of RootInput cannot " 1364 <<
"be used with real data.\n";
1370 RootInputFile::readEventHistoryTree(
unsigned int treeCacheSize)
1373 eventHistoryTree_ =
static_cast<TTree*
>(
1375 if (!eventHistoryTree_) {
1377 <<
"Failed to find the event history tree.\n";
1379 eventHistoryTree_->SetCacheSize(static_cast<Long64_t>(treeCacheSize));
1383 RootInputFile::initializeDuplicateChecker()
1385 if (duplicateChecker_.get() ==
nullptr) {
1388 if (eventTree().entries()) {
1391 fillAuxiliary_Event(0);
1392 duplicateChecker_->init(eventAux_.isRealData(), fileIndex_);
1396 pair<RootInputFile::EntryNumbers, bool>
1400 if (fiIter_ == fiEnd_) {
1401 return pair<EntryNumbers, bool>{enumbers,
true};
1403 auto const eid = fiIter_->eventID_;
1404 auto iter = fiIter_;
1405 for (; (iter != fiEnd_) && (iter->eventID_ == eid); ++iter) {
1406 enumbers.push_back(iter->entry_);
1408 if ((bt ==
InEvent) && (enumbers.size() > 1ul)) {
1410 <<
" has multiple entries for\n" 1413 bool const lastInSubRun{(iter == fiEnd_) ||
1414 (iter->eventID_.subRun() != eid.subRun())};
1415 return pair<EntryNumbers, bool>{enumbers, lastInSubRun};
1420 bool const dropDescendants,
1423 auto dropOnInputForBranchType =
1424 [
this, &rules, dropDescendants, &tables](
BranchType const bt) {
1425 auto& prodList = tables.
get(bt).descriptions;
1433 set<ProductID> branchesToDrop;
1434 for (
auto const& prod : prodList) {
1435 auto const& pd = prod.second;
1436 if (!groupSelector.selected(pd)) {
1437 if (dropDescendants) {
1440 branchesToDrop.insert(pd.productID());
1446 auto branchesToDropEnd = branchesToDrop.cend();
1447 for (
auto I = prodList.begin(),
E = prodList.end(); I !=
E;) {
1448 auto const& bd = I->second;
1449 bool drop = branchesToDrop.find(bd.productID()) != branchesToDropEnd;
1455 if (groupSelector.selected(bd)) {
1457 <<
"Branch '" << bd.branchName()
1458 <<
"' is being dropped from the input\n" 1459 <<
"of file '" << fileName_
1460 <<
"' because it is dependent on a branch\n" 1461 <<
"that was explicitly dropped.\n";
1463 treePointers_[bt]->dropBranch(bd.branchName());
1465 prodList.erase(icopy);
1472 RootInputFile::openSecondaryFile(
int const idx)
1474 secondaryFiles_[idx] =
1475 rifSequence_->openSecondaryFile(secondaryFileNames_[idx],
this);
1478 unique_ptr<art::ResultsPrincipal>
1479 RootInputFile::readResults()
1481 unique_ptr<art::ResultsPrincipal> resp;
1482 if (!resultsTree().isValid()) {
1483 resp = make_unique<ResultsPrincipal>(
1490 assert(entryNumbers.size() == 1ull);
1491 fillAuxiliary_Results(entryNumbers.front());
1492 resp = std::make_unique<ResultsPrincipal>(
1494 processConfiguration_,
1496 make_unique<RootDelayedReader>(fileFormatVersion_,
1499 &resultsTree().branches(),
1500 resultsTree().productProvenanceBranch(),
1501 saveMemoryObjectThreshold_,
1506 compactSubRunRanges_));
std::string const & BranchTypeToProductTreeName(BranchType const bt)
std::string const & productProvenanceBranchName(BranchType const bt)
std::vector< BranchIDList > BranchIDLists
constexpr auto const & right(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
RangeSetInfo resolveRangeSetInfo(sqlite3 *, std::string const &filename, BranchType, unsigned RangeSetID, bool compact)
void appendToDescendants(ProductID parent, ProductIDSet &descendants) const
static ParameterSetID const & put(ParameterSet const &ps)
RunID const & runID() const noexcept
void readFileIndex(TFile *file, TTree *metaDataTree, FileIndex *&findexPtr)
std::string const & parentageTreeName()
std::string const & BranchTypeToMetaDataTreeName(BranchType const bt)
void mergeAuxiliary(SubRunAuxiliary &left, SubRunAuxiliary const &right)
std::string const & eventHistoryTreeName()
auto & get(BranchType const bt)
void make_ParameterSet(intermediate_table const &tbl, ParameterSet &ps)
bool present() const noexcept
std::string const & BranchTypeToAuxiliaryBranchName(BranchType const bt)
bool fastCloningPermitted() const
RangeSet resolveRangeSet(RangeSetInfo const &rs)
std::string couldNotFindTree(std::string const &treename)
bool mergeAuxiliary(RunAuxiliary const &)
std::string const & metaDataTreeName()
off_t remainingSubRuns() const
void swap(Handle< T > &a, Handle< T > &b)
exempt_ptr< E > make_exempt_ptr(E *) noexcept
std::string const & parentageBranchName()
bool mergeAuxiliary(SubRunAuxiliary const &)
bool dropped() const noexcept
std::string const & parentageIDBranchName()
void invoke(ProductTables const &)
ParameterSetID id() const
std::string const & getFileFormatEra()
std::string const & BranchTypeToString(BranchType const bt)
void swap(exempt_ptr< E > &, exempt_ptr< E > &) noexcept
RunNumber_t run() const noexcept
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
off_t remainingEvents() const
constexpr auto const & left(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
std::string const & eventHistoryBranchName()
void checkDictionaries(BranchDescription const &productDesc)
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
void for_each_branch_type(F f)
std::map< fhicl::ParameterSetID, ParameterSetBlob > ParameterSetMap
auto make_product_descriptions(ProductList const &productList)
std::string const & branchName() const noexcept
ProductID productID() const noexcept
T readMetadata(TTree *md, bool const requireDict=true)
IDNumber_t< Level::Run > RunNumber_t
static void importFrom(sqlite3 *db)