14 #include <dqm/analysis/modules/DQMHistOutputToEPICS.h>
34 addParam(
"HistoList", m_histlist,
"histname, pvname");
35 B2DEBUG(99,
"DQMHistOutputToEPICS: Constructor done.");
38 DQMHistOutputToEPICSModule::~DQMHistOutputToEPICSModule()
41 if (ca_current_context()) ca_context_destroy();
45 void DQMHistOutputToEPICSModule::initialize()
48 if (!ca_current_context()) SEVCHK(ca_context_create(ca_disable_preemptive_callback),
"ca_context_create");
50 for (
auto& it : m_histlist) {
52 B2WARNING(
"Histolist with wrong nr of parameters " << it.size());
57 n->histoname = it.at(0);
58 SEVCHK(ca_create_channel(it.at(1).c_str(), NULL, NULL, 10, &n->mychid),
"ca_create_channel failure");
60 SEVCHK(ca_create_channel(it.at(2).c_str(), NULL, NULL, 10, &n->mychid_last),
"ca_create_channel failure");
69 SEVCHK(ca_pend_io(5.0),
"ca_pend_io failure");
71 B2DEBUG(99,
"DQMHistOutputToEPICS: initialized.");
74 void DQMHistOutputToEPICSModule::cleanPVs(
void)
77 for (
auto* it : pmynode) {
78 if (!it->mychid)
continue;
79 int length = int(ca_element_count(it->mychid));
81 it->data.resize(length, 0.0);
82 SEVCHK(ca_array_put(DBR_DOUBLE, length, it->mychid, (
void*)(it->data.data())),
"ca_put failure");
83 if (it->mychid_last) {
84 if (length ==
int(ca_element_count(it->mychid_last))) {
85 SEVCHK(ca_array_put(DBR_DOUBLE, length, it->mychid_last, (
void*)(it->data.data())),
"ca_put failure");
93 void DQMHistOutputToEPICSModule::beginRun()
95 B2DEBUG(99,
"DQMHistOutputToEPICS: beginRun called.");
100 void DQMHistOutputToEPICSModule::event()
103 for (
auto& it : pmynode) {
104 if (!it->mychid)
continue;
105 int length = it->data.size();
106 TH1* hh1 = findHist(it->histoname);
107 if (hh1 && hh1->GetNcells() > 2 && length > 0 && length ==
int(ca_element_count(it->mychid))) {
110 if (hh1->GetDimension() == 1) {
112 int nx = hh1->GetNbinsX() + 1;
113 for (
int x = 1; x < nx && i < length ; x++) {
114 it->data[i++] = hh1->GetBinContent(x);
117 }
else if (hh1->GetDimension() == 2) {
119 int nx = hh1->GetNbinsX() + 1;
120 int ny = hh1->GetNbinsY() + 1;
121 for (
int y = 1; y < ny && i < length; y++) {
122 for (
int x = 1; x < nx && i < length ; x++) {
123 it->data[i++] = hh1->GetBinContent(x, y);
128 SEVCHK(ca_array_put(DBR_DOUBLE, length, it->mychid, (
void*)it->data.data()),
"ca_set failure");
131 SEVCHK(ca_pend_io(5.0),
"ca_pend_io failure");
135 void DQMHistOutputToEPICSModule::copyToLast(
void)
137 if (!m_dirty)
return;
139 for (
auto* it : pmynode) {
140 if (it->mychid && it->mychid_last) {
142 int length = it->data.size();
143 if (length > 0 && length ==
int(ca_element_count(it->mychid_last))) {
144 SEVCHK(ca_array_put(DBR_DOUBLE, length, it->mychid_last, (
void*)it->data.data()),
"ca_put failure");
148 SEVCHK(ca_pend_io(5.0),
"ca_pend_io failure");
154 void DQMHistOutputToEPICSModule::endRun()
156 B2DEBUG(99,
"DQMHistOutputToEPICS: endRun called");
160 void DQMHistOutputToEPICSModule::terminate()
162 B2DEBUG(99,
"DQMHistOutputToEPICS: terminate called");
166 for (
auto* it : pmynode) {
167 if (it->mychid) SEVCHK(ca_clear_channel(it->mychid),
"ca_clear_channel failure");
168 if (it->mychid_last) SEVCHK(ca_clear_channel(it->mychid_last),
"ca_clear_channel failure");
170 SEVCHK(ca_pend_io(5.0),
"ca_pend_io failure");
The base class for the histogram analysis module.
Write DQM Histogram Content to EPICS Arrays.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.