CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
InitMsgBuilder.cc
Go to the documentation of this file.
4 #include <cassert>
5 #include <cstring>
6 #include <stdint.h>
7 #include <unistd.h>
8 
9 #define MAX_INITHOSTNAME_LEN 25
10 
12  uint32 run, const Version& v,
13  const char* release_tag,
14  const char* process_name,
15  const char* output_module_label,
16  uint32 output_module_id,
17  const Strings& hlt_names,
18  const Strings& hlt_selections,
19  const Strings& l1_names,
20  uint32 adler_chksum, const char* host_name):
21  buf_((uint8*)buf),size_(size)
22 {
24  // fixed length parts
25  new (&h->version_) Version(v);
26  convert(run,h->run_);
27  // variable length parts
28  uint32 tag_len = strlen(release_tag);
29  assert(tag_len < 0x00ff);
30  uint8* pos = buf_+sizeof(InitHeader);
31 
32  *pos++ = tag_len; // length of release tag
33  memcpy(pos,release_tag,tag_len); // copy release tag in
34  pos += tag_len;
35 
36  //Lets put Process Name (Length and then Name) right after release_tag
37  uint32 process_name_len = strlen(process_name);
38  assert(process_name_len < 0x00ff);
39  //Put process_name_len
40  *pos++ = process_name_len;
41  //Put process_name
42  memcpy(pos,process_name,process_name_len);
43  pos += process_name_len;
44 
45  // output module label next
46  uint32 outmod_label_len = strlen(output_module_label);
47  assert(outmod_label_len < 0x00ff);
48  *pos++ = outmod_label_len;
49  memcpy(pos,output_module_label,outmod_label_len);
50  pos += outmod_label_len;
51 
52  // output module ID next
53  convert(output_module_id, pos);
54  pos += sizeof(char_uint32);
55 
56  pos = MsgTools::fillNames(hlt_names,pos);
57  pos = MsgTools::fillNames(hlt_selections,pos);
58  pos = MsgTools::fillNames(l1_names,pos);
59 
60  // adler32 check sum of data blob
61  convert(adler_chksum, pos);
62  pos = pos + sizeof(uint32);
63 
64  // put host name (Length and then Name) right after check sum
65  //uint32 host_name_len = strlen(host_name);
66  // actually make the host_name a fixed length as the init message header size appears in the
67  // Init message and only one goes to a file whereas events can come from any node
68  // We want the max length to be determined inside this Init Message Builder
69  uint32 host_name_len = MAX_INITHOSTNAME_LEN;
70  assert(host_name_len < 0x00ff);
71  //Put host_name_len
72  *pos++ = host_name_len;
73 
74  //Put host_name
75  uint32 real_len = strlen(host_name);
76  if(real_len < host_name_len) {
77  char hostname_2use[MAX_INITHOSTNAME_LEN];
78  memset(hostname_2use,'\0',host_name_len);
79  memcpy(hostname_2use,host_name,real_len);
80  memcpy(pos,hostname_2use,host_name_len);
81  } else {
82  memcpy(pos,host_name,host_name_len);
83  }
84  pos += host_name_len;
85 
86  data_addr_ = pos + sizeof(char_uint32);
87  setDataLength(0);
88 
89  // Two news fileds added to InitMsg in Proto V3 init_header_size, and event_header_size.
90  //Set the size of Init Header Start of buf to Start of desc.
92 
93  // 18-Apr-2008, KAB: create a dummy event message so that we can
94  // determine the expected event header size. (Previously, the event
95  // header size was hard-coded.)
96  std::vector<bool> dummyL1Bits(l1_names.size());
97  std::vector<char> dummyHLTBits(hlt_names.size());
98  const uint32 TEMP_BUFFER_SIZE = 256;
99  char msgBuff[TEMP_BUFFER_SIZE]; // not large enough for a real event!
100  uint32_t adler32 = 0;
101  //char host_name[255];
102  //int got_host = gethostname(host_name, 255);
103  //if(got_host != 0) strcpy(host_name, "noHostNameFoundOrTooLong");
104  EventMsgBuilder dummyMsg(&msgBuff[0], TEMP_BUFFER_SIZE, 0, 0, 0, 0, 0,
105  dummyL1Bits, (uint8*) &dummyHLTBits[0],
106  hlt_names.size(), adler32, host_name);
107 
108  //Size of Event Header
109  uint32 eventHeaderSize = dummyMsg.headerSize();
110  convert(eventHeaderSize, h->event_header_size_);
111 }
112 
114 {
115  convert(len,data_addr_-sizeof(char_uint32));
117  new (&h->header_) Header(Header::INIT, data_addr_ - buf_ + len);
118 }
119 
120 
122 {
123 
124  HeaderView v(buf_);
125  return v.size();
126 }
127 
128 
130 {
132  return convert32(h->run_);
133 }
134 
Header header_
Definition: InitMessage.h:53
std::vector< std::string > Strings
Definition: MsgTools.h:18
char_uint32 event_header_size_
Definition: InitMessage.h:57
uint8 * data_addr_
void setDataLength(uint32 registry_length)
void convert(uint32 i, char_uint32 v)
Definition: MsgTools.h:46
uint32 size() const
Version version_
Definition: InitMessage.h:54
InitMsgBuilder(void *msg_mem, uint32 size, uint32 run, const Version &v, const char *release_tag, const char *process_name, const char *output_module_label, uint32 output_module_id, const Strings &hlt_names, const Strings &hlt_selections, const Strings &l1_names, uint32 adler32_chksum, const char *host_name)
unsigned int uint32
Definition: MsgTools.h:13
unsigned char char_uint32[sizeof(uint32)]
Definition: MsgTools.h:16
#define MAX_INITHOSTNAME_LEN
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
uint32 size() const
Definition: MsgHeader.h:35
char_uint32 run_
Definition: InitMessage.h:55
uint32 convert32(char_uint32 v)
Definition: MsgTools.h:30
unsigned char uint8
Definition: MsgTools.h:11
uint8 * fillNames(const Strings &names, uint8 *pos)
Definition: MsgTools.h:75
uint32 headerSize() const
size_(0)
Definition: OwnArray.h:181
uint32 run() const
tuple size
Write out results.
mathSSE::Vec4< T > v
char_uint32 init_header_size_
Definition: InitMessage.h:56