CMS 3D CMS Logo

Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes

MulticoreRunLumiEventChecker Class Reference

#include <FWCore/Modules/src/MulticoreRunLumiEventChecker.cc>

Inheritance diagram for MulticoreRunLumiEventChecker:
edm::EDAnalyzer

List of all members.

Public Member Functions

 MulticoreRunLumiEventChecker (edm::ParameterSet const &)
 ~MulticoreRunLumiEventChecker ()

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)

Private Member Functions

virtual void analyze (edm::Event const &, edm::EventSetup const &)
virtual void beginJob ()
virtual void beginLuminosityBlock (edm::LuminosityBlock const &lumi, edm::EventSetup const &es)
virtual void beginRun (edm::Run const &run, edm::EventSetup const &es)
void check (edm::EventID const &iID, bool isEvent)
virtual void endJob ()
virtual void endLuminosityBlock (edm::LuminosityBlock const &lumi, edm::EventSetup const &es)
virtual void endRun (edm::Run const &run, edm::EventSetup const &es)
virtual void postForkReacquireResources (unsigned int iChildIndex, unsigned int iNumberOfChildren)
virtual void preForkReleaseResources ()

Private Attributes

std::vector< edm::EventIDids_
unsigned int index_
boost::shared_ptr< boost::thread > listenerThread_
int messageQueue_
unsigned int multiProcessSequentialEvents_
bool mustSearch_
unsigned int numberOfEventsLeftBeforeSearch_
std::map< edm::EventID,
unsigned int > 
seenIDs_

Detailed Description

Description: Checks that the events passed to it come in the order specified in its configuration

Implementation: <Notes on="" implementation>="">

Definition at line 52 of file MulticoreRunLumiEventChecker.cc.


Constructor & Destructor Documentation

MulticoreRunLumiEventChecker::MulticoreRunLumiEventChecker ( edm::ParameterSet const &  iConfig) [explicit]

Definition at line 97 of file MulticoreRunLumiEventChecker.cc.

                                                                                         :
  ids_(iConfig.getUntrackedParameter<std::vector<edm::EventID> >("eventSequence")),
  index_(0),
  multiProcessSequentialEvents_(iConfig.getUntrackedParameter<unsigned int>("multiProcessSequentialEvents")),
  numberOfEventsLeftBeforeSearch_(0),
  mustSearch_(false),
  messageQueue_(-1)
{
   //now do what ever initialization is needed
}
MulticoreRunLumiEventChecker::~MulticoreRunLumiEventChecker ( )

Definition at line 109 of file MulticoreRunLumiEventChecker.cc.

                                                            {
   // do anything here that needs to be done at desctruction time
   // (e.g. close files, deallocate resources etc.)
}

Member Function Documentation

void MulticoreRunLumiEventChecker::analyze ( edm::Event const &  iEvent,
edm::EventSetup const &   
) [private, virtual]

Implements edm::EDAnalyzer.

Definition at line 211 of file MulticoreRunLumiEventChecker.cc.

References check(), and edm::EventBase::id().

                                                                                  {
   check(iEvent.id(), true);
}
void MulticoreRunLumiEventChecker::beginJob ( void  ) [private, virtual]

Reimplemented from edm::EDAnalyzer.

Definition at line 237 of file MulticoreRunLumiEventChecker.cc.

                                       {
}
void MulticoreRunLumiEventChecker::beginLuminosityBlock ( edm::LuminosityBlock const &  lumi,
edm::EventSetup const &  es 
) [private, virtual]

Reimplemented from edm::EDAnalyzer.

Definition at line 225 of file MulticoreRunLumiEventChecker.cc.

References check(), and edm::LuminosityBlockBase::id().

                                                                                                       {
   check(edm::EventID(lumi.id().run(), lumi.id().luminosityBlock(), 0), false);   
}
void MulticoreRunLumiEventChecker::beginRun ( edm::Run const &  run,
edm::EventSetup const &  es 
) [private, virtual]

Reimplemented from edm::EDAnalyzer.

Definition at line 216 of file MulticoreRunLumiEventChecker.cc.

