Belle II Software release-09-00-00
DQMHistAnalysis.h
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8//+
9// File : DQMHistAnalysis.h
10// Description : Baseclass for histogram analysis module for DQM
11//-
12
13#pragma once
14
15#include <framework/core/Module.h>
16#include <dqm/core/MonitoringObject.h>
17#include <dqm/analysis/HistObject.h>
18#include <dqm/analysis/HistDelta.h>
19#include <TFile.h>
20#include <TH1.h>
21
22#include <string>
23#include <map>
24
25#ifdef _BELLE2_EPICS
26// EPICS
27#include "cadef.h"
28#endif
29
30namespace Belle2 {
40
41 public:
45 enum EStatus {
50 c_StatusError = 4
51 };
52
57 c_ColorTooFew = kGray,
58 c_ColorDefault = kWhite,
59 c_ColorGood = kGreen,
60 c_ColorWarning = kYellow,
61 c_ColorError = kRed
62 };
63
67 typedef std::map<std::string, HistObject> HistList;
71 typedef std::map<std::string, MonitoringObject> MonObjList;
72
76 typedef std::map<std::string, HistDelta> DeltaList;
77
81 typedef std::map<std::string, bool> CanvasUpdatedList;
82
86 void clearlist(void);
87
88 private:
97
98 public:
103 private:
104
109
117 inline static int s_eventProcessed = 0;
118
122 inline static std::string s_runType = "";
123
128 static bool m_useEpics;
129
134 static bool m_epicsReadOnly;
135
139 static std::string m_PVPrefix;
140
141
142#ifdef _BELLE2_EPICS
144 static std::vector <chid> m_epicsChID;
146 std::map <std::string, chid> m_epicsNameToChID;
147#endif
148
156 int registerEpicsPVwithPrefix(std::string prefix, std::string pvname, std::string keyname = "");
157
158 public:
163 static /*const*/ HistList& getHistList() { return s_histList;};
164
169 static /*const*/ MonObjList& getMonObjList() { return s_monObjList;};
170
175 static const DeltaList& getDeltaList() { return s_deltaList;};
176
182
187 static const std::string& getRunType(void) { return s_runType;};
188
193 static int getEventProcessed(void) { return s_eventProcessed;};
194
199 void setRunType(std::string& t) {s_runType = t;};
200
206
212 TCanvas* findCanvas(TString cname);
213
220 static TH1* findHist(const std::string& histname, bool onlyIfUpdated = false);
221
229 static TH1* findHist(const std::string& dirname,
230 const std::string& histname, bool onlyIfUpdated = false);
231
238 static TH1* findHistInFile(TFile* file, const std::string& histname);
239
246 TH1* findHistInCanvas(const std::string& hname, TCanvas** canvas = nullptr);
247
253 static MonitoringObject* findMonitoringObject(const std::string& objName);
254
261 double getSigma68(TH1* h) const;
262
263 public:
271 static bool addHist(const std::string& dirname,
272 const std::string& histname, TH1* h);
273
279 static MonitoringObject* getMonitoringObject(const std::string& name);
280
284 void clearCanvases(void);
285
289 static void initHistListBeforeEvent(void);
290
294 static void clearHistList(void);
295
299 void resetDeltaList(void);
300
308 TH1* getDelta(const std::string& fullname, int n = 0, bool onlyIfUpdated = true);
309
318 TH1* getDelta(const std::string& dirname, const std::string& histname, int n = 0, bool onlyIfUpdated = true);
319
328 void addDeltaPar(const std::string& dirname, const std::string& histname, HistDelta::EDeltaType t, int p, unsigned int a = 1);
329
336 bool hasDeltaPar(const std::string& dirname, const std::string& histname);
337
343 void UpdateCanvas(std::string name, bool updated = true);
344
350 void UpdateCanvas(TCanvas* canvas, bool updated = true);
351
355 void ExtractRunType(std::vector <TH1*>& hs);
356
360 void ExtractEvent(std::vector <TH1*>& hs);
361
363
370 int registerEpicsPV(std::string pvname, std::string keyname = "");
371
378 int registerExternalEpicsPV(std::string pvname, std::string keyname = "");
379
385 void setEpicsPV(std::string keyname, double value);
386
392 void setEpicsPV(std::string keyname, int value);
393
399 void setEpicsStringPV(std::string keyname, std::string value);
400
406 void setEpicsPV(int index, double value);
407
413 void setEpicsPV(int index, int value);
414
420 void setEpicsStringPV(int index, std::string value);
421
427 double getEpicsPV(std::string keyname);
428
434 double getEpicsPV(int index);
435
442 std::string getEpicsStringPV(std::string keyname, bool& status);
443
450 std::string getEpicsStringPV(int index, bool& status);
451
457 int updateEpicsPVs(float timeout);
458
464 chid getEpicsPVChID(std::string keyname);
465
471 chid getEpicsPVChID(int index);
472
482 bool requestLimitsFromEpicsPVs(chid id, double& lowerAlarm, double& lowerWarn, double& upperWarn, double& upperAlarm);
483
493 bool requestLimitsFromEpicsPVs(std::string keyname, double& lowerAlarm, double& lowerWarn, double& upperWarn, double& upperAlarm);
494
504 bool requestLimitsFromEpicsPVs(int index, double& lowerAlarm, double& lowerWarn, double& upperWarn, double& upperAlarm);
505
510 void setUseEpics(bool flag) {m_useEpics = flag;};
511
516 void setUseEpicsReadOnly(bool flag) {m_epicsReadOnly = flag;};
517
522 bool getUseEpics(void) {return m_useEpics;};
523
529
533 void cleanupEpicsPVs(void);
534
539 std::string& getPVPrefix(void) {return m_PVPrefix;};
540
545 void setPVPrefix(std::string& prefix) { m_PVPrefix = prefix;};
546
554 EStatus makeStatus(bool enough, bool warn_flag, bool error_flag);
555
561 void colorizeCanvas(TCanvas* canvas, EStatus status);
562
569
573 void checkPVStatus(void);
574
580 void printPVStatus(chid pv, bool onlyError = true);
581
588 void CheckEpicsError(int state, const std::string& message, const std::string& name);
589
596 void CheckEpicsError(int state, const std::string& message, chid id);
597
598
599 // Public functions
600 public:
601
604 virtual ~DQMHistAnalysisModule() {};
605
612 std::vector <std::string> StringSplit(const std::string& s, const char delim);
613
614 // Data members
615 private:
616 };
618} // end namespace Belle2
619
The base class for the histogram analysis module.
static MonObjList s_monObjList
The list of MonitoringObjects.
TCanvas * findCanvas(TString cname)
Find canvas by name.
void printPVStatus(chid pv, bool onlyError=true)
check the status of a PVs and report if disconnected or not found
bool hasDeltaPar(const std::string &dirname, const std::string &histname)
Check if Delta histogram parameters exist for histogram.
void setPVPrefix(std::string &prefix)
set global Prefix for EPICS PVs
std::map< std::string, HistObject > HistList
The type of list of histograms.
static MonitoringObject * getMonitoringObject(const std::string &name)
Get MonitoringObject with given name (new object is created if non-existing)
std::map< std::string, MonitoringObject > MonObjList
The type of list of MonitoringObjects.
static const CanvasUpdatedList & getCanvasUpdatedList()
Get the list of the canvas update status.
void addDeltaPar(const std::string &dirname, const std::string &histname, HistDelta::EDeltaType t, int p, unsigned int a=1)
Add Delta histogram parameters.
static TH1 * findHistInFile(TFile *file, const std::string &histname)
Find histogram in specific TFile (e.g.
EStatusColor getStatusColor(EStatus status)
Return color for canvas state.
void colorizeCanvas(TCanvas *canvas, EStatus status)
Helper function for Canvas colorization.
static TH1 * findHist(const std::string &histname, bool onlyIfUpdated=false)
Get histogram from list (no other search).
static MonitoringObject * findMonitoringObject(const std::string &objName)
Find MonitoringObject.
void clearlist(void)
Clear all static global lists.
double getSigma68(TH1 *h) const
Helper function to compute half of the central interval covering 68% of a distribution.
EStatusColor
Status colors of histogram/canvas (corresponding to status)
@ c_ColorWarning
Analysis result: Warning, there may be minor issues.
@ c_ColorError
Analysis result: Severe issue found.
@ c_ColorTooFew
Not enough entries/event to judge.
@ c_ColorGood
Analysis result: Good.
@ c_ColorDefault
default for non-coloring
double getEpicsPV(std::string keyname)
Read value from a EPICS PV.
static int s_eventProcessed
Number of Events processed to fill histograms.
std::map< std::string, bool > CanvasUpdatedList
The type of list of canvas updated status.
std::string getEpicsStringPV(std::string keyname, bool &status)
Read value from a EPICS PV.
int registerExternalEpicsPV(std::string pvname, std::string keyname="")
Register a PV with its name and a key name.
static HistList s_histList
The list of Histograms.
bool getUseEpicsReadOnly(void)
Getter EPICS flag in read only mode.
static const std::string & getRunType(void)
Get the Run Type.
static std::string s_runType
The Run type.
void setUseEpics(bool flag)
Setter for EPICS usage.
static void clearHistList(void)
Clears the list of histograms.
TH1 * getDelta(const std::string &fullname, int n=0, bool onlyIfUpdated=true)
Get Delta histogram.
std::vector< std::string > StringSplit(const std::string &s, const char delim)
Helper function for string token split.
void setRunType(std::string &t)
Set the Run Type.
std::map< std::string, HistDelta > DeltaList
The type of list of delta settings and histograms.
void setEpicsPV(std::string keyname, double value)
Write value to a EPICS PV.
void setUseEpicsReadOnly(bool flag)
Setter EPICS flag in read only mode.
static DeltaList s_deltaList
The list of Delta Histograms and settings.
DQMHistAnalysisModule()
Constructor / Destructor.
void checkPVStatus(void)
Check the status of all PVs and report if disconnected or not found.
void setEventProcessed(int e)
Set the number of processed events.
static bool m_epicsReadOnly
Flag if to use EPICS in ReadOnly mode (for reading limits) do not set by yourself,...
std::string & getPVPrefix(void)
get global Prefix for EPICS PVs
EStatus
Status flag of histogram/canvas.
@ c_StatusDefault
default for non-coloring
@ c_StatusTooFew
Not enough entries/event to judge.
@ c_StatusError
Analysis result: Severe issue found.
@ c_StatusWarning
Analysis result: Warning, there may be minor issues.
@ c_StatusGood
Analysis result: Good.
static bool addHist(const std::string &dirname, const std::string &histname, TH1 *h)
Add histogram.
bool getUseEpics(void)
Getter for EPICS usage.
void ExtractRunType(std::vector< TH1 * > &hs)
Extract Run Type from histogram title, called from input module.
void CheckEpicsError(int state, const std::string &message, const std::string &name)
check the return status and check PV in case of error
TH1 * findHistInCanvas(const std::string &hname, TCanvas **canvas=nullptr)
Find histogram in corresponding canvas.
static std::string m_PVPrefix
The Prefix for EPICS PVs.
static HistList & getHistList()
Get the list of the histograms.
void cleanupEpicsPVs(void)
Unsubscribe from EPICS PVs on terminate.
void clearCanvases(void)
Clear content of all Canvases.
static int getEventProcessed(void)
Get the number of processed events.
EStatus makeStatus(bool enough, bool warn_flag, bool error_flag)
Helper function to judge the status for coloring and EPICS.
static bool m_useEpics
Flag if to use EPICS do not set by yourself, use EpicsEnable module to set.
static void initHistListBeforeEvent(void)
Reset the list of histograms.
static MonObjList & getMonObjList()
Get the list of MonitoringObjects.
void ExtractEvent(std::vector< TH1 * > &hs)
Extract event processed from daq histogram, called from input module.
int registerEpicsPV(std::string pvname, std::string keyname="")
EPICS related Functions.
static const DeltaList & getDeltaList()
Get the list of the delta histograms.
void UpdateCanvas(std::string name, bool updated=true)
Mark canvas as updated (or not)
void resetDeltaList(void)
Reset Delta.
chid getEpicsPVChID(std::string keyname)
Get EPICS PV Channel Id.
bool requestLimitsFromEpicsPVs(chid id, double &lowerAlarm, double &lowerWarn, double &upperWarn, double &upperAlarm)
Get Alarm Limits from EPICS PV.
int registerEpicsPVwithPrefix(std::string prefix, std::string pvname, std::string keyname="")
Register a PV with its name and a key name.
void setEpicsStringPV(std::string keyname, std::string value)
Write string to a EPICS PV.
int updateEpicsPVs(float timeout)
Update all EPICS PV (flush to network)
static CanvasUpdatedList s_canvasUpdatedList
The list of canvas updated status.
EDeltaType
enum definition for delta algo Disabled: nothing Entries: use nr histogram entries Underflow: use ent...
Definition: HistDelta.h:32
Base class for Modules.
Definition: Module.h:72
MonitoringObject is a basic object to hold data for the run-dependency monitoring Run summary TCanvas...
Abstract base class for different kinds of events.