00001 #include "IOPool/Streamer/interface/InitMsgBuilder.h"
00002 #include "IOPool/Streamer/interface/EventMsgBuilder.h"
00003 #include "IOPool/Streamer/interface/MsgHeader.h"
00004 #include <cassert>
00005 #include <cstring>
00006 #include <stdint.h>
00007 #include <unistd.h>
00008
00009 #define MAX_INITHOSTNAME_LEN 25
00010
00011 InitMsgBuilder::InitMsgBuilder(void* buf, uint32 size,
00012 uint32 run, const Version& v,
00013 const char* release_tag,
00014 const char* process_name,
00015 const char* output_module_label,
00016 uint32 output_module_id,
00017 const Strings& hlt_names,
00018 const Strings& hlt_selections,
00019 const Strings& l1_names,
00020 uint32 adler_chksum, const char* host_name):
00021 buf_((uint8*)buf),size_(size)
00022 {
00023 InitHeader* h = (InitHeader*)buf_;
00024
00025 new (&h->version_) Version(v);
00026 convert(run,h->run_);
00027
00028 uint32 tag_len = strlen(release_tag);
00029 assert(tag_len < 0x00ff);
00030 uint8* pos = buf_+sizeof(InitHeader);
00031
00032 *pos++ = tag_len;
00033 memcpy(pos,release_tag,tag_len);
00034 pos += tag_len;
00035
00036
00037 uint32 process_name_len = strlen(process_name);
00038 assert(process_name_len < 0x00ff);
00039
00040 *pos++ = process_name_len;
00041
00042 memcpy(pos,process_name,process_name_len);
00043 pos += process_name_len;
00044
00045
00046 uint32 outmod_label_len = strlen(output_module_label);
00047 assert(outmod_label_len < 0x00ff);
00048 *pos++ = outmod_label_len;
00049 memcpy(pos,output_module_label,outmod_label_len);
00050 pos += outmod_label_len;
00051
00052
00053 convert(output_module_id, pos);
00054 pos += sizeof(char_uint32);
00055
00056 pos = MsgTools::fillNames(hlt_names,pos);
00057 pos = MsgTools::fillNames(hlt_selections,pos);
00058 pos = MsgTools::fillNames(l1_names,pos);
00059
00060
00061 convert(adler_chksum, pos);
00062 pos = pos + sizeof(uint32);
00063
00064
00065
00066
00067
00068
00069 uint32 host_name_len = MAX_INITHOSTNAME_LEN;
00070 assert(host_name_len < 0x00ff);
00071
00072 *pos++ = host_name_len;
00073
00074
00075 uint32 real_len = strlen(host_name);
00076 if(real_len < host_name_len) {
00077 char hostname_2use[MAX_INITHOSTNAME_LEN];
00078 memset(hostname_2use,'\0',host_name_len);
00079 memcpy(hostname_2use,host_name,real_len);
00080 memcpy(pos,hostname_2use,host_name_len);
00081 } else {
00082 memcpy(pos,host_name,host_name_len);
00083 }
00084 pos += host_name_len;
00085
00086 data_addr_ = pos + sizeof(char_uint32);
00087 setDataLength(0);
00088
00089
00090
00091 convert((uint32)(data_addr_ - buf_), h->init_header_size_);
00092
00093
00094
00095
00096 std::vector<bool> dummyL1Bits(l1_names.size());
00097 std::vector<char> dummyHLTBits(hlt_names.size());
00098 const uint32 TEMP_BUFFER_SIZE = 256;
00099 char msgBuff[TEMP_BUFFER_SIZE];
00100 uint32_t adler32 = 0;
00101
00102
00103
00104 EventMsgBuilder dummyMsg(&msgBuff[0], TEMP_BUFFER_SIZE, 0, 0, 0, 0, 0,
00105 dummyL1Bits, (uint8*) &dummyHLTBits[0],
00106 hlt_names.size(), adler32, host_name);
00107
00108
00109 uint32 eventHeaderSize = dummyMsg.headerSize();
00110 convert(eventHeaderSize, h->event_header_size_);
00111 }
00112
00113 void InitMsgBuilder::setDataLength(uint32 len)
00114 {
00115 convert(len,data_addr_-sizeof(char_uint32));
00116 InitHeader* h = (InitHeader*)buf_;
00117 new (&h->header_) Header(Header::INIT, data_addr_ - buf_ + len);
00118 }
00119
00120
00121 uint32 InitMsgBuilder::size() const
00122 {
00123
00124 HeaderView v(buf_);
00125 return v.size();
00126 }
00127
00128
00129 uint32 InitMsgBuilder::run() const
00130 {
00131 InitHeader* h = (InitHeader*)buf_;
00132 return convert32(h->run_);
00133 }
00134