CMS 3D CMS Logo

Public Member Functions | Private Attributes

FUShmReader Class Reference

#include <FUShmReader.h>

Inheritance diagram for FUShmReader:
DaqBaseReader

List of all members.

Public Member Functions

int fillRawData (edm::EventID &eID, edm::Timestamp &tstamp, FEDRawDataCollection *&data)
 FUShmReader ()
virtual void setRunNumber (edm::RunNumber_t runNumber)
 set the run number
virtual ~FUShmReader ()

Private Attributes

FEDRawDataCollectionevent_
unsigned int evtNumber_
unsigned int lastCellIndex_
unsigned int runNumber_
evf::FUShmBuffershmBuffer_

Detailed Description

Definition at line 10 of file FUShmReader.h.


Constructor & Destructor Documentation

FUShmReader::FUShmReader ( )

Definition at line 31 of file FUShmReader.cc.

  : event_(0)
  , shmBuffer_(0)
  , runNumber_(0xffffffff)
  , evtNumber_(0xffffffff)
  , lastCellIndex_(0xffffffff)
{
  //  shmBuffer_=FUShmBuffer::getShmBuffer();
}
FUShmReader::~FUShmReader ( ) [virtual]

Definition at line 43 of file FUShmReader.cc.

References lastCellIndex_, evf::FUShmBuffer::removeClientPrcId(), runNumber_, shmBuffer_, summarizeEdmComparisonLogfiles::success, and evf::FUShmBuffer::writeErrorEventData().

{
  if (0!=shmBuffer_) {
    edm::LogInfo("FUShmReader")<<"detach from shared memory segment."<<endl;
    if (lastCellIndex_<0xffffffff) {
      edm::LogWarning("FUShmReader") << "Class destructor called without received STOP event!"<<endl;
      if (lastCellIndex_<0xfffffffe)//not sending lumi cell to the error stream
        shmBuffer_->writeErrorEventData(runNumber_,getpid(),lastCellIndex_,true);
      bool success = shmBuffer_->removeClientPrcId(getpid());
      if (!success)
        edm::LogWarning("ShmMissingPID")<<"Destructor: did not find pid in shared memory index"<<endl;
    }
    shmdt(shmBuffer_);
  }
}

Member Function Documentation

int FUShmReader::fillRawData ( edm::EventID eID,
edm::Timestamp tstamp,
FEDRawDataCollection *&  data 
) [virtual]

overload to fill the fed collection to be put in the transient event store. NOTE: the FEDRawDataCollection data must be created (with new) within the method; ownership is passed to the caller.

Implements DaqBaseReader.

Definition at line 65 of file FUShmReader.cc.

References gather_cfg::cout, FEDRawData::data(), evf::evt::EMPTY, evf::evt::EOL, event_, evf::FUShmRawCell::evtNumber(), evtNumber_, evf::FUShmBuffer::evtState(), Exception, FEDRawDataCollection::FEDData(), evf::FUShmRawCell::fedSize(), evf::FUShmBuffer::finishReadingRawCell(), evf::FUShmRawCell::getEventType(), evf::FUShmRawCell::getLumiSection(), i, evf::FUShmRawCell::index(), lastCellIndex_, python::rootplot::utilities::ls(), evf::evt::LUMISECTION, evf::FUShmRawCell::nFed(), evf::FUShmBuffer::rawCellToRead(), evf::evt::RAWREADING, evf::FUShmRawCell::readFed(), FEDRawData::resize(), runNumber_, evf::FUShmBuffer::scheduleRawCellForDiscard(), evf::FUShmBuffer::scheduleRawEmptyCellForDiscard(), evf::FUShmBuffer::sem_print(), shmBuffer_, evf::evt::STOP, evf::evt::STOPPER, and summarizeEdmComparisonLogfiles::success.

