#include <AlgThread.h>
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 Record & | GetRecord () const |
unsigned int | NPass () const |
unsigned int | NFail () const |
Private Member Functions | |
void | Run () |
AlgThread () | |
AlgThread (const AlgThread &) | |
AlgThread & | operator= (const AlgThread &) |
Private Attributes | |
Mutex | fMutex |
pthread_t | fThread |
int | fThreadStatus |
Handle< AlgSnarl > | fAlg |
std::string | fName |
Record | fRecord |
unsigned int | fNPass |
unsigned int | fNFail |
Friends | |
void * | run_alg_thread (void *) |
Definition at line 31 of file AlgThread.h.
Anp::AlgThread::~AlgThread | ( | ) |
Definition at line 42 of file AlgThread.cxx.
Anp::AlgThread::AlgThread | ( | ) | [private] |
Anp::AlgThread::AlgThread | ( | const AlgThread & | ) | [private] |
void Anp::AlgThread::End | ( | const DataBlock & | block | ) |
Definition at line 123 of file AlgThread.cxx.
References fAlg, and Anp::Handle< T >::valid().
const Record & Anp::AlgThread::GetRecord | ( | ) | const [inline] |
bool Anp::AlgThread::Init | ( | const Header & | header | ) |
Definition at line 107 of file AlgThread.cxx.
References fAlg, and Anp::Handle< T >::valid().
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] |
unsigned int Anp::AlgThread::NPass | ( | ) | const [inline] |
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 }
void* run_alg_thread | ( | void * | ) | [friend] |
Handle<AlgSnarl> Anp::AlgThread::fAlg [private] |
Definition at line 72 of file AlgThread.h.
Mutex Anp::AlgThread::fMutex [private] |
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().
Record Anp::AlgThread::fRecord [private] |
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.
int Anp::AlgThread::fThreadStatus [private] |
Definition at line 70 of file AlgThread.h.