CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SharedResources.h
Go to the documentation of this file.
1 //
3 // SharedResources.h
4 // -------
5 //
6 // Resources shared between FSM states.
7 //
8 // Created on: Sep 21, 2011
9 // Andrei Spataru : aspataru@cern.ch
11 
12 #ifndef RBSHAREDRESOURCES_H_
13 #define RBSHAREDRESOURCES_H_
14 
21 
23 
24 #include "boost/statechart/event_base.hpp"
25 #include <boost/shared_ptr.hpp>
26 
27 #include "xdata/InfoSpace.h"
28 #include "xdata/Integer32.h"
29 #include "xdata/UnsignedInteger32.h"
30 #include "xdata/Integer.h"
31 #include "xdata/Double.h"
32 #include "xdata/Boolean.h"
33 #include "xdata/String.h"
34 
35 #include "toolbox/task/Action.h"
36 #include "toolbox/task/WorkLoop.h"
37 #include "toolbox/task/WorkLoopFactory.h"
38 
39 #include <semaphore.h>
40 #include <iostream>
41 #include <queue>
42 
43 namespace evf {
44 
45 class FUResourceBroker;
46 
47 namespace rb_statemachine {
48 
49 typedef boost::shared_ptr<boost::statechart::event_base> EventPtr;
50 
51 // forward declaration of state classes
52 class Halted;
53 class Configuring;
54 class Ready;
55 class Stopped;
56 class Enabling;
57 class Enabled;
58 class Running;
59 class Stopping;
60 class Halting;
61 class Normal;
62 class Failed;
63 
71 class SharedResources: public toolbox::lang::Class {
72 
73 public:
74  SharedResources(Logger log);
76 
77  // in SharedResources because it's called by Configuring and Stopping
81  void configureResources(xdaq::Application* app);
82 
83  // in SharedResources because it's called by Configuring and Stopping
87  void reset();
89  //lock();
90  gui_->updateExternalState(newState);
91  //unlock();
92  }
94  //lock();
95  gui_->updateInternalState(newState);
96  //unlock();
97  }
98  void setFsmPointer(RBStateMachine* const fsm) {
99  fsm_ = fsm;
100  }
101 
102  void cancelAllWorkloops();
103 
104  /*
105  * CONCURRENT ACCESS
106  */
107  void lock() {
108  while (0 != sem_wait(&lock_)) {
109  if (errno != EINTR) {
110  LOG4CPLUS_ERROR(log_, "Cannot obtain lock on sem LOCK!");
111  }
112  }
113  }
114  void unlock() {
115  sem_post(&lock_);
116  }
117 
118  void lockRSAccess() {
119  while (0 != sem_wait(&accessToResourceStructureLock_)) {
120  if (errno != EINTR) {
121  LOG4CPLUS_ERROR(log_, "Cannot obtain lock on sem accessToResourceStructureLock_!");
122  }
123  }
124  }
125 
127  if (sem_trywait(&accessToResourceStructureLock_)) return -1;
128  return 0;
129  }
130 
131  void unlockRSAccess() {
133  }
134 
135  void printWorkLoopStatus();
136 
137 private:
138 
139  /*
140  * Workloop starters and dispatch actions.
141  * Used by friend state classes.
142  */
150  bool monitoring(toolbox::task::WorkLoop* wl);
154  void startWatchingWorkLoop() throw (evf::Exception);
158  bool watching(toolbox::task::WorkLoop* wl);
159  double deltaT(const struct timeval *start, const struct timeval *end);
160 
164  void startSendDataWorkLoop() throw (evf::Exception);
168  bool sendData(toolbox::task::WorkLoop* wl);
169 
173  void startSendDqmWorkLoop() throw (evf::Exception);
177  bool sendDqm(toolbox::task::WorkLoop* wl);
178 
182  void startDiscardWorkLoop() throw (evf::Exception);
186  bool discard(toolbox::task::WorkLoop* wl);
187 
191  void goToFailedState(evf::Exception& e);
192 
193 private:
194 
195  typedef toolbox::task::WorkLoop WorkLoop_t;
196  typedef toolbox::task::ActionSignature ActionSignature_t;
197 
198  /*
199  * Workloops and action signatures
200  */
201 
202  // workloop / action signature for monitoring
203  WorkLoop_t *wlMonitoring_;
204  ActionSignature_t *asMonitoring_;
205  // workloop / action signature for watching
206  WorkLoop_t *wlWatching_;
207  ActionSignature_t *asWatching_;
208 
209  WorkLoop_t *wlSendData_;
210  ActionSignature_t *asSendData_;
211  WorkLoop_t *wlSendDqm_;
212  ActionSignature_t *asSendDqm_;
213  WorkLoop_t *wlDiscard_;
214  ActionSignature_t *asDiscard_;
215 
216  //
217  // member data
218  //
219 
220  // pointer to FSM
222 
223  // Hyper DAQ Independent web GUI
225 
226  // Command Queue containing state machine events
228 
229  // application logger
230  Logger log_;
231 
232  // BuilderUnit (BU) to receive raw even data from
234 
235  // StorageManager (SM) to send selected events to
237 
238  // memory pool for bu <-> fu comunication messages
239  toolbox::mem::Pool* i2oPool_;
240 
241  // managed resources
244 
245  // application identifier
246  std::string sourceId_;
247 
248  // monitored parameters
249  xdata::UnsignedInteger32 runNumber_;
250 
251  xdata::Double deltaT_;
252  xdata::UnsignedInteger32 deltaN_;
253  xdata::Double deltaSumOfSquares_;
254  xdata::UnsignedInteger32 deltaSumOfSizes_;
255 
256  xdata::Double throughput_;
257  xdata::Double rate_;
258  xdata::Double average_;
259  xdata::Double rms_;
260 
261  // monitored counters
262  xdata::UnsignedInteger32 nbAllocatedEvents_;
263  xdata::UnsignedInteger32 nbPendingRequests_;
264  xdata::UnsignedInteger32 nbReceivedEvents_;
265  xdata::UnsignedInteger32 nbProcessedEvents_;
266  xdata::UnsignedInteger32 nbSentEvents_;
267  xdata::UnsignedInteger32 nbSentDqmEvents_;
268  xdata::UnsignedInteger32 nbSentErrorEvents_;
269  xdata::UnsignedInteger32 nbPendingSMDiscards_;
270  xdata::UnsignedInteger32 nbPendingSMDqmDiscards_;
271  xdata::UnsignedInteger32 nbDiscardedEvents_;
272 
273  // UPDATED
274  xdata::UnsignedInteger32 nbReceivedEol_;
275  xdata::UnsignedInteger32 highestEolReceived_;
276  xdata::UnsignedInteger32 nbEolPosted_;
277  xdata::UnsignedInteger32 nbEolDiscarded_;
278 
279  xdata::UnsignedInteger32 nbLostEvents_;
280  xdata::UnsignedInteger32 nbDataErrors_;
281  xdata::UnsignedInteger32 nbCrcErrors_;
282  xdata::UnsignedInteger32 nbTimeoutsWithEvent_;
283  xdata::UnsignedInteger32 nbTimeoutsWithoutEvent_;
284  xdata::UnsignedInteger32 dataErrorFlag_;
285 
286  // standard parameters
287  xdata::Boolean segmentationMode_;
288  xdata::Boolean useMessageQueueIPC_;
289  xdata::UnsignedInteger32 nbClients_;
290  xdata::String clientPrcIds_;
291  xdata::UnsignedInteger32 nbRawCells_;
292  xdata::UnsignedInteger32 nbRecoCells_;
293  xdata::UnsignedInteger32 nbDqmCells_;
294  xdata::UnsignedInteger32 rawCellSize_;
295  xdata::UnsignedInteger32 recoCellSize_;
296  xdata::UnsignedInteger32 dqmCellSize_;
297  // UPDATE freeResourcesRequiredForAllocate
299 
300  xdata::Boolean doDropEvents_;
301  xdata::Boolean doFedIdCheck_;
302  xdata::UnsignedInteger32 doCrcCheck_;
303  xdata::UnsignedInteger32 doDumpEvents_;
304 
305  xdata::String buClassName_;
306  xdata::UnsignedInteger32 buInstance_;
307  xdata::String smClassName_;
308  xdata::UnsignedInteger32 smInstance_;
309 
310  xdata::UnsignedInteger32 resourceStructureTimeout_;
311  xdata::UnsignedInteger32 monSleepSec_;
312  xdata::UnsignedInteger32 watchSleepSec_;
313  xdata::UnsignedInteger32 timeOutSec_;
314  xdata::Boolean processKillerEnabled_;
315  xdata::Boolean useEvmBoard_;
316 
317  xdata::String reasonForFailed_;
318 
319  // debug parameters
320  xdata::UnsignedInteger32 nbAllocateSent_;
321  xdata::UnsignedInteger32 nbTakeReceived_;
322  xdata::UnsignedInteger32 nbDataDiscardReceived_;
323  xdata::UnsignedInteger32 nbDqmDiscardReceived_;
324 
325  // helper variables for monitoring
326  struct timeval monStartTime_;
330 
331  // lock
332  sem_t lock_;
334 
336 
337  // emergency stop protection against I2O access
340 
341  /*
342  * FRIENDS
343  */
344  friend class evf::FUResourceBroker;
345 
346  friend class Halted;
347  friend class Configuring;
348  friend class Ready;
349  friend class Stopped;
350  friend class Enabling;
351  friend class Enabled;
352  friend class Running;
353  friend class Stopping;
354  friend class Halting;
355  friend class Normal;
356  friend class Failed;
357 };
358 
359 typedef boost::shared_ptr<SharedResources> SharedResourcesPtr_t;
360 
361 } // end namespace rb_statemachine
362 
363 } //end namespace evf
364 
365 #endif /* RBSHAREDRESOURCES_H_ */
xdata::UnsignedInteger32 nbSentEvents_
void updateExternalState(std::string newState)
double deltaT(const struct timeval *start, const struct timeval *end)
tuple start
Check for commandline option errors.
Definition: dqm_diff.py:58
xdata::UnsignedInteger32 recoCellSize_
void updateGUIExternalState(std::string newState)
bool discard(toolbox::task::WorkLoop *wl)
xdata::UnsignedInteger32 nbDiscardedEvents_
xdata::UnsignedInteger32 nbDataDiscardReceived_
boost::shared_ptr< SharedResources > SharedResourcesPtr_t
xdata::UnsignedInteger32 nbProcessedEvents_
xdata::UnsignedInteger32 nbTakeReceived_
xdata::UnsignedInteger32 nbRawCells_
void setFsmPointer(RBStateMachine *const fsm)
xdata::UnsignedInteger32 nbAllocateSent_
boost::shared_ptr< boost::statechart::event_base > EventPtr
Definition: CommandQueue.h:23
xdata::UnsignedInteger32 highestEolReceived_
xdata::UnsignedInteger32 resourceStructureTimeout_
xdata::UnsignedInteger32 dataErrorFlag_
xdata::UnsignedInteger32 smInstance_
xdata::UnsignedInteger32 nbTimeoutsWithEvent_
xdata::UnsignedInteger32 nbLostEvents_
xdata::UnsignedInteger32 doDumpEvents_
bool sendData(toolbox::task::WorkLoop *wl)
xdata::UnsignedInteger32 nbSentErrorEvents_
xdata::UnsignedInteger32 nbDqmCells_
xdata::UnsignedInteger32 monSleepSec_
xdata::UnsignedInteger32 nbDqmDiscardReceived_
bool sendDqm(toolbox::task::WorkLoop *wl)
bool watching(toolbox::task::WorkLoop *wl)
xdata::UnsignedInteger32 deltaSumOfSizes_
void updateInternalState(std::string newState)
xdata::UnsignedInteger32 nbEolPosted_
xdata::UnsignedInteger32 buInstance_
xdata::UnsignedInteger32 nbSentDqmEvents_
uint16_t mem[nChs][nEvts]
#define end
Definition: vmac.h:38
xdata::UnsignedInteger32 nbDataErrors_
xdata::UnsignedInteger32 nbReceivedEvents_
xdata::UnsignedInteger32 watchSleepSec_
xdata::UnsignedInteger32 nbAllocatedEvents_
xdata::UnsignedInteger32 nbPendingSMDiscards_
unsigned int UInt_t
Definition: FUTypes.h:12
void updateGUIInternalState(std::string newState)
xdata::UnsignedInteger32 nbReceivedEol_
xdata::UnsignedInteger32 nbPendingRequests_
unsigned long long uint64_t
Definition: Time.h:15
xdata::UnsignedInteger32 nbRecoCells_
xdata::UnsignedInteger32 runNumber_
xdata::UnsignedInteger32 nbPendingSMDqmDiscards_
bool monitoring(toolbox::task::WorkLoop *wl)
string const
Definition: compareJSON.py:14
xdata::UnsignedInteger32 nbTimeoutsWithoutEvent_
#define private
Definition: FWFileEntry.h:18
xdata::UnsignedInteger32 doCrcCheck_
xdata::UnsignedInteger32 nbClients_
xdata::UnsignedInteger32 rawCellSize_
xdata::UnsignedInteger32 dqmCellSize_
void goToFailedState(evf::Exception &e)
toolbox::task::ActionSignature ActionSignature_t
xdata::UnsignedInteger32 nbCrcErrors_
void configureResources(xdaq::Application *app)
xdata::UnsignedInteger32 timeOutSec_
xdata::UnsignedInteger32 nbEolDiscarded_