CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_6/src/IOPool/Streamer/src/DQMEventMsgBuilder.cc

Go to the documentation of this file.
00001 
00008 #include "IOPool/Streamer/interface/DQMEventMsgBuilder.h"
00009 #include "IOPool/Streamer/interface/MsgHeader.h"
00010 #include "FWCore/Utilities/interface/Exception.h"
00011 #include <cassert>
00012 #include <cstring>
00013 
00014 
00018 DQMEventMsgBuilder::DQMEventMsgBuilder(void* buf, uint32 bufSize,
00019                             uint32 run, uint32 event,
00020                             edm::Timestamp timeStamp,
00021                             //uint64 timeStamp,
00022                             uint32 lumiSection, uint32 updateNumber,
00023                             uint32 adler_chksum,
00024                             const char* host_name,
00025                             std::string const& releaseTag,
00026                             std::string const& topFolderName,
00027                             DQMEvent::TObjectTable monitorElementsBySubFolder):
00028   buf_((uint8*)buf),bufSize_(bufSize)
00029 {
00030   DQMEventHeader* evtHdr;
00031   uint8* bufPtr;
00032   uint32 len;
00033   uint32 protocolVersion = 3;
00034 
00035   // fill in event header information
00036   bufPtr = buf_ + sizeof(DQMEventHeader);
00037   if (((uint32) (bufPtr - buf_)) > bufSize_)
00038     {
00039       throw cms::Exception("MessageBuilding", "DQMEventMsgBuilder")
00040         << "Input buffer size is too small for required header "
00041         << "information.  Size = " << bufSize_
00042         << ", necessary size is >= "
00043         << ((uint32) (bufPtr - buf_)) << ".\n";
00044     }
00045 
00046   evtHdr = (DQMEventHeader*) buf_;
00047   convert(protocolVersion, evtHdr->protocolVersion_);
00048   convert(run, evtHdr->runNumber_);
00049   convert(event, evtHdr->eventNumber_);
00050 
00051   convert(timeStamp.value(), evtHdr->timeStamp_);
00052 
00053   convert(lumiSection, evtHdr->lumiSection_);
00054   convert(updateNumber, evtHdr->updateNumber_);
00055 
00056   // copy the release tag into the message
00057   len = releaseTag.length();
00058   if (((uint32) (bufPtr + len + sizeof(uint32) - buf_)) > bufSize_)
00059     {
00060       throw cms::Exception("MessageBuilding", "DQMEventMsgBuilder")
00061         << "Input buffer size is too small for required header "
00062         << "information.  Size = " << bufSize_
00063         << ", necessary size is >= "
00064         << ((uint32) (bufPtr + len + sizeof(uint32) - buf_)) << ".\n";
00065     }
00066   convert(len, bufPtr);
00067   bufPtr += sizeof(uint32);
00068   releaseTag.copy((char*) bufPtr, len);
00069   bufPtr += len;
00070 
00071   // copy the top folder name into the message
00072   len = topFolderName.length();
00073   if (((uint32) (bufPtr + len + sizeof(uint32) - buf_)) > bufSize_)
00074     {
00075       throw cms::Exception("MessageBuilding", "DQMEventMsgBuilder")
00076         << "Input buffer size is too small for required header "
00077         << "information.  Size = " << bufSize_
00078         << ", necessary size is >= "
00079         << ((uint32) (bufPtr + len + sizeof(uint32) - buf_)) << ".\n";
00080     }
00081   convert(len, bufPtr);
00082   bufPtr += sizeof(uint32);
00083   topFolderName.copy((char*) bufPtr, len);
00084   bufPtr += len;
00085 
00086   // copy the subfolder count into the message
00087   convert(static_cast<uint32>(monitorElementsBySubFolder.size()), bufPtr);
00088   bufPtr += sizeof(uint32);
00089 
00090   // copy the ME count and name for each subfolder into the message
00091   DQMEvent::TObjectTable::const_iterator sfIter;
00092   for (sfIter = monitorElementsBySubFolder.begin();
00093        sfIter != monitorElementsBySubFolder.end(); sfIter++)
00094     {
00095       std::string subFolderName = sfIter->first;
00096       std::vector<TObject *> toList = sfIter->second;
00097 
00098       convert(static_cast<uint32>(toList.size()), bufPtr);
00099       bufPtr += sizeof(uint32);
00100 
00101       len = subFolderName.length();
00102       convert(len, bufPtr);
00103       bufPtr += sizeof(uint32);
00104       subFolderName.copy((char*) bufPtr, len);
00105       bufPtr += len;
00106     }
00107   // adler32 check sum of data blob
00108   convert(adler_chksum, bufPtr);
00109   bufPtr +=  sizeof(uint32);
00110 
00111   // put host name (Length and then Name) right after check sum
00112   uint32 host_name_len = strlen(host_name);
00113   assert(host_name_len < 0x00ff);
00114   //Put host_name_len
00115   *bufPtr++ = host_name_len;
00116   //Put host_name 
00117   memcpy(bufPtr,host_name,host_name_len);
00118   bufPtr += host_name_len;
00119 
00120   // set the header size and the event address, taking into account the
00121   // size of the event length field
00122   if (((uint32) (bufPtr + sizeof(uint32) - buf_)) > bufSize_)
00123     {
00124       throw cms::Exception("MessageBuilding", "DQMEventMsgBuilder")
00125         << "Input buffer size is too small for required header "
00126         << "information.  Size = " << bufSize_
00127         << ", necessary size is >= "
00128         << ((uint32) (bufPtr + sizeof(uint32) - buf_)) << ".\n";
00129     }
00130   convert(((uint32) (bufPtr - buf_)), evtHdr->headerSize_);
00131   bufPtr += sizeof(uint32);
00132   eventAddr_ = bufPtr;
00133 
00134   // set the event length to 0 initially.  (The setEventLength method
00135   // sets the message code and message size for us.  It shouldn't be called
00136   // until *after* the event address is set.)
00137   setEventLength(0);
00138 
00139   // initialize the compression flag to zero
00140   setCompressionFlag(0);
00141 
00142   // initialize the filter unit process ID to zero
00143   setFUProcessId(0);
00144 
00145   // initialize the filter unit GUID to zero
00146   setFUGuid(0);
00147 
00148   // initialize the merge count to zero
00149   setMergeCount(0);
00150 }
00151 
00157 void DQMEventMsgBuilder::setEventLength(uint32 len)
00158 {
00159   if (((uint32) (eventAddr_ + len - buf_)) > bufSize_)
00160     {
00161       throw cms::Exception("MessageBuilding", "DQMEventMsgBuilder")
00162         << "Event data overflows buffer. Buffer size = " << bufSize_
00163         << ", header size = " << this->headerSize()
00164         << ", event size = " << len << ".\n";
00165     }
00166   convert(len, eventAddr_ - sizeof(char_uint32));
00167   DQMEventHeader* evtHdr = (DQMEventHeader*) buf_;
00168   new (&evtHdr->header_) Header(Header::DQM_EVENT, (eventAddr_ - buf_ + len));
00169 }
00170 
00174 void DQMEventMsgBuilder::setCompressionFlag(uint32 value)
00175 {
00176   DQMEventHeader* evtHdr = (DQMEventHeader*) buf_;
00177   convert(value, evtHdr->compressionFlag_);
00178 }
00179 
00183 void DQMEventMsgBuilder::setFUProcessId(uint32 value)
00184 {
00185   DQMEventHeader* evtHdr = (DQMEventHeader*) buf_;
00186   convert(value, evtHdr->fuProcessId_);
00187 }
00188 
00192 void DQMEventMsgBuilder::setFUGuid(uint32 value)
00193 {
00194   DQMEventHeader* evtHdr = (DQMEventHeader*) buf_;
00195   convert(value, evtHdr->fuGuid_);
00196 }
00197 
00201 void DQMEventMsgBuilder::setMergeCount(uint32 value)
00202 {
00203   DQMEventHeader* evtHdr = (DQMEventHeader*) buf_;
00204   convert(value, evtHdr->mergeCount_);
00205 }
00206 
00210 uint32 DQMEventMsgBuilder::size() const
00211 {
00212   HeaderView v(buf_);
00213   return v.size();
00214 }
00215 
00216 
00217