CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FUShmReader.cc
Go to the documentation of this file.
1 //
3 // FUShmReader
4 // -----------
5 //
6 // 11/03/2006 Philipp Schieferdecker <philipp.schieferdecker@cern.ch>
8 
9 
11 
16 
17 
18 #include <iostream>
19 
20 
21 using namespace std;
22 using namespace evf;
23 using namespace edm;
24 
25 
27 // construction/destruction
29 
30 //______________________________________________________________________________
32  : event_(0)
33  , shmBuffer_(0)
34  , runNumber_(0xffffffff)
35  , evtNumber_(0xffffffff)
36  , lastCellIndex_(0xffffffff)
37 {
38  // shmBuffer_=FUShmBuffer::getShmBuffer();
39 }
40 
41 
42 //______________________________________________________________________________
44 {
45  if (0!=shmBuffer_) {
46  edm::LogInfo("FUShmReader")<<"detach from shared memory segment."<<endl;
47  if (lastCellIndex_<0xffffffff) {
48  edm::LogWarning("FUShmReader") << "Class destructor called without received STOP event!"<<endl;
49  if (lastCellIndex_<0xfffffffe)//not sending lumi cell to the error stream
51  bool success = shmBuffer_->removeClientPrcId(getpid());
52  if (!success)
53  edm::LogWarning("ShmMissingPID")<<"Destructor: did not find pid in shared memory index"<<endl;
54  }
55  shmdt(shmBuffer_);
56  }
57 }
58 
59 
61 // implementation of member functions
63 
64 //______________________________________________________________________________
66  Timestamp& tstamp,
68 {
69  // just in case the reader hasn't yet attached to the shm segment
70  if (0==shmBuffer_) {
71  shmBuffer_=FUShmBuffer::getShmBuffer();
72  if(0==shmBuffer_) {
73  edm::LogError("NoShmBuffer")<<"Failed to retrieve shm segment."<<endl;
74  throw cms::Exception("NullPointer")<<"Failed to retrieve shm segment."<<endl;
75  }
76  }
77 
78  // discard old event
79  if(0!=event_) {
81  event_ = 0;
82  }
83 
84  // wait for an event to become available, retrieve it
86 
87  // if the event is 'stop', the reader is being told to shut down!
89  if (state==evt::STOP) {
90  edm::LogInfo("ShutDown")<<"Received STOP event, shut down."<<endl;
91  std::cout << getpid() << " Received STOP event, shut down." << std::endl;
92  if(newCell->getEventType() != evt::STOPPER){
93  edm::LogError("InconsistentStopCell") << getpid()
94  << " GOT what claims to be a STOPPER event but eventType is "
95  << newCell->getEventType()
96  << std::endl;
97  }
98  bool pidstatus=true;
99  bool success = shmBuffer_->scheduleRawEmptyCellForDiscard(newCell,pidstatus);
100  if (!success) //should not happen for STOPPER cell
101  edm::LogError("InconsistentStopCell")<<"fillRawData:STOP: failed to discard STOP event raw cell!"<<endl;
102  else if (!pidstatus)
103  edm::LogWarning("ShmMissingPID")<<"fillRawData:STOP: did not find pid in shared memory pid index"<<endl;
104  shmdt(shmBuffer_);
105  shmBuffer_=0;
106  event_=0;
107  lastCellIndex_=0xffffffff;
108  return 0;
109  }
110  else if(state==evt::LUMISECTION){
111  unsigned int ls = newCell->getLumiSection();
112  if(newCell->getEventType() != evt::EOL){
113  edm::LogError("InconsistentLsCell") << getpid()
114  << " GOT what claims to be an EOL event but eventType is "
115  << newCell->getEventType()
116  << " and ls is " << ls
117  << std::endl;
119  }
121  lastCellIndex_=0xfffffffe;
122  if(ls==0){
123  edm::LogError("ZeroLsCell") << getpid()
124  << " GOT an EOL event for ls 0!!!"
125  << std::endl;
126  return fillRawData(eID, tstamp, data);
127  }
128  return (-1)*ls;
129  }
130  // getting an 'empty' event here is a pathological condition !!!
131  else if(state==evt::EMPTY){
132  edm::LogError("EmptyRawCell")
133  <<"Received empty event, this should not happen !!!" <<endl;
134  std::cout << getpid() << "Received EPTY event!!! ERROR." << std::endl;
135  return fillRawData(eID, tstamp, data);
136  }
137  else assert(state==evt::RAWREADING);
138 
139  // read the event data into the fwk raw data format
140  evtNumber_ =newCell->evtNumber();
141  lastCellIndex_=newCell->index();
143  for (unsigned int i=0;i<newCell->nFed();i++) {
144  unsigned int fedSize=newCell->fedSize(i);
145  if (fedSize>0) {
146  FEDRawData& fedData=event_->FEDData(i);
147  fedData.resize(fedSize);
148  newCell->readFed(i,fedData.data());
149  }
150  }
151 
152  // reading the cell is finished (new state will be 'isProcessing')
154  eID=EventID(runNumber_,1U,evtNumber_);
155  data=event_;
156  if(evtNumber_==0)
157  std::cout << getpid() << " ShmReader got event number zero !!! "
158  << std::endl;
159  return 1;
160 }
161 
162 
164 // CMSSW framwork macros
166 
167 
static const char runNumber_[]
FUShmRawCell * rawCellToRead()
Definition: FUShmBuffer.cc:317
int i
Definition: DBlmapReader.cc:9
bool writeErrorEventData(unsigned int runNumber, unsigned int fuProcessId, unsigned int iRawCell, bool checkValue)
Definition: FUShmBuffer.cc:746
virtual ~FUShmReader()
Definition: FUShmReader.cc:43
int fillRawData(edm::EventID &eID, edm::Timestamp &tstamp, FEDRawDataCollection *&data)
Definition: FUShmReader.cc:65
unsigned int lastCellIndex_
Definition: FUShmReader.h:42
bool removeClientPrcId(pid_t prcId)
FEDRawDataCollection * event_
Definition: FUShmReader.h:37
evt::State_t evtState(unsigned int index)
unsigned int evtNumber() const
Definition: FUShmRawCell.h:28
unsigned int getLumiSection() const
Definition: FUShmRawCell.h:70
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
void resize(size_t newsize)
Definition: FEDRawData.cc:33
unsigned int getEventType() const
Definition: FUShmRawCell.h:69
evf::FUShmBuffer * shmBuffer_
Definition: FUShmReader.h:38
void scheduleRawEmptyCellForDiscard()
Definition: FUShmBuffer.cc:638
unsigned int readFed(unsigned int i, unsigned char *buffer) const
unsigned int evtNumber_
Definition: FUShmReader.h:41
char state
Definition: procUtils.cc:75
unsigned int index() const
Definition: FUShmRawCell.h:25
unsigned int nFed() const
Definition: FUShmRawCell.h:33
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
void event_()
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:29
tuple cout
Definition: gather_cfg.py:121
#define DEFINE_EDM_PLUGIN(factory, type, name)
unsigned int fedSize(unsigned int i) const
Definition: FUShmRawCell.cc:82
unsigned int runNumber_
Definition: FUShmReader.h:40
void finishReadingRawCell(FUShmRawCell *cell)
Definition: FUShmBuffer.cc:410
void scheduleRawCellForDiscard(unsigned int iCell)
Definition: FUShmBuffer.cc:454