Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00011
00012
00013 #ifndef IPCMETHOD_H_
00014 #define IPCMETHOD_H_
00015
00016 #include "EventFilter/ResourceBroker/interface/FUResource.h"
00017 #include "EventFilter/ResourceBroker/interface/BUProxy.h"
00018 #include "EventFilter/ResourceBroker/interface/SMProxy.h"
00019 #include "EventFilter/ResourceBroker/interface/FUTypes.h"
00020 #include "EventFilter/Utilities/interface/Exception.h"
00021
00022 #include "log4cplus/logger.h"
00023
00024 #include <sys/types.h>
00025 #include <string>
00026 #include <vector>
00027 #include <queue>
00028 #include <semaphore.h>
00029
00030 namespace evf {
00031
00039 class IPCMethod: public toolbox::lang::Class {
00040
00041 public:
00042
00043
00044
00045 IPCMethod(bool segmentationMode, UInt_t nbRawCells, UInt_t nbRecoCells,
00046 UInt_t nbDqmCells, UInt_t rawCellSize, UInt_t recoCellSize,
00047 UInt_t dqmCellSize, int freeResReq, BUProxy *bu, SMProxy *sm,
00048 log4cplus::Logger logger, unsigned int timeout,
00049 EvffedFillerRB *frb, xdaq::Application*app) throw (evf::Exception);
00050
00051 virtual ~IPCMethod();
00052
00053
00054
00055
00056
00057
00058 void setRunNumber(UInt_t runNumber) {
00059 runNumber_ = runNumber;
00060 }
00061
00065 virtual bool sendData() = 0;
00069 virtual bool sendDataWhileHalting() = 0;
00073 virtual bool sendDqm() = 0;
00077 virtual bool sendDqmWhileHalting() = 0;
00081 virtual bool discard() = 0;
00085 virtual bool discardWhileHalting(bool sendDiscards) = 0;
00086
00090 UInt_t allocateResource();
00091
00095 virtual bool buildResource(MemRef_t* bufRef) = 0;
00096
00100 virtual bool discardDataEvent(MemRef_t* bufRef) = 0;
00104 virtual bool discardDataEventWhileHalting(MemRef_t* bufRef) = 0;
00105
00109 virtual bool discardDqmEvent(MemRef_t* bufRef) = 0;
00113 virtual bool discardDqmEventWhileHalting(MemRef_t* bufRef) = 0;
00114
00118 virtual void postEndOfLumiSection(MemRef_t* bufRef) = 0;
00119
00123 virtual void dropEvent() = 0;
00124
00128 virtual bool handleCrashedEP(UInt_t runNumber, pid_t pid) = 0;
00129
00133 void dumpEvent(evf::FUShmRawCell* cell);
00134
00138 virtual void shutDownClients() = 0;
00139
00143 virtual void clear() = 0;
00144
00148 virtual void resetCounters() = 0;
00149
00153 void setDoCrcCheck(UInt_t doCrcCheck) {
00154 doCrcCheck_ = doCrcCheck;
00155 }
00156
00160 void setDoDumpEvents(UInt_t doDumpEvents) {
00161 doDumpEvents_ = doDumpEvents;
00162 }
00163
00167 bool isActive() const {
00168 return isActive_;
00169 }
00170
00171 void setActive(bool activeValue) {
00172 isActive_ = activeValue;
00173 }
00174
00178 bool isReadyToShutDown() const {
00179 return isReadyToShutDown_;
00180 }
00181
00182 void setReadyToShutDown(bool readyValue) {
00183 isReadyToShutDown_ = readyValue;
00184 }
00185
00186
00187 virtual UInt_t nbResources() const = 0;
00188 UInt_t nbFreeSlots() const {
00189 return freeResourceIds_.size();
00190 }
00191 UInt_t nbAllocated() const {
00192 return nbAllocated_;
00193 }
00194 UInt_t nbPending() const {
00195 return nbPending_;
00196 }
00197 UInt_t nbCompleted() const {
00198 return nbCompleted_;
00199 }
00200 UInt_t nbSent() const {
00201 return nbSent_;
00202 }
00203 UInt_t nbSentError() const {
00204 return nbSentError_;
00205 }
00206 UInt_t nbSentDqm() const {
00207 return nbSentDqm_;
00208 }
00209 UInt_t nbPendingSMDiscards() const {
00210 return nbPendingSMDiscards_;
00211 }
00212 UInt_t nbPendingSMDqmDiscards() const {
00213 return nbPendingSMDqmDiscards_;
00214 }
00215 UInt_t nbDiscarded() const {
00216 return nbDiscarded_;
00217 }
00218 UInt_t nbLost() const {
00219 return nbLost_;
00220 }
00221
00222
00223 UInt_t nbEolPosted() const {
00224 return nbEolPosted_;
00225 }
00226 UInt_t nbEolDiscarded() const {
00227 return nbEolDiscarded_;
00228 }
00229
00230 UInt_t nbErrors() const {
00231 return nbErrors_;
00232 }
00233 UInt_t nbCrcErrors() const {
00234 return nbCrcErrors_;
00235 }
00236 UInt_t nbAllocSent() const {
00237 return nbAllocSent_;
00238 }
00239
00240 uint64_t sumOfSquares() const {
00241 return sumOfSquares_;
00242 }
00243 UInt_t sumOfSizes() const {
00244 return sumOfSizes_;
00245 }
00246
00247
00248 virtual UInt_t nbClients() const = 0;
00249 virtual std::vector<pid_t> clientPrcIds() const = 0;
00250 virtual std::string clientPrcIdsAsString() const = 0;
00251 virtual std::vector<std::string> cellStates() const = 0;
00252 virtual std::vector<std::string> dqmCellStates() const = 0;
00253 virtual std::vector<UInt_t> cellEvtNumbers() const = 0;
00254 virtual std::vector<pid_t> cellPrcIds() const = 0;
00255 virtual std::vector<time_t> cellTimeStamps() const = 0;
00256
00257
00258
00259
00260 void sendAllocate();
00262 void resetPendingAllocates();
00264 void releaseResources();
00266 virtual void resetIPC() = 0;
00267
00268 void sendDiscard(UInt_t buResourceId);
00269
00270 void sendInitMessage(UInt_t fuResourceId, UInt_t outModId,
00271 UInt_t fuProcessId, UInt_t fuGuid, UChar_t*data, UInt_t dataSize,
00272 UInt_t nExpectedEPs);
00273
00274 void sendDataEvent(UInt_t fuResourceId, UInt_t runNumber, UInt_t evtNumber,
00275 UInt_t outModId, UInt_t fuProcessId, UInt_t fuGuid, UChar_t*data,
00276 UInt_t dataSize);
00277
00278 void sendErrorEvent(UInt_t fuResourceId, UInt_t runNumber,
00279 UInt_t evtNumber, UInt_t fuProcessId, UInt_t fuGuid, UChar_t*data,
00280 UInt_t dataSize);
00281
00282 void sendDqmEvent(UInt_t fuDqmId, UInt_t runNumber, UInt_t evtAtUpdate,
00283 UInt_t folderId, UInt_t fuProcessId, UInt_t fuGuid, UChar_t*data,
00284 UInt_t dataSize);
00285
00286 bool isLastMessageOfEvent(MemRef_t* bufRef);
00287
00288 void injectCRCError();
00289
00290 void lock() {
00291
00292 while (0 != sem_wait(&lock_)) {
00293 if (errno != EINTR) {
00294 LOG4CPLUS_ERROR(log_, "Cannot obtain lock on sem LOCK!");
00295 }
00296 }
00297 }
00298 void unlock() {
00299
00300 sem_post(&lock_);
00301 }
00302
00306 virtual void lastResort() = 0;
00307
00308 protected:
00309
00310
00311
00312
00313 BUProxy *bu_;
00314 SMProxy *sm_;
00315
00316 log4cplus::Logger log_;
00317
00318 UInt_t nbDqmCells_;
00319 UInt_t nbRawCells_;
00320 UInt_t nbRecoCells_;
00321
00322 std::queue<UInt_t> freeResourceIds_;
00323
00324 unsigned int freeResRequiredForAllocate_;
00325
00326 bool *acceptSMDataDiscard_;
00327 int *acceptSMDqmDiscard_;
00328
00329 UInt_t doCrcCheck_;
00330 UInt_t doDumpEvents_;
00331 unsigned int shutdownTimeout_;
00332
00333 UInt_t nbAllocated_;
00334 UInt_t nbPending_;
00335 UInt_t nbCompleted_;
00336 UInt_t nbSent_;
00337 UInt_t nbSentError_;
00338 UInt_t nbSentDqm_;
00339 UInt_t nbPendingSMDiscards_;
00340 UInt_t nbPendingSMDqmDiscards_;
00341 UInt_t nbDiscarded_;
00342 UInt_t nbLost_;
00343
00344 UInt_t nbEolPosted_;
00345 UInt_t nbEolDiscarded_;
00346
00347 UInt_t nbClientsToShutDown_;
00348 bool isReadyToShutDown_;
00349 bool isActive_;
00350
00351 UInt_t nbErrors_;
00352 UInt_t nbCrcErrors_;
00353 UInt_t nbAllocSent_;
00354
00355 uint64_t sumOfSquares_;
00356 UInt_t sumOfSizes_;
00357
00358 UInt_t runNumber_;
00359
00360 sem_t lock_;
00361 EvffedFillerRB *frb_;
00362 xdaq::Application *app_;
00363
00364 FUResourceVec_t resources_;
00365
00366 };
00367
00368 }
00369
00370 #endif