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
0008
0009
0010
0011
0012
0013
0014
0015
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);
0033 l1_bits_count_ = convert32(l1_bit_size_ptr);
0034 uint32 l1_sz = l1_bits_count_;
0035
0036
0037
0038
0039
0040
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
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 }