CMS 3D CMS Logo

EventMsgBuilder.cc
Go to the documentation of this file.
5 #include <cassert>
6 #include <cstring>
7 
8 static constexpr int MAX_HOSTNAME_LEN = 25;
9 
10 using namespace edm::streamer;
11 
13  uint32 size,
14  uint32 run,
15  uint64 event,
16  uint32 lumi,
17  uint32 outModId,
18  uint32 droppedEventsCount,
19  std::vector<bool>& l1_bits,
20  uint8* hlt_bits,
21  uint32 hlt_bit_count,
22  uint32 adler_chksum,
23  const char* host_name)
24  : buf_((uint8*)buf), size_(size) {
25  uint32 expectedHeaderSize = computeHeaderSize(l1_bits.size(), hlt_bit_count);
26  if (expectedHeaderSize > size_) {
27  throw cms::Exception("EventMsgBuilder")
28  << "The buffer used to build the event message (" << size_
29  << " bytes) is not large enough to holde the event header (" << expectedHeaderSize << " bytes)";
30  }
31 
32  // Note: any change to the pos increment logic should be reflected in computeHeaderSize()
33  uint8* pos = buf_;
34 
35  // Set the event header
37  h->protocolVersion_ = 11;
38  convert(run, h->run_);
39  convert(event, h->event_);
40  convert(lumi, h->lumi_);
41  convert(outModId, h->outModId_);
42  convert(droppedEventsCount, h->droppedEventsCount_);
43  pos += sizeof(EventHeader);
44 
45  // Set the L1T triggers count
46  uint32 l1_count = l1_bits.size();
47  convert(l1_count, pos);
48  pos += sizeof(uint32);
49 
50  // Set the L1T bits
51  uint32 l1_sz = (l1_bits.size() + 8 - 1) / 8; // L1T results (1 bit per trigger)
52  memset(pos, 0x00, l1_sz); // clear the bits
53  for (std::vector<bool>::size_type i = 0; i < l1_bits.size(); ++i) {
54  uint8 v = l1_bits[i] ? 1 : 0;
55  pos[i / 8] |= (v << (i & 0x07));
56  }
57  pos += l1_sz;
58 
59  // Set HLT triggers count
60  convert(hlt_bit_count, pos);
61  pos += sizeof(uint32);
62 
63  // Copy the HLT bits and increment pos
64  uint32 hlt_sz = (hlt_bit_count + 4 - 1) / 4; // HLT results (2 bits per trigger)
65  pos = std::copy(hlt_bits, hlt_bits + hlt_sz, pos);
66 
67  // Set the Adler32 check sum of data blob
68  convert(adler_chksum, pos);
69  pos += sizeof(uint32);
70 
71  // Put the host name (length and then name) right after the check sum.
72  // Use a fixed length for the host_name because the event header size appears in the
73  // init message and only one goes to a file whereas events can come from any node,
74  // while we want the max length to be determined inside this Event Message Builder.
75 
76  // Set the host_name_len and increment pos
77  assert(MAX_HOSTNAME_LEN < 0x00ff);
78  *pos++ = MAX_HOSTNAME_LEN;
79 
80  // Copy up to MAX_HOSTNAME_LEN characters of the host_name and pad any extra space
81  // with null characters
82  memset(pos, '\0', MAX_HOSTNAME_LEN);
83  strncpy((char*)pos, host_name, MAX_HOSTNAME_LEN - 1);
85 
86  event_addr_ = pos + sizeof(char_uint32);
87  setEventLength(0);
88 
89  // Check that the size computed by computeHeaderSize() matches what is actually used.
90  if (headerSize() != expectedHeaderSize) {
91  throw cms::Exception("EventMsgBuilder")
92  << "The event message header size (" << headerSize() << " bytes) does not match the computed value ("
93  << expectedHeaderSize << " bytes)";
94  }
95 }
96 
99  convert(value, h->origDataSize_);
100 }
101 
103  convert(len, event_addr_ - sizeof(char_uint32));
105  new (&h->header_) Header(Header::EVENT, event_addr_ - buf_ + len);
106 }
107 
109  HeaderView v(buf_);
110  return v.size();
111 }
112 
114  uint32 size = sizeof(EventHeader); // event header
115  size += sizeof(uint32); // L1T triggers count
116  size += (l1t_bit_count + 8 - 1) / 8; // L1T results (1 bit per trigger)
117  size += sizeof(uint32); // HLT triggers count
118  size += (hlt_bit_count + 4 - 1) / 4; // HLT results (2 bits per trigger)
119  size += sizeof(uint32); // adler32 check sum
120  size += 1; // host name length
121  size += MAX_HOSTNAME_LEN; // host name
122  size += sizeof(char_uint32); // event address
123  return size;
124 }
void convert(uint32 i, char_uint32 v)
Definition: MsgTools.h:43
EventMsgBuilder(void *buf, uint32 size, uint32 run, uint64 event, uint32 lumi, uint32 outModId, uint32 droppedEventsCount, std::vector< bool > &l1_bits, uint8 *hlt_bits, uint32 hlt_bit_count, uint32 adler32_chksum, const char *host_name)
assert(be >=bs)
uint16_t size_type
unsigned char uint8
Definition: MsgTools.h:12
Definition: value.py:1
static constexpr int MAX_HOSTNAME_LEN
static uint32 computeHeaderSize(uint32 l1t_bit_count, uint32 hlt_bit_count)
unsigned long long uint64
Definition: MsgTools.h:15
unsigned char char_uint32[sizeof(uint32)]
Definition: MsgTools.h:17
unsigned int uint32
Definition: MsgTools.h:14
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
Definition: event.py:1