CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TestFileReader.cc
Go to the documentation of this file.
1 
9 
10 #include "boost/bind.hpp"
11 #include "boost/shared_array.hpp"
12 
13 #include <algorithm>
14 #include <cstdlib>
15 #include <iterator>
16 
17 using namespace edm;
18 
19 namespace edmtestp
20 {
21 
22  namespace
23  {
24  struct BufHelper
25  {
26  explicit BufHelper(int len): buf_(new char[len]) { }
27  ~BufHelper() {}
28  void release() {buf_.reset();}
29  char* get() const { return buf_.get(); }
30 
31  private:
32  BufHelper(const BufHelper& ) { }
33  BufHelper& operator=(const BufHelper&) { return *this; }
34 
35  boost::shared_array<char> buf_;
36  };
37  }
38 
39  // ----------------------------------
40 
41  TestFileReader::TestFileReader(const std::string& filename,
43  edm::ProductRegistry& prods):
44  filename_(filename),
45  //ist_(filename_.c_str(),ios_base::binary | ios_base::in),
46  //reader_(ist_),
47  streamReader_(new StreamerInputFile(filename)),
48  to_(to) {
49 
50  const InitMsgView* init = streamReader_->startMessage();
51  std::auto_ptr<edm::SendJobHeader> p = StreamerInputSource::deserializeRegistry(*init);
64  if(edm::registryIsSubset(*p, prods) == false) {
65  throw edm::Exception(errors::Configuration,"TestFileReader")
66  << "the header record in file " << filename_
67  << "is not consistent with the one for the program \n";
68  }
69 
70  // 13-Oct-2008, KAB - Added the following code to put the
71  // INIT message on the input queue.
73  int len = init->size();
74  char* buf_ = new char[len];
75  memcpy(buf_, init->startAddress(), len);
76  new (b.buffer()) stor::FragEntry(buf_, buf_, len, 1, 1,
77  init->code(), init->run(),
78  0, init->outputModuleId(),
79  getpid(), 0);
80  b.commit(sizeof(stor::FragEntry));
81  }
82 
84  }
85 
87  me_.reset(new boost::thread(boost::bind(TestFileReader::run,this)));
88  }
89 
91  me_->join();
92  }
93 
95  t->readEvents();
96  }
97 
99 
100  while(streamReader_->next()) {
102  const EventMsgView* eview = streamReader_->currentRecord();
103 
104  // 13-Oct-2008, KAB - we need to make a copy of the event message
105  // for two reasons: 1) the processing of the events is often done
106  // asynchronously in the code that uses this reader, so we can't
107  // keep re-using the same buffer from the stream_reader, and
108  // 2) the code that uses this reader often uses deleters to
109  // free up the memory used by the FragEntry, so we want the
110  // first argument to the FragEntry to be something that can
111  // be deleted successfully.
112  int len = eview->size();
113  char* buf_ = new char[len];
114  memcpy(buf_, eview->startAddress(), len);
115 
116  //stor::FragEntry* msg =
117  // new (b.buffer()) stor::FragEntry(eview->startAddress(),
118  // eview->startAddress(),
119  // the first arg should be startAddress() right?
120  //new (b.buffer()) stor::FragEntry((void*)eview->eventData(),
121  new (b.buffer()) stor::FragEntry(buf_, buf_, len, 1, 1,
122  eview->code(), eview->run(),
123  eview->event(), eview->outModId(),
124  getpid(), 0);
125  b.commit(sizeof(stor::FragEntry));
126  }
127 
128  /***
129  while(1)
130  {
131  int len=0;
132  ist_.read((char*)&len,sizeof(int));
133 
134  if(!ist_ || len==0 || ist_.eof()) break;
135 
136  EventBuffer::ProducerBuffer b(to_);
137  // Pay attention here.
138  // This is a bit of a mess.
139  // Here we allocate an array (on the heap), fill it with data
140  // from the file, then pass the bare pointer off onto the queue.
141  // The ownership is to be picked up by the code that pulls it
142  // off the queue. The current implementation of the queue
143  // is primitive - it knows nothing about the types of things
144  // that are on the queue.
145 
146  BufHelper data(len);
147  //std::cout << "allocated frag " << len << std::endl;
148  ist_.read((char*)data.get(),len);
149  //std::cout << "read frag to " << (void*)data.get() << std::endl;
150  if(!ist_ || ist_.eof()) std::cerr << "got end!!!!" << std::endl;
151  //HEREHERE need a real event number here for id
152  stor::FragEntry* msg =
153  new (b.buffer()) stor::FragEntry(data.get(),data.get(),len,1,1,Header::EVENT,0,1,0);
154  assert(msg); // Suppresses compiler warning about unused variable
155  //new (b.buffer()) stor::FragEntry(0,0,len);
156  //std::cout << "make entry for frag " << (void*)msg << " " << msg->buffer_address_ << std::endl;
157  data.release();
158  //std::cout << "release frag" << std::endl;
159  b.commit(sizeof(stor::FragEntry));
160  //std::cout << "commit frag " << sizeof(stor::FragEntry) << std::endl;
161  //sleep(2);
162  } **/
163  }
164 
165 }
nocap nocap const skelname & operator=(const skelname &)
uint8 * startAddress() const
Definition: EventMessage.h:79
boost::shared_array< char > buf_
int init
Definition: HydjetWrapper.h:63
boost::shared_ptr< edm::StreamerInputFile > streamReader_
uint32 outModId() const
Definition: EventMessage.cc:97
uint32 run() const
Definition: EventMessage.cc:73
uint8 * startAddress() const
Definition: InitMessage.h:67
bool registryIsSubset(SendJobHeader const &, ProductRegistry const &reg)
Definition: Utilities.cc:85
uint32 code() const
Definition: EventMessage.h:75
boost::shared_ptr< boost::thread > me_
uint32 event() const
Definition: EventMessage.cc:79
uint32 size() const
Definition: EventMessage.h:76
double b
Definition: hdecay.h:120
edm::EventBuffer & to_
uint32 outputModuleId() const
Definition: InitMessage.h:75
uint32 code() const
Definition: InitMessage.h:65
author Stefano ARGIRO author Bill Tanenbaum
tuple filename
Definition: lut2db_cfg.py:20
uint32 run() const
Definition: InitMessage.cc:80
uint32 size() const
Definition: InitMessage.h:66
static void run(TestFileReader *)