Go to the documentation of this file.00001 #include "IOPool/Streamer/interface/InitMessage.h"
00002 #include "FWCore/Utilities/interface/Exception.h"
00003 #include <iostream>
00004 #include <iterator>
00005 #include <cstring>
00006
00007 InitMsgView::InitMsgView(void* buf):
00008 buf_((uint8*)buf),head_(buf)
00009 {
00010 if (protocolVersion() == 2) {
00011 std::cout << "Protocol Version 2 encountered" << std::endl;
00012 release_start_ = buf_ + sizeof(InitHeader) - (sizeof(uint32)*2);
00013
00014
00015 } else {
00016 release_start_ = buf_ + sizeof(InitHeader);
00017 }
00018 release_len_ = *release_start_;
00019 release_start_ += sizeof(uint8);
00020 uint8* pos = release_start_ + release_len_;
00021
00022
00023 if (protocolVersion() > 3) {
00024
00025 processName_len_ = *pos;
00026 processName_start_ = (uint8*)(pos + sizeof(uint8));
00027 pos = processName_start_ + processName_len_;
00028
00029
00030 if (protocolVersion() > 4) {
00031 outputModuleLabel_len_ = *pos;
00032 outputModuleLabel_start_ = (uint8*)(pos + sizeof(uint8));
00033 pos = outputModuleLabel_start_ + outputModuleLabel_len_;
00034
00035
00036 if (protocolVersion() > 5) {
00037 outputModuleId_ = convert32(pos);
00038 pos += sizeof(char_uint32);
00039 }
00040 }
00041 }
00042
00043
00044 hlt_trig_start_ = pos;
00045 hlt_trig_count_ = convert32(hlt_trig_start_);
00046 hlt_trig_start_ += sizeof(char_uint32);
00047 hlt_trig_len_ = convert32(hlt_trig_start_);
00048 hlt_trig_start_ += sizeof(char_uint32);
00049 pos = hlt_trig_start_ + hlt_trig_len_;
00050
00051 if (protocolVersion() > 4) {
00052 hlt_select_start_ = pos;
00053 hlt_select_count_ = convert32(hlt_select_start_);
00054 hlt_select_start_ += sizeof(char_uint32);
00055 hlt_select_len_ = convert32(hlt_select_start_);
00056 hlt_select_start_ += sizeof(char_uint32);
00057 pos = hlt_select_start_ + hlt_select_len_;
00058 }
00059
00060 l1_trig_start_ = pos;
00061 l1_trig_count_ = convert32(l1_trig_start_);
00062 l1_trig_start_ += sizeof(char_uint32);
00063 l1_trig_len_ = convert32(l1_trig_start_);
00064 l1_trig_start_ += sizeof(char_uint32);
00065 pos = l1_trig_start_ + l1_trig_len_;
00066
00067 if (protocolVersion() > 7) {
00068 adler32_chksum_ = convert32(pos);
00069 host_name_start_ = pos + sizeof(uint32);
00070 host_name_len_ = *host_name_start_;
00071 host_name_start_ += sizeof(uint8);
00072 pos = host_name_start_ + host_name_len_;
00073 }
00074
00075 desc_start_ = pos;
00076 desc_len_ = convert32(desc_start_);
00077 desc_start_ += sizeof(char_uint32);
00078 }
00079
00080 uint32 InitMsgView::run() const
00081 {
00082 InitHeader* h = reinterpret_cast<InitHeader*>(buf_);
00083 return convert32(h->run_);
00084 }
00085
00086 uint32 InitMsgView::protocolVersion() const
00087 {
00088 InitHeader* h = reinterpret_cast<InitHeader*>(buf_);
00089 return h->version_.protocol_;
00090 }
00091
00092 void InitMsgView::pset(uint8* put_here) const
00093 {
00094 InitHeader* h = reinterpret_cast<InitHeader*>(buf_);
00095 memcpy(put_here,h->version_.pset_id_,sizeof(h->version_.pset_id_));
00096 }
00097
00098 std::string InitMsgView::releaseTag() const
00099 {
00100 return std::string(reinterpret_cast<char *>(release_start_),release_len_);
00101 }
00102
00103 std::string InitMsgView::processName() const
00104 {
00105 if (protocolVersion() < 4)
00106 throw cms::Exception("Invalid Message Version", "InitMsgView")
00107 << "Process Name is only supported in Protocol Version 4 and above" << ".\n";
00108
00109 return std::string(reinterpret_cast<char *>(processName_start_),processName_len_);
00110 }
00111
00112 std::string InitMsgView::outputModuleLabel() const
00113 {
00114 if (protocolVersion() < 5)
00115 throw cms::Exception("Invalid Message Version", "InitMsgView")
00116 << "Output Module Label is only supported in Protocol Version 5 and above" << ".\n";
00117
00118 return std::string(reinterpret_cast<char *>(outputModuleLabel_start_),outputModuleLabel_len_);
00119 }
00120
00121
00122 void InitMsgView::hltTriggerNames(Strings& save_here) const
00123 {
00124 MsgTools::getNames(hlt_trig_start_,hlt_trig_len_,save_here);
00125 }
00126
00127 void InitMsgView::hltTriggerSelections(Strings& save_here) const
00128 {
00129 if (protocolVersion() < 5)
00130 throw cms::Exception("Invalid Message Version", "InitMsgView")
00131 << "HLT trigger selections are only supported in Protocol Version 5 and above" << ".\n";
00132
00133 MsgTools::getNames(hlt_select_start_,hlt_select_len_,save_here);
00134 }
00135
00136 void InitMsgView::l1TriggerNames(Strings& save_here) const
00137 {
00138 MsgTools::getNames(l1_trig_start_,l1_trig_len_,save_here);
00139 }
00140
00141 uint32 InitMsgView::eventHeaderSize() const
00142 {
00143 if (protocolVersion() == 2) {
00146 uint32 hlt_sz = get_hlt_bit_cnt();
00147 if (hlt_sz != 0 ) hlt_sz = 1+ ((hlt_sz-1)/4);
00148
00149 uint32 l1_sz = get_l1_bit_cnt();
00150 if (l1_sz != 0) l1_sz = 1 + ((l1_sz-1)/8);
00151
00152 return 1 + (4*8) + hlt_sz+l1_sz;
00153 }
00154
00155 InitHeader* h = reinterpret_cast<InitHeader*>(buf_);
00156 return convert32(h->event_header_size_);
00157 }
00158
00159
00160
00161
00162
00163
00164
00165
00166 std::string InitMsgView::hostName() const
00167 {
00168
00169 std::string host_name(reinterpret_cast<char *>(host_name_start_),host_name_len_);
00170 size_t found = host_name.find('\0');
00171 if(found != std::string::npos) {
00172 return std::string(host_name, 0, found);
00173 } else {
00174 return host_name;
00175 }
00176 }