CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/EventFilter/StorageManager/src/ErrorEventData.cc

Go to the documentation of this file.
00001 // $Id: ErrorEventData.cc,v 1.7 2011/03/07 15:31:32 mommsen Exp $
00003 
00004 #include "EventFilter/StorageManager/src/ChainData.h"
00005 
00006 #include "IOPool/Streamer/interface/FRDEventMessage.h"
00007 
00008 namespace stor
00009 {
00010 
00011   namespace detail
00012   {
00013 
00014     ErrorEventMsgData::ErrorEventMsgData(toolbox::mem::Reference* pRef) :
00015       ChainData(I2O_SM_ERROR, Header::ERROR_EVENT),
00016       headerFieldsCached_(false)
00017     {
00018       addFirstFragment(pRef);
00019       parseI2OHeader();
00020     }
00021 
00022     inline size_t ErrorEventMsgData::do_i2oFrameSize() const
00023     {
00024       return sizeof(I2O_SM_DATA_MESSAGE_FRAME);
00025     }
00026 
00027     unsigned long ErrorEventMsgData::do_headerSize() const
00028     {
00029       if ( !headerOkay() )
00030       {
00031         return 0;
00032       }
00033 
00034       if (! headerFieldsCached_) {cacheHeaderFields();}
00035       return headerSize_;
00036     }
00037 
00038     unsigned char* ErrorEventMsgData::do_headerLocation() const
00039     {
00040       if ( !headerOkay() )
00041       {
00042         return 0;
00043       }
00044 
00045       if (! headerFieldsCached_) {cacheHeaderFields();}
00046       return headerLocation_;
00047     }
00048 
00049     inline unsigned char*
00050     ErrorEventMsgData::do_fragmentLocation(unsigned char* dataLoc) const
00051     {
00052       if ( parsable() )
00053       {
00054         I2O_SM_DATA_MESSAGE_FRAME *smMsg =
00055           (I2O_SM_DATA_MESSAGE_FRAME*) dataLoc;
00056         return (unsigned char*) smMsg->dataPtr();
00057       }
00058       else
00059       {
00060         return dataLoc;
00061       }
00062     }
00063 
00064     void
00065     ErrorEventMsgData::do_assertRunNumber(uint32_t runNumber)
00066     {
00067       if ( headerOkay() && do_runNumber() != runNumber )
00068       {
00069         std::ostringstream errorMsg;
00070         errorMsg << "Run number " << do_runNumber() 
00071           << " of error event " << do_eventNumber() <<
00072           " received from " << hltURL() << 
00073           " (FU process id " << fuProcessId() << ")" <<
00074           " does not match the run number " << runNumber << 
00075           " used to configure the StorageManager." <<
00076           " Enforce usage of configured run number.";
00077         runNumber_ = runNumber;
00078         XCEPT_RAISE(stor::exception::RunNumberMismatch, errorMsg.str());
00079       }
00080     }
00081 
00082     uint32_t ErrorEventMsgData::do_runNumber() const
00083     {
00084       if ( !headerOkay() )
00085       {
00086         std::stringstream msg;
00087         msg << "A run number can not be determined from a ";
00088         msg << "faulty or incomplete ErrorEvent message.";
00089         XCEPT_RAISE(stor::exception::IncompleteEventMessage, msg.str());
00090       }
00091       
00092       if (! headerFieldsCached_) {cacheHeaderFields();}
00093       return runNumber_;
00094     }
00095 
00096     uint32_t ErrorEventMsgData::do_lumiSection() const
00097     {
00098       if ( !headerOkay() )
00099       {
00100         std::stringstream msg;
00101         msg << "A luminosity section can not be determined from a ";
00102         msg << "faulty or incomplete ErrorEvent message.";
00103         XCEPT_RAISE(stor::exception::IncompleteEventMessage, msg.str());
00104       }
00105       
00106       if (! headerFieldsCached_) {cacheHeaderFields();}
00107       return lumiSection_;
00108     }
00109 
00110     uint32_t ErrorEventMsgData::do_eventNumber() const
00111     {
00112       if ( !headerOkay() )
00113       {
00114         std::stringstream msg;
00115         msg << "An event number can not be determined from a ";
00116         msg << "faulty or incomplete ErrorEvent message.";
00117         XCEPT_RAISE(stor::exception::IncompleteEventMessage, msg.str());
00118       }
00119       
00120       if (! headerFieldsCached_) {cacheHeaderFields();}
00121       return eventNumber_;
00122     }
00123 
00124     inline void ErrorEventMsgData::parseI2OHeader()
00125     {
00126       if ( parsable() )
00127       {
00128         I2O_SM_DATA_MESSAGE_FRAME *smMsg =
00129           (I2O_SM_DATA_MESSAGE_FRAME*) ref_->getDataLocation();
00130         fragKey_.code_ = messageCode_;
00131         fragKey_.run_ = smMsg->runID;
00132         fragKey_.event_ = smMsg->eventID;
00133         fragKey_.secondaryId_ = smMsg->outModID;
00134         fragKey_.originatorPid_ = smMsg->fuProcID;
00135         fragKey_.originatorGuid_ = smMsg->fuGUID;
00136         rbBufferId_ = smMsg->rbBufferID;
00137         hltLocalId_ = smMsg->hltLocalId;
00138         hltInstance_ = smMsg->hltInstance;
00139         hltTid_ = smMsg->hltTid;
00140         fuProcessId_ = smMsg->fuProcID;
00141         fuGuid_ = smMsg->fuGUID;
00142       }
00143     }
00144 
00145     void ErrorEventMsgData::cacheHeaderFields() const
00146     {
00147       unsigned char* firstFragLoc = dataLocation(0);
00148       unsigned long firstFragSize = dataSize(0);
00149       bool useFirstFrag = false;
00150 
00151       // if there is only one fragment, use it
00152       if (fragmentCount_ == 1)
00153       {
00154         useFirstFrag = true;
00155       }
00156       // otherwise, check if the first fragment is large enough to hold
00157       // the full Event message header  (FRD events have fixed header
00158       // size, so the check is easy)
00159       else if (firstFragSize > sizeof(FRDEventHeader_V2))
00160       {
00161         useFirstFrag = true;
00162       }
00163 
00164       boost::shared_ptr<FRDEventMsgView> msgView;
00165       if (useFirstFrag)
00166       {
00167         msgView.reset(new FRDEventMsgView(firstFragLoc));
00168       }
00169       else
00170       {
00171         copyFragmentsIntoBuffer(headerCopy_);
00172         msgView.reset(new FRDEventMsgView(&headerCopy_[0]));
00173       }
00174 
00175       headerSize_ = sizeof(FRDEventHeader_V2);
00176       headerLocation_ = msgView->startAddress();
00177 
00178       runNumber_ = msgView->run();
00179       lumiSection_ = msgView->lumi();
00180       eventNumber_ = msgView->event();
00181 
00182       headerFieldsCached_ = true;
00183     }
00184 
00185   } // namespace detail
00186 
00187 } // namespace stor
00188 
00189