CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
IPCMethod.h
Go to the documentation of this file.
1 //
3 // IPCMethod.h
4 // -------
5 //
6 // Contains common functionality for FUResourceTable and FUResourceQueue.
7 //
8 // Created on: Oct 26, 2011
9 // Andrei Spataru : aspataru@cern.ch
11 
12 
13 #ifndef IPCMETHOD_H_
14 #define IPCMETHOD_H_
15 
21 
22 #include "log4cplus/logger.h"
23 
24 #include <sys/types.h>
25 #include <string>
26 #include <vector>
27 #include <queue>
28 #include <semaphore.h>
29 //#include <pthread.h>
30 #include <mutex>
31 #include <atomic>
32 
33 namespace evf {
34 
42 class IPCMethod: public toolbox::lang::Class {
43 
44 public:
45  //
46  // construction/destruction
47  //
48  IPCMethod(bool segmentationMode, UInt_t nbRawCells, UInt_t nbRecoCells,
49  UInt_t nbDqmCells, UInt_t rawCellSize, UInt_t recoCellSize,
50  UInt_t dqmCellSize, int freeResReq, BUProxy *bu, SMProxy *sm,
51  log4cplus::Logger logger, unsigned int timeout,
52  EvffedFillerRB *frb, xdaq::Application*app) throw (evf::Exception);
53 
54  virtual ~IPCMethod();
55 
56  //
57  // member functions
58  //
59 
60  // set the run number
63  }
64 
68  virtual bool sendData() = 0;
72  virtual bool sendDataWhileHalting() = 0;
76  virtual bool sendDqm() = 0;
80  virtual bool sendDqmWhileHalting() = 0;
84  virtual bool discard() = 0;
88  virtual bool discardWhileHalting(bool sendDiscards) = 0;
89 
94 
98  virtual bool buildResource(MemRef_t* bufRef) = 0;
99 
103  virtual bool discardDataEvent(MemRef_t* bufRef) = 0;
107  virtual bool discardDataEventWhileHalting(MemRef_t* bufRef) = 0;
108 
112  virtual bool discardDqmEvent(MemRef_t* bufRef) = 0;
116  virtual bool discardDqmEventWhileHalting(MemRef_t* bufRef) = 0;
117 
121  virtual void postEndOfLumiSection(MemRef_t* bufRef) = 0;
122 
126  virtual void dropEvent() = 0;
127 
131  virtual bool handleCrashedEP(UInt_t runNumber, pid_t pid) = 0;
132 
136  void dumpEvent(evf::FUShmRawCell* cell);
137 
141  virtual std::string printStatus();
142 
146  virtual void shutDownClients() = 0;
147 
151  virtual void clear() = 0;
152 
156  virtual void resetCounters() = 0;
157 
161  void setDoCrcCheck(UInt_t doCrcCheck) {
162  doCrcCheck_ = doCrcCheck;
163  }
164 
168  void setDoDumpEvents(UInt_t doDumpEvents) {
169  doDumpEvents_ = doDumpEvents;
170  }
171 
175  bool isActive() const {
176  return isActive_;
177  }
178 
179  void setActive(bool activeValue) {
180  isActive_ = activeValue;
181  }
182 
186  bool isReadyToShutDown() const {
187  return isReadyToShutDown_;
188  }
189 
190  void setReadyToShutDown(bool readyValue) {
191  isReadyToShutDown_ = readyValue;
192  }
193 
195  return shutdownStatus_;
196  }
197 
198  void setStopFlag(bool status) {
200  }
201 
202  // various counters
203  virtual UInt_t nbResources() const = 0; /* Implemented in subclass */
204  UInt_t nbFreeSlots() const {
205  return freeResourceIds_.size();
206  }
207  UInt_t nbAllocated() const {
208  return nbAllocated_;
209  }
210  UInt_t nbPending() const {
211  return nbPending_;
212  }
213  UInt_t nbCompleted() const {
214  return nbCompleted_;
215  }
216  UInt_t nbSent() const {
217  return nbSent_;
218  }
219  UInt_t nbSentError() const {
220  return nbSentError_;
221  }
222  UInt_t nbSentDqm() const {
223  return nbSentDqm_;
224  }
226  return nbPendingSMDiscards_;
227  }
230  }
231  UInt_t nbDiscarded() const {
232  return nbDiscarded_;
233  }
234  UInt_t nbLost() const {
235  return nbLost_;
236  }
237 
238  // UPDATED
239  UInt_t nbEolPosted() const {
240  return nbEolPosted_;
241  }
243  return nbEolDiscarded_;
244  }
245 
246  UInt_t nbErrors() const {
247  return nbErrors_;
248  }
249  UInt_t nbCrcErrors() const {
250  return nbCrcErrors_;
251  }
252  UInt_t nbAllocSent() const {
253  return nbAllocSent_;
254  }
255 
257  return sumOfSquares_;
258  }
259  UInt_t sumOfSizes() const {
260  return sumOfSizes_;
261  }
262 
263  // information about (raw) shared memory cells
264  virtual UInt_t nbClients() const = 0;
265  virtual std::vector<pid_t> clientPrcIds() const = 0;
266  virtual std::string clientPrcIdsAsString() const = 0;
267  virtual std::vector<std::string> cellStates() const = 0;
268  virtual std::vector<std::string> dqmCellStates() const = 0;
269  virtual std::vector<UInt_t> cellEvtNumbers() const = 0;
270  virtual std::vector<pid_t> cellPrcIds() const = 0;
271  virtual std::vector<time_t> cellTimeStamps() const = 0;
272 
273  //
274  // helpers
275  //
276  void sendAllocate();
278  void resetPendingAllocates();
280  void releaseResources();
282  virtual void resetIPC() = 0;
283 
284  void sendDiscard(UInt_t buResourceId);
285 
286  void sendInitMessage(UInt_t fuResourceId, UInt_t outModId,
287  UInt_t fuProcessId, UInt_t fuGuid, UChar_t*data, UInt_t dataSize,
288  UInt_t nExpectedEPs);
289 
290  void sendDataEvent(UInt_t fuResourceId, UInt_t runNumber, UInt_t evtNumber,
291  UInt_t outModId, UInt_t fuProcessId, UInt_t fuGuid, UChar_t*data,
292  UInt_t dataSize);
293 
294  void sendErrorEvent(UInt_t fuResourceId, UInt_t runNumber,
295  UInt_t evtNumber, UInt_t fuProcessId, UInt_t fuGuid, UChar_t*data,
296  UInt_t dataSize);
297 
298  void sendDqmEvent(UInt_t fuDqmId, UInt_t runNumber, UInt_t evtAtUpdate,
299  UInt_t folderId, UInt_t fuProcessId, UInt_t fuGuid, UChar_t*data,
300  UInt_t dataSize);
301 
302  bool isLastMessageOfEvent(MemRef_t* bufRef);
303 
304  void injectCRCError();
305 
306  void lock() {
307  //lock_.take();
308  while (0 != sem_wait(&lock_)) {
309  if (errno != EINTR) {
310  LOG4CPLUS_ERROR(log_, "Cannot obtain lock on sem LOCK!");
311  }
312  }
313  }
314  void unlock() {
315  //lock_.give();
316  sem_post(&lock_);
317  }
318  #ifdef linux
319  std::unique_lock<std::timed_mutex> lockCrashHandler() {
320  std::unique_lock<std::timed_mutex> lk(crashHandlerLock_);
321  return lk;
322  }
323 
324  std::unique_lock<std::timed_mutex> lockCrashHandlerTimed(unsigned int seconds) {
325  std::unique_lock<std::timed_mutex> lk(crashHandlerLock_,std::chrono::seconds(seconds));
326  return lk;
327  }
328  #endif
329 
332  virtual void lastResort() = 0;
333 
334 protected:
335  //
336  // member data
337  //
338 
341 
342  log4cplus::Logger log_;
343 
347 
348  std::queue<UInt_t> freeResourceIds_;
349  // number of free resources required to ask BU for more events
351 
354 
357  unsigned int shutdownTimeout_;
358 
366  std::atomic<int> nbPendingSMDqmDiscards_;
369  // UPDATED
372 
375  bool isActive_;
376 
380 
383 
385 
386  sem_t lock_;
387  #ifdef linux
388  std::timed_mutex crashHandlerLock_;
389  #endif
391  xdaq::Application *app_;
392 
394 
396  bool stopFlag_;
397 
398 };
399 
400 }
401 
402 #endif /* IPCMETHOD_H_ */
virtual bool sendDqmWhileHalting()=0
virtual std::vector< std::string > dqmCellStates() const =0
virtual std::vector< pid_t > clientPrcIds() const =0
void sendDiscard(UInt_t buResourceId)
Definition: IPCMethod.cc:150
UInt_t nbEolPosted_
Definition: IPCMethod.h:370
double seconds()
virtual std::vector< std::string > cellStates() const =0
bool * acceptSMDataDiscard_
Definition: IPCMethod.h:352
virtual std::vector< time_t > cellTimeStamps() const =0
uint64_t sumOfSquares_
Definition: IPCMethod.h:381
virtual void lastResort()=0
virtual bool buildResource(MemRef_t *bufRef)=0
UInt_t doCrcCheck_
Definition: IPCMethod.h:355
void setDoCrcCheck(UInt_t doCrcCheck)
Definition: IPCMethod.h:161
void releaseResources()
releases all FUResource&#39;s
Definition: IPCMethod.cc:143
virtual bool discardDataEvent(MemRef_t *bufRef)=0
UInt_t nbErrors_
Definition: IPCMethod.h:377
UInt_t nbDiscarded_
Definition: IPCMethod.h:367
void sendAllocate()
Definition: IPCMethod.cc:111
std::ostream & logger()
Definition: fwLog.cc:41
virtual ~IPCMethod()
Definition: IPCMethod.cc:51
toolbox::mem::Reference MemRef_t
Definition: FUTypes.h:10
bool isReadyToShutDown_
Definition: IPCMethod.h:374
void setActive(bool activeValue)
Definition: IPCMethod.h:179
virtual std::vector< UInt_t > cellEvtNumbers() const =0
virtual void resetCounters()=0
UInt_t nbLost() const
Definition: IPCMethod.h:234
virtual bool discardWhileHalting(bool sendDiscards)=0
UInt_t nbSentError() const
Definition: IPCMethod.h:219
virtual void dropEvent()=0
bool isLastMessageOfEvent(MemRef_t *bufRef)
Definition: IPCMethod.cc:248
log4cplus::Logger log_
Definition: IPCMethod.h:342
UInt_t nbEolDiscarded_
Definition: IPCMethod.h:371
UInt_t nbCompleted() const
Definition: IPCMethod.h:213
SMProxy * sm_
Definition: IPCMethod.h:340
UInt_t nbRawCells_
Definition: IPCMethod.h:345
UInt_t nbSentDqm_
Definition: IPCMethod.h:364
virtual std::string printStatus()
Definition: IPCMethod.cc:101
virtual bool discard()=0
UInt_t nbDiscarded() const
Definition: IPCMethod.h:231
virtual std::string clientPrcIdsAsString() const =0
UInt_t nbAllocated() const
Definition: IPCMethod.h:207
void resetPendingAllocates()
resets free resources to the maximum number
Definition: IPCMethod.cc:129
UInt_t nbEolPosted() const
Definition: IPCMethod.h:239
void dumpEvent(evf::FUShmRawCell *cell)
Definition: IPCMethod.cc:74
UInt_t nbPendingSMDiscards_
Definition: IPCMethod.h:365
IPCMethod(bool segmentationMode, UInt_t nbRawCells, UInt_t nbRecoCells, UInt_t nbDqmCells, UInt_t rawCellSize, UInt_t recoCellSize, UInt_t dqmCellSize, int freeResReq, BUProxy *bu, SMProxy *sm, log4cplus::Logger logger, unsigned int timeout, EvffedFillerRB *frb, xdaq::Application *app)
Definition: IPCMethod.cc:28
virtual UInt_t nbClients() const =0
virtual bool sendDqm()=0
UInt_t nbEolDiscarded() const
Definition: IPCMethod.h:242
UInt_t nbPending() const
Definition: IPCMethod.h:210
UInt_t nbCompleted_
Definition: IPCMethod.h:361
UInt_t nbPending_
Definition: IPCMethod.h:360
UInt_t sumOfSizes() const
Definition: IPCMethod.h:259
virtual bool discardDqmEvent(MemRef_t *bufRef)=0
UInt_t nbPendingSMDiscards() const
Definition: IPCMethod.h:225
int nbPendingSMDqmDiscards() const
Definition: IPCMethod.h:228
UInt_t allocateResource()
Definition: IPCMethod.cc:60
unsigned char UChar_t
Definition: FUTypes.h:14
UInt_t nbSentError_
Definition: IPCMethod.h:363
bool isReadyToShutDown() const
Definition: IPCMethod.h:186
std::vector< FUResource * > FUResourceVec_t
Definition: FUResource.h:209
UInt_t nbCrcErrors_
Definition: IPCMethod.h:378
void sendDqmEvent(UInt_t fuDqmId, UInt_t runNumber, UInt_t evtAtUpdate, UInt_t folderId, UInt_t fuProcessId, UInt_t fuGuid, UChar_t *data, UInt_t dataSize)
Definition: IPCMethod.cc:224
int * acceptSMDqmDiscard_
Definition: IPCMethod.h:353
FUResourceVec_t resources_
Definition: IPCMethod.h:393
unsigned int freeResRequiredForAllocate_
Definition: IPCMethod.h:350
xdaq::Application * app_
Definition: IPCMethod.h:391
void setRunNumber(UInt_t runNumber)
Definition: IPCMethod.h:61
UInt_t nbAllocSent() const
Definition: IPCMethod.h:252
void injectCRCError()
Definition: IPCMethod.cc:264
void setDoDumpEvents(UInt_t doDumpEvents)
Definition: IPCMethod.h:168
UInt_t nbCrcErrors() const
Definition: IPCMethod.h:249
virtual bool handleCrashedEP(UInt_t runNumber, pid_t pid)=0
UInt_t runNumber_
Definition: IPCMethod.h:384
uint64_t sumOfSquares() const
Definition: IPCMethod.h:256
UInt_t nbLost_
Definition: IPCMethod.h:368
UInt_t nbFreeSlots() const
Definition: IPCMethod.h:204
UInt_t shutdownStatus_
Definition: IPCMethod.h:395
unsigned int UInt_t
Definition: FUTypes.h:12
unsigned long long uint64_t
Definition: Time.h:15
UInt_t shutdownStatus()
Definition: IPCMethod.h:194
UInt_t nbClientsToShutDown_
Definition: IPCMethod.h:373
virtual bool discardDataEventWhileHalting(MemRef_t *bufRef)=0
unsigned int shutdownTimeout_
Definition: IPCMethod.h:357
virtual UInt_t nbResources() const =0
UInt_t nbSentDqm() const
Definition: IPCMethod.h:222
EvffedFillerRB * frb_
Definition: IPCMethod.h:390
std::atomic< int > nbPendingSMDqmDiscards_
Definition: IPCMethod.h:366
virtual bool discardDqmEventWhileHalting(MemRef_t *bufRef)=0
void sendErrorEvent(UInt_t fuResourceId, UInt_t runNumber, UInt_t evtNumber, UInt_t fuProcessId, UInt_t fuGuid, UChar_t *data, UInt_t dataSize)
Definition: IPCMethod.cc:186
UInt_t nbRecoCells_
Definition: IPCMethod.h:346
virtual void postEndOfLumiSection(MemRef_t *bufRef)=0
UInt_t nbAllocSent_
Definition: IPCMethod.h:379
UInt_t sumOfSizes_
Definition: IPCMethod.h:382
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
virtual bool sendData()=0
UInt_t nbSent_
Definition: IPCMethod.h:362
void sendDataEvent(UInt_t fuResourceId, UInt_t runNumber, UInt_t evtNumber, UInt_t outModId, UInt_t fuProcessId, UInt_t fuGuid, UChar_t *data, UInt_t dataSize)
Definition: IPCMethod.cc:171
UInt_t nbAllocated_
Definition: IPCMethod.h:359
void setStopFlag(bool status)
Definition: IPCMethod.h:198
virtual void clear()=0
bool isActive() const
Definition: IPCMethod.h:175
std::queue< UInt_t > freeResourceIds_
Definition: IPCMethod.h:348
UInt_t nbErrors() const
Definition: IPCMethod.h:246
void unlock()
Definition: IPCMethod.h:314
virtual void resetIPC()=0
resets the underlying IPC method to the initial state
UInt_t nbSent() const
Definition: IPCMethod.h:216
void sendInitMessage(UInt_t fuResourceId, UInt_t outModId, UInt_t fuProcessId, UInt_t fuGuid, UChar_t *data, UInt_t dataSize, UInt_t nExpectedEPs)
Definition: IPCMethod.cc:156
virtual std::vector< pid_t > cellPrcIds() const =0
tuple status
Definition: ntuplemaker.py:245
virtual void shutDownClients()=0
BUProxy * bu_
Definition: IPCMethod.h:339
void setReadyToShutDown(bool readyValue)
Definition: IPCMethod.h:190
UInt_t nbDqmCells_
Definition: IPCMethod.h:344
virtual bool sendDataWhileHalting()=0
UInt_t doDumpEvents_
Definition: IPCMethod.h:356