CMS 3D CMS Logo

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