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_, and evf::FUShmBuffer::writeErrorEventData().

{
  if (0!=shmBuffer_) {
    edm::LogInfo("FUShmReader")<<"detach from shared memory segment."<<endl;
    if (lastCellIndex_<0xffffffff) {
      shmBuffer_->writeErrorEventData(runNumber_,getpid(),lastCellIndex_);
      shmBuffer_->removeClientPrcId(getpid());
    }
    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 61 of file FUShmReader.cc.

References gather_cfg::cout, FEDRawData::data(), evf::evt::EMPTY, event_, evf::FUShmRawCell::evtNumber(), evtNumber_, evf::FUShmBuffer::evtState(), Exception, FEDRawDataCollection::FEDData(), ExpressReco_HICollisions_FallBack::FEDRawDataCollection, evf::FUShmRawCell::fedSize(), evf::FUShmBuffer::finishReadingRawCell(), evf::FUShmRawCell::getLumiSection(), i, evf::FUShmRawCell::index(), lastCellIndex_, edm::errors::LogicError, 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(), shmBuffer_, and evf::evt::STOP.

{
  // 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;
    shmBuffer_->scheduleRawEmptyCellForDiscard(newCell);
    shmdt(shmBuffer_);
    shmBuffer_=0;
    event_=0;
    lastCellIndex_=0xffffffff;
    return 0;
  }
  else if(state==evt::LUMISECTION){
    unsigned int ls = newCell->getLumiSection();
    //shmBuffer_->setEvtState(newCell->index(),evt::PROCESSING);
    shmBuffer_->scheduleRawCellForDiscard(newCell->index());
    if(ls==0){
      std::cout << getpid() << " GOT an EOL event for ls 0!!!" 
                << std::endl;
      throw edm::Exception(errors::LogicError)
        << "FUShmReader received an EOL event with ls = 0 !!!";
    }
    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 evtNumber_;
}
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 ExpressReco_HICollisions_FallBack::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().