CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_2_9_HLT1_bphpatch4/src/EventFilter/ResourceBroker/interface/FUResourceTable.h

Go to the documentation of this file.
00001 #ifndef FURESOURCETABLE_H
00002 #define FURESOURCETABLE_H 1
00003 
00004 
00005 #include "EventFilter/ResourceBroker/interface/FUResource.h"
00006 #include "EventFilter/ResourceBroker/interface/BUProxy.h"
00007 #include "EventFilter/ResourceBroker/interface/SMProxy.h"
00008 #include "EventFilter/ResourceBroker/interface/FUTypes.h"
00009 #include "EventFilter/ShmBuffer/interface/FUShmBuffer.h"
00010 #include "EventFilter/Utilities/interface/Exception.h"
00011 
00012 #include "log4cplus/logger.h"
00013 #include "toolbox/lang/Class.h"
00014 #include "toolbox/task/Action.h"
00015 #include "toolbox/task/WorkLoop.h"
00016 #include "toolbox/BSem.h"
00017 
00018 #include <sys/types.h>
00019 #include <string>
00020 #include <vector>
00021 #include <queue>
00022 
00023 
00024 namespace evf {
00025 
00026   class EvffedFillerRB;
00027   
00028   class FUResourceTable : public toolbox::lang::Class
00029   {
00030   public:
00031     //
00032     // construction/destruction
00033     //
00034     FUResourceTable(bool   segmentationMode,
00035                     UInt_t nbRawCells, UInt_t nbRecoCells, UInt_t nbDqmCells,
00036                     UInt_t rawCellSize,UInt_t recoCellSize,UInt_t dqmCellSize,
00037                     BUProxy* bu,SMProxy* sm,
00038                     log4cplus::Logger logger, 
00039                     unsigned int, 
00040                     EvffedFillerRB*frb,
00041                     xdaq::Application*) throw (evf::Exception);
00042     virtual ~FUResourceTable();
00043     
00044     
00045     //
00046     // member functions
00047     //
00048     
00049     // set fed filler
00050     //    void setFedFiller(){frb_ = frb;}
00051 
00052     // set the run number
00053     void   setRunNumber(UInt_t runNumber) { runNumber_ = runNumber; }
00054 
00055     // initialization of the resource queue
00056     void   initialize(bool   segmentationMode,
00057                       UInt_t nbRawCells, UInt_t nbRecoCells, UInt_t nbDqmCells,
00058                       UInt_t rawCellSize,UInt_t recoCellSize,UInt_t dqmCellSize)
00059       throw (evf::Exception);
00060     
00061     // work loop to send data events to storage manager
00062     void   startSendDataWorkLoop() throw (evf::Exception);
00063     bool   sendData(toolbox::task::WorkLoop* workLoop);
00064     
00065     // work loop to send dqm events to storage manager
00066     void   startSendDqmWorkLoop() throw (evf::Exception);
00067     bool   sendDqm(toolbox::task::WorkLoop* workLoop);
00068     
00069     // work loop to discard events to builder unit
00070     void   startDiscardWorkLoop() throw (evf::Exception);
00071     bool   discard(toolbox::task::WorkLoop* workLoop);
00072     
00073     // returns the fuResourceId of the allocated resource
00074     UInt_t allocateResource();
00075     
00076     // process buffer received via I2O_FU_TAKE message
00077     bool   buildResource(MemRef_t* bufRef);
00078     
00079     // process buffer received via I2O_SM_DATA_DISCARD message
00080     bool   discardDataEvent(MemRef_t* bufRef);
00081     
00082     // process buffer received via I2O_SM_DQM_DISCARD message
00083     bool   discardDqmEvent(MemRef_t* bufRef);
00084     
00085     // post end-of-ls event to shmem
00086     void   postEndOfLumiSection(MemRef_t* bufRef);
00087 
00088     // drop next available event
00089     void   dropEvent();
00090 
00091     // send event belonging to crashed process to error stream (return false
00092     // if no event is found)    
00093     bool   handleCrashedEP(UInt_t runNumber,pid_t pid);
00094 
00095     // dump event to ascii file
00096     void   dumpEvent(evf::FUShmRawCell* cell);
00097     
00098     // send empty events to notify clients to shutdown
00099     void   stop();
00100     void   halt();
00101     void   shutDownClients();
00102     
00103     // emtpy all containers (resources & ids)
00104     void   clear();
00105 
00106     // reset event & error counters
00107     void   resetCounters();
00108 
00109     // tell resources wether to check the crc
00110     void   setDoCrcCheck(UInt_t doCrcCheck) { doCrcCheck_=doCrcCheck; }
00111 
00112     // tell resources wether to dump events to an ascii file
00113     void   setDoDumpEvents(UInt_t doDumpEvents) { doDumpEvents_=doDumpEvents; }
00114 
00115     // check if resource table is active (enabled)
00116     bool   isActive() const { return isActive_; }
00117 
00118     // check if resource table can be savely destroyed
00119     bool   isReadyToShutDown() const { return isReadyToShutDown_; }
00120 
00121     // various counters
00122     UInt_t   nbResources()        const { return resources_.size(); }
00123     UInt_t   nbFreeSlots()        const { return freeResourceIds_.size(); }
00124     UInt_t   nbAllocated()        const { return nbAllocated_; }
00125     UInt_t   nbPending()          const { return nbPending_; }
00126     UInt_t   nbCompleted()        const { return nbCompleted_; }
00127     UInt_t   nbSent()             const { return nbSent_; }
00128     UInt_t   nbSentError()        const { return nbSentError_; }
00129     UInt_t   nbSentDqm()          const { return nbSentDqm_; }
00130     UInt_t   nbPendingSMDiscards()const { return nbPendingSMDiscards_; }
00131     UInt_t   nbPendingSMDqmDiscards()const { return nbPendingSMDqmDiscards_; }
00132     UInt_t   nbDiscarded()        const { return nbDiscarded_; }
00133     UInt_t   nbLost()             const { return nbLost_; }
00134     UInt_t   nbEolPosted()        const { return nbEolPosted_; }
00135     UInt_t   nbEolDiscarded()     const { return nbEolDiscarded_; }
00136     
00137     UInt_t   nbErrors()           const { return nbErrors_; }
00138     UInt_t   nbCrcErrors()        const { return nbCrcErrors_; }
00139     UInt_t   nbAllocSent()        const { return nbAllocSent_; }
00140     
00141     uint64_t sumOfSquares()       const { return sumOfSquares_; }
00142     UInt_t   sumOfSizes()         const { return sumOfSizes_; }
00143     
00144     
00145     // information about (raw) shared memory cells
00146     UInt_t                   nbClients()                           const;
00147     std::vector<pid_t>       clientPrcIds()                        const;
00148     std::string              clientPrcIdsAsString()                const;
00149     std::vector<std::string> cellStates()                          const;
00150     std::vector<std::string> dqmCellStates()                       const;
00151     std::vector<UInt_t>      cellEvtNumbers()                      const;
00152     std::vector<pid_t>       cellPrcIds()                          const;
00153     std::vector<time_t>      cellTimeStamps()                      const;
00154     
00155 
00156     
00157     //
00158     // helpers
00159     //
00160     void   sendAllocate();
00161     void   sendDiscard(UInt_t buResourceId);
00162     
00163     void   sendInitMessage(UInt_t  fuResourceId,
00164                            UInt_t  outModId,
00165                            UInt_t  fuProcessId,
00166                            UInt_t  fuGuid,
00167                            UChar_t*data,
00168                            UInt_t  dataSize);
00169 
00170     void   sendDataEvent(UInt_t  fuResourceId,
00171                          UInt_t  runNumber,
00172                          UInt_t  evtNumber,
00173                          UInt_t  outModId,
00174                          UInt_t  fuProcessId,
00175                          UInt_t  fuGuid,
00176                          UChar_t*data,
00177                          UInt_t  dataSize);
00178 
00179     void   sendErrorEvent(UInt_t  fuResourceId,
00180                           UInt_t  runNumber,
00181                           UInt_t  evtNumber,
00182                           UInt_t  fuProcessId,
00183                           UInt_t  fuGuid,
00184                           UChar_t*data,
00185                           UInt_t  dataSize);
00186     
00187     void   sendDqmEvent(UInt_t  fuDqmId,
00188                         UInt_t  runNumber,
00189                         UInt_t  evtAtUpdate,
00190                         UInt_t  folderId,
00191                         UInt_t  fuProcessId,
00192                         UInt_t  fuGuid,
00193                         UChar_t*data,
00194                         UInt_t  dataSize);
00195     
00196     bool   isLastMessageOfEvent(MemRef_t* bufRef);
00197     
00198     void   injectCRCError();
00199     
00200     void   lock()      { lock_.take(); }
00201     void   unlock()    { lock_.give(); }
00202     //void   lockShm()   { shmBuffer_->lock(); }
00203     //void   unlockShm() { shmBuffer_->unlock(); }
00204     void   printWorkLoopStatus();
00205 
00206     void   lastResort();
00207 
00208   private:
00209     //
00210     // member data
00211     //
00212     typedef toolbox::task::WorkLoop        WorkLoop_t;
00213     typedef toolbox::task::ActionSignature ActionSignature_t;
00214 
00215     BUProxy           *bu_;
00216     SMProxy           *sm_;
00217 
00218     log4cplus::Logger  log_;
00219     
00220     WorkLoop_t        *wlSendData_;
00221     ActionSignature_t *asSendData_;
00222 
00223     WorkLoop_t        *wlSendDqm_;
00224     ActionSignature_t *asSendDqm_;
00225 
00226     WorkLoop_t        *wlDiscard_;
00227     ActionSignature_t *asDiscard_;
00228 
00229     FUShmBuffer       *shmBuffer_;
00230     FUResourceVec_t    resources_;
00231     UInt_t             nbDqmCells_;
00232     UInt_t             nbRawCells_;
00233     UInt_t             nbRecoCells_;
00234     std::queue<UInt_t> freeResourceIds_;
00235     
00236     bool              *acceptSMDataDiscard_;
00237     int               *acceptSMDqmDiscard_;
00238     
00239     UInt_t             doCrcCheck_;
00240     UInt_t             doDumpEvents_;
00241     unsigned int       shutdownTimeout_;
00242 
00243     UInt_t             nbAllocated_;
00244     UInt_t             nbPending_;
00245     UInt_t             nbCompleted_;
00246     UInt_t             nbSent_;
00247     UInt_t             nbSentError_;
00248     UInt_t             nbSentDqm_;
00249     UInt_t             nbPendingSMDiscards_;
00250     UInt_t             nbPendingSMDqmDiscards_;
00251     UInt_t             nbDiscarded_;
00252     UInt_t             nbLost_;
00253     UInt_t             nbEolPosted_;
00254     UInt_t             nbEolDiscarded_;
00255     
00256     UInt_t             nbClientsToShutDown_;
00257     bool               isReadyToShutDown_;
00258     bool               isActive_;
00259     bool               isHalting_;
00260     bool               isStopping_;
00261     
00262     UInt_t             nbErrors_;
00263     UInt_t             nbCrcErrors_;
00264     UInt_t             nbAllocSent_;
00265     
00266     uint64_t           sumOfSquares_;
00267     UInt_t             sumOfSizes_;
00268 
00269     UInt_t             runNumber_;
00270     
00271     toolbox::BSem      lock_;
00272     EvffedFillerRB    *frb_;    
00273     xdaq::Application *app_;
00274   };
00275   
00276 } // namespace evf
00277 
00278 
00279 #endif