CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/IOPool/Streamer/src/InitMsgBuilder.cc

Go to the documentation of this file.
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   // fixed length parts
00025   new (&h->version_) Version(v);
00026   convert(run,h->run_);
00027   // variable length parts
00028   uint32 tag_len = strlen(release_tag);
00029   assert(tag_len < 0x00ff);
00030   uint8* pos = buf_+sizeof(InitHeader);
00031 
00032   *pos++ = tag_len; // length of release tag
00033   memcpy(pos,release_tag,tag_len); // copy release tag in
00034   pos += tag_len;
00035 
00036   //Lets put Process Name (Length and then Name) right after release_tag
00037   uint32 process_name_len = strlen(process_name);
00038   assert(process_name_len < 0x00ff);
00039   //Put process_name_len
00040   *pos++ = process_name_len;
00041   //Put process_name
00042   memcpy(pos,process_name,process_name_len);
00043   pos += process_name_len;
00044 
00045   // output module label next
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   // output module ID next
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   // adler32 check sum of data blob
00061   convert(adler_chksum, pos);
00062   pos = pos + sizeof(uint32);
00063 
00064   // put host name (Length and then Name) right after check sum
00065   //uint32 host_name_len = strlen(host_name);
00066   // actually make the host_name a fixed length as the init message header size appears in the
00067   // Init message and only one goes to a file whereas events can come from any node
00068   // We want the max length to be determined inside this Init Message Builder
00069   uint32 host_name_len = MAX_INITHOSTNAME_LEN;
00070   assert(host_name_len < 0x00ff);
00071   //Put host_name_len
00072   *pos++ = host_name_len;
00073 
00074   //Put host_name
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   // Two news fileds added to InitMsg in Proto V3 init_header_size, and event_header_size.
00090   //Set the size of Init Header Start of buf to Start of desc.
00091   convert((uint32)(data_addr_ - buf_), h->init_header_size_);
00092 
00093   // 18-Apr-2008, KAB:  create a dummy event message so that we can
00094   // determine the expected event header size.  (Previously, the event
00095   // header size was hard-coded.)
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];  // not large enough for a real event!
00100   uint32_t adler32 = 0;
00101   //char host_name[255];
00102   //int got_host = gethostname(host_name, 255);
00103   //if(got_host != 0) strcpy(host_name, "noHostNameFoundOrTooLong");
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   //Size of Event Header
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