Anp::AlgThread Class Reference

#include <AlgThread.h>

List of all members.

Public Member Functions

 AlgThread (Handle< AlgSnarl > alg, const std::string &name)
 ~AlgThread ()
bool Init (const Header &header)
void Run (Record &record, bool new_thread)
int Join (void)
void End (const DataBlock &block)
const RecordGetRecord () const
unsigned int NPass () const
unsigned int NFail () const

Private Member Functions

void Run ()
 AlgThread ()
 AlgThread (const AlgThread &)
AlgThreadoperator= (const AlgThread &)

Private Attributes

Mutex fMutex
pthread_t fThread
int fThreadStatus
Handle< AlgSnarlfAlg
std::string fName
Record fRecord
unsigned int fNPass
unsigned int fNFail

Friends

void * run_alg_thread (void *)

Detailed Description

Definition at line 31 of file AlgThread.h.


Constructor & Destructor Documentation

Anp::AlgThread::AlgThread ( Handle< AlgSnarl alg,
const std::string &  name 
)
Anp::AlgThread::~AlgThread (  ) 

Definition at line 42 of file AlgThread.cxx.

00043 {
00044 }

Anp::AlgThread::AlgThread (  )  [private]
Anp::AlgThread::AlgThread ( const AlgThread  )  [private]

Member Function Documentation

void Anp::AlgThread::End ( const DataBlock block  ) 

Definition at line 123 of file AlgThread.cxx.

References fAlg, and Anp::Handle< T >::valid().

00124 {
00125    //
00126    // Send signal to algirithm that we are done here...
00127    //
00128    if(fAlg.valid()) fAlg -> End(block);
00129 }

const Record & Anp::AlgThread::GetRecord (  )  const [inline]

Definition at line 103 of file AlgThread.h.

References fRecord.

00103 { return fRecord; }

bool Anp::AlgThread::Init ( const Header header  ) 

Definition at line 107 of file AlgThread.cxx.

References fAlg, and Anp::Handle< T >::valid().

00108 {
00109    //
00110    // Initiliaze FillkNN::AlgSnarl algorithm
00111    //
00112    
00113    if(!fAlg.valid())
00114    {
00115       cerr << "AlgThread::Init - invalid AlgSnarl handle" << endl;
00116       return false;
00117    }
00118 
00119    return fAlg -> Init(header);
00120 }

int Anp::AlgThread::Join ( void   ) 

Definition at line 93 of file AlgThread.cxx.

References fThread, and fThreadStatus.

00094 {
00095    //
00096    // If there is parallel thread running then attempt to join to main thread
00097    //
00098    if(fThreadStatus == 0)
00099    {
00100       return pthread_join(fThread, NULL);
00101    }
00102 
00103    return fThreadStatus;
00104 }

unsigned int Anp::AlgThread::NFail (  )  const [inline]

Definition at line 105 of file AlgThread.h.

References fNFail.

00105 { return fNFail; }

unsigned int Anp::AlgThread::NPass (  )  const [inline]

Definition at line 104 of file AlgThread.h.

References fNPass.

00104 { return fNPass; }

AlgThread& Anp::AlgThread::operator= ( const AlgThread  )  [private]
void Anp::AlgThread::Run (  )  [private]

Definition at line 132 of file AlgThread.cxx.

References Anp::Record::EventBegIterator(), Anp::Record::EventEndIterator(), fAlg, fMutex, fRecord, it, Anp::Record::TrackBegIterator(), Anp::Record::TrackEndIterator(), and Anp::Handle< T >::valid().

Referenced by Run().

