QIGUICoSessionHandler.hh

00001 #ifndef _QIGUI_CO_SESSION_HANDLER__H_
00002 #define _QIGUI_CO_SESSION_HANDLER__H_
00003 
00004 #include <QObject>
00005 #include <QCoincidence.hh>
00006 #include <map>
00007 #include <string>
00008 #include <TMutex.h>
00009 
00010 class QIGUISession;
00011 class QCoincidenceFiller;
00012 class QIGUICoCut;
00013 class QIGUIPlotData;
00014 class TThread;
00015 class QProgressBar;
00016 class QTimer;
00017 class QCoProjector;
00018 //class TTree;
00019 class TNtuple;
00020 
00021 
00022 class QIGUICoSessionHandler: public QObject
00023 {
00024    Q_OBJECT
00025 
00026   public:
00027     enum Status 
00028     {
00029       CoToDoEventList = 0,
00030       CoToDoCoCut,
00031       CoDone
00032     };
00033     Status fStatus;
00034 
00035   private:
00036 
00037     QCoincidenceFiller* fFiller;
00038     QIGUICoCut * fCoCut;
00039 
00041     QIGUISession * fSession;
00042     QIGUIPlotData * fPlotData;
00043 
00044     QString fName;
00045     std::string fEnergyVar;
00046     std::string fTimeVar;
00047 
00048     // Time coincidence type (kind of filler)
00049     std::string fType;
00050     double fTimeWindow;
00051 
00052     TThread * fCoThread;
00053     TMutex  fCoMutex; // protect CoStatus
00054     int fNEvents; 
00055     int fNCoincidences;
00056     QProgressBar * fProgressBar;
00057     QTimer * fTimer;
00058 
00059     // Projector
00060     QCoProjector * fCoProjector;
00061 
00062   public:
00063     // Ctr, Dtr, initialization
00064     QIGUICoSessionHandler (QString name, QObject * parent=0);
00065     QIGUICoSessionHandler (QString name, QIGUISession * session, QObject * parent=0);
00066     virtual ~QIGUICoSessionHandler();
00067     void Init();
00068 
00069     int BuildCoincidences(QProgressBar * bar);
00070     int CreateFiller();
00071     int BuildTimeCoincidences();
00072     int BuildCoCutCoincidences();
00073     void CoAnalysisEnd();
00074     // Apply cut and generate a new list with the coincidences that pass the filter
00075     std::list<QCoincidence> Filter (const std::list<QCoincidence>& coincList);
00076     
00077 
00078 
00079     // Setters, getters
00080     QString        GetName() {return fName;}
00081     QIGUISession * GetSession() { return fSession;}
00082     QIGUIPlotData *GetPlotData() { return fPlotData;}
00083     QCoincidenceFiller * GetFiller () {return fFiller;}
00084     std::string    GetType() {return fType;}
00085     double         GetTimeWindow () {return fTimeWindow;}
00086     QTimer *       GetTimer() {return fTimer;}
00087     std::string    GetEnergyVar() {return fEnergyVar;}
00088     std::string    GetTimeVar() {return fTimeVar;}
00089     QIGUICoCut *   GetCoCut () {return fCoCut;}
00090     int            GetNEvents() {return fNEvents;}
00091     int            GetNCoincidences() {return fNCoincidences;}
00092     QProgressBar * GetProgressBar() {return fProgressBar;}
00093 
00094     void SetSession (QIGUISession * session) {fSession = session;fStatus=CoToDoEventList;}
00095     void SetPlotData(QIGUIPlotData * plotdata) {fPlotData = plotdata;fStatus=CoToDoEventList;}
00096 
00097     // These functions modify Status = CoToDoEventList 
00098     void SetType (std::string type);
00099     void SetTimeWindow(double timeWindow);
00100     void SetEnergyVar(std::string energy);
00101     void SetTimeVar(std::string time);
00102 
00103     // These functions dont modify Status. Status is modified by signals
00104     void SetCoCut (QIGUICoCut * coCut) {fCoCut = coCut;}
00105 
00106     void SetNEvents(int nev) {fNEvents=nev;}
00107     void SetNCoincidences(int nc) {fNCoincidences=nc;}
00108 
00109     // get pointer to projector. If CoSessionHandler Status is different form CoDone, 
00110     // regenerate coincidence list
00111     QCoProjector * GetCoProjector();
00112 
00113     // Get and Set Status(protected by Mutex)
00114     void SetStatus (Status st); 
00115     Status GetStatus (); 
00116 
00117     // Lock and UnLock Mutex that protects fStatus.
00118     void LockCoMutex();
00119     void UnLockCoMutex();
00120 
00121     //void GetCoincidentEvents(unsigned int ev, QCoincidentEvent & coev, std::vector<QCoincidentEvent> &tempCoin, std::vector<QCoincidentEvent> &spatialCoin);
00122     // return 0 on success, -1 on error
00123     //int GetCoincidentEvents(unsigned int ev, int & channel, QCoincidence & tempCoin, QCoincidence & spatialCoin);
00124     std::pair<const QCoincidence*, const QCoincidence*> GetCoincidentEvents(unsigned int ev, int & channel);
00125     void CreateIndexT();
00126 
00127     // Fill fPtCoincidences
00128     void SetCoincidentEvents();
00129     void AddEventBasedCoin();
00130     void RemoveEventBasedCoin();
00131     
00132   private:
00133     // Thread function
00134     static void *LaunchCoAnalysis(void * coSessionHandler);
00135 
00136     // Map of the temporal and spatial coincidences
00137     // For every event, indexed by the pair <StartTimeUnix, Eventumber> we get: 
00138     // first: pointer to temporal coincidence
00139     // second:  pointer to spatial coincidence
00140     //std::map< std::pair<Int_t, Int_t> , std::pair<QCoincidence* , QCoincidence*> >  fPtCoincidences;
00141     std::map< Int_t , std::pair<const QCoincidence* , const QCoincidence*> >  fPtCoincidences; // event number, coincidences
00142 
00143     //TTree * fIndexT;
00144     TNtuple * fIndexT;
00145 
00146 
00147   public slots:
00148     void UpdateProgressBar();
00149     void DeleteProgressBar();
00150     void DeleteTimer();
00151 
00152   signals:
00153     void UpdateProgressBar(int );
00154     void CoAnalysisEnd(QString, int);
00155 
00156 };
00157 
00158 #endif

Generated on Tue Nov 16 10:49:59 2010 for CUORE Software by  doxygen 1.5.6
INFN Genova privacy policy