FSUDAQ_Qt6/analyzers/Analyser.h

133 lines
3.1 KiB
C
Raw Normal View History

#ifndef ANALYZER_H
#define ANALYZER_H
2023-05-26 18:06:37 -04:00
#include <QMainWindow>
#include <QChart>
#include <QChartView>
#include <QLabel>
#include <QPushButton>
#include <QCheckBox>
#include <QLineEdit>
#include <QGridLayout>
#include <QGroupBox>
#include "macro.h"
#include "ClassDigitizer.h"
#include "CustomThreads.h"
#include "CustomWidgets.h"
#include "MultiBuilder.h"
#include "ClassInfluxDB.h"
2023-05-26 18:06:37 -04:00
/**************************************
This class is for, obviously, Online analysis.
It provides essential event building, histograms, and filling.
This is the mother of all other derivative analysis class.
derivative class should define the SetUpCanvas() and UpdateHistogram();
2024-08-21 13:40:11 -04:00
After creating a new class based on the Analyzer class,
users need to add the class files to the FSUDAQ_Qt6.pro project file,
include the header file in FSUDAQ.cpp,
modify the MainWindow::OpenAnalyzer() method,
and recompile FSUDAQ to incorporate the changes and activate the custom analyzer.
2023-05-26 18:06:37 -04:00
***************************************/
#include "Histogram1D.h"
#include "Histogram2D.h"
2023-05-26 18:06:37 -04:00
class AnalyzerWorker; //Forward decalration
2024-08-28 17:58:12 -04:00
2023-05-26 18:06:37 -04:00
//^==============================================
//^==============================================
class Analyzer : public QMainWindow{
2023-05-26 18:06:37 -04:00
Q_OBJECT
public:
Analyzer(Digitizer ** digi, unsigned int nDigi, QMainWindow * parent = nullptr);
virtual ~Analyzer();
2023-05-26 18:06:37 -04:00
MultiBuilder * GetEventBuilder() { return mb;}
void RedefineEventBuilder(std::vector<int> idList);
void SetBackwardBuild(bool TF, int maxNumEvent = 100) { isBuildBackward = TF; maxNumEventBuilt = maxNumEvent;}
void SetDatabase(QString IP, QString Name, QString Token);
2023-06-12 16:32:01 -04:00
double RandomGauss(double mean, double sigma);
void SetDatabaseButton();
double GetUpdateTimeInSec() const {return waitTimeinSec;}
virtual void SetUpCanvas();
2023-06-12 16:32:01 -04:00
virtual void UpdateHistograms(); // where event-building, analysis, and ploting
2023-05-26 18:06:37 -04:00
public slots:
void startWork(){
// printf("start timer\n");
mb->ForceStop(false);
mb->ClearEvents();
anaTimer->start(waitTimeinSec*1000);
}
void stopWork(){
// printf("stop worker\n");
anaTimer->stop();
mb->ForceStop(true);
}
2023-05-26 18:06:37 -04:00
private slots:
2023-06-12 16:32:01 -04:00
protected:
QGridLayout * layout;
void BuildEvents(bool verbose = false);
void SetUpdateTimeInSec(double sec = 1.0) { waitTimeinSec = sec; }
2023-05-26 18:06:37 -04:00
InfluxDB * influx;
QString dataBaseIP;
QString dataBaseName;
QString dataBaseToken;
bool isWorking; // a flag to indicate the worker is working
2023-05-26 18:06:37 -04:00
Digitizer ** digi;
unsigned short nDigi;
Data ** dataList;
std::vector<int> typeList;
std::vector<int> snList;
2023-06-12 16:32:01 -04:00
double waitTimeinSec;
MultiBuilder * mb;
bool isBuildBackward;
int maxNumEventBuilt;
// TimingThread * buildTimerThread;
QThread * anaThread;
AnalyzerWorker * anaWorker;
QTimer * anaTimer;
2023-05-26 18:06:37 -04:00
};
2024-08-28 17:58:12 -04:00
//^================================================ AnalyzerWorker
class AnalyzerWorker : public QObject{
Q_OBJECT
public:
AnalyzerWorker(Analyzer * parent): SS(parent){}
2024-08-28 17:58:12 -04:00
public slots:
void UpdateHistograms(){
SS->UpdateHistograms();
emit workDone();
}
2024-08-28 17:58:12 -04:00
signals:
void workDone();
2024-08-28 17:58:12 -04:00
private:
Analyzer * SS;
};
2024-08-28 17:58:12 -04:00
2023-05-26 18:06:37 -04:00
#endif