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 230 of file StreamSerializer.cc.

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

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

233  {
234  unsigned int resultSize = 0;
235 
236  // what are these magic numbers? (jbk)
237  unsigned long dest_size = (unsigned long)(double(inputSize)*
238  1.002 + 1.0) + 12;
239  if(outputBuffer.size() < dest_size) outputBuffer.resize(dest_size);
240 
241  // compression 1-9, 6 is zlib default, 0 none
242  int ret = compress2(&outputBuffer[0], &dest_size, inputBuffer,
243  inputSize, compressionLevel);
244 
245  // check status
246  if(ret == Z_OK) {
247  // return the correct length
248  resultSize = dest_size;
249 
250  FDEBUG(1) << " original size = " << inputSize
251  << " final size = " << dest_size
252  << " ratio = " << double(dest_size)/double(inputSize)
253  << std::endl;
254  } else {
255  // compression failed, return a size of zero
256  FDEBUG(9) << "Compression Return value: " << ret
257  << " Okay = " << Z_OK << std::endl;
258  // do we throw an exception here?
259  std::cerr << "Compression Return value: " << ret << " Okay = " << Z_OK << std::endl;
260 
261  }
262 
263  return resultSize;
264  }
#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 127 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().

131  {
132  Parentage parentage;
133 
134  EventSelectionIDVector selectionIDs = eventPrincipal.eventSelectionIDs();
135  selectionIDs.push_back(selectorConfig);
136  SendEvent se(eventPrincipal.aux(), eventPrincipal.processHistory(), selectionIDs, eventPrincipal.branchListIndexes());
137 
138  SelectedProducts::const_iterator i(selections_->begin()),ie(selections_->end());
139  // Loop over EDProducts, fill the provenance, and write.
140 
141  for(SelectedProducts::const_iterator i = selections_->begin(), iEnd = selections_->end(); i != iEnd; ++i) {
142  BranchDescription const& desc = **i;
143  BranchID const& id = desc.branchID();
144 
145  OutputHandle const oh = eventPrincipal.getForOutput(id, true, mcc);
146  if(!oh.productProvenance()) {
147  // No product with this ID was put in the event.
148  // Create and write the provenance.
149  se.products().push_back(StreamedProduct(desc));
150  } else {
151  bool found = ParentageRegistry::instance()->getMapped(oh.productProvenance()->parentageID(), parentage);
152  assert(found);
153  se.products().push_back(StreamedProduct(oh.wrapper(),
154  desc,
155  oh.wrapper() != 0,
156  &parentage.parents()));
157  }
158  }
159 
160  data_buffer.rootbuf_.Reset();
161  RootDebug tracer(10,10);
162 
163  //TClass* tc = getTClass(typeid(SendEvent));
164  int bres = data_buffer.rootbuf_.WriteObjectAny(&se,tc_);
165  switch(bres) {
166  case 0: // failure
167  {
168  throw cms::Exception("StreamTranslation","Event serialization failed")
169  << "StreamSerializer failed to serialize event: "
170  << eventPrincipal.id();
171  break;
172  }
173  case 1: // succcess
174  break;
175  case 2: // truncated result
176  {
177  throw cms::Exception("StreamTranslation","Event serialization truncated")
178  << "StreamSerializer module attempted to serialize an event\n"
179  << "that is to big for the allocated buffers: "
180  << eventPrincipal.id();
181  break;
182  }
183  default: // unknown
184  {
185  throw cms::Exception("StreamTranslation","Event serialization failed")
186  << "StreamSerializer module got an unknown error code\n"
187  << " while attempting to serialize event: "
188  << eventPrincipal.id();
189  break;
190  }
191  }
192 
193  data_buffer.curr_event_size_ = data_buffer.rootbuf_.Length();
194  data_buffer.curr_space_used_ = data_buffer.curr_event_size_;
195  data_buffer.ptr_ = (unsigned char*)data_buffer.rootbuf_.Buffer();
196 #if 0
197  if(data_buffer.ptr_ != data_.ptr_) {
198  std::cerr << "ROOT reset the buffer!!!!\n";
199  data_.ptr_ = data_buffer.ptr_; // ROOT may have reset our data pointer!!!!
200  }
201 #endif
202  // std::copy(rootbuf_.Buffer(),rootbuf_.Buffer()+rootbuf_.Length(),
203  // eventMessage.eventAddr());
204  // eventMessage.setEventLength(rootbuf.Length());
205 
206  // compress before return if we need to
207  // should test if compressed already - should never be?
208  // as double compression can have problems
209  if(use_compression) {
210  unsigned int dest_size =
211  compressBuffer(data_buffer.ptr_, data_buffer.curr_event_size_, data_buffer.comp_buf_, compression_level);
212  if(dest_size != 0) {
213  data_buffer.ptr_ = &data_buffer.comp_buf_[0]; // reset to point at compressed area
214  data_buffer.curr_space_used_ = dest_size;
215  }
216  }
217  // calculate the adler32 checksum and fill it into the struct
218  data_buffer.adler32_chksum_ = cms::Adler32((char*)data_buffer.ptr_, data_buffer.curr_space_used_);
219  //std::cout << "Adler32 checksum of event = " << data_buffer.adler32_chksum_ << std::endl;
220 
221  return data_buffer.curr_space_used_;
222  }
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
unsigned int curr_space_used_
void Adler32(char const *data, size_t len, uint32_t &a, uint32_t &b)
SelectedProducts const * selections_
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_, alignCSCRings::e, edm::hlt::Exception, FDEBUG, edm::pset::Registry::fillMap(), edm::getTClass(), i, 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  SelectedProducts::const_iterator i(selections_->begin()), e(selections_->end());
50 
51  FDEBUG(9) << "Product List: " << std::endl;
52 
53 
54  for(auto const& selection : *selections_) {
55  sd.push_back(*selection);
56  FDEBUG(9) << "StreamOutput got product = " << selection->className()
57  << std::endl;
58  }
60  sd.setBranchIDLists(branchIDLists);
62 
64  sd.setParameterSetMap(psetMap);
65 
66  data_buffer.rootbuf_.Reset();
67 
68  RootDebug tracer(10,10);
69 
70  TClass* tc = getTClass(typeid(SendJobHeader));
71  int bres = data_buffer.rootbuf_.WriteObjectAny((char*)&sd, tc);
72 
73  switch(bres) {
74  case 0: // failure
75  {
76  throw cms::Exception("StreamTranslation","Registry serialization failed")
77  << "StreamSerializer failed to serialize registry\n";
78  break;
79  }
80  case 1: // succcess
81  break;
82  case 2: // truncated result
83  {
84  throw cms::Exception("StreamTranslation","Registry serialization truncated")
85  << "StreamSerializer module attempted to serialize\n"
86  << "a registry that is to big for the allocated buffers\n";
87  break;
88  }
89  default: // unknown
90  {
91  throw cms::Exception("StreamTranslation","Registry serialization failed")
92  << "StreamSerializer module got an unknown error code\n"
93  << " while attempting to serialize registry\n";
94  break;
95  }
96  }
97 
98  data_buffer.curr_event_size_ = data_buffer.rootbuf_.Length();
99  data_buffer.curr_space_used_ = data_buffer.curr_event_size_;
100  data_buffer.ptr_ = (unsigned char*)data_buffer.rootbuf_.Buffer();
101  // calculate the adler32 checksum and fill it into the struct
102  data_buffer.adler32_chksum_ = cms::Adler32((char*)data_buffer.ptr_, data_buffer.curr_space_used_);
103  //std::cout << "Adler32 checksum of init message = " << data_buffer.adler32_chksum_ << std::endl;
104  return data_buffer.curr_space_used_;
105  }
int i
Definition: DBlmapReader.cc:9
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().