CMS 3D CMS Logo

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 FUResourceTable : public toolbox::lang::Class
00027   {
00028   public:
00029     //
00030     // construction/destruction
00031     //
00032     FUResourceTable(bool   segmentationMode,
00033                     UInt_t nbRawCells, UInt_t nbRecoCells, UInt_t nbDqmCells,
00034                     UInt_t rawCellSize,UInt_t recoCellSize,UInt_t dqmCellSize,
00035                     BUProxy* bu,SMProxy* sm,
00036                     log4cplus::Logger logger) throw (evf::Exception);
00037     virtual ~FUResourceTable();
00038     
00039     
00040     //
00041     // member functions
00042     //
00043     
00044     // set the run number
00045     void   setRunNumber(UInt_t runNumber) { runNumber_ = runNumber; }
00046 
00047     // initialization of the resource queue
00048     void   initialize(bool   segmentationMode,
00049                       UInt_t nbRawCells, UInt_t nbRecoCells, UInt_t nbDqmCells,
00050                       UInt_t rawCellSize,UInt_t recoCellSize,UInt_t dqmCellSize)
00051       throw (evf::Exception);
00052     
00053     // work loop to send data events to storage manager
00054     void   startSendDataWorkLoop() throw (evf::Exception);
00055     bool   sendData(toolbox::task::WorkLoop* workLoop);
00056     
00057     // work loop to send dqm events to storage manager
00058     void   startSendDqmWorkLoop() throw (evf::Exception);
00059     bool   sendDqm(toolbox::task::WorkLoop* workLoop);
00060     
00061     // work loop to discard events to builder unit
00062     void   startDiscardWorkLoop() throw (evf::Exception);
00063     bool   discard(toolbox::task::WorkLoop* workLoop);
00064     
00065     // returns the fuResourceId of the allocated resource
00066     UInt_t allocateResource();
00067     
00068     // process buffer received via I2O_FU_TAKE message
00069     bool   buildResource(MemRef_t* bufRef);
00070     
00071     // process buffer received via I2O_SM_DATA_DISCARD message
00072     bool   discardDataEvent(MemRef_t* bufRef);
00073     
00074     // process buffer received via I2O_SM_DQM_DISCARD message
00075     bool   discardDqmEvent(MemRef_t* bufRef);
00076     
00077     // drop next available event
00078     void   dropEvent();
00079     
00080     // dump event to ascii file
00081     void   handleCrashedEP(UInt_t runNumber,pid_t pid);
00082     void   dumpEvent(evf::FUShmRawCell* cell);
00083     
00084     // send empty events to notify clients to shutdown
00085     void   stop();
00086     void   halt();
00087     void   shutDownClients();
00088     
00089     // emtpy all containers (resources & ids)
00090     void   clear();
00091 
00092     // reset event & error counters
00093     void   resetCounters();
00094 
00095     // tell resources wether to check the crc
00096     void   setDoCrcCheck(UInt_t doCrcCheck) { doCrcCheck_=doCrcCheck; }
00097 
00098     // tell resources wether to dump events to an ascii file
00099     void   setDoDumpEvents(UInt_t doDumpEvents) { doDumpEvents_=doDumpEvents; }
00100 
00101     // check if resource table is active (enabled)
00102     bool   isActive() const { return isActive_; }
00103 
00104     // check if resource table can be savely destroyed
00105     bool   isReadyToShutDown() const { return isReadyToShutDown_; }
00106 
00107     // various counters
00108     UInt_t   nbResources()        const { return resources_.size(); }
00109     UInt_t   nbFreeSlots()        const { return freeResourceIds_.size(); }
00110     UInt_t   nbAllocated()        const { return nbAllocated_; }
00111     UInt_t   nbPending()          const { return nbPending_; }
00112     UInt_t   nbCompleted()        const { return nbCompleted_; }
00113     UInt_t   nbSent()             const { return nbSent_; }
00114     UInt_t   nbSentError()        const { return nbSentError_; }
00115     UInt_t   nbSentDqm()          const { return nbSentDqm_; }
00116     UInt_t   nbPendingSMDiscards()const { return nbPendingSMDiscards_; }
00117     UInt_t   nbDiscarded()        const { return nbDiscarded_; }
00118     UInt_t   nbLost()             const { return nbLost_; }
00119     
00120     UInt_t   nbErrors()           const { return nbErrors_; }
00121     UInt_t   nbCrcErrors()        const { return nbCrcErrors_; }
00122     UInt_t   nbAllocSent()        const { return nbAllocSent_; }
00123     
00124     uint64_t sumOfSquares()       const { return sumOfSquares_; }
00125     UInt_t   sumOfSizes()         const { return sumOfSizes_; }
00126     
00127     
00128     // information about (raw) shared memory cells
00129     UInt_t                   nbClients()                           const;
00130     std::vector<pid_t>       clientPrcIds()                        const;
00131     std::string              clientPrcIdsAsString()                const;
00132     std::vector<std::string> cellStates()                          const;
00133     std::vector<UInt_t>      cellEvtNumbers()                      const;
00134     std::vector<pid_t>       cellPrcIds()                          const;
00135     std::vector<time_t>      cellTimeStamps()                      const;
00136     
00137 
00138     
00139     //
00140     // helpers
00141     //
00142     void   sendAllocate();
00143     void   sendDiscard(UInt_t buResourceId);
00144     
00145     void   sendInitMessage(UInt_t  fuResourceId,
00146                            UInt_t  outModId,
00147                            UInt_t  fuProcessId,
00148                            UInt_t  fuGuid,
00149                            UChar_t*data,
00150                            UInt_t  dataSize);
00151 
00152     void   sendDataEvent(UInt_t  fuResourceId,
00153                          UInt_t  runNumber,
00154                          UInt_t  evtNumber,
00155                          UInt_t  outModId,
00156                          UInt_t  fuProcessId,
00157                          UInt_t  fuGuid,
00158                          UChar_t*data,
00159                          UInt_t  dataSize);
00160 
00161     void   sendErrorEvent(UInt_t  fuResourceId,
00162                           UInt_t  runNumber,
00163                           UInt_t  evtNumber,
00164                           UInt_t  fuProcessId,
00165                           UInt_t  fuGuid,
00166                           UChar_t*data,
00167                           UInt_t  dataSize);
00168     
00169     void   sendDqmEvent(UInt_t  fuDqmId,
00170                         UInt_t  runNumber,
00171                         UInt_t  evtAtUpdate,
00172                         UInt_t  folderId,
00173                         UInt_t  fuProcessId,
00174                         UInt_t  fuGuid,
00175                         UChar_t*data,
00176                         UInt_t  dataSize);
00177     
00178     bool   isLastMessageOfEvent(MemRef_t* bufRef);
00179     
00180     void   lock()      { lock_.take(); }
00181     void   unlock()    { lock_.give(); }
00182     //void   lockShm()   { shmBuffer_->lock(); }
00183     //void   unlockShm() { shmBuffer_->unlock(); }
00184 
00185 
00186   private:
00187     //
00188     // member data
00189     //
00190     typedef toolbox::task::WorkLoop        WorkLoop_t;
00191     typedef toolbox::task::ActionSignature ActionSignature_t;
00192 
00193     BUProxy           *bu_;
00194     SMProxy           *sm_;
00195 
00196     log4cplus::Logger  log_;
00197     
00198     WorkLoop_t        *wlSendData_;
00199     ActionSignature_t *asSendData_;
00200 
00201     WorkLoop_t        *wlSendDqm_;
00202     ActionSignature_t *asSendDqm_;
00203 
00204     WorkLoop_t        *wlDiscard_;
00205     ActionSignature_t *asDiscard_;
00206 
00207     FUShmBuffer       *shmBuffer_;
00208     FUResourceVec_t    resources_;
00209     std::queue<UInt_t> freeResourceIds_;
00210     
00211     bool              *acceptSMDataDiscard_;
00212     bool              *acceptSMDqmDiscard_;
00213     
00214     UInt_t             doCrcCheck_;
00215     UInt_t             doDumpEvents_;
00216 
00217     UInt_t             nbAllocated_;
00218     UInt_t             nbPending_;
00219     UInt_t             nbCompleted_;
00220     UInt_t             nbSent_;
00221     UInt_t             nbSentError_;
00222     UInt_t             nbSentDqm_;
00223     UInt_t             nbPendingSMDiscards_;
00224     UInt_t             nbDiscarded_;
00225     UInt_t             nbLost_;
00226     
00227     UInt_t             nbClientsToShutDown_;
00228     bool               isReadyToShutDown_;
00229     bool               isActive_;
00230     bool               isHalting_;
00231     
00232     UInt_t             nbErrors_;
00233     UInt_t             nbCrcErrors_;
00234     UInt_t             nbAllocSent_;
00235     
00236     uint64_t           sumOfSquares_;
00237     UInt_t             sumOfSizes_;
00238 
00239     UInt_t             runNumber_;
00240     
00241     toolbox::BSem      lock_;
00242     
00243   };
00244   
00245 } // namespace evf
00246 
00247 
00248 #endif

Generated on Tue Jun 9 17:34:46 2009 for CMSSW by  doxygen 1.5.4