File indexing completed on 2023-03-17 11:10:27
0001 #include "IOPool/Streamer/interface/EventMessage.h"
0002 #include "FWCore/Utilities/interface/Exception.h"
0003
0004 EventMsgView::EventMsgView(void* buf) : buf_((uint8*)buf), head_(buf), v2Detected_(false) {
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 if (protocolVersion() != 11) {
0015 throw cms::Exception("EventMsgView", "Invalid Message Version:")
0016 << "Only message version 10 is currently supported \n"
0017 << "(invalid value = " << protocolVersion() << ").\n"
0018 << "We support only reading and converting streamer files\n"
0019 << "using the same version of CMSSW used to created the\n"
0020 << "streamer file. This is because the streamer format is\n"
0021 << "only a temporary format, as such we do not support\n"
0022 << "backwards compatibility. If you really need a streamer\n"
0023 << "file for some reason, the work around is that you convert\n"
0024 << "the streamer file to a Root file using the CMSSW version\n"
0025 << "that created the streamer file, then convert the Root file\n"
0026 << "to a streamer file using a newer release that will produce\n"
0027 << "the version of streamer file that you desire.\n";
0028 }
0029
0030 uint8* l1_bit_size_ptr = buf_ + sizeof(EventHeader);
0031 l1_bits_count_ = convert32(l1_bit_size_ptr);
0032 uint32 l1_sz = l1_bits_count_;
0033
0034
0035
0036
0037
0038
0039
0040
0041 l1_bits_start_ = buf_ + sizeof(EventHeader) + sizeof(uint32);
0042
0043 if (v2Detected_ == false) {
0044 if (l1_sz != 0)
0045 l1_sz = 1 + ((l1_sz - 1) / 8);
0046 }
0047 uint8* hlt_bit_size_ptr = l1_bits_start_ + l1_sz;
0048 hlt_bits_count_ = convert32(hlt_bit_size_ptr);
0049 hlt_bits_start_ = hlt_bit_size_ptr + sizeof(uint32);
0050 uint32 hlt_sz = hlt_bits_count_;
0051 if (hlt_sz != 0)
0052 hlt_sz = 1 + ((hlt_sz - 1) / 4);
0053
0054 if (v2Detected_)
0055 hlt_sz = 2;
0056 uint8* adler32_start = hlt_bits_start_ + hlt_sz;
0057 adler32_chksum_ = convert32(adler32_start);
0058 host_name_start_ = adler32_start + sizeof(uint32);
0059 host_name_len_ = *host_name_start_;
0060 host_name_start_ += sizeof(uint8);
0061 event_start_ = host_name_start_ + host_name_len_;
0062 event_len_ = convert32(event_start_);
0063 event_start_ += sizeof(char_uint32);
0064 }
0065
0066 uint32 EventMsgView::protocolVersion() const {
0067 EventHeader* h = (EventHeader*)buf_;
0068 return h->protocolVersion_;
0069 }
0070
0071 uint32 EventMsgView::run() const {
0072 EventHeader* h = (EventHeader*)buf_;
0073 return convert32(h->run_);
0074 }
0075
0076 uint64 EventMsgView::event() const {
0077 EventHeader* h = (EventHeader*)buf_;
0078 return convert64(h->event_);
0079 }
0080
0081 uint32 EventMsgView::lumi() const {
0082 EventHeader* h = (EventHeader*)buf_;
0083 return convert32(h->lumi_);
0084 }
0085
0086 uint32 EventMsgView::origDataSize() const {
0087 EventHeader* h = (EventHeader*)buf_;
0088 return convert32(h->origDataSize_);
0089 }
0090
0091 uint32 EventMsgView::outModId() const {
0092 EventHeader* h = (EventHeader*)buf_;
0093 return convert32(h->outModId_);
0094 }
0095
0096 uint32 EventMsgView::droppedEventsCount() const {
0097 EventHeader* h = (EventHeader*)buf_;
0098 return convert32(h->droppedEventsCount_);
0099 return 0;
0100 }
0101
0102 void EventMsgView::l1TriggerBits(std::vector<bool>& put_here) const {
0103 put_here.clear();
0104 put_here.resize(l1_bits_count_);
0105
0106 for (std::vector<bool>::size_type i = 0; i < l1_bits_count_; ++i)
0107 put_here[i] = (bool)(l1_bits_start_[i / 8] & (1 << ((i & 0x07))));
0108 }
0109
0110 void EventMsgView::hltTriggerBits(uint8* put_here) const {
0111 uint32 hlt_sz = hlt_bits_count_;
0112 if (hlt_sz != 0)
0113 hlt_sz = 1 + ((hlt_sz - 1) / 4);
0114
0115 if (v2Detected_)
0116 hlt_sz = 2;
0117
0118 std::copy(hlt_bits_start_, hlt_bits_start_ + hlt_sz, put_here);
0119 }
0120
0121 std::string EventMsgView::hostName() const {
0122
0123 std::string host_name(reinterpret_cast<char*>(host_name_start_), host_name_len_);
0124 size_t found = host_name.find('\0');
0125 if (found != std::string::npos) {
0126 return std::string(host_name, 0, found);
0127 } else {
0128 return host_name;
0129 }
0130 }