CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
BU.h
Go to the documentation of this file.
1 #ifndef AUTOBU_BU_H
2 #define AUTOBU_BU_H 1
3 
4 
6 
10 
12 
13 #include "xdaq/Application.h"
14 
15 #include "toolbox/mem/HeapAllocator.h"
16 #include "toolbox/mem/MemoryPoolFactory.h"
17 #include "toolbox/net/URN.h"
18 #include "toolbox/fsm/exception/Exception.h"
19 
20 #include "xdata/InfoSpace.h"
21 #include "xdata/UnsignedInteger32.h"
22 #include "xdata/Double.h"
23 #include "xdata/Boolean.h"
24 #include "xdata/String.h"
25 
26 #include "interface/evb/i2oEVBMsgs.h"
27 #include "interface/shared/i2oXFunctionCodes.h"
28 
29 #include "interface/shared/frl_header.h"
30 #include "interface/shared/fed_header.h"
31 #include "interface/shared/fed_trailer.h"
32 
33 #include "i2o/Method.h"
34 #include "i2o/utils/AddressMap.h"
35 
36 #include "CLHEP/Random/RandGauss.h"
37 
38 
39 #include <vector>
40 #include <queue>
41 #include <cmath>
42 #include <semaphore.h>
43 #include <sys/time.h>
44 
45 
46 namespace evf {
47 
48 
49  class BU : public xdaq::Application,
50  public xdata::ActionListener
51  {
52  public:
53  //
54  // xdaq instantiator macro
55  //
57 
58 
59  //
60  // construction/destruction
61  //
62  BU(xdaq::ApplicationStub *s);
63  virtual ~BU();
64 
65 
66  //
67  // public member functions
68  //
69 
70  // work loop functions to be executed during transitional states (async)
71  bool configuring(toolbox::task::WorkLoop* wl);
72  bool enabling(toolbox::task::WorkLoop* wl);
73  bool stopping(toolbox::task::WorkLoop* wl);
74  bool halting(toolbox::task::WorkLoop* wl);
75 
76  // fsm soap command callback
77  xoap::MessageReference fsmCallback(xoap::MessageReference msg)
79 
80  // i2o callbacks
81  void I2O_BU_ALLOCATE_Callback(toolbox::mem::Reference *bufRef);
82  void I2O_BU_DISCARD_Callback(toolbox::mem::Reference *bufRef);
83 
84  // xdata::ActionListener callback
85  void actionPerformed(xdata::Event& e);
86 
87  // Hyper DAQ web interface [see Utilities/WebGUI]
92 
93  // build events (random or playback)
95  bool building(toolbox::task::WorkLoop* wl);
96 
97  // send events to connected FU
98  void startSendingWorkLoop() throw (evf::Exception);
99  bool sending(toolbox::task::WorkLoop* wl);
100 
101  // calculate monitoring information in separate thread
103  bool monitoring(toolbox::task::WorkLoop* wl);
104 
105 
106  private:
107  //
108  // private member functions
109  //
110  void lock() { sem_wait(&lock_); }
111  void unlock() { sem_post(&lock_); }
112  void waitBuild() { sem_wait(&buildSem_); }
113  void postBuild() { sem_post(&buildSem_); }
114  void waitSend() { sem_wait(&sendSem_); }
115  void postSend() { sem_post(&sendSem_); }
116  void waitRqst() { sem_wait(&rqstSem_); }
117  void postRqst() { sem_post(&rqstSem_); }
118 
119  void exportParameters();
120  void reset();
121  double deltaT(const struct timeval *start,const struct timeval *end);
122 
123  bool generateEvent(evf::BUEvent* evt);
124  toolbox::mem::Reference *createMsgChain(evf::BUEvent *evt,
125  unsigned int fuResourceId);
126 
127 
128  void dumpFrame(unsigned char* data,unsigned int len);
129 
130 
131  private:
132  //
133  // member data
134  //
135 
136  // BU message logger
137  Logger log_;
138 
139  // BU application descriptor
140  xdaq::ApplicationDescriptor *buAppDesc_;
141 
142  // FU application descriptor
143  xdaq::ApplicationDescriptor *fuAppDesc_;
144 
145  // BU application context
146  xdaq::ApplicationContext *buAppContext_;
147 
148  // BU state machine
150 
151  // BU web interface
153 
154  // resource management
155  std::vector<evf::BUEvent*> events_;
156  std::queue<unsigned int> rqstIds_;
157  std::queue<unsigned int> freeIds_;
158  std::queue<unsigned int> builtIds_;
159  std::set<unsigned int> sentIds_;
160  unsigned int evtNumber_;
161  std::vector<unsigned int> validFedIds_;
162 
166 
167  // workloop / action signature for building events
168  toolbox::task::WorkLoop *wlBuilding_;
169  toolbox::task::ActionSignature *asBuilding_;
170 
171  // workloop / action signature for sending events
172  toolbox::task::WorkLoop *wlSending_;
173  toolbox::task::ActionSignature *asSending_;
174 
175  // workloop / action signature for monitoring
176  toolbox::task::WorkLoop *wlMonitoring_;
177  toolbox::task::ActionSignature *asMonitoring_;
178 
179 
180  std::string sourceId_;
181 
182  // monitored parameters
183  xdata::String url_;
184  xdata::String class_;
185  xdata::UnsignedInteger32 instance_;
186  xdata::String hostname_;
187  xdata::UnsignedInteger32 runNumber_;
188  xdata::Double memUsedInMB_;
189 
190  xdata::Double deltaT_;
191  xdata::UnsignedInteger32 deltaN_;
192  xdata::Double deltaSumOfSquares_;
193  xdata::UnsignedInteger32 deltaSumOfSizes_;
194 
195  xdata::Double throughput_;
196  xdata::Double average_;
197  xdata::Double rate_;
198  xdata::Double rms_;
199 
200  // monitored counters
201  xdata::UnsignedInteger32 nbEventsInBU_;
202  xdata::UnsignedInteger32 nbEventsRequested_;
203  xdata::UnsignedInteger32 nbEventsBuilt_;
204  xdata::UnsignedInteger32 nbEventsSent_;
205  xdata::UnsignedInteger32 nbEventsDiscarded_;
206 
207  // standard parameters
208  xdata::String mode_;
209  xdata::Boolean replay_;
210  xdata::Boolean crc_;
211  xdata::Boolean overwriteEvtId_;
212  xdata::Boolean overwriteLsId_;
213  xdata::UnsignedInteger32 fakeLsUpdateSecs_;
214  xdata::UnsignedInteger32 firstEvent_;
215  xdata::UnsignedInteger32 queueSize_;
216  xdata::UnsignedInteger32 eventBufferSize_;
217  xdata::UnsignedInteger32 msgBufferSize_;
218  xdata::UnsignedInteger32 fedSizeMax_;
219  xdata::UnsignedInteger32 fedSizeMean_;
220  xdata::UnsignedInteger32 fedSizeWidth_;
221  xdata::Boolean useFixedFedSize_;
222  xdata::UnsignedInteger32 monSleepSec_;
223 
224  unsigned int fakeLs_;
225  timeval lastLsUpdate_;
226  // gaussian aprameters for randpm fed size generation (log-normal)
229 
230  // monitoring helpers
231  struct timeval monStartTime_;
232  unsigned int monLastN_;
234  unsigned int monLastSumOfSizes_;
236  unsigned int sumOfSizes_;
237 
238 
239  // memory pool for i20 communication
240  toolbox::mem::Pool* i2oPool_;
241 
242  // synchronization
243  sem_t lock_;
244  sem_t buildSem_;
245  sem_t sendSem_;
246  sem_t rqstSem_;
247 
248 
249  //
250  // static member data
251  //
252  static const int frlHeaderSize_ =sizeof(frlh_t);
253  static const int fedHeaderSize_ =sizeof(fedh_t);
254  static const int fedTrailerSize_=sizeof(fedt_t);
255 
256  }; // class BU
257 
258 
259 } // namespace evf
260 
261 
262 #endif
xdata::UnsignedInteger32 nbEventsInBU_
Definition: BU.h:201
void unlock()
Definition: BU.h:111
#define Input(cl)
Definition: vmac.h:189
struct fedt_struct fedt_t
bool configuring(toolbox::task::WorkLoop *wl)
Definition: BU.cc:178
void webPageRequest(xgi::Input *in, xgi::Output *out)
Definition: BU.cc:402
xdata::Boolean overwriteEvtId_
Definition: BU.h:211
toolbox::task::ActionSignature * asMonitoring_
Definition: BU.h:177
xdata::Double memUsedInMB_
Definition: BU.h:188
xdata::Boolean replay_
Definition: BU.h:209
std::queue< unsigned int > builtIds_
Definition: BU.h:158
double gaussianWidth_
Definition: BU.h:228
bool sending(toolbox::task::WorkLoop *wl)
Definition: BU.cc:501
xdata::String mode_
Definition: BU.h:208
xdata::UnsignedInteger32 msgBufferSize_
Definition: BU.h:217
xdata::String class_
Definition: BU.h:184
StateMachine fsm_
Definition: BU.h:149
xdaq::ApplicationContext * buAppContext_
Definition: BU.h:146
toolbox::mem::Reference * createMsgChain(evf::BUEvent *evt, unsigned int fuResourceId)
Definition: BU.cc:805
xdata::Boolean useFixedFedSize_
Definition: BU.h:221
double deltaT(const struct timeval *start, const struct timeval *end)
Definition: BU.cc:727
Logger log_
Definition: BU.h:137
xdata::UnsignedInteger32 fedSizeWidth_
Definition: BU.h:220
static const int frlHeaderSize_
Definition: BU.h:252
std::queue< unsigned int > rqstIds_
Definition: BU.h:156
bool isSending_
Definition: BU.h:164
xdata::Double rate_
Definition: BU.h:197
bool monitoring(toolbox::task::WorkLoop *wl)
Definition: BU.cc:562
xdata::UnsignedInteger32 instance_
Definition: BU.h:185
unsigned int evtNumber_
Definition: BU.h:160
sem_t sendSem_
Definition: BU.h:245
void postBuild()
Definition: BU.h:113
xdata::Boolean overwriteLsId_
Definition: BU.h:212
xdata::Double throughput_
Definition: BU.h:195
xdata::UnsignedInteger32 fakeLsUpdateSecs_
Definition: BU.h:213
void startMonitoringWorkLoop()
Definition: BU.cc:539
static const int fedTrailerSize_
Definition: BU.h:254
void lock()
Definition: BU.h:110
void customWebPage(xgi::Input *in, xgi::Output *out)
Definition: BU.cc:412
void waitSend()
Definition: BU.h:114
bool stopping(toolbox::task::WorkLoop *wl)
Definition: BU.cc:227
void actionPerformed(xdata::Event &e)
Definition: BU.cc:385
void waitRqst()
Definition: BU.h:116
xdata::Double deltaSumOfSquares_
Definition: BU.h:192
void startBuildingWorkLoop()
Definition: BU.cc:420
WebGUI * gui_
Definition: BU.h:152
xoap::MessageReference fsmCallback(xoap::MessageReference msg)
Definition: BU.cc:311
unsigned int sumOfSizes_
Definition: BU.h:236
void reset()
Definition: BU.cc:685
toolbox::task::ActionSignature * asBuilding_
Definition: BU.h:169
toolbox::task::WorkLoop * wlSending_
Definition: BU.h:172
xdata::UnsignedInteger32 nbEventsSent_
Definition: BU.h:204
void I2O_BU_ALLOCATE_Callback(toolbox::mem::Reference *bufRef)
Definition: BU.cc:319
xdata::UnsignedInteger32 nbEventsRequested_
Definition: BU.h:202
xdata::Double rms_
Definition: BU.h:198
Definition: BU.h:49
virtual ~BU()
Definition: BU.cc:167
uint64_t sumOfSquares_
Definition: BU.h:235
BU(xdaq::ApplicationStub *s)
Definition: BU.cc:36
std::string sourceId_
Definition: BU.h:180
toolbox::task::WorkLoop * wlBuilding_
Definition: BU.h:168
bool isBuilding_
Definition: BU.h:163
xdata::Boolean crc_
Definition: BU.h:210
xdaq::ApplicationDescriptor * buAppDesc_
Definition: BU.h:140
sem_t lock_
Definition: BU.h:243
XDAQ_INSTANTIATOR()
xdata::Double deltaT_
Definition: BU.h:190
double gaussianMean_
Definition: BU.h:227
bool isHalting_
Definition: BU.h:165
xdata::UnsignedInteger32 monSleepSec_
Definition: BU.h:222
#define end
Definition: vmac.h:38
void dumpFrame(unsigned char *data, unsigned int len)
Definition: BU.cc:1144
toolbox::task::ActionSignature * asSending_
Definition: BU.h:173
struct fedh_struct fedh_t
xdata::UnsignedInteger32 deltaN_
Definition: BU.h:191
std::vector< unsigned int > validFedIds_
Definition: BU.h:161
tuple out
Definition: dbtoconf.py:99
sem_t buildSem_
Definition: BU.h:244
toolbox::task::WorkLoop * wlMonitoring_
Definition: BU.h:176
xdata::String hostname_
Definition: BU.h:186
unsigned long long uint64_t
Definition: Time.h:15
xdata::UnsignedInteger32 fedSizeMax_
Definition: BU.h:218
void exportParameters()
Definition: BU.cc:629
bool generateEvent(evf::BUEvent *evt)
Definition: BU.cc:747
bool halting(toolbox::task::WorkLoop *wl)
Definition: BU.cc:280
sem_t rqstSem_
Definition: BU.h:246
void waitBuild()
Definition: BU.h:112
xdata::Double average_
Definition: BU.h:196
toolbox::mem::Pool * i2oPool_
Definition: BU.h:240
xdata::UnsignedInteger32 deltaSumOfSizes_
Definition: BU.h:193
bool building(toolbox::task::WorkLoop *wl)
Definition: BU.cc:441
std::vector< evf::BUEvent * > events_
Definition: BU.h:155
xdata::UnsignedInteger32 runNumber_
Definition: BU.h:187
xdata::UnsignedInteger32 eventBufferSize_
Definition: BU.h:216
xdata::UnsignedInteger32 fedSizeMean_
Definition: BU.h:219
void I2O_BU_DISCARD_Callback(toolbox::mem::Reference *bufRef)
Definition: BU.cc:353
std::queue< unsigned int > freeIds_
Definition: BU.h:157
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
xdaq::ApplicationDescriptor * fuAppDesc_
Definition: BU.h:143
unsigned int monLastN_
Definition: BU.h:232
#define Output(cl)
Definition: vmac.h:193
std::set< unsigned int > sentIds_
Definition: BU.h:159
void startSendingWorkLoop()
Definition: BU.cc:480
unsigned int monLastSumOfSizes_
Definition: BU.h:234
uint64_t monLastSumOfSquares_
Definition: BU.h:233
timeval lastLsUpdate_
Definition: BU.h:225
xdata::UnsignedInteger32 nbEventsDiscarded_
Definition: BU.h:205
void postSend()
Definition: BU.h:115
static const int fedHeaderSize_
Definition: BU.h:253
xdata::UnsignedInteger32 queueSize_
Definition: BU.h:215
bool enabling(toolbox::task::WorkLoop *wl)
Definition: BU.cc:197
unsigned int fakeLs_
Definition: BU.h:224
xdata::UnsignedInteger32 nbEventsBuilt_
Definition: BU.h:203
struct timeval monStartTime_
Definition: BU.h:231
void postRqst()
Definition: BU.h:117
xdata::String url_
Definition: BU.h:183
xdata::UnsignedInteger32 firstEvent_
Definition: BU.h:214