14#include <framework/core/ModuleParam.templateDetails.h>
15#include <dqm/analysis/modules/DQMHistAnalysisInputPVSrv.h>
17#include <TDirectory.h>
34static void printChidInfo(chid ichid,
const char* message)
37 B2DEBUG(20,
"pv: " << ca_name(ichid) <<
" type(" << ca_field_type(ichid) <<
") nelements(" << ca_element_count(
38 ichid) <<
") host(" << ca_host_name(ichid)
39 <<
") read(" << ca_read_access(ichid) <<
") write(" << ca_write_access(ichid) <<
") state(" << ca_state(ichid) <<
")");
42static void exceptionCallback(
struct exception_handler_args args)
44 chid ichid = args.chid;
45 long stat = args.stat;
47 const char* noname =
"unknown";
49 channel = (ichid ? ca_name(ichid) : noname);
52 if (ichid) printChidInfo(ichid,
"exceptionCallback");
53 printf(
"exceptionCallback stat %s channel %s\n", ca_message(stat), channel);
56static void connectionCallback(
struct connection_handler_args args)
58 chid ichid = args.chid;
60 printChidInfo(ichid,
"connectionCallback");
63static void accessRightsCallback(
struct access_rights_handler_args args)
65 chid ichid = args.chid;
67 printChidInfo(ichid,
"accessRightsCallback");
69static void eventCallback(
struct event_handler_args eha)
71 chid ichid = eha.chid;
72 MYNODE* n = (MYNODE*)eha.usr;
74 if (eha.status != ECA_NORMAL) {
75 printChidInfo(ichid,
"eventCallback");
91 addParam(
"HistoList",
m_histlist,
"pvname, histname, histtitle, (bins,min,max[,bins,min,max])");
94 B2DEBUG(20,
"DQMHistAnalysisInputPVSrv: Constructor done.");
103 SEVCHK(ca_add_exception_event(exceptionCallback, NULL),
"ca_add_exception_event");
105 if (it.size() != 4 && it.size() != 5) {
106 B2WARNING(
"Histolist with wrong nr of parameters " << it.size());
109 auto n = (MYNODE*) callocMustSucceed(1,
sizeof(MYNODE),
"caMonitor");
110 pmynode.push_back(n);
113 TDirectory* oldDir = gDirectory;
114 TDirectory* d = oldDir;
115 TString myl = it.at(1).c_str();
118 while (myl.Tokenize(tok, from,
"/")) {
122 if (myl.Tokenize(dummy, f,
"/")) {
123 d = d->mkdir(tok,
"",
true);
130 B2DEBUG(20,
"Create Histo " << tok);
134 strncpy(n->name, it.at(0).c_str(), MAX_PV_NAME_LEN - 1);
135 istringstream is(it.at(3));
139 if (it.size() == 4) {
140 n->histo = (TH1*)
new TH1F(tok, it.at(2).c_str(), x, xmin, xmax);
147 istringstream iss(it.at(4));
151 n->histo = (TH1*)
new TH2F(tok, it.at(2).c_str(), x, xmin, xmax, y, ymin, ymax);
163 for (
auto n : pmynode) {
164 SEVCHK(ca_create_channel(n->name, connectionCallback, n, 20, &n->mychid),
"ca_create_channel");
165 SEVCHK(ca_replace_access_rights_event(n->mychid, accessRightsCallback),
"ca_replace_access_rights_event");
167 SEVCHK(ca_create_subscription(DBR_STRING, 1, n->mychid, DBE_VALUE, eventCallback, n, &n->myevid),
"ca_create_subscription");
172 B2DEBUG(20,
"DQMHistAnalysisInputPVSrv: initialized.");
178 B2DEBUG(20,
"DQMHistAnalysisInputPVSrv: beginRun called.");
192 SEVCHK(ca_pend_event(0.0001),
"ca_pend_event");
194 for (
auto n : pmynode) {
197 if (ca_field_type(n->mychid) != DBF_LONG && ca_field_type(n->mychid) != DBF_FLOAT)
continue;
200#pragma GCC diagnostic push
201#pragma GCC diagnostic ignored "-Wtype-limits"
202 auto bufferorg =
new char[dbr_size_n(ca_field_type(n->mychid), ca_element_count(n->mychid))];
203#pragma GCC diagnostic pop
205 void* buffer = (
void*) bufferorg;
208 status = ca_array_get(ca_field_type(n->mychid), ca_element_count(n->mychid), n->mychid, buffer);
209 SEVCHK(status,
"ca_array_get()");
210 status = ca_pend_io(15.0);
211 if (status != ECA_NORMAL) {
212 B2WARNING(
"EPICS ca_array_get " << ca_name(n->mychid) <<
" didn't return a value.");
217 bins = ca_element_count(n->mychid) < n->binmax ? ca_element_count(n->mychid) : n->binmax;
218 TH1* histo = n->histo;
219 for (
unsigned int j = ca_element_count(n->mychid); j < n->binmax; j++) histo->SetBinContent(j + 1, 0);
220 switch (ca_field_type(n->mychid)) {
222 dbr_char_t* b = (dbr_char_t*)buffer;
223 for (
unsigned int j = 0; j < bins; j++) {
224 histo->SetBinContent(j + 1, b[j]);
229 dbr_short_t* b = (dbr_short_t*)buffer;
230 for (
unsigned int j = 0; j < bins; j++) {
231 histo->SetBinContent(j + 1, b[j]);
235 dbr_long_t* b = (dbr_long_t*)buffer;
236 for (
unsigned int j = 0; j < bins; j++) {
237 histo->SetBinContent(j + 1, b[j]);
241 dbr_float_t* b = (dbr_float_t*)buffer;
242 for (
unsigned int j = 0; j < bins; j++) {
243 histo->SetBinContent(j + 1, b[j]);
247 dbr_double_t* b = (dbr_double_t*)buffer;
248 for (
unsigned int j = 0; j < bins; j++) {
249 histo->SetBinContent(j + 1, b[j]);
264 }
while (!t.CheckTimer(gSystem->Now()));
270 B2DEBUG(20,
"DQMHistAnalysisInputPVSrv: endRun called");
276 B2DEBUG(20,
"DQMHistAnalysisInputPVSrv: terminate called");
DQMHistAnalysisModule()
Constructor / Destructor.
void addParam(const std::string &name, T ¶mVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Abstract base class for different kinds of events.