00001 #ifndef ANP_ALGTHREAD_H
00002 #define ANP_ALGTHREAD_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include <algorithm>
00015 #include <map>
00016
00017 #ifndef __CINT__
00018 #include <pthread.h>
00019 #else
00020 struct pthread_t;
00021 #endif
00022
00023
00024 #include "PhysicsNtuple/AlgSnarl.h"
00025 #include "PhysicsNtuple/Mutex.h"
00026
00027 namespace Anp
00028 {
00029 void* run_alg_thread(void *data_);
00030
00031 class AlgThread
00032 {
00033 public:
00034
00035 AlgThread(Handle<AlgSnarl> alg, const std::string &name);
00036 ~AlgThread();
00037
00038 bool Init(const Header &header);
00039
00040 void Run(Record &record, bool new_thread);
00041
00042 int Join(void);
00043
00044 void End(const DataBlock &block);
00045
00046 const Record& GetRecord() const;
00047
00048 unsigned int NPass() const;
00049 unsigned int NFail() const;
00050
00051 private:
00052
00053 void Run();
00054
00055 friend void* run_alg_thread(void *);
00056
00057 private:
00058
00059
00060
00061
00062 AlgThread();
00063 AlgThread(const AlgThread &);
00064 AlgThread& operator=(const AlgThread &);
00065
00066 private:
00067
00068 Mutex fMutex;
00069 pthread_t fThread;
00070 int fThreadStatus;
00071
00072 Handle<AlgSnarl> fAlg;
00073 std::string fName;
00074
00075 Record fRecord;
00076
00077 unsigned int fNPass;
00078 unsigned int fNFail;
00079 };
00080
00081
00082
00083
00084 struct PrevDataKey : public std::unary_function<double, void>
00085 {
00086 PrevDataKey();
00087 PrevDataKey(DataIter ibeg, DataIter iend);
00088 explicit PrevDataKey(const std::vector<short> &kvec_);
00089
00090 bool operator()(const Data &data) const;
00091 bool operator()(Event &event) const;
00092 bool operator()(Track &track) const;
00093
00094 private:
00095
00096 DataVec dvec;
00097 bool valid;
00098 };
00099
00100
00101
00102
00103 inline const Record& AlgThread::GetRecord() const { return fRecord; }
00104 inline unsigned int AlgThread::NPass() const { return fNPass; }
00105 inline unsigned int AlgThread::NFail() const { return fNFail; }
00106 }
00107
00108 #endif