Go to the documentation of this file.00001
00003
00004 #include "EventFilter/StorageManager/src/ChainData.h"
00005
00006 #include "IOPool/Streamer/interface/EventMessage.h"
00007
00008 #include <stdlib.h>
00009
00010 namespace stor
00011 {
00012
00013 namespace detail
00014 {
00015
00016 EventMsgData::EventMsgData(toolbox::mem::Reference* pRef) :
00017 ChainData(I2O_SM_DATA, Header::EVENT),
00018 headerFieldsCached_(false)
00019 {
00020 addFirstFragment(pRef);
00021 parseI2OHeader();
00022 }
00023
00024 inline size_t EventMsgData::do_i2oFrameSize() const
00025 {
00026 return sizeof(I2O_SM_DATA_MESSAGE_FRAME);
00027 }
00028
00029 unsigned long EventMsgData::do_headerSize() const
00030 {
00031 if ( !headerOkay() )
00032 {
00033 return 0;
00034 }
00035
00036 if (! headerFieldsCached_) {cacheHeaderFields();}
00037 return headerSize_;
00038 }
00039
00040 unsigned char* EventMsgData::do_headerLocation() const
00041 {
00042 if ( !headerOkay() )
00043 {
00044 return 0;
00045 }
00046
00047 if (! headerFieldsCached_) {cacheHeaderFields();}
00048 return headerLocation_;
00049 }
00050
00051 inline unsigned char*
00052 EventMsgData::do_fragmentLocation(unsigned char* dataLoc) const
00053 {
00054 if ( parsable() )
00055 {
00056 I2O_SM_DATA_MESSAGE_FRAME *smMsg =
00057 (I2O_SM_DATA_MESSAGE_FRAME*) dataLoc;
00058 return (unsigned char*) smMsg->dataPtr();
00059 }
00060 else
00061 {
00062 return dataLoc;
00063 }
00064 }
00065
00066 uint32_t EventMsgData::do_outputModuleId() const
00067 {
00068 if ( !headerOkay() )
00069 {
00070 std::stringstream msg;
00071 msg << "An output module ID can not be determined from a ";
00072 msg << "faulty or incomplete Event message.";
00073 XCEPT_RAISE(stor::exception::IncompleteEventMessage, msg.str());
00074 }
00075
00076 if (! headerFieldsCached_) {cacheHeaderFields();}
00077 return outputModuleId_;
00078 }
00079
00080 uint32_t EventMsgData::do_hltTriggerCount() const
00081 {
00082 if ( !headerOkay() )
00083 {
00084 std::stringstream msg;
00085 msg << "The number of HLT trigger bits can not be determined ";
00086 msg << "from a faulty or incomplete Event message.";
00087 XCEPT_RAISE(stor::exception::IncompleteEventMessage, msg.str());
00088 }
00089
00090 if (! headerFieldsCached_) {cacheHeaderFields();}
00091 return hltTriggerCount_;
00092 }
00093
00094 void
00095 EventMsgData::do_hltTriggerBits(std::vector<unsigned char>& bitList) const
00096 {
00097 if ( !headerOkay() )
00098 {
00099 std::stringstream msg;
00100 msg << "The HLT trigger bits can not be determined from a ";
00101 msg << "faulty or incomplete Event message.";
00102 XCEPT_RAISE(stor::exception::IncompleteEventMessage, msg.str());
00103 }
00104
00105 if (! headerFieldsCached_) {cacheHeaderFields();}
00106 bitList = hltTriggerBits_;
00107 }
00108
00109 void
00110 EventMsgData::do_assertRunNumber(uint32_t runNumber)
00111 {
00112 if ( headerOkay() && do_runNumber() != runNumber )
00113 {
00114 std::ostringstream errorMsg;
00115 errorMsg << "Run number " << do_runNumber()
00116 << " of event " << do_eventNumber() <<
00117 " received from " << hltURL() <<
00118 " (FU process id " << fuProcessId() << ")" <<
00119 " does not match the run number " << runNumber <<
00120 " used to configure the StorageManager.";
00121 XCEPT_RAISE(stor::exception::RunNumberMismatch, errorMsg.str());
00122 }
00123 }
00124
00125 uint32_t EventMsgData::do_runNumber() const
00126 {
00127 if ( !headerOkay() )
00128 {
00129 std::stringstream msg;
00130 msg << "A run number can not be determined from a ";
00131 msg << "faulty or incomplete Event message.";
00132 XCEPT_RAISE(stor::exception::IncompleteEventMessage, msg.str());
00133 }
00134
00135 if (! headerFieldsCached_) {cacheHeaderFields();}
00136 return runNumber_;
00137 }
00138
00139 uint32_t EventMsgData::do_lumiSection() const
00140 {
00141 if ( !headerOkay() )
00142 {
00143 std::stringstream msg;
00144 msg << "A luminosity section can not be determined from a ";
00145 msg << "faulty or incomplete Event message.";
00146 XCEPT_RAISE(stor::exception::IncompleteEventMessage, msg.str());
00147 }
00148
00149 if (! headerFieldsCached_) {cacheHeaderFields();}
00150 return lumiSection_;
00151 }
00152
00153 uint32_t EventMsgData::do_eventNumber() const
00154 {
00155 if ( !headerOkay() )
00156 {
00157 std::stringstream msg;
00158 msg << "An event number can not be determined from a ";
00159 msg << "faulty or incomplete Event message.";
00160 XCEPT_RAISE(stor::exception::IncompleteEventMessage, msg.str());
00161 }
00162
00163 if (! headerFieldsCached_) {cacheHeaderFields();}
00164 return eventNumber_;
00165 }
00166
00167 uint32_t EventMsgData::do_adler32Checksum() const
00168 {
00169 if ( !headerOkay() )
00170 {
00171 std::stringstream msg;
00172 msg << "An adler32 checksum can not be determined from a ";
00173 msg << "faulty or incomplete Event message.";
00174 XCEPT_RAISE(stor::exception::IncompleteEventMessage, msg.str());
00175 }
00176
00177 if (! headerFieldsCached_) {cacheHeaderFields();}
00178 return adler32_;
00179 }
00180
00181 inline void EventMsgData::parseI2OHeader()
00182 {
00183 if ( parsable() )
00184 {
00185 I2O_SM_DATA_MESSAGE_FRAME *smMsg =
00186 (I2O_SM_DATA_MESSAGE_FRAME*) ref_->getDataLocation();
00187 fragKey_.code_ = messageCode_;
00188 fragKey_.run_ = smMsg->runID;
00189 fragKey_.event_ = smMsg->eventID;
00190 fragKey_.secondaryId_ = smMsg->outModID;
00191 fragKey_.originatorPid_ = smMsg->fuProcID;
00192 fragKey_.originatorGuid_ = smMsg->fuGUID;
00193 rbBufferId_ = smMsg->rbBufferID;
00194 hltLocalId_ = smMsg->hltLocalId;
00195 hltInstance_ = smMsg->hltInstance;
00196 hltTid_ = smMsg->hltTid;
00197 fuProcessId_ = smMsg->fuProcID;
00198 fuGuid_ = smMsg->fuGUID;
00199 }
00200 }
00201
00202 void EventMsgData::cacheHeaderFields() const
00203 {
00204 unsigned char* firstFragLoc = dataLocation(0);
00205 unsigned long firstFragSize = dataSize(0);
00206 bool useFirstFrag = false;
00207
00208
00209 if (fragmentCount_ == 1)
00210 {
00211 useFirstFrag = true;
00212 }
00213
00214
00215
00216
00217 else if (firstFragSize > (sizeof(EventHeader) + 4096))
00218 {
00219 EventMsgView view(firstFragLoc);
00220 if (view.headerSize() <= firstFragSize)
00221 {
00222 useFirstFrag = true;
00223 }
00224 }
00225
00226 boost::shared_ptr<EventMsgView> msgView;
00227 if (useFirstFrag)
00228 {
00229 msgView.reset(new EventMsgView(firstFragLoc));
00230 }
00231 else
00232 {
00233 copyFragmentsIntoBuffer(headerCopy_);
00234 msgView.reset(new EventMsgView(&headerCopy_[0]));
00235 }
00236
00237 headerSize_ = msgView->headerSize();
00238 headerLocation_ = msgView->startAddress();
00239 outputModuleId_ = msgView->outModId();
00240 hltTriggerCount_ = msgView->hltCount();
00241 if (hltTriggerCount_ > 0)
00242 {
00243 hltTriggerBits_.resize(1 + (hltTriggerCount_-1)/4);
00244 }
00245 msgView->hltTriggerBits(&hltTriggerBits_[0]);
00246
00247 runNumber_ = msgView->run();
00248 lumiSection_ = msgView->lumi();
00249 eventNumber_ = msgView->event();
00250 adler32_ = msgView->adler32_chksum();
00251
00252 headerFieldsCached_ = true;
00253
00254 #ifdef STOR_DEBUG_WRONG_ADLER
00255 double r = rand()/static_cast<double>(RAND_MAX);
00256 if (r < 0.01)
00257 {
00258 std::cout << "Simulating corrupt Adler calculation" << std::endl;
00259 headerSize_ += 3;
00260 }
00261 else if (r < 0.02)
00262 {
00263 std::cout << "Simulating corrupt Adler entry" << std::endl;
00264 adler32_ += r*10000;
00265 }
00266 #endif // STOR_DEBUG_WRONG_ADLER
00267 }
00268
00269 }
00270
00271 }
00272
00273