#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 42 of file AlgThread.cxx. 00043 {
00044 }
|
|
|
|
|
|
|
|
|
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 }
|
|
|
Definition at line 103 of file AlgThread.h. 00103 { return fRecord; }
|
|
|
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 }
|
|
|
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 }
|
|
|
Definition at line 105 of file AlgThread.h. 00105 { return fNFail; }
|
|
|
Definition at line 104 of file AlgThread.h. 00104 { return fNPass; }
|
|
|
|
|
|
Definition at line 132 of file AlgThread.cxx. References Anp::Record::EventBegIterator(), Anp::Record::EventEndIterator(), Anp::EventIterator, fAlg, fMutex, fRecord, Anp::Record::TrackBegIterator(), Anp::Record::TrackEndIterator(), Anp::TrackIterator, 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 }
|
|
||||||||||||
|
Definition at line 47 of file AlgThread.cxx. References fMutex, fRecord, fThread, fThreadStatus, and Run(). 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 }
|
|
|
|
|
|
Definition at line 72 of file AlgThread.h. |
|
|
Definition at line 68 of file AlgThread.h. Referenced by Run(). |
|
|
Definition at line 73 of file AlgThread.h. |
|
|
Definition at line 78 of file AlgThread.h. |
|
|
Definition at line 77 of file AlgThread.h. |
|
|
Definition at line 75 of file AlgThread.h. Referenced by Run(). |
|
|
Definition at line 69 of file AlgThread.h. |
|
|
Definition at line 70 of file AlgThread.h. |
1.3.9.1