Go to the documentation of this file.00001
00002 #include "IOPool/Streamer/interface/TestFileReader.h"
00003 #include "IOPool/Streamer/interface/InitMessage.h"
00004 #include "IOPool/Streamer/interface/EventMessage.h"
00005 #include "IOPool/Streamer/interface/HLTInfo.h"
00006 #include "IOPool/Streamer/interface/StreamerInputSource.h"
00007 #include "FWCore/Utilities/interface/EDMException.h"
00008 #include "IOPool/Streamer/interface/Utilities.h"
00009
00010 #include "boost/bind.hpp"
00011 #include "boost/shared_array.hpp"
00012
00013 #include <algorithm>
00014 #include <cstdlib>
00015 #include <iterator>
00016
00017 using namespace edm;
00018
00019 namespace edmtestp
00020 {
00021
00022 namespace
00023 {
00024 struct BufHelper
00025 {
00026 explicit BufHelper(int len): buf_(new char[len]) { }
00027 ~BufHelper() {}
00028 void release() {buf_.reset();}
00029 char* get() const { return buf_.get(); }
00030
00031 private:
00032 BufHelper(const BufHelper& ) { }
00033 BufHelper& operator=(const BufHelper&) { return *this; }
00034
00035 boost::shared_array<char> buf_;
00036 };
00037 }
00038
00039
00040
00041 TestFileReader::TestFileReader(const std::string& filename,
00042 edm::EventBuffer& to,
00043 edm::ProductRegistry& prods):
00044 filename_(filename),
00045
00046
00047 streamReader_(new StreamerInputFile(filename)),
00048 to_(to) {
00049
00050 const InitMsgView* init = streamReader_->startMessage();
00051 std::auto_ptr<edm::SendJobHeader> p = StreamerInputSource::deserializeRegistry(*init);
00064 if(edm::registryIsSubset(*p, prods) == false) {
00065 throw edm::Exception(errors::Configuration,"TestFileReader")
00066 << "the header record in file " << filename_
00067 << "is not consistent with the one for the program \n";
00068 }
00069
00070
00071
00072 EventBuffer::ProducerBuffer b(to_);
00073 int len = init->size();
00074 char* buf_ = new char[len];
00075 memcpy(buf_, init->startAddress(), len);
00076 new (b.buffer()) stor::FragEntry(buf_, buf_, len, 1, 1,
00077 init->code(), init->run(),
00078 0, init->outputModuleId(),
00079 getpid(), 0);
00080 b.commit(sizeof(stor::FragEntry));
00081 }
00082
00083 TestFileReader::~TestFileReader() {
00084 }
00085
00086 void TestFileReader::start() {
00087 me_.reset(new boost::thread(boost::bind(TestFileReader::run,this)));
00088 }
00089
00090 void TestFileReader::join() {
00091 me_->join();
00092 }
00093
00094 void TestFileReader::run(TestFileReader* t) {
00095 t->readEvents();
00096 }
00097
00098 void TestFileReader::readEvents() {
00099
00100 while(streamReader_->next()) {
00101 EventBuffer::ProducerBuffer b(to_);
00102 const EventMsgView* eview = streamReader_->currentRecord();
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112 int len = eview->size();
00113 char* buf_ = new char[len];
00114 memcpy(buf_, eview->startAddress(), len);
00115
00116
00117
00118
00119
00120
00121 new (b.buffer()) stor::FragEntry(buf_, buf_, len, 1, 1,
00122 eview->code(), eview->run(),
00123 eview->event(), eview->outModId(),
00124 getpid(), 0);
00125 b.commit(sizeof(stor::FragEntry));
00126 }
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163 }
00164
00165 }