Skip to content

Commit

Permalink
Don't copy event buffer but keep one work buffer per thread
Browse files Browse the repository at this point in the history
  • Loading branch information
hansenjo committed Feb 28, 2015
1 parent a5b207f commit 6a0a5f9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
1 change: 1 addition & 0 deletions DataFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
18 changes: 9 additions & 9 deletions ppodd.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <iostream>
#include <climits>
#include <unistd.h>
#include <algorithm> // for std::swap

// For output module
#include <fstream>
Expand All @@ -39,7 +40,7 @@ struct Context {
int Init( const char* odef_file );

// Per-thread data
vector<evbuf_t> 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
Expand All @@ -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 )
Expand Down Expand Up @@ -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;
}
Expand All @@ -142,7 +143,7 @@ class AnalysisThread : public PoolWorkerThread<Context_t>

// 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;
Expand Down Expand Up @@ -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 );
}
Expand Down

0 comments on commit 6a0a5f9

Please sign in to comment.