References check(), and edm::RunBase::id().

                                                                              {
   check(edm::EventID(run.id().run(), 0, 0), false);   
}
void MulticoreRunLumiEventChecker::check ( edm::EventID const &  iID,
bool  isEvent 
) [private]

Definition at line 174 of file MulticoreRunLumiEventChecker.cc.

References Exception, spr::find(), ids_, index_, messageQueue_, multiProcessSequentialEvents_, mustSearch_, numberOfEventsLeftBeforeSearch_, and relativeConstraints::value.

Referenced by analyze(), beginLuminosityBlock(), beginRun(), endLuminosityBlock(), and endRun().

                                                                             {
   if(mustSearch_) { 
      if(0 == numberOfEventsLeftBeforeSearch_) {
         if(iIsEvent) {
            numberOfEventsLeftBeforeSearch_ = multiProcessSequentialEvents_;
         }
         //the event must be after the last event in our list since multicore doesn't go backwards
         //std::vector<edm::EventID>::iterator itFind= std::find_if(ids_.begin() + index_, ids_.end(), CompareWithoutLumi(iEventID));
         std::vector<edm::EventID>::iterator itFind= std::find(ids_.begin() + index_, ids_.end(), iEventID);
         if(itFind == ids_.end()) {
            throw cms::Exception("MissedEvent") << "The event " << iEventID << "is not in the list.\n";
         }
         index_ = itFind-ids_.begin();
      } 
      if(iIsEvent) {
         --numberOfEventsLeftBeforeSearch_;
      }
      MsgToListener sndmsg;
      sndmsg.id = iEventID;
      errno = 0;
      int value = msgsnd(messageQueue_, &sndmsg, MsgToListener::sizeForBuffer(), 0);
      if(value != 0) {
         throw cms::Exception("MessageFailure") << "Failed to send EventID message " << strerror(errno);
      }
   }
   
   if(index_ >= ids_.size()) {
      throw cms::Exception("TooManyEvents") << "Was passes " << ids_.size() << " EventIDs but have processed more events than that\n";
   }
   if(iEventID  != ids_[index_]) {
      throw cms::Exception("WrongEvent") << "Was expecting event " << ids_[index_] << " but was given " << iEventID << "\n";
   }
   ++index_;
}
void MulticoreRunLumiEventChecker::endJob ( void  ) [private, virtual]

Reimplemented from edm::EDAnalyzer.

Definition at line 242 of file MulticoreRunLumiEventChecker.cc.

References Exception, ids_, index_, listenerThread_, messageQueue_, mustSearch_, seenIDs_, and relativeConstraints::value.

                                     {
   if(mustSearch_) {
      MsgToListener sndmsg;
      sndmsg.id = edm::EventID();
      errno = 0;
      int value = msgsnd(messageQueue_,&sndmsg, MsgToListener::sizeForBuffer(),0);
      if(value != 0) {
        throw cms::Exception("MessageFailure")<<"Failed to send finished message "<<strerror(errno)<<"\n";
      }
   } else {
     if(index_ != ids_.size()) {
         throw cms::Exception("WrongNumberOfEvents")<<"Saw "<<index_<<" events but was supposed to see "<<ids_.size()<<"\n";
     }
   }
   
   if(listenerThread_) {
      listenerThread_->join();
      msgctl(messageQueue_, IPC_RMID, 0);
      
      std::set<edm::EventID> uniqueIDs(ids_.begin(), ids_.end());
      if(seenIDs_.size() != uniqueIDs.size()) {
         throw cms::Exception("WrongNumberOfEvents") << "Saw " << seenIDs_.size() << " events but was supposed to see " << ids_.size() << "\n";
      }
      
      std::set<edm::EventID> duplicates;
      for(std::map<edm::EventID, unsigned int>::iterator it = seenIDs_.begin(), itEnd = seenIDs_.end();
          it != itEnd;
          ++it) {
         if(it->second > 1 && it->first.event() != 0) {
            duplicates.insert(it->first);
         }
      }
      if(duplicates.size() != 0) {
         throw cms::Exception("DuplicateEvents") << "saw " << duplicates.size() << " events\n";
      }
   }
}
void MulticoreRunLumiEventChecker::endLuminosityBlock ( edm::LuminosityBlock const &  lumi,
edm::EventSetup const &  es 
) [private, virtual]

