CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/src/IOPool/Streamer/src/EventMsgBuilder.cc

Go to the documentation of this file.
00001 #include "IOPool/Streamer/interface/EventMsgBuilder.h"
00002 #include "IOPool/Streamer/interface/EventMessage.h"
00003 #include "IOPool/Streamer/interface/MsgHeader.h"
00004 #include <cassert>
00005 #include <cstring>
00006 
00007 #define MAX_HOSTNAME_LEN 25
00008 
00009 EventMsgBuilder::EventMsgBuilder(void* buf, uint32 size,
00010                                  uint32 run, uint32 event, uint32 lumi,
00011                                  uint32 outModId, std::vector<bool>& l1_bits,
00012                                  uint8* hlt_bits, uint32 hlt_bit_count, 
00013                                  uint32 adler_chksum, const char* host_name):
00014   buf_((uint8*)buf),size_(size)
00015 {
00016   EventHeader* h = (EventHeader*)buf_;
00017   h->protocolVersion_ = 8;
00018   convert(run,h->run_);
00019   convert(event,h->event_);
00020   convert(lumi,h->lumi_);
00021   convert(outModId,h->outModId_);
00022   uint8* pos = buf_ + sizeof(EventHeader);
00023 
00024   // l1 count
00025   uint32 l1_count = l1_bits.size();
00026   convert(l1_count, pos);
00027   pos = pos + sizeof(uint32); 
00028 
00029   // set the l1 
00030   uint32 l1_sz = l1_bits.size();
00031   if (l1_sz != 0) l1_sz = 1 + ((l1_sz-1)/8);
00032  
00033   uint8* pos_end = pos + l1_sz;
00034   memset(pos,0x00, pos_end-pos); // clear the bits
00035   for(std::vector<bool>::size_type i = 0; i < l1_bits.size(); ++i) {
00036       uint8 v = l1_bits[i] ? 1 : 0;
00037       pos[i/8] |= (v << (i&0x07));
00038   }
00039   pos = pos_end;
00040 
00041   // hlt count
00042   convert(hlt_bit_count, pos); 
00043   pos = pos + sizeof(uint32);
00044 
00045   uint32 hlt_sz = hlt_bit_count;
00046   if (hlt_sz != 0) hlt_sz = 1+ ((hlt_sz-1)/4);
00047 
00048   // copy the hlt bits over
00049   pos = std::copy(hlt_bits, hlt_bits+hlt_sz, pos);
00050 
00051   // adler32 check sum of data blob
00052   convert(adler_chksum, pos);
00053   pos = pos + sizeof(uint32);
00054 
00055   // put host name (Length and then Name) right after check sum
00056   //uint32 host_name_len = strlen(host_name);
00057   // actually make the host_name a fixed length as the event header size appears in the
00058   // Init message and only one goes to a file whereas events can come from any node
00059   // We want the max length to be determined inside this Event Message Builder
00060   uint32 host_name_len = MAX_HOSTNAME_LEN;
00061   assert(host_name_len < 0x00ff);
00062   //Put host_name_len
00063   *pos++ = host_name_len;
00064 
00065   //Put host_name
00066   uint32 real_len = strlen(host_name);
00067   if(real_len < host_name_len) {
00068     char hostname_2use[MAX_HOSTNAME_LEN];
00069     memset(hostname_2use,'\0',host_name_len);
00070     memcpy(hostname_2use,host_name,real_len);
00071     memcpy(pos,hostname_2use,host_name_len);
00072   } else {
00073     memcpy(pos,host_name,host_name_len);
00074   }
00075   pos += host_name_len;
00076 
00077   event_addr_ = pos + sizeof(char_uint32);
00078   setEventLength(0);
00079 }
00080 
00081 void EventMsgBuilder::setOrigDataSize(uint32 value)
00082 {
00083   EventHeader* h = (EventHeader*)buf_;
00084   convert(value,h->origDataSize_);
00085 }
00086 
00087 void EventMsgBuilder::setEventLength(uint32 len)
00088 {
00089   convert(len,event_addr_-sizeof(char_uint32));
00090   EventHeader* h = (EventHeader*)buf_;
00091   new (&h->header_) Header(Header::EVENT,event_addr_-buf_+len);
00092 }
00093 
00094 uint32 EventMsgBuilder::size() const
00095 {
00096   HeaderView v(buf_);
00097   return v.size();
00098 }