CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/src/FWCore/Modules/src/EventIDChecker.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    Modules
00004 // Class:      EventIDChecker
00005 //
00013 //
00014 // Original Author:  Chris Jones
00015 //         Created:  Tue Jun 16 15:42:17 CDT 2009
00016 //
00017 //
00018 
00019 
00020 // system include files
00021 #include <memory>
00022 #include <vector>
00023 #include <algorithm>
00024 
00025 // user include files
00026 #include "FWCore/Framework/interface/EDAnalyzer.h"
00027 
00028 #include "FWCore/Framework/interface/Event.h"
00029 #include "FWCore/Framework/interface/MakerMacros.h"
00030 
00031 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00032 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
00033 #include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
00034 #include "DataFormats/Provenance/interface/EventID.h"
00035 
00036 //
00037 // class decleration
00038 //
00039 
00040 class EventIDChecker : public edm::EDAnalyzer {
00041 public:
00042    explicit EventIDChecker(edm::ParameterSet const&);
00043    ~EventIDChecker();
00044     static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
00045 
00046 
00047 private:
00048    virtual void beginJob();
00049    virtual void analyze(edm::Event const&, edm::EventSetup const&);
00050    virtual void endJob();
00051    virtual void postForkReacquireResources(unsigned int iChildIndex, unsigned int iNumberOfChildren);
00052 
00053    // ----------member data ---------------------------
00054    std::vector<edm::EventID> ids_;
00055    unsigned int index_;
00056 
00057    unsigned int multiProcessSequentialEvents_;
00058    unsigned int numberOfEventsLeftBeforeSearch_;
00059    bool mustSearch_;
00060 };
00061 
00062 //
00063 // constants, enums and typedefs
00064 //
00065 
00066 //
00067 // static data member definitions
00068 //
00069 
00070 //
00071 // constructors and destructor
00072 //
00073 EventIDChecker::EventIDChecker(edm::ParameterSet const& iConfig) :
00074   ids_(iConfig.getUntrackedParameter<std::vector<edm::EventID> >("eventSequence")),
00075   index_(0),
00076   multiProcessSequentialEvents_(iConfig.getUntrackedParameter<unsigned int>("multiProcessSequentialEvents")),
00077   numberOfEventsLeftBeforeSearch_(0),
00078   mustSearch_(false)
00079 {
00080    //now do what ever initialization is needed
00081 
00082 }
00083 
00084 
00085 EventIDChecker::~EventIDChecker() {
00086 
00087    // do anything here that needs to be done at desctruction time
00088    // (e.g. close files, deallocate resources etc.)
00089 
00090 }
00091 
00092 
00093 //
00094 // member functions
00095 //
00096 
00097 namespace {
00098    struct CompareWithoutLumi {
00099       CompareWithoutLumi( const edm::EventID& iThis):
00100       m_this(iThis) {}
00101       bool operator()(const edm::EventID& iOther) {
00102          return m_this.run() == iOther.run() && m_this.event() == iOther.event();
00103       }
00104       edm::EventID m_this;
00105    };
00106 }
00107 
00108 // ------------ method called to for each event  ------------
00109 void
00110 EventIDChecker::analyze(edm::Event const& iEvent, edm::EventSetup const& iSetup) {
00111    if(mustSearch_) { 
00112       if( 0 == numberOfEventsLeftBeforeSearch_) {
00113          numberOfEventsLeftBeforeSearch_ = multiProcessSequentialEvents_;
00114          //the event must be after the last event in our list since multicore doesn't go backwards
00115          std::vector<edm::EventID>::iterator itFind= std::find_if(ids_.begin()+index_,ids_.end(), CompareWithoutLumi(iEvent.id()));
00116          if(itFind == ids_.end()) {
00117             throw cms::Exception("MissedEvent") << "The event " << iEvent.id() << "is not in the list.\n";
00118          }
00119          index_ = itFind-ids_.begin();
00120       } 
00121       --numberOfEventsLeftBeforeSearch_;
00122    }
00123 
00124    if(index_ >= ids_.size()) {
00125       throw cms::Exception("TooManyEvents")<<"Was passes "<<ids_.size()<<" EventIDs but have processed more events than that\n";
00126    }
00127    if(iEvent.id().run() != ids_[index_].run() || iEvent.id().event() != ids_[index_].event()) {
00128       throw cms::Exception("WrongEvent") << "Was expecting event " << ids_[index_] << " but was given " << iEvent.id() << "\n";
00129    }
00130    ++index_;
00131 }
00132 
00133 
00134 // ------------ method called once each job just before starting event loop  ------------
00135 void
00136 EventIDChecker::beginJob() {
00137 }
00138 
00139 // ------------ method called once each job just after ending the event loop  ------------
00140 void
00141 EventIDChecker::endJob() {
00142 }
00143 
00144 // ------------ method called once each job for validation
00145 void
00146 EventIDChecker::fillDescriptions(edm::ConfigurationDescriptions& descriptions) {
00147   edm::ParameterSetDescription desc;
00148   desc.addUntracked<std::vector<edm::EventID> >("eventSequence");
00149   desc.addUntracked<unsigned int>("multiProcessSequentialEvents", 0U);
00150   descriptions.add("eventIDChecker", desc);
00151 }
00152 
00153 void
00154 EventIDChecker::postForkReacquireResources(unsigned int iChildIndex, unsigned int iNumberOfChildren) {
00155    mustSearch_ = true;
00156 }
00157 
00158 //define this as a plug-in
00159 DEFINE_FWK_MODULE(EventIDChecker);