CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/EventFilter/StorageManager/src/ChainData.h

Go to the documentation of this file.
00001 // $Id: ChainData.h,v 1.20 2012/04/20 10:48:01 mommsen Exp $
00003 
00004 #ifndef CHAINDATA_H
00005 #define CHAINDATA_H
00006 
00007 #include "toolbox/mem/Reference.h"
00008 
00009 #include "IOPool/Streamer/interface/MsgHeader.h"
00010 #include "IOPool/Streamer/interface/MsgTools.h"
00011 
00012 #include "EventFilter/Utilities/interface/i2oEvfMsgs.h"
00013 
00014 #include "EventFilter/StorageManager/interface/Utils.h"
00015 #include "EventFilter/StorageManager/interface/DQMKey.h"
00016 #include "EventFilter/StorageManager/interface/FragKey.h"
00017 #include "EventFilter/StorageManager/interface/StreamID.h"
00018 #include "EventFilter/StorageManager/interface/QueueID.h"
00019 #include "EventFilter/StorageManager/interface/Exception.h"
00020 
00021 
00022 namespace stor
00023 {
00024 
00025   namespace detail
00026   {
00027 
00029     //
00030     // class ChainData is responsible for managing a single chain of
00031     // References and associated status information (such as tags
00032     // applied to the 'event' that lives in the buffer(s) managed by the
00033     // Reference(s).
00034     //
00035     // Only one ChainData object ever manages a given
00036     // Reference. Furthermore, ChainData makes use of References such
00037     // that a duplicate of a given Reference is never made. Thus when a
00038     // ChainData object is destroyed, any and all References managed by
00039     // that object are immediately released.
00040     //
00042     class ChainData
00043     {
00044     protected:
00045       enum BitMasksForFaulty { INVALID_INITIAL_REFERENCE = 0x1,
00046                                CORRUPT_INITIAL_HEADER = 0x2,
00047                                INVALID_SECONDARY_REFERENCE = 0x4,
00048                                CORRUPT_SECONDARY_HEADER = 0x8,
00049                                TOTAL_COUNT_MISMATCH = 0x10,
00050                                FRAGMENTS_OUT_OF_ORDER = 0x20,
00051                                DUPLICATE_FRAGMENT = 0x40,
00052                                INCOMPLETE_MESSAGE = 0x80,
00053                                WRONG_CHECKSUM = 0x100,
00054                                EXTERNALLY_REQUESTED = 0x10000 };
00055 
00056 
00057     public:
00058       explicit ChainData(unsigned short i2oMessageCode = 0x9999,
00059                          unsigned int messageCode = Header::INVALID);
00060       virtual ~ChainData();
00061       bool empty() const;
00062       bool complete() const;
00063       bool faulty() const;
00064       unsigned int faultyBits() const;
00065       bool parsable() const;
00066       bool headerOkay() const;
00067       void addFirstFragment(toolbox::mem::Reference*);
00068       void addToChain(ChainData const&);
00069       void markComplete();
00070       void markFaulty();
00071       void markCorrupt();
00072       unsigned long* getBufferData() const;
00073       void swap(ChainData& other);
00074       unsigned int messageCode() const {return messageCode_;}
00075       unsigned short i2oMessageCode() const {return i2oMessageCode_;}
00076       FragKey const& fragmentKey() const {return fragKey_;}
00077       unsigned int fragmentCount() const {return fragmentCount_;}
00078       unsigned int rbBufferId() const {return rbBufferId_;}
00079       unsigned int hltLocalId() const {return hltLocalId_;}
00080       unsigned int hltInstance() const {return hltInstance_;}
00081       unsigned int hltTid() const {return hltTid_;}
00082       unsigned int fuProcessId() const {return fuProcessId_;}
00083       unsigned int fuGuid() const {return fuGuid_;}
00084       utils::TimePoint_t creationTime() const {return creationTime_;}
00085       utils::TimePoint_t lastFragmentTime() const {return lastFragmentTime_;}
00086       utils::TimePoint_t staleWindowStartTime() const {return staleWindowStartTime_;}
00087       void addToStaleWindowStartTime(const utils::Duration_t duration) {
00088         staleWindowStartTime_ += duration;
00089       }
00090       void resetStaleWindowStartTime() {
00091         staleWindowStartTime_ = utils::getCurrentTime();
00092       }
00093       unsigned int droppedEventsCount() const;
00094       void setDroppedEventsCount(unsigned int);
00095       size_t memoryUsed() const;
00096       unsigned long totalDataSize() const;
00097       unsigned long dataSize(int fragmentIndex) const;
00098       unsigned char* dataLocation(int fragmentIndex) const;
00099       unsigned int getFragmentID(int fragmentIndex) const;
00100       unsigned int copyFragmentsIntoBuffer(std::vector<unsigned char>& buff) const;
00101 
00102       unsigned long headerSize() const;
00103       unsigned char* headerLocation() const;
00104 
00105       std::string hltURL() const;
00106       std::string hltClassName() const;
00107       uint32_t outputModuleId() const;
00108       uint32_t nExpectedEPs() const;
00109 
00110       std::string outputModuleLabel() const;
00111       void hltTriggerNames(Strings& nameList) const;
00112       void hltTriggerSelections(Strings& nameList) const;
00113       void l1TriggerNames(Strings& nameList) const;
00114 
00115       void assertRunNumber(uint32_t runNumber);
00116 
00117       uint32_t runNumber() const;
00118       uint32_t lumiSection() const;
00119       uint32_t eventNumber() const;
00120       uint32_t adler32Checksum() const;
00121 
00122       std::string topFolderName() const;
00123       DQMKey dqmKey() const;
00124 
00125       uint32_t hltTriggerCount() const;
00126       void hltTriggerBits(std::vector<unsigned char>& bitList) const;
00127 
00128       void tagForStream(StreamID);
00129       void tagForEventConsumer(QueueID);
00130       void tagForDQMEventConsumer(QueueID);
00131       bool isTaggedForAnyStream() const {return !streamTags_.empty();}
00132       bool isTaggedForAnyEventConsumer() const {return !eventConsumerTags_.empty();}
00133       bool isTaggedForAnyDQMEventConsumer() const {return !dqmEventConsumerTags_.empty();}
00134       std::vector<StreamID> const& getStreamTags() const;
00135       QueueIDs const& getEventConsumerTags() const;
00136       QueueIDs const& getDQMEventConsumerTags() const;
00137 
00138       bool isEndOfLumiSectionMessage() const;
00139 
00140     private:
00141       std::vector<StreamID> streamTags_;
00142       QueueIDs eventConsumerTags_;
00143       QueueIDs dqmEventConsumerTags_;
00144 
00145       utils::TimePoint_t creationTime_;
00146       utils::TimePoint_t lastFragmentTime_;
00147       utils::TimePoint_t staleWindowStartTime_;
00148 
00149       void checkForCompleteness();
00150       bool validateAdler32Checksum();
00151       uint32_t calculateAdler32() const;
00152 
00153     protected:
00154       toolbox::mem::Reference* ref_;
00155 
00156       bool complete_;
00157       unsigned int faultyBits_;
00158 
00159       unsigned int messageCode_;
00160       unsigned short i2oMessageCode_;
00161       FragKey fragKey_;
00162       unsigned int fragmentCount_;
00163       unsigned int expectedNumberOfFragments_;
00164       unsigned int rbBufferId_;
00165       unsigned int hltLocalId_;
00166       unsigned int hltInstance_;
00167       unsigned int hltTid_;
00168       unsigned int fuProcessId_;
00169       unsigned int fuGuid_;
00170 
00171       inline bool validateDataLocation(
00172         toolbox::mem::Reference* ref,
00173         BitMasksForFaulty maskToUse
00174       );
00175       inline bool validateMessageSize(
00176         toolbox::mem::Reference* ref,
00177         BitMasksForFaulty maskToUse
00178       );
00179       inline bool validateFragmentIndexAndCount(
00180         toolbox::mem::Reference* ref,
00181         BitMasksForFaulty maskToUse
00182       );
00183       inline bool validateExpectedFragmentCount(
00184         toolbox::mem::Reference* ref,
00185         BitMasksForFaulty maskToUse
00186       );
00187       inline bool validateFragmentOrder(
00188         toolbox::mem::Reference* ref,
00189         int& indexValue
00190       );
00191       inline bool validateMessageCode(
00192         toolbox::mem::Reference* ref,
00193         unsigned short expectedI2OMessageCode
00194       );
00195 
00196       virtual inline size_t do_i2oFrameSize() const { return 0; }
00197       virtual inline unsigned long do_headerSize() const { return 0; }
00198       virtual inline unsigned char* do_headerLocation() const { return 0; }
00199       virtual inline unsigned char* do_fragmentLocation(unsigned char* dataLoc) const { return dataLoc; }
00200       virtual inline uint32_t do_adler32Checksum() const { return 0; }
00201 
00202       virtual std::string do_outputModuleLabel() const;
00203       virtual uint32_t do_outputModuleId() const;
00204       virtual uint32_t do_nExpectedEPs() const;
00205       virtual void do_hltTriggerNames(Strings& nameList) const;
00206       virtual void do_hltTriggerSelections(Strings& nameList) const;
00207       virtual void do_l1TriggerNames(Strings& nameList) const;
00208       virtual unsigned int do_droppedEventsCount() const;
00209       virtual void do_setDroppedEventsCount(unsigned int);
00210 
00211       virtual std::string do_topFolderName() const;
00212       virtual DQMKey do_dqmKey() const;
00213 
00214       virtual uint32_t do_hltTriggerCount() const;
00215       virtual void do_hltTriggerBits(std::vector<unsigned char>& bitList) const;
00216 
00217       virtual inline void do_assertRunNumber(uint32_t runNumber) {};
00218 
00219       virtual uint32_t do_runNumber() const;
00220       virtual uint32_t do_lumiSection() const;
00221       virtual uint32_t do_eventNumber() const;
00222 
00223     }; // class ChainData
00224 
00225 
00229 
00230     class InitMsgData : public ChainData
00231     {
00232 
00233     public:
00234 
00235       explicit InitMsgData(toolbox::mem::Reference* pRef);
00236       ~InitMsgData() {}
00237 
00238     protected:
00239 
00240       inline size_t do_i2oFrameSize() const;
00241       inline unsigned long do_headerSize() const;
00242       inline unsigned char* do_headerLocation() const;
00243       inline unsigned char* do_fragmentLocation(unsigned char* dataLoc) const;
00244       inline uint32_t do_adler32Checksum() const;
00245 
00246       std::string do_outputModuleLabel() const;
00247       uint32_t do_outputModuleId() const;
00248       uint32_t do_nExpectedEPs() const { return nExpectedEPs_; };
00249       void do_hltTriggerNames(Strings& nameList) const;
00250       void do_hltTriggerSelections(Strings& nameList) const;
00251       void do_l1TriggerNames(Strings& nameList) const;
00252 
00253     private:
00254 
00255       void parseI2OHeader();
00256       void cacheHeaderFields() const;
00257 
00258       mutable bool headerFieldsCached_;
00259       mutable std::vector<unsigned char> headerCopy_;
00260       mutable unsigned long headerSize_;
00261       mutable unsigned char* headerLocation_;
00262       mutable uint32_t adler32_;
00263       mutable uint32_t outputModuleId_;
00264       mutable uint32_t nExpectedEPs_;
00265       mutable std::string outputModuleLabel_;
00266       mutable Strings hltTriggerNames_;
00267       mutable Strings hltTriggerSelections_;
00268       mutable Strings l1TriggerNames_;
00269 
00270     }; // class InitMsgData
00271 
00272 
00276 
00277     class EventMsgData : public ChainData
00278     {
00279 
00280     public:
00281 
00282       explicit EventMsgData(toolbox::mem::Reference* pRef);
00283       ~EventMsgData() {}
00284 
00285     protected:
00286 
00287       inline size_t do_i2oFrameSize() const;
00288       inline unsigned long do_headerSize() const;
00289       inline unsigned char* do_headerLocation() const;
00290       inline unsigned char* do_fragmentLocation(unsigned char* dataLoc) const;
00291       inline uint32_t do_adler32Checksum() const;
00292 
00293       uint32_t do_outputModuleId() const;
00294       uint32_t do_hltTriggerCount() const;
00295       void do_hltTriggerBits(std::vector<unsigned char>& bitList) const;
00296       void do_assertRunNumber(uint32_t runNumber);
00297       uint32_t do_runNumber() const;
00298       uint32_t do_lumiSection() const;
00299       uint32_t do_eventNumber() const;
00300 
00301       unsigned int do_droppedEventsCount() const;
00302       void do_setDroppedEventsCount(unsigned int);
00303 
00304     private:
00305 
00306       void parseI2OHeader();
00307       void cacheHeaderFields() const;
00308 
00309       mutable bool headerFieldsCached_;
00310       mutable std::vector<unsigned char> headerCopy_;
00311       mutable unsigned long headerSize_;
00312       mutable unsigned char* headerLocation_;
00313       mutable uint32_t outputModuleId_;
00314       mutable uint32_t hltTriggerCount_;
00315       mutable std::vector<unsigned char> hltTriggerBits_;
00316       mutable uint32_t runNumber_;
00317       mutable uint32_t lumiSection_;
00318       mutable uint32_t eventNumber_;
00319       mutable uint32_t adler32_;
00320       mutable unsigned int droppedEventsCount_;
00321 
00322     }; // EventMsgData
00323 
00324 
00328 
00329     class DQMEventMsgData : public ChainData
00330     {
00331 
00332     public:
00333 
00334       explicit DQMEventMsgData(toolbox::mem::Reference* pRef);
00335       ~DQMEventMsgData() {}
00336 
00337     protected:
00338 
00339       inline size_t do_i2oFrameSize() const;
00340       inline unsigned long do_headerSize() const;
00341       inline unsigned char* do_headerLocation() const;
00342       inline unsigned char* do_fragmentLocation(unsigned char* dataLoc) const;
00343       inline uint32_t do_adler32Checksum() const;
00344 
00345       std::string do_topFolderName() const;
00346       DQMKey do_dqmKey() const;
00347       inline void do_assertRunNumber(uint32_t runNumber);
00348       uint32_t do_runNumber() const;
00349       uint32_t do_lumiSection() const;
00350 
00351     private:
00352 
00353       void parseI2OHeader();
00354       void cacheHeaderFields() const;
00355 
00356       mutable bool headerFieldsCached_;
00357       mutable std::vector<unsigned char> headerCopy_;
00358       mutable unsigned long headerSize_;
00359       mutable unsigned char* headerLocation_;
00360       mutable std::string topFolderName_;
00361       mutable DQMKey dqmKey_;
00362       mutable uint32_t adler32_;
00363 
00364     }; // class DQMEventMsgData
00365 
00366 
00370 
00371     class ErrorEventMsgData : public ChainData
00372     {
00373 
00374     public:
00375 
00376       explicit ErrorEventMsgData(toolbox::mem::Reference* pRef);
00377       ~ErrorEventMsgData() {}
00378 
00379     protected:
00380 
00381       inline size_t do_i2oFrameSize() const;
00382       inline unsigned long do_headerSize() const;
00383       inline unsigned char* do_headerLocation() const;
00384       inline unsigned char* do_fragmentLocation(unsigned char* dataLoc) const;
00385       inline void do_assertRunNumber(uint32_t runNumber);
00386       uint32_t do_runNumber() const;
00387       uint32_t do_lumiSection() const;
00388       uint32_t do_eventNumber() const;
00389 
00390     private:
00391 
00392       void parseI2OHeader();
00393       void cacheHeaderFields() const;
00394 
00395       mutable bool headerFieldsCached_;
00396       mutable std::vector<unsigned char> headerCopy_;
00397       mutable unsigned long headerSize_;
00398       mutable unsigned char* headerLocation_;
00399       mutable uint32_t runNumber_;
00400       mutable uint32_t lumiSection_;
00401       mutable uint32_t eventNumber_;
00402 
00403     }; // class ErrorEventMsgData
00404 
00405 
00409 
00410     class EndLumiSectMsgData : public ChainData
00411     {
00412 
00413     public:
00414 
00415       explicit EndLumiSectMsgData( toolbox::mem::Reference* pRef );
00416       ~EndLumiSectMsgData() {}
00417 
00418     protected:
00419 
00420       inline uint32_t do_runNumber() const { return runNumber_; }
00421       inline uint32_t do_lumiSection() const { return lumiSection_; }
00422 
00423     private:
00424 
00425       mutable uint32_t runNumber_;
00426       mutable uint32_t lumiSection_;
00427 
00428     }; // class EndLumiSectMsgData
00429 
00430 
00431   } // namespace detail
00432 
00433 } // namespace stor
00434 
00435 #endif
00436