File indexing completed on 2024-05-31 04:19:42
0001 #include "IOPool/Streamer/interface/InitMessage.h"
0002 #include "FWCore/Utilities/interface/Exception.h"
0003 #include <iostream>
0004 #include <iterator>
0005 #include <cstring>
0006
0007 using namespace edm::streamer;
0008
0009 InitMsgView::InitMsgView(void* buf)
0010 : buf_((uint8*)buf),
0011 head_(buf),
0012 release_start_(nullptr),
0013 release_len_(0),
0014 processName_start_(nullptr),
0015 processName_len_(0),
0016 outputModuleLabel_start_(nullptr),
0017 outputModuleLabel_len_(0),
0018 outputModuleId_(0),
0019 hlt_trig_start_(nullptr),
0020 hlt_trig_count_(0),
0021 hlt_trig_len_(0),
0022 hlt_select_start_(nullptr),
0023 hlt_select_count_(0),
0024 hlt_select_len_(0),
0025 l1_trig_start_(nullptr),
0026 l1_trig_count_(0),
0027 l1_trig_len_(0),
0028 adler32_chksum_(0),
0029 host_name_start_(nullptr),
0030 host_name_len_(0),
0031 desc_start_(nullptr),
0032 desc_len_(0) {
0033 if (protocolVersion() == 2) {
0034 std::cout << "Protocol Version 2 encountered" << std::endl;
0035 release_start_ = buf_ + sizeof(InitHeader) - (sizeof(uint32) * 2);
0036
0037
0038 } else {
0039 release_start_ = buf_ + sizeof(InitHeader);
0040 }
0041 release_len_ = *release_start_;
0042 release_start_ += sizeof(uint8);
0043 uint8* pos = release_start_ + release_len_;
0044
0045
0046 if (protocolVersion() > 3) {
0047
0048 processName_len_ = *pos;
0049 processName_start_ = (uint8*)(pos + sizeof(uint8));
0050 pos = processName_start_ + processName_len_;
0051
0052
0053 if (protocolVersion() > 4) {
0054 outputModuleLabel_len_ = *pos;
0055 outputModuleLabel_start_ = (uint8*)(pos + sizeof(uint8));
0056 pos = outputModuleLabel_start_ + outputModuleLabel_len_;
0057
0058
0059 if (protocolVersion() > 5) {
0060 outputModuleId_ = convert32(pos);
0061 pos += sizeof(char_uint32);
0062 }
0063 }
0064 }
0065
0066 hlt_trig_start_ = pos;
0067 hlt_trig_count_ = convert32(hlt_trig_start_);
0068 hlt_trig_start_ += sizeof(char_uint32);
0069 hlt_trig_len_ = convert32(hlt_trig_start_);
0070 hlt_trig_start_ += sizeof(char_uint32);
0071 pos = hlt_trig_start_ + hlt_trig_len_;
0072
0073 if (protocolVersion() > 4) {
0074 hlt_select_start_ = pos;
0075 hlt_select_count_ = convert32(hlt_select_start_);
0076 hlt_select_start_ += sizeof(char_uint32);
0077 hlt_select_len_ = convert32(hlt_select_start_);
0078 hlt_select_start_ += sizeof(char_uint32);
0079 pos = hlt_select_start_ + hlt_select_len_;
0080 }
0081
0082 l1_trig_start_ = pos;
0083 l1_trig_count_ = convert32(l1_trig_start_);
0084 l1_trig_start_ += sizeof(char_uint32);
0085 l1_trig_len_ = convert32(l1_trig_start_);
0086 l1_trig_start_ += sizeof(char_uint32);
0087 pos = l1_trig_start_ + l1_trig_len_;
0088
0089 if (protocolVersion() > 7) {
0090 adler32_chksum_ = convert32(pos);
0091 pos += sizeof(uint32);
0092
0093 if (protocolVersion() <= 9) {
0094 host_name_start_ = pos;
0095 host_name_len_ = *host_name_start_;
0096 host_name_start_ += sizeof(uint8);
0097 pos = host_name_start_ + host_name_len_;
0098 }
0099 }
0100
0101 desc_start_ = pos;
0102 desc_len_ = convert32(desc_start_);
0103 desc_start_ += sizeof(char_uint32);
0104 }
0105
0106 uint32 InitMsgView::run() const {
0107 InitHeader* h = reinterpret_cast<InitHeader*>(buf_);
0108 return convert32(h->run_);
0109 }
0110
0111 uint32 InitMsgView::protocolVersion() const {
0112 InitHeader* h = reinterpret_cast<InitHeader*>(buf_);
0113 return h->version_.protocol_;
0114 }
0115
0116 void InitMsgView::pset(uint8* put_here) const {
0117 InitHeader* h = reinterpret_cast<InitHeader*>(buf_);
0118 memcpy(put_here, h->version_.pset_id_, sizeof(h->version_.pset_id_));
0119 }
0120
0121 std::string InitMsgView::releaseTag() const {
0122 return std::string(reinterpret_cast<char*>(release_start_), release_len_);
0123 }
0124
0125 std::string InitMsgView::processName() const {
0126 if (protocolVersion() < 4)
0127 throw cms::Exception("Invalid Message Version", "InitMsgView")
0128 << "Process Name is only supported in Protocol Version 4 and above"
0129 << ".\n";
0130
0131 return std::string(reinterpret_cast<char*>(processName_start_), processName_len_);
0132 }
0133
0134 std::string InitMsgView::outputModuleLabel() const {
0135 if (protocolVersion() < 5)
0136 throw cms::Exception("Invalid Message Version", "InitMsgView")
0137 << "Output Module Label is only supported in Protocol Version 5 and above"
0138 << ".\n";
0139
0140 return std::string(reinterpret_cast<char*>(outputModuleLabel_start_), outputModuleLabel_len_);
0141 }
0142
0143 void InitMsgView::hltTriggerNames(Strings& save_here) const {
0144 MsgTools::getNames(hlt_trig_start_, hlt_trig_len_, save_here);
0145 }
0146
0147 void InitMsgView::hltTriggerSelections(Strings& save_here) const {
0148 if (protocolVersion() < 5)
0149 throw cms::Exception("Invalid Message Version", "InitMsgView")
0150 << "HLT trigger selections are only supported in Protocol Version 5 and above"
0151 << ".\n";
0152
0153 MsgTools::getNames(hlt_select_start_, hlt_select_len_, save_here);
0154 }
0155
0156 void InitMsgView::l1TriggerNames(Strings& save_here) const {
0157 MsgTools::getNames(l1_trig_start_, l1_trig_len_, save_here);
0158 }
0159
0160 uint32 InitMsgView::eventHeaderSize() const {
0161 if (protocolVersion() == 2) {
0162
0163
0164 uint32 hlt_sz = get_hlt_bit_cnt();
0165 if (hlt_sz != 0)
0166 hlt_sz = 1 + ((hlt_sz - 1) / 4);
0167
0168 uint32 l1_sz = get_l1_bit_cnt();
0169 if (l1_sz != 0)
0170 l1_sz = 1 + ((l1_sz - 1) / 8);
0171
0172 return 1 + (4 * 8) + hlt_sz + l1_sz;
0173 }
0174
0175 InitHeader* h = reinterpret_cast<InitHeader*>(buf_);
0176 return convert32(h->event_header_size_);
0177 }
0178
0179
0180
0181
0182
0183
0184
0185
0186 std::string InitMsgView::hostName() const {
0187 if (host_name_start_) {
0188 std::string host_name(reinterpret_cast<char*>(host_name_start_), host_name_len_);
0189 size_t found = host_name.find('\0');
0190 if (found != std::string::npos) {
0191 return std::string(host_name, 0, found);
0192 } else {
0193 return host_name;
0194 }
0195 } else {
0196 return "n/a";
0197 }
0198 }