CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FUResourceTable.h
Go to the documentation of this file.
1 #ifndef FURESOURCETABLE_H
2 #define FURESOURCETABLE_H 1
3 
4 
11 
12 #include "log4cplus/logger.h"
13 #include "toolbox/lang/Class.h"
14 #include "toolbox/task/Action.h"
15 #include "toolbox/task/WorkLoop.h"
16 #include "toolbox/BSem.h"
17 
18 #include <sys/types.h>
19 #include <string>
20 #include <vector>
21 #include <queue>
22 
23 
24 namespace evf {
25 
26  class EvffedFillerRB;
27 
28  class FUResourceTable : public toolbox::lang::Class
29  {
30  public:
31  //
32  // construction/destruction
33  //
34  FUResourceTable(bool segmentationMode,
35  UInt_t nbRawCells, UInt_t nbRecoCells, UInt_t nbDqmCells,
36  UInt_t rawCellSize,UInt_t recoCellSize,UInt_t dqmCellSize,
37  BUProxy* bu,SMProxy* sm,
38  log4cplus::Logger logger,
39  unsigned int,
40  EvffedFillerRB*frb,
41  xdaq::Application*) throw (evf::Exception);
42  virtual ~FUResourceTable();
43 
44 
45  //
46  // member functions
47  //
48 
49  // set fed filler
50  // void setFedFiller(){frb_ = frb;}
51 
52  // set the run number
54 
55  // initialization of the resource queue
56  void initialize(bool segmentationMode,
57  UInt_t nbRawCells, UInt_t nbRecoCells, UInt_t nbDqmCells,
58  UInt_t rawCellSize,UInt_t recoCellSize,UInt_t dqmCellSize)
59  throw (evf::Exception);
60 
61  // work loop to send data events to storage manager
63  bool sendData(toolbox::task::WorkLoop* workLoop);
64 
65  // work loop to send dqm events to storage manager
66  void startSendDqmWorkLoop() throw (evf::Exception);
67  bool sendDqm(toolbox::task::WorkLoop* workLoop);
68 
69  // work loop to discard events to builder unit
70  void startDiscardWorkLoop() throw (evf::Exception);
71  bool discard(toolbox::task::WorkLoop* workLoop);
72 
73  // returns the fuResourceId of the allocated resource
75 
76  // process buffer received via I2O_FU_TAKE message
77  bool buildResource(MemRef_t* bufRef);
78 
79  // process buffer received via I2O_SM_DATA_DISCARD message
80  bool discardDataEvent(MemRef_t* bufRef);
81 
82  // process buffer received via I2O_SM_DQM_DISCARD message
83  bool discardDqmEvent(MemRef_t* bufRef);
84 
85  // post end-of-ls event to shmem
86  void postEndOfLumiSection(MemRef_t* bufRef);
87 
88  // drop next available event
89  void dropEvent();
90 
91  // send event belonging to crashed process to error stream (return false
92  // if no event is found)
93  bool handleCrashedEP(UInt_t runNumber,pid_t pid);
94 
95  // dump event to ascii file
96  void dumpEvent(evf::FUShmRawCell* cell);
97 
98  // send empty events to notify clients to shutdown
99  void stop();
100  void halt();
101  void shutDownClients();
102 
103  // emtpy all containers (resources & ids)
104  void clear();
105 
106  // reset event & error counters
107  void resetCounters();
108 
109  // tell resources wether to check the crc
110  void setDoCrcCheck(UInt_t doCrcCheck) { doCrcCheck_=doCrcCheck; }
111 
112  // tell resources wether to dump events to an ascii file
113  void setDoDumpEvents(UInt_t doDumpEvents) { doDumpEvents_=doDumpEvents; }
114 
115  // check if resource table is active (enabled)
116  bool isActive() const { return isActive_; }
117 
118  // check if resource table can be savely destroyed
119  bool isReadyToShutDown() const { return isReadyToShutDown_; }
120 
121  // various counters
122  UInt_t nbResources() const { return resources_.size(); }
123  UInt_t nbFreeSlots() const { return freeResourceIds_.size(); }
124  UInt_t nbAllocated() const { return nbAllocated_; }
125  UInt_t nbPending() const { return nbPending_; }
126  UInt_t nbCompleted() const { return nbCompleted_; }
127  UInt_t nbSent() const { return nbSent_; }
128  UInt_t nbSentError() const { return nbSentError_; }
129  UInt_t nbSentDqm() const { return nbSentDqm_; }
132  UInt_t nbDiscarded() const { return nbDiscarded_; }
133  UInt_t nbLost() const { return nbLost_; }
134  UInt_t nbEolPosted() const { return nbEolPosted_; }
136 
137  UInt_t nbErrors() const { return nbErrors_; }
138  UInt_t nbCrcErrors() const { return nbCrcErrors_; }
139  UInt_t nbAllocSent() const { return nbAllocSent_; }
140 
141  uint64_t sumOfSquares() const { return sumOfSquares_; }
142  UInt_t sumOfSizes() const { return sumOfSizes_; }
143 
144 
145  // information about (raw) shared memory cells
146  UInt_t nbClients() const;
147  std::vector<pid_t> clientPrcIds() const;
148  std::string clientPrcIdsAsString() const;
149  std::vector<std::string> cellStates() const;
150  std::vector<std::string> dqmCellStates() const;
151  std::vector<UInt_t> cellEvtNumbers() const;
152  std::vector<pid_t> cellPrcIds() const;
153  std::vector<time_t> cellTimeStamps() const;
154 
155 
156 
157  //
158  // helpers
159  //
160  void sendAllocate();
161  void sendDiscard(UInt_t buResourceId);
162 
163  void sendInitMessage(UInt_t fuResourceId,
164  UInt_t outModId,
165  UInt_t fuProcessId,
166  UInt_t fuGuid,
167  UChar_t*data,
168  UInt_t dataSize);
169 
170  void sendDataEvent(UInt_t fuResourceId,
172  UInt_t evtNumber,
173  UInt_t outModId,
174  UInt_t fuProcessId,
175  UInt_t fuGuid,
176  UChar_t*data,
177  UInt_t dataSize);
178 
179  void sendErrorEvent(UInt_t fuResourceId,
181  UInt_t evtNumber,
182  UInt_t fuProcessId,
183  UInt_t fuGuid,
184  UChar_t*data,
185  UInt_t dataSize);
186 
187  void sendDqmEvent(UInt_t fuDqmId,
189  UInt_t evtAtUpdate,
190  UInt_t folderId,
191  UInt_t fuProcessId,
192  UInt_t fuGuid,
193  UChar_t*data,
194  UInt_t dataSize);
195 
196  bool isLastMessageOfEvent(MemRef_t* bufRef);
197 
198  void injectCRCError();
199 
200  void lock() { lock_.take(); }
201  void unlock() { lock_.give(); }
202  //void lockShm() { shmBuffer_->lock(); }
203  //void unlockShm() { shmBuffer_->unlock(); }
204  void printWorkLoopStatus();
205 
206  void lastResort();
207 
208  private:
209  //
210  // member data
211  //
212  typedef toolbox::task::WorkLoop WorkLoop_t;
213  typedef toolbox::task::ActionSignature ActionSignature_t;
214 
217 
218  log4cplus::Logger log_;
219 
222 
225 
228 
234  std::queue<UInt_t> freeResourceIds_;
235 
238 
241  unsigned int shutdownTimeout_;
242 
255 
258  bool isActive_;
261 
265 
268 
270 
271  toolbox::BSem lock_;
273  xdaq::Application *app_;
274  };
275 
276 } // namespace evf
277 
278 
279 #endif
bool discardDataEvent(MemRef_t *bufRef)
UInt_t nbFreeSlots() const
std::vector< UInt_t > cellEvtNumbers() const
FUResourceTable(bool segmentationMode, UInt_t nbRawCells, UInt_t nbRecoCells, UInt_t nbDqmCells, UInt_t rawCellSize, UInt_t recoCellSize, UInt_t dqmCellSize, BUProxy *bu, SMProxy *sm, log4cplus::Logger logger, unsigned int, EvffedFillerRB *frb, xdaq::Application *)
std::vector< std::string > cellStates() const
bool handleCrashedEP(UInt_t runNumber, pid_t pid)
void setDoDumpEvents(UInt_t doDumpEvents)
bool isActive() const
std::ostream & logger()
Definition: fwLog.cc:41
toolbox::mem::Reference MemRef_t
Definition: FUTypes.h:10
void sendErrorEvent(UInt_t fuResourceId, UInt_t runNumber, UInt_t evtNumber, UInt_t fuProcessId, UInt_t fuGuid, UChar_t *data, UInt_t dataSize)
UInt_t nbErrors() const
bool buildResource(MemRef_t *bufRef)
bool sendData(toolbox::task::WorkLoop *workLoop)
std::queue< UInt_t > freeResourceIds_
bool sendDqm(toolbox::task::WorkLoop *workLoop)
UInt_t nbLost() const
UInt_t nbClients() const
xdaq::Application * app_
void sendDiscard(UInt_t buResourceId)
UInt_t nbEolDiscarded() const
WorkLoop_t * wlSendData_
FUShmBuffer * shmBuffer_
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)
ActionSignature_t * asDiscard_
ActionSignature_t * asSendData_
UInt_t nbDiscarded() const
bool discard(toolbox::task::WorkLoop *workLoop)
uint64_t sumOfSquares() const
bool isReadyToShutDown() const
UInt_t nbPendingSMDqmDiscards() const
unsigned char UChar_t
Definition: FUTypes.h:14
UInt_t sumOfSizes() const
std::vector< time_t > cellTimeStamps() const
std::vector< pid_t > clientPrcIds() const
std::vector< FUResource * > FUResourceVec_t
Definition: FUResource.h:136
UInt_t nbAllocated() const
toolbox::task::WorkLoop WorkLoop_t
UInt_t nbCrcErrors() const
UInt_t nbResources() const
void setRunNumber(UInt_t runNumber)
EvffedFillerRB * frb_
UInt_t nbSentError() const
bool isLastMessageOfEvent(MemRef_t *bufRef)
ActionSignature_t * asSendDqm_
unsigned int UInt_t
Definition: FUTypes.h:12
std::string clientPrcIdsAsString() const
toolbox::task::ActionSignature ActionSignature_t
UInt_t nbCompleted() const
unsigned long long uint64_t
Definition: Time.h:15
UInt_t nbSent() const
UInt_t nbEolPosted() const
UInt_t nbPendingSMDiscards() const
UInt_t nbAllocSent() const
std::vector< pid_t > cellPrcIds() const
unsigned int shutdownTimeout_
UInt_t nbSentDqm() const
void dumpEvent(evf::FUShmRawCell *cell)
log4cplus::Logger log_
void postEndOfLumiSection(MemRef_t *bufRef)
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)
std::vector< std::string > dqmCellStates() const
bool discardDqmEvent(MemRef_t *bufRef)
FUResourceVec_t resources_
void sendInitMessage(UInt_t fuResourceId, UInt_t outModId, UInt_t fuProcessId, UInt_t fuGuid, UChar_t *data, UInt_t dataSize)
void setDoCrcCheck(UInt_t doCrcCheck)
void initialize(bool segmentationMode, UInt_t nbRawCells, UInt_t nbRecoCells, UInt_t nbDqmCells, UInt_t rawCellSize, UInt_t recoCellSize, UInt_t dqmCellSize)
UInt_t nbPending() const