Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:21:20

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