CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/IOPool/Streamer/src/InitMessage.cc

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