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 
135  UInt_t nbErrors() const { return nbErrors_; }
136  UInt_t nbCrcErrors() const { return nbCrcErrors_; }
137  UInt_t nbAllocSent() const { return nbAllocSent_; }
138 
139  uint64_t sumOfSquares() const { return sumOfSquares_; }
140  UInt_t sumOfSizes() const { return sumOfSizes_; }
141 
142 
143  // information about (raw) shared memory cells
144  UInt_t nbClients() const;
145  std::vector<pid_t> clientPrcIds() const;
146  std::string clientPrcIdsAsString() const;
147  std::vector<std::string> cellStates() const;
148  std::vector<std::string> dqmCellStates() const;
149  std::vector<UInt_t> cellEvtNumbers() const;
150  std::vector<pid_t> cellPrcIds() const;
151  std::vector<time_t> cellTimeStamps() const;
152 
153 
154 
155  //
156  // helpers
157  //
158  void sendAllocate();
159  void sendDiscard(UInt_t buResourceId);
160 
161  void sendInitMessage(UInt_t fuResourceId,
162  UInt_t outModId,
163  UInt_t fuProcessId,
164  UInt_t fuGuid,
165  UChar_t*data,
166  UInt_t dataSize);
167 
168  void sendDataEvent(UInt_t fuResourceId,
170  UInt_t evtNumber,
171  UInt_t outModId,
172  UInt_t fuProcessId,
173  UInt_t fuGuid,
174  UChar_t*data,
175  UInt_t dataSize);
176 
177  void sendErrorEvent(UInt_t fuResourceId,
179  UInt_t evtNumber,
180  UInt_t fuProcessId,
181  UInt_t fuGuid,
182  UChar_t*data,
183  UInt_t dataSize);
184 
185  void sendDqmEvent(UInt_t fuDqmId,
187  UInt_t evtAtUpdate,
188  UInt_t folderId,
189  UInt_t fuProcessId,
190  UInt_t fuGuid,
191  UChar_t*data,
192  UInt_t dataSize);
193 
194  bool isLastMessageOfEvent(MemRef_t* bufRef);
195 
196  void injectCRCError();
197 
198  void lock() { lock_.take(); }
199  void unlock() { lock_.give(); }
200  //void lockShm() { shmBuffer_->lock(); }
201  //void unlockShm() { shmBuffer_->unlock(); }
202  void printWorkLoopStatus();
203 
204  void lastResort();
205 
206  private:
207  //
208  // member data
209  //
210  typedef toolbox::task::WorkLoop WorkLoop_t;
211  typedef toolbox::task::ActionSignature ActionSignature_t;
212 
215 
216  log4cplus::Logger log_;
217 
220 
223 
226 
232  std::queue<UInt_t> freeResourceIds_;
233 
236 
239  unsigned int shutdownTimeout_;
240 
251 
254  bool isActive_;
257 
261 
264 
266 
267  toolbox::BSem lock_;
269  xdaq::Application *app_;
270  };
271 
272 } // namespace evf
273 
274 
275 #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)
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 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