Reimplemented from edm::EDAnalyzer.

Definition at line 230 of file MulticoreRunLumiEventChecker.cc.

References check(), and edm::LuminosityBlockBase::id().

                                                                                                     {
   check(edm::EventID(lumi.id().run(), lumi.id().luminosityBlock(), 0), false);   
}
void MulticoreRunLumiEventChecker::endRun ( edm::Run const &  run,
edm::EventSetup const &  es 
) [private, virtual]

Reimplemented from edm::EDAnalyzer.

Definition at line 220 of file MulticoreRunLumiEventChecker.cc.

References check(), and edm::RunBase::id().

                                                                            {
   check(edm::EventID(run.id().run(), 0, 0), false);   
}
void MulticoreRunLumiEventChecker::fillDescriptions ( edm::ConfigurationDescriptions descriptions) [static]

Reimplemented from edm::EDAnalyzer.

Definition at line 282 of file MulticoreRunLumiEventChecker.cc.

References edm::ConfigurationDescriptions::add(), and edm::ParameterSetDescription::addUntracked().

                                                                                         {
  edm::ParameterSetDescription desc;
  desc.addUntracked<std::vector<edm::EventID> >("eventSequence");
  desc.addUntracked<unsigned int>("multiProcessSequentialEvents", 0U);
  descriptions.add("eventIDChecker", desc);
}
void MulticoreRunLumiEventChecker::postForkReacquireResources ( unsigned int  iChildIndex,
unsigned int  iNumberOfChildren 
) [private, virtual]

Reimplemented from edm::EDAnalyzer.

Definition at line 299 of file MulticoreRunLumiEventChecker.cc.

References edm::disableAllSigs(), listenerThread_, messageQueue_, mustSearch_, edm::reenableSigs(), and seenIDs_.

                                                                                                                 {
   mustSearch_ = true;
   
   if(0 == iChildIndex) {
      //NOTE: must temporarily disable signals so the new thread never tries to process a signal
      sigset_t oldset;
      edm::disableAllSigs(&oldset);
      
      Listener listener(&seenIDs_, messageQueue_, iNumberOfChildren);
      listenerThread_ = boost::shared_ptr<boost::thread>(new boost::thread(listener)) ;
      edm::reenableSigs(&oldset);
   }
}
void MulticoreRunLumiEventChecker::preForkReleaseResources ( ) [private, virtual]

Reimplemented from edm::EDAnalyzer.

Definition at line 290 of file MulticoreRunLumiEventChecker.cc.

References Exception, and messageQueue_.

                                                      {
  //This queue is used to communicate between children
  messageQueue_ = msgget(IPC_PRIVATE, IPC_CREAT|0660);
  if(-1 == messageQueue_) {
    throw cms::Exception("FailedToCreateQueue")<<" call to 'msgget' failed to create a message queue. errno: "<<errno<<" "<<strerror(errno);
  }
}

Member Data Documentation

Definition at line 74 of file MulticoreRunLumiEventChecker.cc.

Referenced by check(), and endJob().

unsigned int MulticoreRunLumiEventChecker::index_ [private]

Definition at line 75 of file MulticoreRunLumiEventChecker.cc.

Referenced by check(), and endJob().

boost::shared_ptr<boost::thread> MulticoreRunLumiEventChecker::listenerThread_ [private]

Definition at line 82 of file MulticoreRunLumiEventChecker.cc.

Referenced by endJob(), and postForkReacquireResources().

Definition at line 78 of file MulticoreRunLumiEventChecker.cc.

Referenced by check().

Definition at line 80 of file MulticoreRunLumiEventChecker.cc.

Referenced by check(), endJob(), and postForkReacquireResources().

Definition at line 79 of file MulticoreRunLumiEventChecker.cc.

Referenced by check().

std::map<edm::EventID, unsigned int> MulticoreRunLumiEventChecker::seenIDs_ [private]

Definition at line 76 of file MulticoreRunLumiEventChecker.cc.

Referenced by endJob(), and postForkReacquireResources().