9 #include <dqm/analysis/modules/DQMHistAnalysisEpicsExample.h>
31 addParam(
"HistoName", m_histoname,
"Name of Histogram (incl dir)", std::string(
""));
32 addParam(
"Function", m_function,
"Fit function definition", std::string(
"gaus"));
33 addParam(
"Parameters", m_parameters,
"Fit function parameters for EPICS", 3);
34 addParam(
"PVName", m_pvPrefix,
"PV Prefix", std::string(
"DQM:TEST:hist:"));
35 B2DEBUG(20,
"DQMHistAnalysisEpicsExample: Constructor done.");
39 DQMHistAnalysisEpicsExampleModule::~DQMHistAnalysisEpicsExampleModule()
42 if (ca_current_context()) ca_context_destroy();
46 void DQMHistAnalysisEpicsExampleModule::initialize()
48 B2DEBUG(20,
"DQMHistAnalysisEpicsExample: initialized.");
52 a.ReplaceAll(
"/",
"_");
53 m_c1 =
new TCanvas(
"c_" + a);
54 m_f1 =
new TF1(
"f_" + a, TString(m_function), -30, 300);
55 m_f1->SetParameter(0, 1000);
56 m_f1->SetParameter(1, 0);
57 m_f1->SetParameter(2, 10);
58 m_f1->SetLineColor(4);
60 m_f1->SetNumberFitPoints(512);
62 m_line =
new TLine(0, 10, 0, 0);
63 m_line->SetVertical(
true);
64 m_line->SetLineColor(8);
65 m_line->SetLineWidth(3);
67 m_line_lo =
new TLine(0, 10, 0, 0);
68 m_line_lo->SetVertical(
true);
69 m_line_lo->SetLineColor(2);
70 m_line_lo->SetLineWidth(3);
72 m_line_hi =
new TLine(0, 10, 0, 0);
73 m_line_hi->SetVertical(
true);
74 m_line_hi->SetLineColor(2);
75 m_line_hi->SetLineWidth(3);
84 if (m_parameters > 0) {
85 if (m_parameters > 10) m_parameters = 10;
87 if (!ca_current_context()) SEVCHK(ca_context_create(ca_disable_preemptive_callback),
"ca_context_create");
89 for (
auto i = 0; i < m_parameters; i++) {
91 aa = m_f1->GetParName(i);
92 if (aa ==
"") aa = string(
"par") + string(TString::Itoa(i, 10).Data());
95 SEVCHK(ca_create_channel(aa.c_str(), NULL, NULL, 10, &mychid[i]),
"ca_create_channel failure");
101 SEVCHK(ca_pend_io(5.0),
"ca_pend_io failure");
109 void DQMHistAnalysisEpicsExampleModule::beginRun()
112 B2DEBUG(20,
"DQMHistAnalysisEpicsExample: beginRun called.");
116 hh1 = findHist(m_histoname.c_str());
119 B2DEBUG(20,
"Histo " << m_histoname <<
" not in memfile");
120 TDirectory* d = gROOT;
121 TString myl = m_histoname;
124 while (myl.Tokenize(tok, from,
"/")) {
128 if (myl.Tokenize(dummy, f,
"/")) {
129 auto e = d->GetDirectory(tok);
131 B2DEBUG(20,
"Cd Dir " << tok);
139 TObject* obj = d->FindObject(tok);
141 if (obj->IsA()->InheritsFrom(
"TH1")) {
142 B2DEBUG(20,
"Histo " << m_histoname <<
" found in mem");
146 B2DEBUG(20,
"Histo " << m_histoname <<
" NOT found in mem");
157 B2DEBUG(20,
"Histo " << m_histoname <<
" not found");
161 void DQMHistAnalysisEpicsExampleModule::event()
166 hh1 = findHist(m_histoname.c_str());
168 B2DEBUG(20,
"Histo " << m_histoname <<
" not in memfile");
169 TDirectory* d = gROOT;
170 TString myl = m_histoname;
173 while (myl.Tokenize(tok, from,
"/")) {
177 if (myl.Tokenize(dummy, f,
"/")) {
178 auto e = d->GetDirectory(tok);
180 B2DEBUG(20,
"Cd Dir " << tok);
188 TObject* obj = d->FindObject(tok);
190 if (obj->IsA()->InheritsFrom(
"TH1")) {
191 B2DEBUG(20,
"Histo " << m_histoname <<
" found in mem");
196 B2DEBUG(20,
"Histo " << m_histoname <<
" NOT found in mem");
202 double y1 = hh1->GetMaximum();
203 double y2 = hh1->GetMinimum();
204 m_line->SetY1(y1 + (y1 - y2) * 0.05);
205 m_line_lo->SetY1(y1 + (y1 - y2) * 0.05);
206 m_line_hi->SetY1(y1 + (y1 - y2) * 0.05);
210 double x = m_f1->GetParameter(1);
222 B2DEBUG(20,
"Histo " << m_histoname <<
" not found");
226 if (m_parameters > 0) {
227 for (
auto i = 0; i < m_parameters; i++) {
229 data = m_f1->GetParameter(i);
230 if (mychid[i]) SEVCHK(ca_put(DBR_DOUBLE, mychid[i], (
void*)&data),
"ca_set failure");
232 SEVCHK(ca_pend_io(5.0),
"ca_pend_io failure");
237 void DQMHistAnalysisEpicsExampleModule::endRun()
239 B2DEBUG(20,
"DQMHistAnalysisEpicsExample : endRun called");
243 void DQMHistAnalysisEpicsExampleModule::terminate()
246 if (m_parameters > 0) {
247 for (
auto i = 0; i < m_parameters; i++) {
248 if (mychid[i]) SEVCHK(ca_clear_channel(mychid[i]),
"ca_clear_channel failure");
250 SEVCHK(ca_pend_io(5.0),
"ca_pend_io failure");
253 B2DEBUG(20,
"DQMHistAnalysisEpicsExample: terminate called");
Class definition for the output module of Sequential ROOT I/O.
The base class for the histogram analysis module.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.