CMS 3D CMS Logo

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

Go to the documentation of this file.
00001 
00008 #include "IOPool/Streamer/interface/DQMEventMessage.h"
00009 #include "FWCore/Utilities/interface/Exception.h"
00010 
00011 #define MAX_STRING_SIZE 10000
00012 
00016 DQMEventMsgView::DQMEventMsgView(void* buf):
00017   buf_((uint8*)buf),head_(buf)
00018 {
00019   uint8* bufPtr;
00020   uint32 len;
00021 
00022   // verify that the buffer actually contains a DQM Event message
00023   if (this->code() != Header::DQM_EVENT)
00024     {
00025       throw cms::Exception("MessageDecoding", "DQMEventMsgView")
00026         << "Invalid DQM Event message code (" << this->code()
00027         << "). Should be " << Header::DQM_EVENT << "\n";
00028     }
00029 
00030   // verify that the message has a protocol that we support
00031   if (this->protocolVersion() != 3)
00032     {
00033       throw cms::Exception("MessageDecoding", "DQMEventMsgView")
00034         << "Unsupport protocol version (" << this->protocolVersion() << ").\n";
00035     }
00036 
00037   // set our buffer pointer to just beyond the fixed header data
00038   bufPtr = buf_ + sizeof(DQMEventHeader);
00039 
00040   // determine the release tag
00041   len = convert32(bufPtr);
00042   bufPtr += sizeof(uint32);
00043   if (len <= MAX_STRING_SIZE) // prevent something totally crazy // len >= 0, since len is unsigned.
00044   {
00045     releaseTag_.append((char *) bufPtr, len);
00046   }
00047   bufPtr += len;
00048 
00049   // determine the top-level folder name
00050   len = convert32(bufPtr);
00051   bufPtr += sizeof(uint32);
00052   if (len <= MAX_STRING_SIZE) // prevent something totally crazy // len >= 0, since len is unsigned.
00053   {
00054     folderName_.append((char *) bufPtr, len);
00055   }
00056   bufPtr += len;
00057 
00058   // determine the number of subfolders
00059   subFolderCount_ = convert32(bufPtr);
00060   bufPtr += sizeof(uint32);
00061 
00062   // loop over the subfolders to extract relevant quantities
00063   nameListPtr_.reset(new std::vector<std::string>());
00064   for (int idx = 0; idx < (int) subFolderCount_; idx++)
00065     {
00066       // number of MEs in subfolder
00067       uint32 meCount = convert32(bufPtr);
00068       bufPtr += sizeof(uint32);
00069       meCountList_.push_back(meCount);
00070 
00071       // subfolder name
00072       std::string subFolderName = "Subfolder " + idx;
00073       uint32 nameLen = convert32(bufPtr);
00074       bufPtr += sizeof(uint32);
00075       if (nameLen <= MAX_STRING_SIZE) // prevent something totally crazy // nameLen >= 0, since nameLen is unsigned.
00076       {
00077         subFolderName.clear();
00078         subFolderName.append((char *) bufPtr, nameLen);
00079       }
00080       bufPtr += nameLen;
00081       nameListPtr_->push_back(subFolderName);
00082       subFolderIndexTable_[subFolderName] = idx;
00083     }
00084   adler32_chksum_ = convert32(bufPtr);
00085   bufPtr += sizeof(uint32);
00086 
00087   host_name_len_ = *bufPtr;
00088   bufPtr += sizeof(uint8);
00089   host_name_start_ = bufPtr;
00090   bufPtr += host_name_len_;
00091 
00092   // determine the event length and address
00093   eventLen_ = convert32(bufPtr);
00094   bufPtr += sizeof(uint32);
00095   eventAddr_ = bufPtr;
00096 
00097   // check that the event data doesn't extend beyond the reported
00098   // size of the message
00099   if ((this->headerSize() + this->eventLength()) > this->size())
00100     {
00101       throw cms::Exception("MessageDecoding", "DQMEventMsgView")
00102         << "Inconsistent data sizes. The size of the header ("
00103         << this->headerSize() << ") and the data (" << this->eventLength()
00104         << ") exceed the size of the message (" << this->size() << ").\n";
00105     }
00106 }
00107 
00111 boost::shared_ptr< std::vector<std::string> >
00112     DQMEventMsgView::subFolderNames() const
00113 {
00114   return nameListPtr_;
00115 }
00116 
00120 std::string DQMEventMsgView::subFolderName(uint32 const subFolderIndex) const
00121 {
00122   // catch attempts to access an invalid entry
00123   if (subFolderIndex >= subFolderCount_)
00124     {
00125       throw cms::Exception("MessageDecoding", "DQMEventMsgView")
00126         << "Invalid subfolder index (" << subFolderIndex << ") - "
00127         << "the number of subfolders is " << subFolderCount_ << ".\n";
00128     }
00129 
00130   return (*nameListPtr_)[subFolderIndex];
00131 }
00132 
00136 uint32 DQMEventMsgView::meCount(std::string const& subFolderName) const
00137 {
00138   // lookup the index of the specified subfolder
00139   std::map<std::string, uint32>::const_iterator subFolderIter;
00140   subFolderIter = subFolderIndexTable_.find(subFolderName);
00141 
00142   // throw an exception if the name was not found
00143   if (subFolderIter == subFolderIndexTable_.end())
00144     {
00145       throw cms::Exception("MessageDecoding", "DQMEventMsgView")
00146         << "Unable to find the subfolder index for \""
00147         << subFolderName << "\".\n";
00148     }
00149 
00150   // fetch the count by index
00151   return this->meCount(subFolderIter->second);
00152 }
00153 
00158 uint32 DQMEventMsgView::meCount(uint32 const subFolderIndex) const
00159 {
00160   // catch attempts to access an invalid entry
00161   if (subFolderIndex >= subFolderCount_)
00162     {
00163       throw cms::Exception("MessageDecoding", "DQMEventMsgView")
00164         << "Invalid subfolder index (" << subFolderIndex << ") - "
00165         << "the number of subfolders is " << subFolderCount_ << ".\n";
00166     }
00167 
00168   return meCountList_[subFolderIndex];
00169 }
00170 
00174 uint32 DQMEventMsgView::protocolVersion() const
00175 {
00176   DQMEventHeader* h = (DQMEventHeader*)buf_;
00177   return convert32(h->protocolVersion_);
00178 }
00179 
00183 uint32 DQMEventMsgView::headerSize() const
00184 {
00185   DQMEventHeader* h = (DQMEventHeader*)buf_;
00186   return convert32(h->headerSize_);
00187 }
00188 
00192 uint32 DQMEventMsgView::runNumber() const
00193 {
00194   DQMEventHeader* h = (DQMEventHeader*)buf_;
00195   return convert32(h->runNumber_);
00196 }
00197 
00201 uint32 DQMEventMsgView::eventNumberAtUpdate() const
00202 {
00203   DQMEventHeader* h = (DQMEventHeader*)buf_;
00204   return convert32(h->eventNumber_);
00205 }
00206 
00210 uint32 DQMEventMsgView::lumiSection() const
00211 {
00212   DQMEventHeader* h = (DQMEventHeader*)buf_;
00213   return convert32(h->lumiSection_);
00214 }
00215 
00219 uint32 DQMEventMsgView::updateNumber() const
00220 {
00221   DQMEventHeader* h = (DQMEventHeader*)buf_;
00222   return convert32(h->updateNumber_);
00223 }
00224 
00228 uint32 DQMEventMsgView::compressionFlag() const
00229 {
00230   DQMEventHeader* h = (DQMEventHeader*)buf_;
00231   return convert32(h->compressionFlag_);
00232 }
00233 
00237 uint32 DQMEventMsgView::fuProcessId() const
00238 {
00239   DQMEventHeader* h = (DQMEventHeader*)buf_;
00240   return convert32(h->fuProcessId_);
00241 }
00242 
00246 uint32 DQMEventMsgView::fuGuid() const
00247 {
00248   DQMEventHeader* h = (DQMEventHeader*)buf_;
00249   return convert32(h->fuGuid_);
00250 }
00251 
00255 uint32 DQMEventMsgView::mergeCount() const
00256 {
00257   DQMEventHeader* h = (DQMEventHeader*)buf_;
00258   return convert32(h->mergeCount_);
00259 }
00260 
00261 //uint64 DQMEventMsgView::timeStamp() const
00262 edm::Timestamp DQMEventMsgView::timeStamp() const
00263 {
00264   DQMEventHeader* h = (DQMEventHeader*)buf_;
00265   return edm::Timestamp(convert64(h->timeStamp_));
00266 }
00267 
00268 std::string DQMEventMsgView::hostName() const
00269 {
00270    return std::string(reinterpret_cast<char *>(host_name_start_),host_name_len_);
00271 }
00272