13 #include <dqm/core/DQMHistAnalysis.h>
14 #include <boost/algorithm/string.hpp>
35 bool DQMHistAnalysisModule::m_useEpics =
false;
36 bool DQMHistAnalysisModule::m_epicsReadOnly =
38 std::string DQMHistAnalysisModule::m_PVPrefix =
"TEST:";
40 DQMHistAnalysisModule::DQMHistAnalysisModule() :
Module()
49 if (dirname.size() > 0) {
50 fullname = dirname +
"/" + histname;
59 B2DEBUG(20,
"Found Delta" << fullname);
60 it->second->update(h);
72 if (dirname.size() > 0) {
73 fullname = dirname +
"/" + histname;
83 if (dirname.size() > 0) {
84 fullname = dirname +
"/" + histname;
94 if (dirname.size() > 0) {
95 fullname = dirname +
"/" + histname;
99 return getDelta(fullname, n, onlyIfUpdated);
106 return it->second->getDelta(n, onlyIfUpdated);
108 B2WARNING(
"Delta hist " << fullname <<
" not found");
118 B2WARNING(
"MonitoringObject " << objName <<
" listed as being in memfile but points to nowhere. New Object will be made.");
124 s_monObjList.insert(MonObjList::value_type(objName, obj));
130 TIter nextkey(gROOT->GetListOfCanvases());
133 while ((obj =
dynamic_cast<TObject*
>(nextkey()))) {
134 if (obj->IsA()->InheritsFrom(
"TCanvas")) {
135 if (obj->GetName() == canvas_name)
136 return dynamic_cast<TCanvas*
>(obj);
145 if (was_updated && !
s_histList[histname].isUpdated())
return nullptr;
149 B2ERROR(
"Histogram " << histname <<
" in histogram list but nullptr.");
152 B2INFO(
"Histogram " << histname <<
" not in list.");
158 if (dirname.size() > 0) {
159 return findHist(dirname +
"/" + histname, updated);
169 B2ERROR(
"findHistInCanvas: histoname not valid (missing dir?), should be 'dirname/histname': " << histo_name);
172 auto dirname = s.at(0);
173 auto hname = s.at(1);
174 std::string canvas_name = dirname +
"/c_" + hname;
177 if (cobj ==
nullptr)
return nullptr;
179 TIter nextkey(((TCanvas*)cobj)->GetListOfPrimitives());
181 while ((obj =
dynamic_cast<TObject*
>(nextkey()))) {
182 if (obj->IsA()->InheritsFrom(
"TH1")) {
183 if (obj->GetName() == histo_name)
184 return dynamic_cast<TH1*
>(obj);
194 if (file && file->IsOpen()) {
195 auto obj = file->Get(histname.data());
196 if (obj !=
nullptr) {
198 if (obj->IsA()->InheritsFrom(
"TH1")) {
199 B2DEBUG(20,
"Histogram " << histname <<
" found in file");
200 return dynamic_cast<TH1*
>(obj);
202 B2INFO(
"Found Object " << histname <<
" in file is not a histogram");
205 B2INFO(
"Histogram " << histname <<
" not found in file");
218 B2ERROR(
"MonitoringObject " << objName <<
" listed as being in memfile but points to nowhere.");
221 B2INFO(
"MonitoringObject " << objName <<
" not in memfile.");
227 double probs[2] = {0.16, 1 - 0.16};
228 double quant[2] = {0, 0};
229 h->GetQuantiles(2, quant, probs);
230 const double sigma68 = (-quant[0] + quant[1]) / 2;
236 std::vector <std::string> out;
237 boost::split(out, in, [delim](
char c) {
return c == delim;});
245 h.second.resetBeforeEvent();
248 d.second->setNotUpdated();
272 for (
size_t i = 0; i < hs.size(); i++) {
273 if (hs[i]->GetName() == std::string(
"DQMInfo/rtype")) {
278 B2ERROR(
"ExtractRunType: Histogram \"DQMInfo/rtype\" missing");
284 for (
size_t i = 0; i < hs.size(); i++) {
285 if (hs[i]->GetName() == std::string(
"DAQ/Nevent")) {
290 B2ERROR(
"ExtractEvent: Histogram \"DAQ/Nevent\" missing");
298 if (m_epicsNameToChID[pvname] !=
nullptr) {
299 B2ERROR(
"Epics PV " << pvname <<
" already registered!");
302 if (keyname !=
"" && m_epicsNameToChID[keyname] !=
nullptr) {
303 B2ERROR(
"Epics PV with key " << keyname <<
" already registered!");
307 m_epicsChID.emplace_back();
308 auto ptr = &m_epicsChID.back();
309 if (!ca_current_context()) SEVCHK(ca_context_create(ca_disable_preemptive_callback),
"ca_context_create");
311 SEVCHK(ca_create_channel((
m_PVPrefix + pvname).data(), NULL, NULL, 10, ptr),
"ca_create_channel failure");
313 if (update_pvs) SEVCHK(ca_pend_io(5.0),
"ca_pend_io failure");
315 m_epicsNameToChID[pvname] = *ptr;
316 if (keyname !=
"") m_epicsNameToChID[keyname] = *ptr;
317 return m_epicsChID.size() - 1;
327 if (m_epicsNameToChID[keyname] ==
nullptr) {
328 B2ERROR(
"Epics PV " << keyname <<
" not registered!");
331 SEVCHK(ca_put(DBR_DOUBLE, m_epicsNameToChID[keyname], (
void*)&value),
"ca_set failure");
339 if (m_epicsNameToChID[keyname] ==
nullptr) {
340 B2ERROR(
"Epics PV " << keyname <<
" not registered!");
343 SEVCHK(ca_put(DBR_SHORT, m_epicsNameToChID[keyname], (
void*)&value),
"ca_set failure");
351 if (m_epicsNameToChID[keyname] ==
nullptr) {
352 B2ERROR(
"Epics PV " << keyname <<
" not registered!");
355 if (value.length() > 40) {
356 B2ERROR(
"Epics string PV " << keyname <<
" too long (>40 characters)!");
360 strcpy(text, value.c_str());
361 SEVCHK(ca_put(DBR_STRING, m_epicsNameToChID[keyname], text),
"ca_set failure");
369 if (index < 0 || index >= (
int)m_epicsChID.size()) {
370 B2ERROR(
"Epics PV with " << index <<
" not registered!");
373 SEVCHK(ca_put(DBR_DOUBLE, m_epicsChID[index], (
void*)&value),
"ca_set failure");
381 if (index < 0 || index >= (
int)m_epicsChID.size()) {
382 B2ERROR(
"Epics PV with " << index <<
" not registered!");
385 SEVCHK(ca_put(DBR_SHORT, m_epicsChID[index], (
void*)&value),
"ca_set failure");
393 if (index < 0 || index >= (
int)m_epicsChID.size()) {
394 B2ERROR(
"Epics PV with " << index <<
" not registered!");
398 strcpy(text, value.c_str());
399 SEVCHK(ca_put(DBR_STRING, m_epicsChID[index], text),
"ca_set failure");
408 if (m_epicsNameToChID[keyname] ==
nullptr) {
409 B2ERROR(
"Epics PV " << keyname <<
" not registered!");
415 auto r = ca_get(DBR_DOUBLE, m_epicsNameToChID[keyname], (
void*)&value);
416 if (r == ECA_NORMAL) r = ca_pend_io(5.0);
417 if (r == ECA_NORMAL) {
420 SEVCHK(r,
"ca_get or ca_pend_io failure");
431 if (index < 0 || index >= (
int)m_epicsChID.size()) {
432 B2ERROR(
"Epics PV with " << index <<
" not registered!");
438 auto r = ca_get(DBR_DOUBLE, m_epicsChID[index], (
void*)&value);
439 if (r == ECA_NORMAL) r = ca_pend_io(5.0);
440 if (r == ECA_NORMAL) {
443 SEVCHK(r,
"ca_get or ca_pend_io failure");
455 if (m_epicsNameToChID[keyname] ==
nullptr) {
456 B2ERROR(
"Epics PV " << keyname <<
" not registered!");
457 return std::string(value);
462 auto r = ca_get(DBR_STRING, m_epicsNameToChID[keyname], value);
463 if (r == ECA_NORMAL) r = ca_pend_io(5.0);
464 if (r == ECA_NORMAL) {
466 return std::string(value);
468 SEVCHK(r,
"ca_get or ca_pend_io failure");
471 return std::string(value);
480 if (index < 0 || index >= (
int)m_epicsChID.size()) {
481 B2ERROR(
"Epics PV with " << index <<
" not registered!");
482 return std::string(value);
487 auto r = ca_get(DBR_DOUBLE, m_epicsChID[index], value);
488 if (r == ECA_NORMAL) r = ca_pend_io(5.0);
489 if (r == ECA_NORMAL) {
491 return std::string(value);
493 SEVCHK(r,
"ca_get or ca_pend_io failure");
496 return std::string(value);
503 if (m_epicsNameToChID[keyname] !=
nullptr) {
504 return m_epicsNameToChID[keyname];
506 B2ERROR(
"Epics PV " << keyname <<
" not registered!");
517 if (index >= 0 && index < (
int)m_epicsChID.size()) {
518 return m_epicsChID[index];
520 B2ERROR(
"Epics PV with " << index <<
" not registered!");
531 if (wait > 0.) SEVCHK(ca_pend_io(wait),
"ca_pend_io failure");
540 for (
auto& it : m_epicsChID) SEVCHK(ca_clear_channel(it),
"ca_clear_channel failure");
544 m_epicsNameToChID.clear();
569 struct dbr_ctrl_double tPvData;
573 auto r = ca_get(DBR_CTRL_DOUBLE, pv, &tPvData);
574 if (r == ECA_NORMAL) r = ca_pend_io(5.0);
575 if (r == ECA_NORMAL) {
576 if (!std::isnan(tPvData.lower_alarm_limit)) {
577 lowerAlarm = tPvData.lower_alarm_limit;
579 if (!std::isnan(tPvData.lower_warning_limit)) {
580 lowerWarn = tPvData.lower_warning_limit;
582 if (!std::isnan(tPvData.upper_warning_limit)) {
583 upperWarn = tPvData.upper_warning_limit;
585 if (!std::isnan(tPvData.upper_alarm_limit)) {
586 upperAlarm = tPvData.upper_alarm_limit;
590 SEVCHK(r,
"ca_get or ca_pend_io failure");
static MonObjList s_monObjList
The list of MonitoringObjects.
TCanvas * findCanvas(TString cname)
Find canvas by name.
bool hasDeltaPar(const std::string &dirname, const std::string &histname)
Check if Delta histogram parameters exist for histogram.
std::map< std::string, HistObject > HistList
The type of list of histograms.
void updateEpicsPVs(float timeout)
Update all EPICS PV (flush to network)
int registerEpicsPV(std::string pvname, std::string keyname="", bool update_pvs=true)
EPICS related Functions.
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.
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.
double getSigma68(TH1 *h) const
Helper function to compute half of the central interval covering 68% of a distribution.
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.
static HistList s_histList
The list of Histograms.
static std::string s_runType
The Run type.
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 setEpicsPV(std::string keyname, double value)
Write value to a EPICS PV.
std::map< std::string, MonitoringObject * > MonObjList
The type of list of MonitoringObjects.
static DeltaList s_deltaList
The list of Delta Histograms and settings.
static bool m_epicsReadOnly
Flag if to use EPICS in ReadOnly mode (for reading limits) do not set by yourself,...
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.
static std::string m_PVPrefix
The Prefix for EPICS PVs.
TH1 * findHistInCanvas(const std::string &hname)
Find histogram in corresponding canvas.
void cleanupEpicsPVs(void)
Unsubscribe from EPICS PVs on terminate.
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.
void ExtractEvent(std::vector< TH1 * > &hs)
Extract event processed from daq histogram, called from input module.
void UpdateCanvas(std::string name, bool updated=true)
Mark canvas as updated (or not)
static MonitoringObject * getMonitoringObject(const std::string &histname)
Get MonitoringObject with given name (new object is created if non-existing)
std::map< std::string, HistDelta * > DeltaList
The type of list of delta settings and histograms.
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.
void setEpicsStringPV(std::string keyname, std::string value)
Write string to a EPICS PV.
static CanvasUpdatedList s_canvasUpdatedList
The list of canvas updated status.
Class to keep track of delta histograms.
EDeltaType
enum definition for delta algo Disabled: nothing Entries: use nr histogram entries Underflow: use ent...
void setDescription(const std::string &description)
Sets the description of the module.
MonitoringObject is a basic object to hold data for the run-dependency monitoring Run summary TCanvas...
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.