CMS 3D CMS Logo

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