CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Static Public Member Functions | Private Attributes
edm::StreamSerializer Class Reference

#include <StreamSerializer.h>

Public Member Functions

int serializeEvent (EventPrincipal const &eventPrincipal, ParameterSetID const &selectorConfig, bool use_compression, int compression_level, SerializeDataBuffer &data_buffer, ModuleCallingContext const *mcc)
 
int serializeRegistry (SerializeDataBuffer &data_buffer, const BranchIDLists &branchIDLists)
 
 StreamSerializer (SelectedProducts const *selections)
 

Static Public Member Functions

static unsigned int compressBuffer (unsigned char *inputBuffer, unsigned int inputSize, std::vector< unsigned char > &outputBuffer, int compressionLevel)
 

Private Attributes

SelectedProducts const * selections_
 
TClass * tc_
 

Detailed Description

Definition at line 64 of file StreamSerializer.h.

Constructor & Destructor Documentation

edm::StreamSerializer::StreamSerializer ( SelectedProducts const *  selections)

Creates a translator instance for the specified product registry.

Definition at line 35 of file StreamSerializer.cc.

35  :
36  selections_(selections),
37  tc_(getTClass(typeid(SendEvent))) {
38  }
TClass * getTClass(const std::type_info &ti)
Definition: ClassFiller.cc:78
SelectedProducts const * selections_

Member Function Documentation

unsigned int edm::StreamSerializer::compressBuffer ( unsigned char *  inputBuffer,
unsigned int  inputSize,
std::vector< unsigned char > &  outputBuffer,
int  compressionLevel 
)
static

Compresses the data in the specified input buffer into the specified output buffer. Returns the size of the compressed data or zero if compression failed.

Definition at line 227 of file StreamSerializer.cc.

References dtNoiseDBValidation_cfg::cerr, FDEBUG, and run_regression::ret.

Referenced by edm::StreamDQMSerializer::serializeDQMEvent(), and serializeEvent().

230  {
231  unsigned int resultSize = 0;
232 
233  // what are these magic numbers? (jbk)
234  unsigned long dest_size = (unsigned long)(double(inputSize)*
235  1.002 + 1.0) + 12;
236  if(outputBuffer.size() < dest_size) outputBuffer.resize(dest_size);
237 
238  // compression 1-9, 6 is zlib default, 0 none
239  int ret = compress2(&outputBuffer[0], &dest_size, inputBuffer,
240  inputSize, compressionLevel);
241 
242  // check status
243  if(ret == Z_OK) {
244  // return the correct length
245  resultSize = dest_size;
246 
247  FDEBUG(1) << " original size = " << inputSize
248  << " final size = " << dest_size
249  << " ratio = " << double(dest_size)/double(inputSize)
250  << std::endl;
251  } else {
252  // compression failed, return a size of zero
253  FDEBUG(9) << "Compression Return value: " << ret
254  << " Okay = " << Z_OK << std::endl;
255  // do we throw an exception here?
256  std::cerr << "Compression Return value: " << ret << " Okay = " << Z_OK << std::endl;
257 
258  }
259 
260  return resultSize;
261  }
#define FDEBUG(lev)
Definition: DebugMacros.h:18
int edm::StreamSerializer::serializeEvent ( EventPrincipal const &  eventPrincipal,
ParameterSetID const &  selectorConfig,
bool  use_compression,
int  compression_level,
SerializeDataBuffer data_buffer,
ModuleCallingContext const *  mcc 
)

Serializes the specified event into the specified event message.

make a char* as a data member, tell ROOT to not adapt it, but still use it. initialize it to 1M, let ROOT resize if it wants, then delete it in the dtor.

change the call to not take an eventMessage, add a member function to return the address of the place that ROOT wrote the serialized data.

