10 #include <dqm/analysis/modules/DQMHistOutputToEPICS.h>
30 addParam(
"HistoList", m_histlist,
"histname, pvname");
31 B2DEBUG(99,
"DQMHistOutputToEPICS: Constructor done.");
34 DQMHistOutputToEPICSModule::~DQMHistOutputToEPICSModule()
37 if (ca_current_context()) ca_context_destroy();
41 void DQMHistOutputToEPICSModule::initialize()
44 if (!ca_current_context()) SEVCHK(ca_context_create(ca_disable_preemptive_callback),
"ca_context_create");
46 for (
auto& it : m_histlist) {
48 B2WARNING(
"Histolist with wrong nr of parameters " << it.size());
53 n->histoname = it.at(0);
54 SEVCHK(ca_create_channel(it.at(1).c_str(), NULL, NULL, 10, &n->mychid),
"ca_create_channel failure");
56 SEVCHK(ca_create_channel(it.at(2).c_str(), NULL, NULL, 10, &n->mychid_last),
"ca_create_channel failure");
65 SEVCHK(ca_pend_io(5.0),
"ca_pend_io failure");
67 B2DEBUG(99,
"DQMHistOutputToEPICS: initialized.");
70 void DQMHistOutputToEPICSModule::cleanPVs(
void)
73 for (
auto* it : pmynode) {
74 if (!it->mychid)
continue;
75 int length = int(ca_element_count(it->mychid));
77 it->data.resize(length, 0.0);
78 SEVCHK(ca_array_put(DBR_DOUBLE, length, it->mychid, (
void*)(it->data.data())),
"ca_put failure");
79 if (it->mychid_last) {
80 if (length ==
int(ca_element_count(it->mychid_last))) {
81 SEVCHK(ca_array_put(DBR_DOUBLE, length, it->mychid_last, (
void*)(it->data.data())),
"ca_put failure");
89 void DQMHistOutputToEPICSModule::beginRun()
91 B2DEBUG(99,
"DQMHistOutputToEPICS: beginRun called.");
96 void DQMHistOutputToEPICSModule::event()
99 for (
auto& it : pmynode) {
100 if (!it->mychid)
continue;
101 int length = it->data.size();
102 TH1* hh1 = findHist(it->histoname);
103 if (hh1 && hh1->GetNcells() > 2 && length > 0 && length ==
int(ca_element_count(it->mychid))) {
106 if (hh1->GetDimension() == 1) {
108 int nx = hh1->GetNbinsX() + 1;
109 for (
int x = 1; x < nx && i < length ; x++) {
110 it->data[i++] = hh1->GetBinContent(x);
113 }
else if (hh1->GetDimension() == 2) {
115 int nx = hh1->GetNbinsX() + 1;
116 int ny = hh1->GetNbinsY() + 1;
117 for (
int y = 1; y < ny && i < length; y++) {
118 for (
int x = 1; x < nx && i < length ; x++) {
119 it->data[i++] = hh1->GetBinContent(x, y);
124 SEVCHK(ca_array_put(DBR_DOUBLE, length, it->mychid, (
void*)it->data.data()),
"ca_set failure");
127 SEVCHK(ca_pend_io(5.0),
"ca_pend_io failure");
131 void DQMHistOutputToEPICSModule::copyToLast(
void)
133 if (!m_dirty)
return;
135 for (
auto* it : pmynode) {
136 if (it->mychid && it->mychid_last) {
138 int length = it->data.size();
139 if (length > 0 && length ==
int(ca_element_count(it->mychid_last))) {
140 SEVCHK(ca_array_put(DBR_DOUBLE, length, it->mychid_last, (
void*)it->data.data()),
"ca_put failure");
144 SEVCHK(ca_pend_io(5.0),
"ca_pend_io failure");
150 void DQMHistOutputToEPICSModule::endRun()
152 B2DEBUG(99,
"DQMHistOutputToEPICS: endRun called");
156 void DQMHistOutputToEPICSModule::terminate()
158 B2DEBUG(99,
"DQMHistOutputToEPICS: terminate called");
162 for (
auto* it : pmynode) {
163 if (it->mychid) SEVCHK(ca_clear_channel(it->mychid),
"ca_clear_channel failure");
164 if (it->mychid_last) SEVCHK(ca_clear_channel(it->mychid_last),
"ca_clear_channel failure");
166 SEVCHK(ca_pend_io(5.0),
"ca_pend_io failure");