00133 {
00134    //
00135    // This function _might_ be running in new thread and will 
00136    // modify internal class data so put lock on current thread.
00137    //
00138    Anp::Lock<Mutex> lock(fMutex);
00139 
00140    if(!fAlg.valid())
00141    {
00142       cerr << "AlgThread::Run - invalid AlgSnarl handle" << endl;
00143       return;
00144    }
00145 
00146    //
00147    // Store all already existing event and track keys
00148    //
00149    map<short, Anp::PrevDataKey> emap, tmap;
00150 
00151    for(EventIterator it = fRecord.EventBegIterator(); it != fRecord.EventEndIterator(); ++it)
00152    {
00153       emap[it -> EventIndex()] = Anp::PrevDataKey(it -> DataBeg(), it -> DataEnd());
00154    }
00155    for(TrackIterator it = fRecord.TrackBegIterator(); it != fRecord.TrackEndIterator(); ++it)
00156    {
00157       tmap[it -> TrackIndex()] = Anp::PrevDataKey(it -> DataBeg(), it -> DataEnd());
00158    }
00159 
00160    //
00161    // Run algorithm...
00162    //
00163    fAlg -> Run(fRecord);
00164 
00165    //
00166    // Erase previous data with keys stored earlier
00167    //
00168    for(EventIterator it = fRecord.EventBegIterator(); it != fRecord.EventEndIterator(); ++it)
00169    {
00170       it -> Erase(std::remove_if(it -> DataBegIterator(),
00171                                  it -> DataEndIterator(),
00172                                  emap[it -> EventIndex()]), it -> DataEndIterator());
00173    }
00174 
00175    //
00176    // Erase previous data with keys stored earlier
00177    //
00178    for(TrackIterator it = fRecord.TrackBegIterator(); it != fRecord.TrackEndIterator(); ++it)
00179    {
00180       it -> Erase(std::remove_if(it -> DataBegIterator(),
00181                                  it -> DataEndIterator(),
00182                                  tmap[it -> TrackIndex()]), it -> DataEndIterator());
00183    }
00184 }

void Anp::AlgThread::Run ( Record record,
bool  new_thread 
)

Definition at line 47 of file AlgThread.cxx.

References fMutex, fRecord, fThread, fThreadStatus, Run(), and Anp::run_alg_thread().

00048 {   
00049    
00050    if(new_thread)
00051    {
00052       //
00053       // Lock mutex ONLY when starting new thread
00054       //
00055       Anp::Lock<Mutex> lock(fMutex);
00056 
00057       //
00058       // Make local copy of input record
00059       //
00060       fRecord = record;
00061 
00062       //
00063       // Run kNN algorithm in this thread in NEW thread
00064       //
00065       fThreadStatus = pthread_create(&fThread, NULL, Anp::run_alg_thread, this);
00066       
00067       if(fThreadStatus != 0)
00068       {
00069          cerr << "AlgThread::Run - invalid thread status: " << fThreadStatus << endl;
00070       }
00071    }
00072    else
00073    {
00074       //
00075       // No thread is created, set thread status to 1,
00076       // so that we do not try later to join same thread
00077       //
00078       fThreadStatus = 1;
00079 
00080       //
00081       // Make local copy of input record
00082       //
00083       fRecord = record;
00084       
00085       //
00086       // Run kNN algorithm in this thread
00087       //
00088       Run();
00089    }
00090 }


Friends And Related Function Documentation

void* run_alg_thread ( void *   )  [friend]

Member Data Documentation

Definition at line 72 of file AlgThread.h.

Referenced by End(), Init(), and Run().

Definition at line 68 of file AlgThread.h.

Referenced by Run().

std::string Anp::AlgThread::fName [private]

Definition at line 73 of file AlgThread.h.

unsigned int Anp::AlgThread::fNFail [private]

Definition at line 78 of file AlgThread.h.

Referenced by NFail().

unsigned int Anp::AlgThread::fNPass [private]

Definition at line 77 of file AlgThread.h.

Referenced by NPass().

Definition at line 75 of file AlgThread.h.

Referenced by GetRecord(), and Run().

pthread_t Anp::AlgThread::fThread [private]

Definition at line 69 of file AlgThread.h.

Referenced by Join(), and Run().

Definition at line 70 of file AlgThread.h.

Referenced by Join(), and Run().


The documentation for this class was generated from the following files:

Generated on 19 Jan 2018 for loon by  doxygen 1.6.1