return the length of the serialized object and the actual length if compression has been done (may want to cache these lengths in this object instead.

the caller will need to copy the data from this object to its final destination in the EventMsgBuilder.

Definition at line 125 of file StreamSerializer.cc.

References cms::Adler32(), SerializeDataBuffer::adler32_chksum_, edm::EventPrincipal::aux(), edm::BranchDescription::branchID(), edm::EventPrincipal::branchListIndexes(), dtNoiseDBValidation_cfg::cerr, SerializeDataBuffer::comp_buf_, compressBuffer(), SerializeDataBuffer::curr_event_size_, SerializeDataBuffer::curr_space_used_, edm::EventPrincipal::eventSelectionIDs(), edm::hlt::Exception, newFWLiteAna::found, edm::Principal::getForOutput(), edm::ParentageRegistry::getMapped(), i, edm::EventPrincipal::id(), edm::ParentageRegistry::instance(), edm::ProductProvenance::parentageID(), edm::Parentage::parents(), edm::Principal::processHistory(), edm::OutputHandle::productProvenance(), SerializeDataBuffer::ptr_, SerializeDataBuffer::rootbuf_, selections_, tc_, and edm::OutputHandle::wrapper().

Referenced by edm::StreamerOutputModuleBase::serializeEvent().

129  {
130  Parentage parentage;
131 
132  EventSelectionIDVector selectionIDs = eventPrincipal.eventSelectionIDs();
133  selectionIDs.push_back(selectorConfig);
134  SendEvent se(eventPrincipal.aux(), eventPrincipal.processHistory(), selectionIDs, eventPrincipal.branchListIndexes());
135 
136  // Loop over EDProducts, fill the provenance, and write.
137 
138  for(SelectedProducts::const_iterator i = selections_->begin(), iEnd = selections_->end(); i != iEnd; ++i) {
139  BranchDescription const& desc = **i;
140  BranchID const& id = desc.branchID();
141 
142  OutputHandle const oh = eventPrincipal.getForOutput(id, true, mcc);
143  if(!oh.productProvenance()) {
144  // No product with this ID was put in the event.
145  // Create and write the provenance.
146  se.products().push_back(StreamedProduct(desc));
147  } else {
148  bool found = ParentageRegistry::instance()->getMapped(oh.productProvenance()->parentageID(), parentage);
149  assert(found);
150  se.products().push_back(StreamedProduct(oh.wrapper(),
151  desc,
152  oh.wrapper() != 0,
153  &parentage.parents()));
154  }
155  }
156 
157  data_buffer.rootbuf_.Reset();
158  RootDebug tracer(10,10);
159 
160  //TClass* tc = getTClass(typeid(SendEvent));
161  int bres = data_buffer.rootbuf_.WriteObjectAny(&se,tc_);
162  switch(bres) {
163  case 0: // failure
164  {
165  throw cms::Exception("StreamTranslation","Event serialization failed")
166  << "StreamSerializer failed to serialize event: "
167  << eventPrincipal.id();
168  break;
169  }
170  case 1: // succcess
171  break;
172  case 2: // truncated result
173  {
174  throw cms::Exception("StreamTranslation","Event serialization truncated")
175  << "StreamSerializer module attempted to serialize an event\n"
176  << "that is to big for the allocated buffers: "
177  << eventPrincipal.id();
178  break;
179  }
180  default: // unknown
181  {
182  throw cms::Exception("StreamTranslation","Event serialization failed")
183  << "StreamSerializer module got an unknown error code\n"
184  << " while attempting to serialize event: "
185  << eventPrincipal.id();
186  break;
187  }
188  }
189 
190  data_buffer.curr_event_size_ = data_buffer.rootbuf_.Length();
191  data_buffer.curr_space_used_ = data_buffer.curr_event_size_;
192  data_buffer.ptr_ = (unsigned char*)data_buffer.rootbuf_.Buffer();
193 #if 0
194  if(data_buffer.ptr_ != data_.ptr_) {
195  std::cerr << "ROOT reset the buffer!!!!\n";
196  data_.ptr_ = data_buffer.ptr_; // ROOT may have reset our data pointer!!!!
197  }
198 #endif
199  // std::copy(rootbuf_.Buffer(),rootbuf_.Buffer()+rootbuf_.Length(),
200  // eventMessage.eventAddr());
201  // eventMessage.setEventLength(rootbuf.Length());
202 
203  // compress before return if we need to
204  // should test if compressed already - should never be?
205  // as double compression can have problems
206  if(use_compression) {
207  unsigned int dest_size =
208  compressBuffer(data_buffer.ptr_, data_buffer.curr_event_size_, data_buffer.comp_buf_, compression_level);
209  if(dest_size != 0) {
210  data_buffer.ptr_ = &data_buffer.comp_buf_[0]; // reset to point at compressed area
211  data_buffer.curr_space_used_ = dest_size;
212  }
213  }
214  // calculate the adler32 checksum and fill it into the struct
215  data_buffer.adler32_chksum_ = cms::Adler32((char*)data_buffer.ptr_, data_buffer.curr_space_used_);
216  //std::cout << "Adler32 checksum of event = " << data_buffer.adler32_chksum_ << std::endl;
217 
218  return data_buffer.curr_space_used_;
219  }
int i
Definition: DBlmapReader.cc:9
static unsigned int compressBuffer(unsigned char *inputBuffer, unsigned int inputSize, std::vector< unsigned char > &outputBuffer, int compressionLevel)
std::vector< EventSelectionID > EventSelectionIDVector
std::vector< unsigned char > comp_buf_
unsigned int curr_event_size_
bool getMapped(key_type const &k, value_type &result) const
tuple compression_level
Definition: fu_pp.py:86
unsigned int curr_space_used_
void Adler32(char const *data, size_t len, uint32_t &a, uint32_t &b)
SelectedProducts const * selections_
tuple use_compression
Definition: fu_pp.py:85
unsigned char * ptr_
static ParentageRegistry * instance()
int edm::StreamSerializer::serializeRegistry ( SerializeDataBuffer data_buffer,
const BranchIDLists branchIDLists 
)

Serializes the product registry (that was specified to the constructor) into the specified InitMessage.

Definition at line 45 of file StreamSerializer.cc.

References cms::Adler32(), SerializeDataBuffer::adler32_chksum_, SerializeDataBuffer::curr_event_size_, SerializeDataBuffer::curr_space_used_, edm::hlt::Exception, FDEBUG, edm::pset::Registry::fillMap(), edm::getTClass(), edm::pset::Registry::instance(), SerializeDataBuffer::ptr_, edm::SendJobHeader::push_back(), SerializeDataBuffer::rootbuf_, sd, corrVsCorr::selection, selections_, edm::SendJobHeader::setBranchIDLists(), and edm::SendJobHeader::setParameterSetMap().

Referenced by edm::StreamerOutputModuleBase::serializeRegistry().

45  {
46  FDEBUG(6) << "StreamSerializer::serializeRegistry" << std::endl;
47  SendJobHeader sd;
48 
49  FDEBUG(9) << "Product List: " << std::endl;
50 
51 
52  for(auto const& selection : *selections_) {
53  sd.push_back(*selection);
54  FDEBUG(9) << "StreamOutput got product = " << selection->className()
55  << std::endl;
56  }
58  sd.setBranchIDLists(branchIDLists);
60 
62  sd.setParameterSetMap(psetMap);
63 
64  data_buffer.rootbuf_.Reset();
65 
66  RootDebug tracer(10,10);
67 
68  TClass* tc = getTClass(typeid(SendJobHeader));
69  int bres = data_buffer.rootbuf_.WriteObjectAny((char*)&sd, tc);
70 
71  switch(bres) {
72  case 0: // failure
73  {
74  throw cms::Exception("StreamTranslation","Registry serialization failed")
75  << "StreamSerializer failed to serialize registry\n";
76  break;
77  }
78  case 1: // succcess
79  break;
80  case 2: // truncated result
81  {
82  throw cms::Exception("StreamTranslation","Registry serialization truncated")
83  << "StreamSerializer module attempted to serialize\n"
84  << "a registry that is to big for the allocated buffers\n";
85  break;
86  }
87  default: // unknown
88  {
89  throw cms::Exception("StreamTranslation","Registry serialization failed")
90  << "StreamSerializer module got an unknown error code\n"
91  << " while attempting to serialize registry\n";
92  break;
93  }
94  }
95 
96  data_buffer.curr_event_size_ = data_buffer.rootbuf_.Length();
97  data_buffer.curr_space_used_ = data_buffer.curr_event_size_;
98  data_buffer.ptr_ = (unsigned char*)data_buffer.rootbuf_.Buffer();
99  // calculate the adler32 checksum and fill it into the struct
100  data_buffer.adler32_chksum_ = cms::Adler32((char*)data_buffer.ptr_, data_buffer.curr_space_used_);
101  //std::cout << "Adler32 checksum of init message = " << data_buffer.adler32_chksum_ << std::endl;
102  return data_buffer.curr_space_used_;
103  }
std::map< ParameterSetID, ParameterSetBlob > ParameterSetMap
selection
main part
Definition: corrVsCorr.py:98
#define FDEBUG(lev)
Definition: DebugMacros.h:18
TClass * getTClass(const std::type_info &ti)
Definition: ClassFiller.cc:78
unsigned int curr_event_size_
unsigned int curr_space_used_
void Adler32(char const *data, size_t len, uint32_t &a, uint32_t &b)
SelectedProducts const * selections_
double sd
unsigned char * ptr_
void fillMap(regmap_type &fillme) const
Definition: Registry.cc:47
static Registry * instance()
Definition: Registry.cc:14

Member Data Documentation

SelectedProducts const* edm::StreamSerializer::selections_
private

Definition at line 90 of file StreamSerializer.h.

Referenced by serializeEvent(), and serializeRegistry().

TClass* edm::StreamSerializer::tc_
private

Definition at line 91 of file StreamSerializer.h.

Referenced by serializeEvent().