CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/EventFilter/StorageManager/src/DQMEventMsgData.cc

Go to the documentation of this file.
00001 // $Id: DQMEventMsgData.cc,v 1.12 2011/03/28 13:49:04 mommsen Exp $
00003 
00004 #include "EventFilter/StorageManager/src/ChainData.h"
00005 
00006 #include "IOPool/Streamer/interface/DQMEventMessage.h"
00007 
00008 namespace stor
00009 {
00010 
00011   namespace detail
00012   {
00013 
00014     DQMEventMsgData::DQMEventMsgData(toolbox::mem::Reference* pRef) :
00015       ChainData(I2O_SM_DQM, Header::DQM_EVENT),
00016       headerFieldsCached_(false)
00017     {
00018       addFirstFragment(pRef);
00019       parseI2OHeader();
00020     }
00021 
00022     inline size_t DQMEventMsgData::do_i2oFrameSize() const
00023     {
00024       return sizeof(I2O_SM_DQM_MESSAGE_FRAME);
00025     }
00026 
00027     std::string DQMEventMsgData::do_topFolderName() const
00028     {
00029       if( !headerOkay() )
00030       {
00031         std::stringstream msg;
00032         msg << "A top folder name can not be determined from a ";
00033         msg << "faulty or incomplete DQM event message.";
00034         XCEPT_RAISE( stor::exception::IncompleteDQMEventMessage, msg.str() );
00035       }
00036 
00037       if( !headerFieldsCached_ ) {cacheHeaderFields();}
00038       return topFolderName_;
00039     }
00040 
00041     uint32_t DQMEventMsgData::do_adler32Checksum() const
00042     {
00043       if( !headerOkay() )
00044       {
00045         std::stringstream msg;
00046         msg << "An adler32 checksum can not be determined from a ";
00047         msg << "faulty or incomplete DQM event message.";
00048         XCEPT_RAISE( stor::exception::IncompleteDQMEventMessage, msg.str() );
00049       }
00050       
00051       if( !headerFieldsCached_ ) {cacheHeaderFields();}
00052       return adler32_;
00053     }
00054 
00055     DQMKey DQMEventMsgData::do_dqmKey() const
00056     {
00057       if( !headerOkay() )
00058       {
00059         std::stringstream msg;
00060         msg << "The DQM key can not be determined from a ";
00061         msg << "faulty or incomplete DQM event message.";
00062         XCEPT_RAISE( stor::exception::IncompleteDQMEventMessage, msg.str() );
00063       }
00064       
00065       if( !headerFieldsCached_ ) {cacheHeaderFields();}
00066       return dqmKey_;
00067     }
00068 
00069     uint32_t DQMEventMsgData::do_runNumber() const
00070     {
00071 
00072       if( !headerOkay() )
00073       {
00074         std::stringstream msg;
00075         msg << "The run number can not be determined from a ";
00076         msg << "faulty or incomplete DQM event message.";
00077         XCEPT_RAISE( stor::exception::IncompleteDQMEventMessage, msg.str() );
00078       }
00079       
00080       if( !headerFieldsCached_ ) {cacheHeaderFields();}
00081       return dqmKey_.runNumber;
00082     }
00083 
00084     uint32_t DQMEventMsgData::do_lumiSection() const
00085     {
00086 
00087       if( !headerOkay() )
00088       {
00089         std::stringstream msg;
00090         msg << "The lumi section can not be determined from a ";
00091         msg << "faulty or incomplete DQM event message.";
00092         XCEPT_RAISE( stor::exception::IncompleteDQMEventMessage, msg.str() );
00093       }
00094       
00095       if( !headerFieldsCached_ ) {cacheHeaderFields();}
00096       return dqmKey_.lumiSection;
00097     }
00098 
00099     void DQMEventMsgData::do_assertRunNumber(uint32_t runNumber)
00100     {
00101       if ( headerOkay() && do_runNumber() != runNumber )
00102       {
00103         std::ostringstream errorMsg;
00104         errorMsg << "Run number " << do_runNumber() 
00105           << " of DQM event for LS " << do_lumiSection() <<
00106           " received from " << hltURL() << 
00107           " (FU process id " << fuProcessId() << ")" <<
00108           " does not match the run number " << runNumber << 
00109           " used to configure the StorageManager.";
00110         XCEPT_RAISE(stor::exception::RunNumberMismatch, errorMsg.str());
00111       }
00112     }
00113 
00114     unsigned long DQMEventMsgData::do_headerSize() const
00115     {
00116       if ( !headerOkay() )
00117       {
00118         return 0;
00119       }
00120     
00121       if (! headerFieldsCached_) {cacheHeaderFields();}
00122       return headerSize_;
00123     }
00124 
00125     unsigned char* DQMEventMsgData::do_headerLocation() const
00126     {
00127       if ( !headerOkay() )
00128       {
00129         return 0;
00130       }
00131 
00132       if (! headerFieldsCached_) {cacheHeaderFields();}
00133       return headerLocation_;
00134     }
00135 
00136     inline unsigned char*
00137     DQMEventMsgData::do_fragmentLocation(unsigned char* dataLoc) const
00138     {
00139       if ( parsable() )
00140       {
00141         I2O_SM_DQM_MESSAGE_FRAME *smMsg =
00142           (I2O_SM_DQM_MESSAGE_FRAME*) dataLoc;
00143         return (unsigned char*) smMsg->dataPtr();
00144       }
00145       else
00146       {
00147         return dataLoc;
00148       }
00149     }
00150   
00151     inline void DQMEventMsgData::parseI2OHeader()
00152     {
00153       if ( parsable() )
00154       {
00155         I2O_SM_DQM_MESSAGE_FRAME *smMsg =
00156           (I2O_SM_DQM_MESSAGE_FRAME*) ref_->getDataLocation();
00157         fragKey_.code_ = messageCode_;
00158         fragKey_.run_ = smMsg->runID;
00159         fragKey_.event_ = smMsg->eventAtUpdateID;
00160         fragKey_.secondaryId_ = smMsg->folderID;
00161         fragKey_.originatorPid_ = smMsg->fuProcID;
00162         fragKey_.originatorGuid_ = smMsg->fuGUID;
00163         rbBufferId_ = smMsg->rbBufferID;
00164         hltLocalId_ = smMsg->hltLocalId;
00165         hltInstance_ = smMsg->hltInstance;
00166         hltTid_ = smMsg->hltTid;
00167         fuProcessId_ = smMsg->fuProcID;
00168         fuGuid_ = smMsg->fuGUID;
00169       }
00170     }
00171 
00172     // Adapted from InitMsgData::cacheHeaderFields
00173     void DQMEventMsgData::cacheHeaderFields() const
00174     {
00175 
00176       unsigned char* firstFragLoc = dataLocation(0);
00177 
00178       boost::shared_ptr<DQMEventMsgView> msgView;
00179       if (fragmentCount_ == 1)
00180       {
00181         msgView.reset(new DQMEventMsgView(firstFragLoc));
00182       }
00183       else
00184       {
00185         copyFragmentsIntoBuffer(headerCopy_);
00186         msgView.reset(new DQMEventMsgView(&headerCopy_[0]));
00187       }
00188 
00189       headerSize_ = msgView->headerSize()
00190         + sizeof(uint32_t); // in contrast to other message types,
00191                           // DQM messages do not contain the data
00192                           // length entry (uint32_t) in headerSize()
00193       headerLocation_ = msgView->startAddress();
00194       topFolderName_ = msgView->topFolderName();
00195       adler32_ = msgView->adler32_chksum();
00196 
00197       dqmKey_.runNumber = msgView->runNumber();
00198       dqmKey_.lumiSection = msgView->lumiSection();
00199       dqmKey_.topLevelFolderName = msgView->topFolderName();
00200 
00201       headerFieldsCached_ = true;
00202 
00203       #ifdef STOR_DEBUG_WRONG_ADLER
00204       double r = rand()/static_cast<double>(RAND_MAX);
00205       if (r < 0.01)
00206       {
00207         std::cout << "Simulating corrupt Adler calculation" << std::endl;
00208         headerSize_ += 3;
00209       }
00210       else if (r < 0.02)
00211       {
00212         std::cout << "Simulating corrupt Adler entry" << std::endl;
00213         adler32_ += r*10000;
00214       }
00215       #endif // STOR_DEBUG_WRONG_ADLER
00216     }
00217 
00218   } // namespace detail
00219 
00220 } // namespace stor
00221 
00222