CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/IOPool/Streamer/src/EventMessage.cc

Go to the documentation of this file.
00001 #include "IOPool/Streamer/interface/EventMessage.h"
00002 #include "FWCore/Utilities/interface/Exception.h"
00003 
00004 
00005 EventMsgView::EventMsgView(void* buf):
00006   buf_((uint8*)buf),head_(buf),
00007   v2Detected_(false)
00008 { 
00009   // 29-Jan-2008, KAB - adding an explicit version number.
00010   // We'll start with 5 to match the new version of the INIT message.
00011   // We support earlier versions of the full protocol, of course, but since
00012   // we didn't have an explicit version number in the Event Message before
00013   // now, we have to limit what we can handle to versions that have the
00014   // version number included (>= 5).
00015 
00016   // 18-Jul-2008, wmtan - payload changed for version 7.
00017   // So we no longer support previous formats.
00018   if (protocolVersion() != 9) {
00019     throw cms::Exception("EventMsgView", "Invalid Message Version:")
00020       << "Only message version 9 is currently supported \n"
00021       << "(invalid value = " << protocolVersion() << ").\n"
00022       << "We support only reading and converting streamer files\n"
00023       << "using the same version of CMSSW used to created the\n"
00024       << "streamer file. This is because the streamer format is\n"
00025       << "only a temporary format, as such we do not support\n"
00026       << "backwards compatibility. If you really need a streamer\n"
00027       << "file for some reason, the work around is that you convert\n"
00028       << "the streamer file to a Root file using the CMSSW version\n"
00029       << "that created the streamer file, then convert the Root file\n"
00030       << "to a streamer file using a newer release that will produce\n"
00031       << "the version of streamer file that you desire.\n";
00032   }
00033 
00034   uint8* l1_bit_size_ptr = buf_ + sizeof(EventHeader); //Just after Header 
00035   l1_bits_count_ = convert32(l1_bit_size_ptr); 
00036   uint32 l1_sz = l1_bits_count_;
00037 // No point! Not supporting older versions and causes problems in unit
00038 // tests that uses l1_bits_count_ == 11, and could cause problems later if using 11
00039   //Lets detect if thats V2 message 
00040   //if (l1_bits_count_ == 11) {
00041   //        l1_sz = 1; 
00042   //        v2Detected_=true;
00043   //}
00044 
00045   l1_bits_start_ = buf_ + sizeof(EventHeader) + sizeof(uint32); 
00046 
00047   if (v2Detected_ == false) { 
00048      if (l1_sz != 0) l1_sz = 1 + ((l1_sz-1)/8);
00049   }
00050   uint8* hlt_bit_size_ptr = l1_bits_start_ + l1_sz; 
00051   hlt_bits_count_ = convert32(hlt_bit_size_ptr); 
00052   hlt_bits_start_ = hlt_bit_size_ptr + sizeof(uint32); 
00053   uint32 hlt_sz = hlt_bits_count_;
00054   if (hlt_sz != 0) hlt_sz = 1+ ((hlt_sz-1)/4);
00055 
00056   if(v2Detected_) hlt_sz=2;
00057   uint8* adler32_start = hlt_bits_start_ + hlt_sz; 
00058   adler32_chksum_ = convert32(adler32_start);
00059   host_name_start_ = adler32_start + sizeof(uint32);
00060   host_name_len_ = *host_name_start_;
00061   host_name_start_ += sizeof(uint8);
00062   event_start_ = host_name_start_ + host_name_len_;
00063   event_len_ = convert32(event_start_); 
00064   event_start_ += sizeof(char_uint32); 
00065 }
00066 
00067 uint32 EventMsgView::protocolVersion() const
00068 {
00069   EventHeader* h = (EventHeader*)buf_;
00070   return h->protocolVersion_;
00071 }
00072 
00073 uint32 EventMsgView::run() const
00074 {
00075   EventHeader* h = (EventHeader*)buf_;
00076   return convert32(h->run_);
00077 }
00078 
00079 uint32 EventMsgView::event() const
00080 {
00081   EventHeader* h = (EventHeader*)buf_;
00082   return convert32(h->event_);
00083 }
00084 
00085 uint32 EventMsgView::lumi() const
00086 {
00087   EventHeader* h = (EventHeader*)buf_;
00088   return convert32(h->lumi_);
00089 }
00090 
00091 uint32 EventMsgView::origDataSize() const
00092 {
00093   EventHeader* h = (EventHeader*)buf_;
00094   return convert32(h->origDataSize_);
00095 }
00096 
00097 uint32 EventMsgView::outModId() const
00098 {
00099   EventHeader* h = (EventHeader*)buf_;
00100   return convert32(h->outModId_);
00101 }
00102 
00103 uint32 EventMsgView::droppedEventsCount() const
00104 {
00105   EventHeader* h = (EventHeader*)buf_;
00106   return convert32(h->droppedEventsCount_);
00107   return 0;
00108 }
00109 
00110 void EventMsgView::l1TriggerBits(std::vector<bool>& put_here) const
00111 {
00112   put_here.clear();
00113   put_here.resize(l1_bits_count_);
00114 
00115   for(std::vector<bool>::size_type i = 0; i < l1_bits_count_; ++i)
00116     put_here[i] = (bool)(l1_bits_start_[i/8] & (1<<((i&0x07))));
00117 }
00118 
00119 void EventMsgView::hltTriggerBits(uint8* put_here) const
00120 {
00121   uint32 hlt_sz = hlt_bits_count_;
00122   if (hlt_sz != 0) hlt_sz = 1 + ((hlt_sz-1)/4);
00123 
00124   if(v2Detected_) hlt_sz=2;
00125 
00126   std::copy(hlt_bits_start_,hlt_bits_start_ + hlt_sz,
00127             put_here);
00128 }
00129 
00130 std::string EventMsgView::hostName() const
00131 {
00132    //return std::string(reinterpret_cast<char *>(host_name_start_),host_name_len_);
00133    std::string host_name(reinterpret_cast<char *>(host_name_start_),host_name_len_);
00134    size_t found = host_name.find('\0');
00135    if(found != std::string::npos) {
00136      return std::string(host_name, 0, found);
00137    } else {
00138      return host_name;
00139    }
00140 }
00141 
00142