CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
StreamerOutputModuleBase.cc
Go to the documentation of this file.
1 
3 
13 //#include "FWCore/Utilities/interface/Digest.h"
17 
18 #include <string>
19 #include <unistd.h>
20 #include "zlib.h"
21 
23 
24 namespace {
25  //A utility function that packs bits from source into bytes, with
26  // packInOneByte as the numeber of bytes that are packed from source to dest.
27  void printBits(unsigned char c) {
28  for (int i = 7; i >= 0; --i) {
29  int bit = ((c >> i) & 1);
30  std::cout << " " << bit;
31  }
32  }
33 
34  void packIntoString(std::vector<unsigned char> const& source,
35  std::vector<unsigned char>& package) {
36  if (source.size() < 1) {return;}
37  unsigned int packInOneByte = 4;
38  unsigned int sizeOfPackage = 1+((source.size()-1)/packInOneByte); //Two bits per HLT
39 
40  package.resize(sizeOfPackage);
41  memset(&package[0], 0x00, sizeOfPackage);
42 
43  for (std::vector<unsigned char>::size_type i=0; i != source.size() ; ++i) {
44  unsigned int whichByte = i/packInOneByte;
45  unsigned int indxWithinByte = i % packInOneByte;
46  package[whichByte] = package[whichByte] | (source[i] << (indxWithinByte*2));
47  }
48  //for (unsigned int i=0; i !=package.size() ; ++i)
49  // printBits(package[i]);
50  // std::cout << std::endl;
51 
52  }
53 }
54 
55 namespace edm {
57  OutputModule(ps),
58  selections_(&keptProducts()[InEvent]),
59  maxEventSize_(ps.getUntrackedParameter<int>("max_event_size")),
60  useCompression_(ps.getUntrackedParameter<bool>("use_compression")),
61  compressionLevel_(ps.getUntrackedParameter<int>("compression_level")),
62  lumiSectionInterval_(ps.getUntrackedParameter<int>("lumiSection_interval")),
63  serializer_(selections_),
64  hltsize_(0),
65  lumi_(0),
66  l1bit_(0),
67  hltbits_(0),
68  origSize_(0) { // no compression as default value - we need this!
69 
70  // test luminosity sections
71  struct timeval now;
72  struct timezone dummyTZ;
73  gettimeofday(&now, &dummyTZ);
74  timeInSecSinceUTC = static_cast<double>(now.tv_sec) + (static_cast<double>(now.tv_usec)/1000000.0);
75 
76  if(useCompression_ == true) {
77  if(compressionLevel_ <= 0) {
78  FDEBUG(9) << "Compression Level = " << compressionLevel_
79  << " no compression" << std::endl;
81  useCompression_ = false;
82  } else if(compressionLevel_ > 9) {
83  FDEBUG(9) << "Compression Level = " << compressionLevel_
84  << " using max compression level 9" << std::endl;
86  }
87  }
88  serialize_databuffer.bufs_.resize(maxEventSize_);
89  int got_host = gethostname(host_name_, 255);
90  if(got_host != 0) strcpy(host_name_, "noHostNameFoundOrTooLong");
91  //loadExtraClasses();
92  // do the line below instead of loadExtraClasses() to avoid Root errors
94 
95  // 25-Jan-2008, KAB - pull out the trigger selection request
96  // which we need for the INIT message
98  }
99 
101 
102  void
104  start();
105  std::auto_ptr<InitMsgBuilder> init_message = serializeRegistry();
106  doOutputHeader(*init_message);
107  }
108 
109  void
111  stop();
112  }
113 
114  void
116 
117  void
119  stop(); // for closing of files, notify storage manager, etc.
120  }
121 
122  void
124 
125  void
127 
128  void
130  std::auto_ptr<EventMsgBuilder> msg = serializeEvent(e);
131  doOutputEvent(*msg); // You can't use msg in StreamerOutputModuleBase after this point
132  }
133 
134  std::auto_ptr<InitMsgBuilder>
136 
137  serializer_.serializeRegistry(serialize_databuffer);
138 
139  // resize bufs_ to reflect space used in serializer_ + header
140  // I just added an overhead for header of 50000 for now
141  unsigned int src_size = serialize_databuffer.currentSpaceUsed();
142  unsigned int new_size = src_size + 50000;
143  if(serialize_databuffer.header_buf_.size() < new_size) serialize_databuffer.header_buf_.resize(new_size);
144 
145  //Build the INIT Message
146  //Following values are strictly DUMMY and will be replaced
147  // once available with Utility function etc.
148  uint32 run = 1;
149 
150  //Get the Process PSet ID
153 
154  //In case we need to print it
155  // cms::Digest dig(toplevel.compactForm());
156  // cms::MD5Result r1 = dig.digest();
157  // std::string hexy = r1.toString();
158  // std::cout << "HEX Representation of Process PSetID: " << hexy << std::endl;
159 
160  //Setting protocol version V
161  Version v(8,(uint8*)toplevel.compactForm().c_str());
162 
163  Strings hltTriggerNames = getAllTriggerNames();
164  hltsize_ = hltTriggerNames.size();
165 
166  //L1 stays dummy as of today
167  Strings l1_names; //3
168  l1_names.push_back("t1");
169  l1_names.push_back("t10");
170  l1_names.push_back("t2");
171 
172  //Setting the process name to HLT
173  std::string processName = OutputModule::processName();
174 
175  std::string moduleLabel = description().moduleLabel();
176  uLong crc = crc32(0L, Z_NULL, 0);
177  Bytef* buf = (Bytef*) moduleLabel.data();
178  crc = crc32(crc, buf, moduleLabel.length());
179  outputModuleId_ = static_cast<uint32>(crc);
180 
181  std::auto_ptr<InitMsgBuilder> init_message(
182  new InitMsgBuilder(&serialize_databuffer.header_buf_[0], serialize_databuffer.header_buf_.size(),
183  run, v, getReleaseVersion().c_str() , processName.c_str(),
184  moduleLabel.c_str(), outputModuleId_,
185  hltTriggerNames, hltTriggerSelections_, l1_names,
186  (uint32)serialize_databuffer.adler32_chksum(), host_name_));
187 
188  // copy data into the destination message
189  unsigned char* src = serialize_databuffer.bufferPointer();
190  std::copy(src, src + src_size, init_message->dataAddress());
191  init_message->setDataLength(src_size);
192  return init_message;
193  }
194 
195  void
197 
198  hltbits_.clear(); // If there was something left over from last event
199 
201  //Trig const& prod = getTrigMask(e);
202  std::vector<unsigned char> vHltState;
203 
204  if (prod.isValid()) {
206  vHltState.push_back(((prod->at(i)).state()));
207  }
208  } else {
209  // We fill all Trigger bits to valid state.
211  vHltState.push_back(hlt::Pass);
212  }
213  }
214  //Pack into member hltbits_
215  packIntoString(vHltState, hltbits_);
216 
217  //This is Just a printing code.
218  //std::cout << "Size of hltbits:" << hltbits_.size() << std::endl;
219  //for(unsigned int i=0; i != hltbits_.size() ; ++i) {
220  // printBits(hltbits_[i]);
221  //}
222  //std::cout << "\n";
223  }
224 
225 // test luminosity sections
226  void
228  struct timeval now;
229  struct timezone dummyTZ;
230  gettimeofday(&now, &dummyTZ);
231  double timeInSec = static_cast<double>(now.tv_sec) + (static_cast<double>(now.tv_usec)/1000000.0) - timeInSecSinceUTC;
232  // what about overflows?
233  if(lumiSectionInterval_ > 0) lumi_ = static_cast<uint32>(timeInSec/lumiSectionInterval_) + 1;
234  }
235 
236  std::auto_ptr<EventMsgBuilder>
238  //Lets Build the Event Message first
239 
240  //Following is strictly DUMMY Data for L! Trig and will be replaced with actual
241  // once figured out, there is no logic involved here.
242  l1bit_.push_back(true);
243  l1bit_.push_back(true);
244  l1bit_.push_back(false);
245  //End of dummy data
246 
247  setHltMask(e);
248 
249  if (lumiSectionInterval_ == 0) {
250  lumi_ = e.luminosityBlock();
251  } else {
252  setLumiSection();
253  }
254 
256 
257  // resize bufs_ to reflect space used in serializer_ + header
258  // I just added an overhead for header of 50000 for now
259  unsigned int src_size = serialize_databuffer.currentSpaceUsed();
260  unsigned int new_size = src_size + 50000;
261  if(serialize_databuffer.bufs_.size() < new_size) serialize_databuffer.bufs_.resize(new_size);
262 
263  std::auto_ptr<EventMsgBuilder>
264  msg(new EventMsgBuilder(&serialize_databuffer.bufs_[0], serialize_databuffer.bufs_.size(), e.id().run(),
265  e.id().event(), lumi_, outputModuleId_,
266  l1bit_, (uint8*)&hltbits_[0], hltsize_,
267  (uint32)serialize_databuffer.adler32_chksum(), host_name_) );
268  msg->setOrigDataSize(origSize_); // we need this set to zero
269 
270  // copy data into the destination message
271  // an alternative is to have serializer only to the serialization
272  // in serializeEvent, and then call a new member "getEventData" that
273  // takes the compression arguments and a place to put the data.
274  // This will require one less copy. The only catch is that the
275  // space provided in bufs_ should be at least the uncompressed
276  // size + overhead for header because we will not know the actual
277  // compressed size.
278 
279  unsigned char* src = serialize_databuffer.bufferPointer();
280  std::copy(src,src + src_size, msg->eventAddr());
281  msg->setEventLength(src_size);
282  if(useCompression_) msg->setOrigDataSize(serialize_databuffer.currentEventSize());
283 
284  l1bit_.clear(); //Clear up for the next event to come.
285  return msg;
286  }
287 
288  void
290  desc.addUntracked<int>("max_event_size", 7000000)
291  ->setComment("Starting size in bytes of the serialized event buffer.");
292  desc.addUntracked<bool>("use_compression", true)
293  ->setComment("If True, compression will be used to write streamer file.");
294  desc.addUntracked<int>("compression_level", 1)
295  ->setComment("ROOT compression level to use.");
296  desc.addUntracked<int>("lumiSection_interval", 0)
297  ->setComment("If 0, use lumi section number from event.\n"
298  "If not 0, the interval in seconds between fake lumi sections.");
300  }
301 } // end of namespace-edm
RunNumber_t run() const
Definition: EventID.h:42
EventNumber_t event() const
Definition: EventID.h:44
static void fillDescription(ParameterSetDescription &desc)
int i
Definition: DBlmapReader.cc:9
void printBits(unsigned char c)
Definition: DumpTools.cc:134
value_type compactForm() const
Definition: Hash.h:192
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
virtual void doOutputHeader(InitMsgBuilder const &init_message) const =0
void setHltMask(EventPrincipal const &e)
std::auto_ptr< EventMsgBuilder > serializeEvent(EventPrincipal const &e)
std::vector< std::string > Strings
Definition: MsgTools.h:18
EventID const & id() const
std::string const & processName() const
Definition: OutputModule.h:56
static SerializeDataBuffer serialize_databuffer
std::auto_ptr< InitMsgBuilder > serializeRegistry()
LuminosityBlockNumber_t luminosityBlock() const
#define FDEBUG(lev)
Definition: DebugMacros.h:18
virtual void doOutputEvent(EventMsgBuilder const &msg) const =0
std::string const & moduleLabel() const
uint16_t size_type
virtual void stop() const =0
virtual void endRun(RunPrincipal const &)
virtual void beginRun(RunPrincipal const &)
unsigned int currentSpaceUsed() const
accept
Definition: HLTenums.h:22
static std::vector< std::string > getEventSelectionVString(edm::ParameterSet const &pset)
virtual void writeRun(RunPrincipal const &)
bool isValid() const
Definition: HandleBase.h:76
virtual void start() const =0
int serializeEvent(EventPrincipal const &eventPrincipal, ParameterSetID const &selectorConfig, bool use_compression, int compression_level, SerializeDataBuffer &data_buffer)
tuple prod
Definition: CrabTask.py:87
unsigned int uint32
Definition: MsgTools.h:13
std::string getReleaseVersion()
StreamerOutputModuleBase(ParameterSet const &ps)
unsigned char * bufferPointer() const
static void fillDescription(ParameterSetDescription &desc)
uint32_t adler32_chksum() const
char state
Definition: procUtils.cc:75
unsigned char uint8
Definition: MsgTools.h:11
std::vector< std::string > const & getAllTriggerNames()
Definition: OutputModule.cc:35
Trig getTriggerResults(Event const &ep) const
int serializeRegistry(SerializeDataBuffer &data_buffer)
tuple cout
Definition: gather_cfg.py:41
ParameterSetID getProcessParameterSetID(Registry const *reg)
Associated free functions.
Definition: Registry.cc:11
static ThreadSafeRegistry * instance()
unsigned int currentEventSize() const
virtual void write(EventPrincipal const &e)
static void enable()
interface for TClass generators
ModuleDescription const & description() const
mathSSE::Vec4< T > v
std::vector< unsigned char > hltbits_
ParameterSetID selectorConfig() const
Definition: OutputModule.h:84
tuple src
Definition: align_tpl.py:87
virtual void writeLuminosityBlock(LuminosityBlockPrincipal const &)
const std::string * moduleLabel() const
Definition: HLTadd.h:40