3 #include "cetlib/container_algorithms.h" 31 entries_.emplace_back(eID, entry);
32 resultCached() =
false;
33 sortState() = kNotSorted;
39 entries_.emplace_back(eID, entry);
40 resultCached() =
false;
44 FileIndex::sortBy_Run_SubRun_Event()
46 stable_sort_all(entries_);
47 resultCached() =
false;
48 sortState() = kSorted_Run_SubRun_Event;
52 FileIndex::sortBy_Run_SubRun_EventEntry()
55 resultCached() =
false;
56 sortState() = kSorted_Run_SubRun_EventEntry;
60 FileIndex::allEventsInEntryOrder()
const 62 if (!resultCached()) {
63 resultCached() =
true;
65 for (
auto const&
e : entries_) {
66 if (
e.getEntryType() == kEvent) {
67 if (
e.entry_ < maxEntry) {
68 allInEntryOrder() =
false;
74 allInEntryOrder() =
true;
77 return allInEntryOrder();
81 FileIndex::eventsUniqueAndOrdered()
const 95 while (it->getEntryType() != kEvent) {
100 auto itPrevious = it;
106 while (it->getEntryType() != kEvent) {
112 for (; it != itEnd; ++it) {
113 if (it->getEntryType() == kEvent) {
114 if (it->eventID_ <= itPrevious->eventID_)
123 FileIndex::findPosition(
EventID const& eID)
const 126 assert(sortState() == kSorted_Run_SubRun_Event);
129 return lower_bound_all(entries_, el);
134 FileIndex::findPosition(
EventID const& eID,
bool exact)
const 137 assert(sortState() == kSorted_Run_SubRun_Event);
139 if (subRunUnspecified(eID)) {
140 return findEventForUnspecifiedSubRun(eID, exact);
145 while (it != itEnd && it->getEntryType() != FileIndex::kEvent) {
150 if (exact && (*it != eID))
157 FileIndex::findPosition(
SubRunID const& srID,
bool exact)
const 159 assert(sortState() != kNotSorted);
161 auto const invID = EventID::invalidEvent(srID);
162 if (sortState() == kSorted_Run_SubRun_EventEntry) {
166 it = findPosition(invID);
168 auto const itEnd = entries_.cend();
169 while (it != itEnd && it->getEntryType() != FileIndex::kSubRun) {
174 if (exact && (it->eventID_.subRunID() != srID))
181 FileIndex::findPosition(
RunID const& rID,
bool exact)
const 183 assert(sortState() != kNotSorted);
185 auto const invID = EventID::invalidEvent(rID);
186 if (sortState() == kSorted_Run_SubRun_EventEntry) {
190 it = findPosition(invID);
192 auto const itEnd = entries_.cend();
193 while (it != itEnd && it->getEntryType() != FileIndex::kRun) {
198 if (exact && (it->eventID_.runID() != rID))
204 FileIndex::findSubRunOrRunPosition(
SubRunID const& srID)
const 206 assert(sortState() != kNotSorted);
208 if (sortState() == kSorted_Run_SubRun_EventEntry) {
209 Element el{EventID::invalidEvent(srID)};
212 it = findPosition(EventID::invalidEvent(srID));
214 auto const itEnd = entries_.cend();
215 while (it != itEnd && it->getEntryType() != FileIndex::kSubRun &&
216 it->getEntryType() != FileIndex::kRun) {
258 os <<
"\nPrinting the list of Runs, SubRuns, and Events stored in the root " 260 os << setw(15) <<
"Run" << setw(15) <<
"SubRun" << setw(15) <<
"Event" 262 for (
auto const&
e : entries_) {
263 if (
e.getEntryType() == FileIndex::kEvent) {
264 os << setw(15) <<
e.eventID_.run() << setw(15) <<
e.eventID_.subRun()
265 << setw(15) <<
e.eventID_.event() <<
"\n";
266 }
else if (
e.getEntryType() == FileIndex::kSubRun) {
267 os << setw(15) <<
e.eventID_.run() << setw(15) <<
e.eventID_.subRun()
270 }
else if (
e.getEntryType() == FileIndex::kRun) {
271 os << setw(15) <<
e.eventID_.run() << setw(15) <<
" " << setw(15) <<
" " 281 os <<
"\nPrinting FileIndex contents. This includes a list of all Runs, " 283 <<
"and Events stored in the root file.\n\n";
284 os << setw(15) <<
"Run" << setw(15) <<
"SubRun" << setw(15) <<
"Event" 285 << setw(15) <<
"TTree Entry" 287 for (
auto const&
e : fileIndex) {
288 if (
e.getEntryType() == FileIndex::kEvent) {
289 os << setw(15) <<
e.eventID_.run() << setw(15) <<
e.eventID_.subRun()
290 << setw(15) <<
e.eventID_.event() << setw(15) <<
e.entry_ <<
"\n";
291 }
else if (
e.getEntryType() == FileIndex::kSubRun) {
292 os << setw(15) <<
e.eventID_.run() << setw(15) <<
e.eventID_.subRun()
293 << setw(15) <<
" " << setw(15) <<
e.entry_ <<
" (SubRun)" 295 }
else if (
e.getEntryType() == FileIndex::kRun) {
296 os << setw(15) <<
e.eventID_.run() << setw(15) <<
" " << setw(15) <<
" " 297 << setw(15) <<
e.entry_ <<
" (Run)" 305 FileIndex::findEventForUnspecifiedSubRun(
EventID const& eID,
bool exact)
const 313 auto const firstEvent =
314 findPosition(EventID::firstEvent(SubRunID::firstSubRun(runID)),
false);
326 while ((it != itEnd) && (it->eventID_.runID() == runID) &&
327 (it->eventID_.event() <
event)) {
328 last_subRunID = it->eventID_.subRunID();
330 it = findPosition(EventID::firstEvent(it->eventID_.subRunID().next()),
335 if ((it != itEnd) && (it->eventID_.runID() == runID) &&
336 (it->eventID_.event() ==
event)) {
339 }
else if (last_subRunID.
isValid()) {
341 result = findPosition(
EventID(last_subRunID,
event), exact);
343 if (result == itEnd) {
346 <<
"Could not find incompletely specified event " << eID
347 <<
" with smart algorithm:\n" 348 <<
"Assuming pathological file structure (event selection?) and\n" 349 <<
"trying again (inefficient).\n" 350 <<
"NOTE: this will find only the event with matching event number " 352 <<
" lowest subrun number: any others are inaccessible via this " 354 SubRunID trySubRun{SubRunID::firstSubRun(runID)};
357 SubRunID lastSubRunInRun{trySubRun};
358 for (; findIt != itEnd && findIt->eventID_.runID() == runID;
360 findPosition(EventID::firstEvent(lastSubRunInRun.next()),
false)) {
361 lastSubRunInRun = findIt->eventID_.subRunID();
364 while ((findIt = findPosition(
EventID(trySubRun,
event),
true)) ==
366 trySubRun < lastSubRunInRun) {
367 trySubRun = trySubRun.
next();
RunID const & runID() const
SubRunID const & subRunID() const
int print_event_list(InfoDumperInputFile const &file, ostream &output)
static SubRunID firstSubRun()
ostream & operator<<(ostream &os, FileIndex const &fileIndex)
std::vector< Element >::const_iterator const_iterator
MaybeLogger_< ELseverityLevel::ELsev_warning, false > LogWarning
IDNumber_t< Level::Event > EventNumber_t
EventNumber_t event() const
bool operator<(FileIndex::Element const &lh, FileIndex::Element const &rh)
Event finding and building.