Belle II Software development
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/core/HistObject.h>
18#include <dqm/core/RefHistObject.h>
19#include <dqm/core/HistDelta.h>
20#include <TFile.h>
21#include <TH1.h>
22
23#include <string>
24#include <map>
25
26#ifdef _BELLE2_EPICS
27// EPICS
28#include "cadef.h"
29#endif
30
31namespace Belle2 {
36
41
42 public:
53
58 c_ColorTooFew = kGray,
59 c_ColorDefault = kWhite,
60 c_ColorGood = kGreen,
61 c_ColorWarning = kYellow,
63 };
64
73
77 typedef std::map<std::string, HistObject> HistList;
81 typedef std::map<std::string, MonitoringObject> MonObjList;
82
86 typedef std::map<std::string, HistDelta> DeltaList;
87
91 typedef std::map<std::string, bool> CanvasUpdatedList;
92
96 typedef std::map<std::string, RefHistObject> RefList;
97
101 void clearlist(void);
102
103
104 private:
113
114 public:
119 private:
120
125
130
138 inline static int s_eventProcessed = 0;
139
143 inline static std::string s_runType = "";
144
149 static bool m_useEpics;
150
155 static bool m_epicsReadOnly;
156
160 static std::string m_PVPrefix;
161
162
163#ifdef _BELLE2_EPICS
165 static std::vector <chid> m_epicsChID;
167 std::map <std::string, chid> m_epicsNameToChID;
168#endif
169
177 int registerEpicsPVwithPrefix(const std::string& prefix, const std::string& pvname, const std::string& keyname = "");
178
179 public:
184 static /*const*/ HistList& getHistList() { return s_histList;};
185
190 static /*const*/ MonObjList& getMonObjList() { return s_monObjList;};
191
196 static const DeltaList& getDeltaList() { return s_deltaList;};
197
203
208 // Unused:
209 //static const RefList& getRefList() { return s_refList;};
210
215 static const std::string& getRunType(void) { return s_runType;};
216
221 static int getEventProcessed(void) { return s_eventProcessed;};
222
227 static void setRunType(const std::string& t) {s_runType = t;};
228
233 static void setEventProcessed(int e) {s_eventProcessed = e;};
234
240 static TCanvas* findCanvas(TString cname);
241
248 static TH1* findHist(const std::string& histname, bool onlyIfUpdated = false);
249
257 static TH1* findHist(const std::string& dirname,
258 const std::string& histname, bool onlyIfUpdated = false);
259
267 static TH1* findRefHist(const std::string& histname, ERefScaling scaling = ERefScaling::c_RefScaleNone, const TH1* hist = nullptr);
268
277 static TH1* findRefHist(const std::string& dirname,
278 const std::string& histname, ERefScaling scaling = ERefScaling::c_RefScaleNone, const TH1* hist = nullptr);
279
286 static TH1* scaleReference(ERefScaling scaling, const TH1* hist, TH1* ref);
287
294 static TH1* findHistInFile(TFile* file, const std::string& histname);
295
302 TH1* findHistInCanvas(const std::string& hname, TCanvas** canvas = nullptr);
303
309 static MonitoringObject* findMonitoringObject(const std::string& objName);
310
317 static double getSigma68(TH1* h);
318
319 public:
327 static bool addHist(const std::string& dirname,
328 const std::string& histname, TH1* h);
329
335 static void addRefHist(const std::string& dirname, TH1* hist);
336
337
343 static MonitoringObject* getMonitoringObject(const std::string& name);
344
348 static void clearCanvases(void);
349
353 static void initHistListBeforeEvent(void);
354
358 static void clearHistList(void);
359
363 static void clearRefList(void);
364
368 static void resetDeltaList(void);
369
377 TH1* getDelta(const std::string& fullname, int n = 0, bool onlyIfUpdated = true);
378
387 TH1* getDelta(const std::string& dirname, const std::string& histname, int n = 0, bool onlyIfUpdated = true);
388
397 static void addDeltaPar(const std::string& dirname, const std::string& histname, HistDelta::EDeltaType t, int p,
398 unsigned int a = 1);
399
406 static bool hasDeltaPar(const std::string& dirname, const std::string& histname);
407
413 static void UpdateCanvas(const std::string& name, bool updated = true);
414
420 static void UpdateCanvas(TCanvas* canvas, bool updated = true);
421
425 static void ExtractRunType(std::vector <TH1*>& hs);
426
430 static void ExtractNEvent(std::vector <TH1*>& hs);
431
433
440 int registerEpicsPV(const std::string& pvname, const std::string& keyname = "");
441
448 int registerExternalEpicsPV(const std::string& pvname, const std::string& keyname = "");
449
455 void setEpicsPV(const std::string& keyname, double value);
456
462 void setEpicsPV(const std::string& keyname, int value);
463
469 void setEpicsStringPV(const std::string& keyname, const std::string& value);
470
476 void setEpicsPV(int index, double value);
477
483 void setEpicsPV(int index, int value);
484
490 void setEpicsStringPV(int index, std::string value);
491
497 double getEpicsPV(const std::string& keyname);
498
504 double getEpicsPV(int index);
505
512 std::string getEpicsStringPV(const std::string& keyname, bool& status);
513
520 std::string getEpicsStringPV(int index, bool& status);
521
527 int updateEpicsPVs(float timeout);
528
534 chid getEpicsPVChID(const std::string& keyname);
535
541 chid getEpicsPVChID(int index);
542
552 bool requestLimitsFromEpicsPVs(chid id, double& lowerAlarm, double& lowerWarn, double& upperWarn, double& upperAlarm);
553
563 bool requestLimitsFromEpicsPVs(const std::string& keyname, double& lowerAlarm, double& lowerWarn, double& upperWarn,
564 double& upperAlarm);
565
575 bool requestLimitsFromEpicsPVs(int index, double& lowerAlarm, double& lowerWarn, double& upperWarn, double& upperAlarm);
576
581 void setUseEpics(bool flag) {m_useEpics = flag;};
582
587 static void setUseEpicsReadOnly(bool flag) {m_epicsReadOnly = flag;};
588
593 static bool getUseEpics(void) {return m_useEpics;};
594
599 static bool getUseEpicsReadOnly(void) {return m_epicsReadOnly;};
600
604 void cleanupEpicsPVs(void);
605
610 static std::string& getPVPrefix(void) {return m_PVPrefix;};
611
616 static void setPVPrefix(const std::string& prefix) { m_PVPrefix = prefix;};
617
625 static EStatus makeStatus(bool enough, bool warn_flag, bool error_flag);
626
632 static void colorizeCanvas(TCanvas* canvas, EStatus status);
633
639 static EStatusColor getStatusColor(EStatus status);
640
644 void checkPVStatus(void);
645
651 static void printPVStatus(chid pv, bool onlyError = true);
652
659 void CheckEpicsError(int state, const std::string& message, const std::string& name);
660
667 void CheckEpicsError(int state, const std::string& message, chid id);
668
669
670 // Public functions
671 public:
672
675 virtual ~DQMHistAnalysisModule() {};
676
683 static std::vector <std::string> StringSplit(const std::string& s, const char delim);
684
685 // Data members
686 private:
687 };
688
689} // end namespace Belle2
690
The base class for the histogram analysis module.
static MonObjList s_monObjList
The list of MonitoringObjects.
static bool getUseEpicsReadOnly(void)
Getter EPICS flag in read only mode.
static void setPVPrefix(const std::string &prefix)
set global prefix for EPICS PVs
static TCanvas * findCanvas(TString cname)
Find canvas by name.
static void printPVStatus(chid pv, bool onlyError=true)
check the status of a PVs and report if disconnected or not found
static TH1 * findRefHist(const std::string &histname, ERefScaling scaling=ERefScaling::c_RefScaleNone, const TH1 *hist=nullptr)
Get referencehistogram from list (no other search).
static bool hasDeltaPar(const std::string &dirname, const std::string &histname)
Check if Delta histogram parameters exist for histogram.
chid getEpicsPVChID(const std::string &keyname)
Get EPICS PV Channel Id.
static bool getUseEpics(void)
Getter for EPICS usage.
std::map< std::string, HistObject > HistList
The type of list of histograms.
int registerEpicsPV(const std::string &pvname, const std::string &keyname="")
EPICS related Functions.
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 TH1 * scaleReference(ERefScaling scaling, const TH1 *hist, TH1 *ref)
Using the original and reference, create scaled version.
static void setEventProcessed(int e)
Set the number of processed events.
static const CanvasUpdatedList & getCanvasUpdatedList()
Get the list of the canvas update status.
int registerExternalEpicsPV(const std::string &pvname, const std::string &keyname="")
Register a PV with its name and a key name.
static void setUseEpicsReadOnly(bool flag)
Setter EPICS flag in read only mode.
static void addDeltaPar(const std::string &dirname, const std::string &histname, HistDelta::EDeltaType t, int p, unsigned int a=1)
Add Delta histogram parameters.
static double getSigma68(TH1 *h)
Helper function to compute half of the central interval covering 68% of a distribution.
static void addRefHist(const std::string &dirname, TH1 *hist)
Add reference histogram.
static TH1 * findHistInFile(TFile *file, const std::string &histname)
Find histogram in specific TFile (e.g.
static EStatusColor getStatusColor(EStatus status)
Return color for canvas state.
static 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.
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
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.
static void UpdateCanvas(const std::string &name, bool updated=true)
Mark canvas as updated (or not)
static HistList s_histList
The list of Histograms.
static const std::string & getRunType(void)
Get the list of the reference histograms.
static RefList s_refList
The list of references.
static void ExtractNEvent(std::vector< TH1 * > &hs)
Extract event processed from daq histogram, called from input module.
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.
static std::vector< std::string > StringSplit(const std::string &s, const char delim)
Helper function for string token split.
static void clearRefList(void)
Clears the list of ref histograms.
std::map< std::string, HistDelta > DeltaList
The type of list of delta settings and histograms.
void setEpicsStringPV(const std::string &keyname, const std::string &value)
Write string to a EPICS PV.
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.
std::map< std::string, RefHistObject > RefList
The type of list of references.
static bool m_epicsReadOnly
Flag if to use EPICS in ReadOnly mode (for reading limits) do not set by yourself,...
std::string getEpicsStringPV(const std::string &keyname, bool &status)
Read value from a EPICS PV.
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.
static void setRunType(const std::string &t)
Set the Run Type.
static 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 & getPVPrefix(void)
get global prefix for EPICS PVs
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.
static void clearCanvases(void)
Clear content of all Canvases.
ERefScaling
Reference plot scaling type.
@ c_RefScaleEntries
to number of entries (integral)
@ c_RefScaleMax
to maximum (bin entry)
static int getEventProcessed(void)
Get the number of processed events.
static 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.
int registerEpicsPVwithPrefix(const std::string &prefix, const std::string &pvname, const std::string &keyname="")
Register a PV with its name and a key name.
static const DeltaList & getDeltaList()
Get the list of the delta histograms.
double getEpicsPV(const std::string &keyname)
Read value from a EPICS PV.
static void resetDeltaList(void)
Reset Delta.
bool requestLimitsFromEpicsPVs(chid id, double &lowerAlarm, double &lowerWarn, double &upperWarn, double &upperAlarm)
Get Alarm Limits from EPICS PV.
void setEpicsPV(const std::string &keyname, double value)
Write value 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
Module()
Constructor.
Definition Module.cc:30
MonitoringObject is a basic object to hold data for the run-dependency monitoring Run summary TCanvas...
Abstract base class for different kinds of events.