00001
00002
00003
00004
00005
00006
00008
00009
00010 #include "EventFilter/ShmReader/interface/FUShmReader.h"
00011
00012 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00013 #include "FWCore/PluginManager/interface/ModuleDef.h"
00014 #include "IORawData/DaqSource/interface/DaqReaderPluginFactory.h"
00015 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
00016
00017
00018 #include <iostream>
00019
00020
00021 using namespace std;
00022 using namespace evf;
00023 using namespace edm;
00024
00025
00027
00029
00030
00031 FUShmReader::FUShmReader()
00032 : event_(0)
00033 , shmBuffer_(0)
00034 , runNumber_(0xffffffff)
00035 , evtNumber_(0xffffffff)
00036 , lastCellIndex_(0xffffffff)
00037 {
00038 shmBuffer_=FUShmBuffer::getShmBuffer();
00039 }
00040
00041
00042
00043 FUShmReader::~FUShmReader()
00044 {
00045 if (0!=shmBuffer_) {
00046 edm::LogInfo("FUShmReader")<<"detach from shared memory segment."<<endl;
00047 if (lastCellIndex_<0xffffffff) {
00048 shmBuffer_->writeErrorEventData(runNumber_,getpid(),lastCellIndex_);
00049 shmBuffer_->removeClientPrcId(getpid());
00050 }
00051 shmdt(shmBuffer_);
00052 }
00053 }
00054
00055
00057
00059
00060
00061 bool FUShmReader::fillRawData(EventID& eID,
00062 Timestamp& tstamp,
00063 FEDRawDataCollection*& data)
00064 {
00065
00066 if (0==shmBuffer_) {
00067 shmBuffer_=FUShmBuffer::getShmBuffer();
00068 if(0==shmBuffer_) {
00069 edm::LogError("NoShmBuffer")<<"Failed to retrieve shm segment."<<endl;
00070 throw cms::Exception("NullPointer")<<"Failed to retrieve shm segment."<<endl;
00071 }
00072 }
00073
00074
00075 if(0!=event_) {
00076 shmBuffer_->scheduleRawCellForDiscard(lastCellIndex_);
00077 event_ = 0;
00078 }
00079
00080
00081 FUShmRawCell* newCell=shmBuffer_->rawCellToRead();
00082
00083
00084 evt::State_t state=shmBuffer_->evtState(newCell->index());
00085 if (state==evt::EMPTY) {
00086 edm::LogInfo("ShutDown")<<"Received empty event, shut down."<<endl;
00087 shmBuffer_->scheduleRawEmptyCellForDiscard(newCell);
00088 shmdt(shmBuffer_);
00089 shmBuffer_=0;
00090 event_=0;
00091 lastCellIndex_=0xffffffff;
00092 return false;
00093 }
00094 else assert(state==evt::RAWREADING);
00095
00096
00097 evtNumber_ =newCell->evtNumber();
00098 lastCellIndex_=newCell->index();
00099 event_ =new FEDRawDataCollection();
00100 for (unsigned int i=0;i<newCell->nFed();i++) {
00101 unsigned int fedSize=newCell->fedSize(i);
00102 if (fedSize>0) {
00103 FEDRawData& fedData=event_->FEDData(i);
00104 fedData.resize(fedSize);
00105 newCell->readFed(i,fedData.data());
00106 }
00107 }
00108
00109
00110 shmBuffer_->finishReadingRawCell(newCell);
00111 eID=EventID(runNumber_,evtNumber_);
00112 data=event_;
00113
00114 return true;
00115 }
00116
00117
00119
00121
00122 DEFINE_SEAL_MODULE();
00123 DEFINE_EDM_PLUGIN(DaqReaderPluginFactoryU,FUShmReader,"FUShmReader");