diff --git a/DataFile.h b/DataFile.h index 33d1b99..c4cf7b6 100644 --- a/DataFile.h +++ b/DataFile.h @@ -20,6 +20,7 @@ class DataFile { int Close(); evbuf_t* GetEvBuffer() const { return buffer; } + evbuf_t*& GetEvBuffer() { return buffer; } evbuf_t GetEvSize() const { return buffer[0]; } size_t GetEvWords() const { return GetEvSize()/sizeof(evbuf_t); } int ReadEvent(); diff --git a/ppodd.cxx b/ppodd.cxx index 3c3caa7..93e89a4 100644 --- a/ppodd.cxx +++ b/ppodd.cxx @@ -13,6 +13,7 @@ #include #include #include +#include // for std::swap // For output module #include @@ -39,7 +40,7 @@ struct Context { int Init( const char* odef_file ); // Per-thread data - vector evbuffer; // Copy of event buffer read from file + evbuf_t* evbuffer; // Event buffer read from file Decoder evdata; // Decoded data detlst_t detectors; // Detectors with private event-by-event data varlst_t variables; // Interface to analysis results @@ -51,19 +52,16 @@ struct Context { static const int INIT_EVSIZE = 1024; }; -Context::Context() : is_init(false) +Context::Context() : evbuffer(0), is_init(false) { - evbuffer.reserve(INIT_EVSIZE); } Context::~Context() { DeleteContainer( outvars ); DeleteContainer( detectors ); - if( !variables.empty() ) { - cerr << "Warning: variable list not empty!" << endl; - } DeleteContainer( variables ); + delete [] evbuffer; } int Context::Init( const char* odef_file ) @@ -120,6 +118,9 @@ int Context::Init( const char* odef_file ) return 3; } + evbuffer = new evbuf_t[INIT_EVSIZE]; + evbuffer[0] = 0; + is_init = true; return 0; } @@ -142,7 +143,7 @@ class AnalysisThread : public PoolWorkerThread // Process all defined analysis objects - int status = ctx->evdata.Load( &ctx->evbuffer[0] ); + int status = ctx->evdata.Load( ctx->evbuffer ); if( status != 0 ) { cerr << "Decoding error = " << status << " at event " << ctx->nev << endl; @@ -410,8 +411,7 @@ int main( int argc, char* const *argv ) break; }; - curCtx->evbuffer.assign( inp.GetEvBuffer(), - inp.GetEvBuffer()+inp.GetEvWords() ); + swap( curCtx->evbuffer, inp.GetEvBuffer() ); curCtx->nev = nev; pool.Process( curCtx ); }