{
  // just in case the reader hasn't yet attached to the shm segment
  if (0==shmBuffer_) {
    shmBuffer_=FUShmBuffer::getShmBuffer();
    if(0==shmBuffer_) {
      edm::LogError("NoShmBuffer")<<"Failed to retrieve shm segment."<<endl;
      throw cms::Exception("NullPointer")<<"Failed to retrieve shm segment."<<endl;
    }
  }
  
  // discard old event
  if(0!=event_) {
    shmBuffer_->scheduleRawCellForDiscard(lastCellIndex_);
    event_ = 0;
  }
  
  // wait for an event to become available, retrieve it
  FUShmRawCell* newCell=shmBuffer_->rawCellToRead();
  
  // if the event is 'stop', the reader is being told to shut down!
  evt::State_t state=shmBuffer_->evtState(newCell->index());
  if (state==evt::STOP) {
    edm::LogInfo("ShutDown")<<"Received STOP event, shut down."<<endl;
    std::cout << getpid() << " Received STOP event, shut down." << std::endl;
    if(newCell->getEventType() != evt::STOPPER){
      edm::LogError("InconsistentStopCell") << getpid() 
                                          << " GOT what claims to be a STOPPER event but eventType is " 
                                          <<  newCell->getEventType()
                                          << std::endl;
    }
    bool pidstatus=true;
    bool success = shmBuffer_->scheduleRawEmptyCellForDiscard(newCell,pidstatus);
    if (!success) //should not happen for STOPPER cell
        edm::LogError("InconsistentStopCell")<<"fillRawData:STOP: failed to discard STOP event raw cell!"<<endl;
    else if (!pidstatus) 
        edm::LogWarning("ShmMissingPID")<<"fillRawData:STOP: did not find pid in shared memory pid index"<<endl;
    shmdt(shmBuffer_);
    shmBuffer_=0;
    event_=0;
    lastCellIndex_=0xffffffff;
    return 0;
  }
  else if(state==evt::LUMISECTION){
    unsigned int ls = newCell->getLumiSection();
    if(newCell->getEventType() != evt::EOL){
      edm::LogError("InconsistentLsCell") << getpid() 
                                          << " GOT what claims to be an EOL event but eventType is " 
                                          <<  newCell->getEventType()
                                          << " and ls is " << ls
                                          << std::endl;
      shmBuffer_->sem_print();
    }
    shmBuffer_->scheduleRawCellForDiscard(newCell->index());
    lastCellIndex_=0xfffffffe;
    if(ls==0){
      edm::LogError("ZeroLsCell") << getpid() 
                                  << " GOT an EOL event for ls 0!!!" 
                                  << std::endl;
      return fillRawData(eID, tstamp, data);
    }
    return (-1)*ls;
  }
  // getting an 'empty' event here is a pathological condition !!!
  else if(state==evt::EMPTY){
    edm::LogError("EmptyRawCell")
      <<"Received empty event, this should not happen !!!" <<endl;
    std::cout << getpid() << "Received EPTY event!!! ERROR." << std::endl;
    return fillRawData(eID, tstamp, data);
  }
  else assert(state==evt::RAWREADING);
  
  // read the event data into the fwk raw data format
  evtNumber_    =newCell->evtNumber();
  lastCellIndex_=newCell->index();
  event_        =new FEDRawDataCollection();
  for (unsigned int i=0;i<newCell->nFed();i++) {
    unsigned int fedSize=newCell->fedSize(i);
    if (fedSize>0) {
      FEDRawData& fedData=event_->FEDData(i);
      fedData.resize(fedSize);
      newCell->readFed(i,fedData.data());
    }
  }
  
  // reading the cell is finished (new state will be 'isProcessing')
  shmBuffer_->finishReadingRawCell(newCell);
  eID=EventID(runNumber_,1U,evtNumber_);
  data=event_;
  if(evtNumber_==0) 
    std::cout << getpid() << " ShmReader got event number zero !!! " 
              << std::endl;
  return 1;
}
virtual void FUShmReader::setRunNumber ( edm::RunNumber_t  runNumber) [inline, virtual]

set the run number

Reimplemented from DaqBaseReader.

Definition at line 26 of file FUShmReader.h.

References convertSQLiteXML::runNumber, and runNumber_.


Member Data Documentation

Definition at line 37 of file FUShmReader.h.

Referenced by fillRawData().

unsigned int FUShmReader::evtNumber_ [private]

Definition at line 41 of file FUShmReader.h.

Referenced by fillRawData().

unsigned int FUShmReader::lastCellIndex_ [private]

Definition at line 42 of file FUShmReader.h.

Referenced by fillRawData(), and ~FUShmReader().

unsigned int FUShmReader::runNumber_ [private]

Definition at line 40 of file FUShmReader.h.

Referenced by fillRawData(), setRunNumber(), and ~FUShmReader().

Definition at line 38 of file FUShmReader.h.

Referenced by fillRawData(), and ~FUShmReader().