Skip to content

Commit

Permalink
make looping back to the first file a function argument instead of a …
Browse files Browse the repository at this point in the history
…pset parameter; this touches FWCore/Sources/interface/VectorInputSource.h, so the changes are more intrusive than the pset hack
  • Loading branch information
Dan Riley authored and Dan Riley committed Sep 6, 2017
1 parent c572620 commit c556672
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
'SpyFileNameWhichNeedsToBeSet SiStripSpyEventMatcher.SpySource.fileNames'
),
sequential = cms.untracked.bool(True),
recycleFiles = cms.untracked.bool(False),
),
CounterDiffMaxAllowed = cms.uint32(100)
)
Expand Down
3 changes: 2 additions & 1 deletion DQM/SiStripMonitorHardware/src/SiStripSpyEventMatcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ namespace sistrip {
{
size_t fileNameHash = 0U;
//add spy events to the map until there are none left
source_->loopOverEvents(*eventPrincipal_,fileNameHash,std::numeric_limits<size_t>::max(),boost::bind(&SpyEventMatcher::addNextEventToMap,this,_1));
source_->loopOverEvents(*eventPrincipal_,fileNameHash,std::numeric_limits<size_t>::max(),boost::bind(&SpyEventMatcher::addNextEventToMap,this,_1),
nullptr,nullptr,false);
//debug
std::ostringstream ss;
ss << "Events with possible matches (eventID,apvAddress): ";
Expand Down
8 changes: 4 additions & 4 deletions FWCore/Sources/interface/VectorInputSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace edm {
virtual ~VectorInputSource();

template<typename T>
size_t loopOverEvents(EventPrincipal& cache, size_t& fileNameHash, size_t number, T eventOperator, CLHEP::HepRandomEngine* = nullptr, EventID const* id = nullptr);
size_t loopOverEvents(EventPrincipal& cache, size_t& fileNameHash, size_t number, T eventOperator, CLHEP::HepRandomEngine* = nullptr, EventID const* id = nullptr, bool recycleFiles = true);

template<typename T, typename Iterator>
size_t loopSpecified(EventPrincipal& cache, size_t& fileNameHash, Iterator const& begin, Iterator const& end, T eventOperator);
Expand All @@ -54,7 +54,7 @@ namespace edm {
void clearEventPrincipal(EventPrincipal& cache);

private:
virtual bool readOneEvent(EventPrincipal& cache, size_t& fileNameHash, CLHEP::HepRandomEngine*, EventID const* id) = 0;
virtual bool readOneEvent(EventPrincipal& cache, size_t& fileNameHash, CLHEP::HepRandomEngine*, EventID const* id, bool recycleFiles) = 0;
virtual void readOneSpecified(EventPrincipal& cache, size_t& fileNameHash, SecondaryEventIDAndFileInfo const& event) = 0;
void readOneSpecified(EventPrincipal& cache, size_t& fileNameHash, EventID const& event) {
SecondaryEventIDAndFileInfo info(event, fileNameHash);
Expand All @@ -70,11 +70,11 @@ namespace edm {
};

template<typename T>
size_t VectorInputSource::loopOverEvents(EventPrincipal& cache, size_t& fileNameHash, size_t number, T eventOperator, CLHEP::HepRandomEngine* engine, EventID const* id) {
size_t VectorInputSource::loopOverEvents(EventPrincipal& cache, size_t& fileNameHash, size_t number, T eventOperator, CLHEP::HepRandomEngine* engine, EventID const* id, bool recycleFiles) {
size_t i = 0U;
for(; i < number; ++i) {
clearEventPrincipal(cache);
bool found = readOneEvent(cache, fileNameHash, engine, id);
bool found = readOneEvent(cache, fileNameHash, engine, id, recycleFiles);
if(!found) break;
eventOperator(cache, fileNameHash);
}
Expand Down
4 changes: 2 additions & 2 deletions IOPool/Input/src/EmbeddedRootSource.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ namespace edm {
}

bool
EmbeddedRootSource::readOneEvent(EventPrincipal& cache, size_t& fileNameHash, CLHEP::HepRandomEngine* engine, EventID const* id) {
return fileSequence_->readOneEvent(cache, fileNameHash, engine, id);
EmbeddedRootSource::readOneEvent(EventPrincipal& cache, size_t& fileNameHash, CLHEP::HepRandomEngine* engine, EventID const* id, bool recycleFiles) {
return fileSequence_->readOneEvent(cache, fileNameHash, engine, id, recycleFiles);
}

void
Expand Down
2 changes: 1 addition & 1 deletion IOPool/Input/src/EmbeddedRootSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ namespace edm {
virtual void closeFile_();
void beginJob() override;
void endJob() override;
bool readOneEvent(EventPrincipal& cache, size_t& fileNameHash, CLHEP::HepRandomEngine*, EventID const* id) override;
bool readOneEvent(EventPrincipal& cache, size_t& fileNameHash, CLHEP::HepRandomEngine*, EventID const* id, bool recycleFiles) override;
void readOneSpecified(EventPrincipal& cache, size_t& fileNameHash, SecondaryEventIDAndFileInfo const& id) override;
void dropUnwantedBranches_(std::vector<std::string> const& wantedBranches) override;

Expand Down
28 changes: 12 additions & 16 deletions IOPool/Input/src/RootEmbeddedFileSequence.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ namespace edm {
input_(input),
orderedProcessHistoryIDs_(),
sequential_(pset.getUntrackedParameter<bool>("sequential", false)),
recycle_(pset.getUntrackedParameter<bool>("recycleFiles", true)),
sameLumiBlock_(pset.getUntrackedParameter<bool>("sameLumiBlock", false)),
fptr_(nullptr),
eventsRemainingInFile_(0),
Expand Down Expand Up @@ -165,38 +164,38 @@ namespace edm {
}

bool
RootEmbeddedFileSequence::readOneSequential(EventPrincipal& cache, size_t& fileNameHash, CLHEP::HepRandomEngine*, EventID const*) {
RootEmbeddedFileSequence::readOneSequential(EventPrincipal& cache, size_t& fileNameHash, CLHEP::HepRandomEngine*, EventID const*, bool recycleFiles) {
assert(rootFile());
rootFile()->nextEventEntry();
bool found = rootFile()->readCurrentEvent(cache);
if(!found) {
setAtNextFile();
if(noMoreFiles()) {
if (recycle_) {
setAtFirstFile();
if (recycleFiles) {
setAtFirstFile();
} else {
return false;
}
}
initFile(false);
assert(rootFile());
rootFile()->setAtEventEntry(IndexIntoFile::invalidEntry);
return readOneSequential(cache, fileNameHash, nullptr, nullptr);
return readOneSequential(cache, fileNameHash, nullptr, nullptr, recycleFiles);
}
fileNameHash = lfnHash();
return true;
}

bool
RootEmbeddedFileSequence::readOneSequentialWithID(EventPrincipal& cache, size_t& fileNameHash, CLHEP::HepRandomEngine*, EventID const* idp) {
RootEmbeddedFileSequence::readOneSequentialWithID(EventPrincipal& cache, size_t& fileNameHash, CLHEP::HepRandomEngine*, EventID const* idp, bool recycleFiles) {
assert(idp);
EventID const& id = *idp;
int offset = initialNumberOfEventsToSkip_;
initialNumberOfEventsToSkip_ = 0;
if(offset > 0) {
assert(rootFile());
while(offset > 0) {
bool found = readOneSequentialWithID(cache, fileNameHash, nullptr, idp);
bool found = readOneSequentialWithID(cache, fileNameHash, nullptr, idp, recycleFiles);
if(!found) {
return false;
}
Expand All @@ -222,7 +221,7 @@ namespace edm {
if(!found) {
return false;
}
return readOneSequentialWithID(cache, fileNameHash, nullptr, idp);
return readOneSequentialWithID(cache, fileNameHash, nullptr, idp, recycleFiles);
}
fileNameHash = lfnHash();
return true;
Expand All @@ -247,7 +246,7 @@ namespace edm {
}

bool
RootEmbeddedFileSequence::readOneRandom(EventPrincipal& cache, size_t& fileNameHash, CLHEP::HepRandomEngine* engine, EventID const*) {
RootEmbeddedFileSequence::readOneRandom(EventPrincipal& cache, size_t& fileNameHash, CLHEP::HepRandomEngine* engine, EventID const*, bool) {
assert(rootFile());
assert(engine);
unsigned int currentSeqNumber = sequenceNumberOfFile();
Expand Down Expand Up @@ -280,7 +279,7 @@ namespace edm {
}

bool
RootEmbeddedFileSequence::readOneRandomWithID(EventPrincipal& cache, size_t& fileNameHash, CLHEP::HepRandomEngine* engine, EventID const* idp) {
RootEmbeddedFileSequence::readOneRandomWithID(EventPrincipal& cache, size_t& fileNameHash, CLHEP::HepRandomEngine* engine, EventID const* idp, bool recycleFiles) {
assert(engine);
assert(idp);
EventID const& id = *idp;
Expand Down Expand Up @@ -312,27 +311,24 @@ namespace edm {
if(!found) {
return false;
}
return readOneRandomWithID(cache, fileNameHash, engine, idp);
return readOneRandomWithID(cache, fileNameHash, engine, idp, recycleFiles);
}
fileNameHash = lfnHash();
return true;
}

bool
RootEmbeddedFileSequence::readOneEvent(EventPrincipal& cache, size_t& fileNameHash, CLHEP::HepRandomEngine* engine, EventID const* id) {
RootEmbeddedFileSequence::readOneEvent(EventPrincipal& cache, size_t& fileNameHash, CLHEP::HepRandomEngine* engine, EventID const* id, bool recycleFiles) {
assert(!sameLumiBlock_ || id != nullptr);
assert(sequential_ || engine != nullptr);
return (this->*fptr_)(cache, fileNameHash, engine, id);
return (this->*fptr_)(cache, fileNameHash, engine, id, recycleFiles);
}

void
RootEmbeddedFileSequence::fillDescription(ParameterSetDescription & desc) {
desc.addUntracked<bool>("sequential", false)
->setComment("True: loopEvents() reads events sequentially from beginning of first file.\n"
"False: loopEvents() first reads events beginning at random event. New files also chosen randomly");
desc.addUntracked<bool>("recycleFiles", true)
->setComment("True: readOneSequential() loops back to the first file at the end of the last file.\n"
"False: readOneSequential() returns false at the end of the last file");
desc.addUntracked<bool>("sameLumiBlock", false)
->setComment("True: loopEvents() reads events only in same lumi as the specified event.\n"
"False: loopEvents() reads events regardless of lumi.");
Expand Down
13 changes: 6 additions & 7 deletions IOPool/Input/src/RootEmbeddedFileSequence.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ namespace edm {
void closeFile_() override;
void endJob();
void skipEntries(unsigned int offset);
bool readOneEvent(EventPrincipal& cache, size_t& fileNameHash, CLHEP::HepRandomEngine*, EventID const* id);
bool readOneRandom(EventPrincipal& cache, size_t& fileNameHash, CLHEP::HepRandomEngine*, EventID const*);
bool readOneRandomWithID(EventPrincipal& cache, size_t& fileNameHash, CLHEP::HepRandomEngine*, EventID const* id);
bool readOneSequential(EventPrincipal& cache, size_t& fileNameHash, CLHEP::HepRandomEngine*, EventID const*);
bool readOneSequentialWithID(EventPrincipal& cache, size_t& fileNameHash, CLHEP::HepRandomEngine*, EventID const* id);
bool readOneEvent(EventPrincipal& cache, size_t& fileNameHash, CLHEP::HepRandomEngine*, EventID const* id, bool recycleFiles);
bool readOneRandom(EventPrincipal& cache, size_t& fileNameHash, CLHEP::HepRandomEngine*, EventID const*, bool);
bool readOneRandomWithID(EventPrincipal& cache, size_t& fileNameHash, CLHEP::HepRandomEngine*, EventID const* id, bool);
bool readOneSequential(EventPrincipal& cache, size_t& fileNameHash, CLHEP::HepRandomEngine*, EventID const*, bool recycleFiles);
bool readOneSequentialWithID(EventPrincipal& cache, size_t& fileNameHash, CLHEP::HepRandomEngine*, EventID const* id, bool);
void readOneSpecified(EventPrincipal& cache, size_t& fileNameHash, SecondaryEventIDAndFileInfo const& id);

static void fillDescription(ParameterSetDescription & desc);
Expand All @@ -59,9 +59,8 @@ namespace edm {
std::vector<ProcessHistoryID> orderedProcessHistoryIDs_;

bool sequential_;
bool recycle_;
bool sameLumiBlock_;
bool (RootEmbeddedFileSequence::* fptr_)(EventPrincipal&, size_t&, CLHEP::HepRandomEngine*, EventID const*);
bool (RootEmbeddedFileSequence::* fptr_)(EventPrincipal&, size_t&, CLHEP::HepRandomEngine*, EventID const*, bool);
int eventsRemainingInFile_;
int initialNumberOfEventsToSkip_;
unsigned int treeCacheSize_;
Expand Down

0 comments on commit c556672

Please sign in to comment.