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
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
00031 if (this->protocolVersion() != 2)
00032 {
00033 throw cms::Exception("MessageDecoding", "DQMEventMsgView")
00034 << "Unsupport protocol version (" << this->protocolVersion() << ").\n";
00035 }
00036
00037
00038 bufPtr = buf_ + sizeof(DQMEventHeader);
00039
00040
00041 len = convert32(bufPtr);
00042 bufPtr += sizeof(uint32);
00043 if (len >= 0)
00044 {
00045 if (len <= MAX_STRING_SIZE)
00046 {
00047 releaseTag_.append((char *) bufPtr, len);
00048 }
00049 bufPtr += len;
00050 }
00051
00052
00053 len = convert32(bufPtr);
00054 bufPtr += sizeof(uint32);
00055 if (len >= 0)
00056 {
00057 if (len <= MAX_STRING_SIZE)
00058 {
00059 folderName_.append((char *) bufPtr, len);
00060 }
00061 bufPtr += len;
00062 }
00063
00064
00065 subFolderCount_ = convert32(bufPtr);
00066 bufPtr += sizeof(uint32);
00067
00068
00069 nameListPtr_.reset(new std::vector<std::string>());
00070 for (int idx = 0; idx < (int) subFolderCount_; idx++)
00071 {
00072
00073 uint32 meCount = convert32(bufPtr);
00074 bufPtr += sizeof(uint32);
00075 meCountList_.push_back(meCount);
00076
00077
00078 std::string subFolderName = "Subfolder " + idx;
00079 uint32 nameLen = convert32(bufPtr);
00080 bufPtr += sizeof(uint32);
00081 if (nameLen >= 0)
00082 {
00083 if (nameLen <= MAX_STRING_SIZE)
00084 {
00085 subFolderName.clear();
00086 subFolderName.append((char *) bufPtr, nameLen);
00087 }
00088 bufPtr += nameLen;
00089 }
00090 nameListPtr_->push_back(subFolderName);
00091 subFolderIndexTable_[subFolderName] = idx;
00092 }
00093
00094
00095 eventLen_ = convert32(bufPtr);
00096 bufPtr += sizeof(uint32);
00097 eventAddr_ = bufPtr;
00098
00099
00100
00101 if ((this->headerSize() + this->eventLength()) > this->size())
00102 {
00103 throw cms::Exception("MessageDecoding", "DQMEventMsgView")
00104 << "Inconsistent data sizes. The size of the header ("
00105 << this->headerSize() << ") and the data (" << this->eventLength()
00106 << ") exceed the size of the message (" << this->size() << ").\n";
00107 }
00108 }
00109
00113 boost::shared_ptr< std::vector<std::string> >
00114 DQMEventMsgView::subFolderNames() const
00115 {
00116 return nameListPtr_;
00117 }
00118
00122 std::string DQMEventMsgView::subFolderName(uint32 const subFolderIndex) const
00123 {
00124
00125 if (subFolderIndex >= subFolderCount_)
00126 {
00127 throw cms::Exception("MessageDecoding", "DQMEventMsgView")
00128 << "Invalid subfolder index (" << subFolderIndex << ") - "
00129 << "the number of subfolders is " << subFolderCount_ << ".\n";
00130 }
00131
00132 return (*nameListPtr_)[subFolderIndex];
00133 }
00134
00138 uint32 DQMEventMsgView::meCount(std::string const& subFolderName) const
00139 {
00140
00141 std::map<std::string, uint32>::const_iterator subFolderIter;
00142 subFolderIter = subFolderIndexTable_.find(subFolderName);
00143
00144
00145 if (subFolderIter == subFolderIndexTable_.end())
00146 {
00147 throw cms::Exception("MessageDecoding", "DQMEventMsgView")
00148 << "Unable to find the subfolder index for \""
00149 << subFolderName << "\".\n";
00150 }
00151
00152
00153 return this->meCount(subFolderIter->second);
00154 }
00155
00160 uint32 DQMEventMsgView::meCount(uint32 const subFolderIndex) const
00161 {
00162
00163 if (subFolderIndex >= subFolderCount_)
00164 {
00165 throw cms::Exception("MessageDecoding", "DQMEventMsgView")
00166 << "Invalid subfolder index (" << subFolderIndex << ") - "
00167 << "the number of subfolders is " << subFolderCount_ << ".\n";
00168 }
00169
00170 return meCountList_[subFolderIndex];
00171 }
00172
00176 uint32 DQMEventMsgView::protocolVersion() const
00177 {
00178 DQMEventHeader* h = (DQMEventHeader*)buf_;
00179 return convert32(h->protocolVersion_);
00180 }
00181
00185 uint32 DQMEventMsgView::headerSize() const
00186 {
00187 DQMEventHeader* h = (DQMEventHeader*)buf_;
00188 return convert32(h->headerSize_);
00189 }
00190
00194 uint32 DQMEventMsgView::runNumber() const
00195 {
00196 DQMEventHeader* h = (DQMEventHeader*)buf_;
00197 return convert32(h->runNumber_);
00198 }
00199
00203 uint32 DQMEventMsgView::eventNumberAtUpdate() const
00204 {
00205 DQMEventHeader* h = (DQMEventHeader*)buf_;
00206 return convert32(h->eventNumber_);
00207 }
00208
00212 uint32 DQMEventMsgView::lumiSection() const
00213 {
00214 DQMEventHeader* h = (DQMEventHeader*)buf_;
00215 return convert32(h->lumiSection_);
00216 }
00217
00221 uint32 DQMEventMsgView::updateNumber() const
00222 {
00223 DQMEventHeader* h = (DQMEventHeader*)buf_;
00224 return convert32(h->updateNumber_);
00225 }
00226
00230 uint32 DQMEventMsgView::compressionFlag() const
00231 {
00232 DQMEventHeader* h = (DQMEventHeader*)buf_;
00233 return convert32(h->compressionFlag_);
00234 }
00235
00239 uint32 DQMEventMsgView::fuProcessId() const
00240 {
00241 DQMEventHeader* h = (DQMEventHeader*)buf_;
00242 return convert32(h->fuProcessId_);
00243 }
00244
00248 uint32 DQMEventMsgView::fuGuid() const
00249 {
00250 DQMEventHeader* h = (DQMEventHeader*)buf_;
00251 return convert32(h->fuGuid_);
00252 }
00253
00257 uint32 DQMEventMsgView::reserved() const
00258 {
00259 DQMEventHeader* h = (DQMEventHeader*)buf_;
00260 return convert32(h->reserved_);
00261 }
00262
00263
00264 edm::Timestamp DQMEventMsgView::timeStamp() const
00265 {
00266 DQMEventHeader* h = (DQMEventHeader*)buf_;
00267 return edm::Timestamp(convert64(h->timeStamp_));
00268 }
00269