Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-05-31 04:19:42

0001 #include "IOPool/Streamer/interface/EventMessage.h"
0002 #include "FWCore/Utilities/interface/Exception.h"
0003 
0004 using namespace edm::streamer;
0005 
0006 EventMsgView::EventMsgView(void* buf) : buf_((uint8*)buf), head_(buf), v2Detected_(false) {
0007   // 29-Jan-2008, KAB - adding an explicit version number.
0008   // We'll start with 5 to match the new version of the INIT message.
0009   // We support earlier versions of the full protocol, of course, but since
0010   // we didn't have an explicit version number in the Event Message before
0011   // now, we have to limit what we can handle to versions that have the
0012   // version number included (>= 5).
0013 
0014   // 18-Jul-2008, wmtan - payload changed for version 7.
0015   // So we no longer support previous formats.
0016   if (protocolVersion() != 11) {
0017     throw cms::Exception("EventMsgView", "Invalid Message Version:")
0018         << "Only message version 10 is currently supported \n"
0019         << "(invalid value = " << protocolVersion() << ").\n"
0020         << "We support only reading and converting streamer files\n"
0021         << "using the same version of CMSSW used to created the\n"
0022         << "streamer file. This is because the streamer format is\n"
0023         << "only a temporary format, as such we do not support\n"
0024         << "backwards compatibility. If you really need a streamer\n"
0025         << "file for some reason, the work around is that you convert\n"
0026         << "the streamer file to a Root file using the CMSSW version\n"
0027         << "that created the streamer file, then convert the Root file\n"
0028         << "to a streamer file using a newer release that will produce\n"
0029         << "the version of streamer file that you desire.\n";
0030   }
0031 
0032   uint8* l1_bit_size_ptr = buf_ + sizeof(EventHeader);  //Just after Header
0033   l1_bits_count_ = convert32(l1_bit_size_ptr);
0034   uint32 l1_sz = l1_bits_count_;
0035   // No point! Not supporting older versions and causes problems in unit
0036   // tests that uses l1_bits_count_ == 11, and could cause problems later if using 11
0037   //Lets detect if thats V2 message
0038   //if (l1_bits_count_ == 11) {
0039   //        l1_sz = 1;
0040   //        v2Detected_=true;
0041   //}
0042 
0043   l1_bits_start_ = buf_ + sizeof(EventHeader) + sizeof(uint32);
0044 
0045   if (v2Detected_ == false) {
0046     if (l1_sz != 0)
0047       l1_sz = 1 + ((l1_sz - 1) / 8);
0048   }
0049   uint8* hlt_bit_size_ptr = l1_bits_start_ + l1_sz;
0050   hlt_bits_count_ = convert32(hlt_bit_size_ptr);
0051   hlt_bits_start_ = hlt_bit_size_ptr + sizeof(uint32);
0052   uint32 hlt_sz = hlt_bits_count_;
0053   if (hlt_sz != 0)
0054     hlt_sz = 1 + ((hlt_sz - 1) / 4);
0055 
0056   if (v2Detected_)
0057     hlt_sz = 2;
0058   uint8* adler32_start = hlt_bits_start_ + hlt_sz;
0059   adler32_chksum_ = convert32(adler32_start);
0060   host_name_start_ = adler32_start + sizeof(uint32);
0061   host_name_len_ = *host_name_start_;
0062   host_name_start_ += sizeof(uint8);
0063   event_start_ = host_name_start_ + host_name_len_;
0064   event_len_ = convert32(event_start_);
0065   event_start_ += sizeof(char_uint32);
0066 }
0067 
0068 uint32 EventMsgView::protocolVersion() const {
0069   EventHeader* h = reinterpret_cast<EventHeader*>(buf_);
0070   return h->protocolVersion_;
0071 }
0072 
0073 uint32 EventMsgView::run() const {
0074   EventHeader* h = reinterpret_cast<EventHeader*>(buf_);
0075   return convert32(h->run_);
0076 }
0077 
0078 uint64 EventMsgView::event() const {
0079   EventHeader* h = reinterpret_cast<EventHeader*>(buf_);
0080   return convert64(h->event_);
0081 }
0082 
0083 uint32 EventMsgView::lumi() const {
0084   EventHeader* h = reinterpret_cast<EventHeader*>(buf_);
0085   return convert32(h->lumi_);
0086 }
0087 
0088 uint32 EventMsgView::origDataSize() const {
0089   EventHeader* h = reinterpret_cast<EventHeader*>(buf_);
0090   return convert32(h->origDataSize_);
0091 }
0092 
0093 uint32 EventMsgView::outModId() const {
0094   EventHeader* h = reinterpret_cast<EventHeader*>(buf_);
0095   return convert32(h->outModId_);
0096 }
0097 
0098 uint32 EventMsgView::droppedEventsCount() const {
0099   EventHeader* h = reinterpret_cast<EventHeader*>(buf_);
0100   return convert32(h->droppedEventsCount_);
0101   return 0;
0102 }
0103 
0104 bool EventMsgView::isEventMetaData() const { return run() == 0; }
0105 
0106 void EventMsgView::l1TriggerBits(std::vector<bool>& put_here) const {
0107   put_here.clear();
0108   put_here.resize(l1_bits_count_);
0109 
0110   for (std::vector<bool>::size_type i = 0; i < l1_bits_count_; ++i)
0111     put_here[i] = (bool)(l1_bits_start_[i / 8] & (1 << ((i & 0x07))));
0112 }
0113 
0114 void EventMsgView::hltTriggerBits(uint8* put_here) const {
0115   uint32 hlt_sz = hlt_bits_count_;
0116   if (hlt_sz != 0)
0117     hlt_sz = 1 + ((hlt_sz - 1) / 4);
0118 
0119   if (v2Detected_)
0120     hlt_sz = 2;
0121 
0122   std::copy(hlt_bits_start_, hlt_bits_start_ + hlt_sz, put_here);
0123 }
0124 
0125 std::string EventMsgView::hostName() const {
0126   //return std::string(reinterpret_cast<char *>(host_name_start_),host_name_len_);
0127   std::string host_name(reinterpret_cast<char*>(host_name_start_), host_name_len_);
0128   size_t found = host_name.find('\0');
0129   if (found != std::string::npos) {
0130     return std::string(host_name, 0, found);
0131   } else {
0132     return host_name;
0133   }
0134 }