Skip to content

Commit 9e54dae

Browse files
Merge pull request #86 from ISISComputingGroup/fix_period_uah_update
Add reading of per period uah
2 parents 32d0680 + 8be51db commit 9e54dae

File tree

13 files changed

+250
-31
lines changed

13 files changed

+250
-31
lines changed

isisdaeApp/Db/isisdae.db

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,17 @@ record(ai, "$(P)$(Q)TOTALUAMPS")
315315
info(archive, "-5.0 VAL")
316316
}
317317

318+
record(ai, "$(P)$(Q)TOTALUAMPS_PD")
319+
{
320+
field(DESC, "DAE Raw Period Microamps")
321+
field(DTYP, "asynFloat64")
322+
field(INP, "@asyn(icp,0,0)TOTALUAMPSPD")
323+
field(PREC, "3")
324+
field(SCAN, "I/O Intr")
325+
field(EGU, "uA hour")
326+
info(archive, "-5.0 VAL")
327+
}
328+
318329
record(ai, "$(P)$(Q)MEVENTS")
319330
{
320331
field(DESC, "DAE millions of events")

isisdaeApp/src/NORDPV.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,55 @@ bool NORDPV<T>::getNewValue(smartGDDPointer& pDD)
2929
return true;
3030
}
3131

32+
template <typename T>
33+
NORDSPECPV<T>::NORDSPECPV ( exServer & cas, pvInfo &setup, bool preCreateFlag, bool scanOnIn, T& nord, int spec, bool is_edges) : NORDPV<T>(cas, setup, preCreateFlag, scanOnIn, nord), m_is_edges(is_edges), m_spec(spec)
34+
{
35+
36+
}
37+
38+
template <typename T>
39+
bool NORDSPECPV<T>::getNewValue(smartGDDPointer& pDD)
40+
{
41+
try {
42+
setNORD(cas.iface()->getSpectrumSize(m_spec) + (m_is_edges ? 1 : 0));
43+
}
44+
catch(const std::exception& ex) {
45+
std::cerr << "CAS: Exception in NORDSPECPV::getNewValue(): " << ex.what() << std::endl;
46+
return false;
47+
}
48+
catch(...) {
49+
std::cerr << "CAS: Exception in NORDSPECPV::getNewValue()" << std::endl;
50+
return false;
51+
}
52+
return NORDPV<T>::getNewValue(pDD);
53+
}
54+
55+
template <typename T>
56+
NORDMONPV<T>::NORDMONPV ( exServer & cas, pvInfo &setup, bool preCreateFlag, bool scanOnIn, T& nord, int mon, bool is_edges) : NORDPV<T>(cas, setup, preCreateFlag, scanOnIn, nord), m_is_edges(is_edges), m_mon(mon)
57+
{
58+
59+
}
60+
61+
template <typename T>
62+
bool NORDMONPV<T>::getNewValue(smartGDDPointer& pDD)
63+
{
64+
try {
65+
int spec = cas.iface()->getSpectrumNumberForMonitor(m_mon);
66+
setNORD(cas.iface()->getSpectrumSize(spec) + (m_is_edges ? 1 : 0));
67+
}
68+
catch(const std::exception& ex) {
69+
std::cerr << "CAS: Exception in NORDMONPV::getNewValue(): " << ex.what() << std::endl;
70+
return false;
71+
}
72+
catch(...) {
73+
std::cerr << "CAS: Exception in NORDMONPV::getNewValue()" << std::endl;
74+
return false;
75+
}
76+
return NORDPV<T>::getNewValue(pDD);
77+
}
78+
3279
template class NORDPV<int>;
3380
template class NORDPV<float>;
81+
82+
template class NORDSPECPV<int>;
83+
template class NORDMONPV<int>;

isisdaeApp/src/SpectrumPV.cc

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,16 @@ bool SpectrumPV::getNewValue(smartGDDPointer& pDD)
3333
return false;
3434
}
3535
int n = 0;
36+
bool as_histogram = (m_axis == "XE" ? true : false); // is X bin boundaries
37+
bool as_distribution = (m_axis == "YC" ? false : true); // is Y a distribution
3638
try {
3739
if (m_axis == "YC")
3840
{
39-
n = cas.iface()->getSpectrum(m_spec, m_period, pX, pY, nmax, false);
41+
n = cas.iface()->getSpectrum(m_spec, m_period, pX, pY, nmax, as_histogram, as_distribution);
4042
}
4143
else
4244
{
43-
n = cas.iface()->getSpectrum(m_spec, m_period, pX, pY, nmax, true);
45+
n = cas.iface()->getSpectrum(m_spec, m_period, pX, pY, nmax, as_histogram, as_distribution);
4446
}
4547
}
4648
catch(const std::exception& ex) {
@@ -55,9 +57,9 @@ bool SpectrumPV::getNewValue(smartGDDPointer& pDD)
5557
delete[] pY;
5658
return false;
5759
}
58-
m_nord = n; // number of elements used
5960
if (m_axis == "Y" || m_axis == "YC")
6061
{
62+
m_nord = n; // number of elements used
6163
delete[] pX;
6264
if ( this->pValue.valid() )
6365
{
@@ -87,8 +89,12 @@ bool SpectrumPV::getNewValue(smartGDDPointer& pDD)
8789
m_maxval = *(minmax.second);
8890
return true;
8991
}
90-
else if (m_axis == "X")
92+
else if (m_axis == "X" || m_axis == "XE")
9193
{
94+
if (as_histogram && n < nmax) {
95+
++n; // we have bin boundaries
96+
}
97+
m_nord = n; // number of elements used
9298
delete[] pY;
9399
// check to see if value has actually changed since last time
94100
if ( this->pValue.valid() )
@@ -121,6 +127,7 @@ bool SpectrumPV::getNewValue(smartGDDPointer& pDD)
121127
}
122128
else
123129
{
130+
m_nord = 0; // number of elements used
124131
delete[] pX;
125132
delete[] pY;
126133
return false;

isisdaeApp/src/dae.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ namespace ISISICPINT
2323
ISISICPINT_DllExport extern int(startSEWait)(std::string& messages);
2424
ISISICPINT_DllExport extern int(endSEWait)(std::string& messages);
2525
ISISICPINT_DllExport extern int(getSpectrum)(long spectrum_number, long period, std::vector<double>& time_channels, std::vector<double>& signal, bool as_histogram, bool as_distribution, long& sum, std::string& messages);
26+
ISISICPINT_DllExport extern long(getSpectrumSize)(long spectrum_number, std::string& messages);
2627
ISISICPINT_DllExport extern int(changeTCB)(const std::string& tcb_xml, std::string& messages);
2728
ISISICPINT_DllExport extern int(changeDAEsettings)(const std::string& dae_xml, std::string& messages);
2829
ISISICPINT_DllExport extern int(getSpectrumIntegral)(long spectrum_number, long period, float time_low, float time_high, long& counts, std::string& messages);
@@ -33,6 +34,7 @@ namespace ISISICPINT
3334
ISISICPINT_DllExport extern long(getRawFramesTotal)(std::string& messages); // retval
3435
ISISICPINT_DllExport extern long(getGoodFramesTotal)(std::string& messages); // retval
3536
ISISICPINT_DllExport extern double(getGoodUAmpH)(std::string& messages); // retval
37+
ISISICPINT_DllExport extern double(getRawUAmpH)(std::string& messages); // retval
3638
ISISICPINT_DllExport extern int(getSpectraSum)(long period, long first_spec, long num_spec, long spec_type, double time_low, double time_high, std::vector<long>& sums, std::vector<long>& max_vals, std::vector<long>& spec_nums, std::string& messages);
3739
ISISICPINT_DllExport extern int(changeSample)(const std::string& sample_xml, std::string& messages);
3840
ISISICPINT_DllExport extern int(changeUser)(const std::string& user_xml, std::string& messages);
@@ -86,6 +88,8 @@ namespace ISISICPINT
8688
ISISICPINT_DllExport extern int(getStatusMessages)(long stream, std::list<std::string>& messages);
8789
ISISICPINT_DllExport extern long(getGoodFramesPeriod)(std::string& messages); // retval
8890
ISISICPINT_DllExport extern double(getGoodUAmpHPeriod)(std::string& messages); // retval
91+
ISISICPINT_DllExport extern long(getRawFramesPeriod)(std::string& messages); // retval
92+
ISISICPINT_DllExport extern double(getRawUAmpHPeriod)(std::string& messages); // retval
8993
ISISICPINT_DllExport extern int(getFramesAllPeriods)(std::vector<long>& good_frames, std::vector<long>& raw_frames, std::string& messages);
9094
ISISICPINT_DllExport extern int(getUAmpHAllPeriods)(std::vector<float>& good_uamph, std::vector<float>& raw_uamph, std::string& messages);
9195
ISISICPINT_DllExport extern double(getMEventsPeriod)(long period, std::string& messages); // retval

isisdaeApp/src/dae_isisicpint_dummy.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ double ISISICPINT::getGoodUAmpH(std::string& messages)
112112
return 0;
113113
}
114114

115+
double ISISICPINT::getRawUAmpH(std::string& messages)
116+
{
117+
return 0;
118+
}
119+
115120
int ISISICPINT::getSpectraSum(long period, long first_spec, long num_spec, long spec_type, double time_low, double time_high, std::vector<long>& sums, std::vector<long>& max_vals, std::vector<long>& spec_nums, std::string& messages)
116121
{
117122
return 0;
@@ -387,6 +392,16 @@ double ISISICPINT::getGoodUAmpHPeriod(std::string& messages)
387392
return 0.0;
388393
}
389394

395+
long ISISICPINT::getRawFramesPeriod(std::string& messages)
396+
{
397+
return 0;
398+
}
399+
400+
double ISISICPINT::getRawUAmpHPeriod(std::string& messages)
401+
{
402+
return 0.0;
403+
}
404+
390405
int ISISICPINT::getFramesAllPeriods(std::vector<long>& good_frames, std::vector<long>& raw_frames, std::string& messages)
391406
{
392407
return 0;
@@ -402,6 +417,12 @@ int ISISICPINT::updateCRPTSpectra(LONG period, LONG spec_start, LONG nspec, std:
402417
return 0;
403418
}
404419

420+
long ISISICPINT::getSpectrumSize(long spectrum_number, std::string& messages)
421+
{
422+
return 0;
423+
}
424+
425+
405426
int ISISICPINT::getCRPTSpectraIntegral(const std::vector<long>& spectrum_numbers, long period, const std::vector<float>& time_low, const std::vector<float>& time_high, std::vector<long>& counts, std::string& messages)
406427
{
407428
return 0;

isisdaeApp/src/exServer.cc

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -349,9 +349,11 @@ void exServer::createAxisPVs(bool is_monitor, int id, int period, const char* ax
349349
}
350350

351351
sprintf(buffer, "%s:%d:%d:%s.NORD", prefix, period, id, axis);
352+
bool is_edges = (strcmp(axis, "XE") == 0);
352353
pPVI = new pvInfo (0.5, buffer, static_cast<float>(m_ntc), 1.0f, "", aitEnumInt32, 1);
353354
m_pvList[buffer] = pPVI;
354-
exPV* pPV = new NORDPV<int>(*this, *pPVI, true, scanOn, pSPV->getNORD());
355+
exPV* pPV = (is_monitor ? static_cast<NORDPV<int>*>(new NORDMONPV<int>(*this, *pPVI, true, scanOn, pSPV->getNORD(), id, is_edges)) :
356+
static_cast<NORDPV<int>*>(new NORDSPECPV<int>(*this, *pPVI, true, scanOn, pSPV->getNORD(), id, is_edges)));
355357
pPVI->setPV(pPV);
356358
sprintf(pvAlias, "%s%s", m_pvPrefix.c_str(), buffer);
357359
this->installAliasName(*pPVI, pvAlias);
@@ -520,6 +522,7 @@ bool exServer::createSpecPVs(const std::string& pvStr)
520522
}
521523

522524
createAxisPVs(false, spec, period, "X", m_tof_units);
525+
createAxisPVs(false, spec, period, "XE", m_tof_units);
523526
createAxisPVs(false, spec, period, "Y", std::string("cnt /") + m_tof_units); // currently MAX_UNIT_SIZE = 8 for CTRL_DOUBLE calls
524527
createAxisPVs(false, spec, period, "YC", "cnt");
525528
createCountsPV(false, spec, period);
@@ -543,6 +546,7 @@ bool exServer::createMonitorPVs(const std::string& pvStr)
543546
}
544547

545548
createAxisPVs(true, mon, period, "X", m_tof_units);
549+
createAxisPVs(true, mon, period, "XE", m_tof_units);
546550
createAxisPVs(true, mon, period, "Y", std::string("cnt /") + m_tof_units); // currently MAX_UNIT_SIZE = 8 for CTRL_DOUBLE calls
547551
createAxisPVs(true, mon, period, "YC", "cnt");
548552
createCountsPV(true, mon, period);
@@ -570,8 +574,8 @@ bool exServer::createMonitorPVs(const std::string& pvStr)
570574
bool parseSpecPV(const std::string& pvStr, int& spec, int& period, std::string& axis, std::string& field)
571575
{
572576
//Assumes period then spectrum
573-
pcrecpp::RE spec_per_re("SPEC:(\\d+):(\\d+):(X|YC|Y|C)([.].*)?");
574-
pcrecpp::RE spec_re("SPEC:(\\d+):(X|YC|Y|C)([.].*)?");
577+
pcrecpp::RE spec_per_re("SPEC:(\\d+):(\\d+):(XE|X|YC|Y|C)([.].*)?");
578+
pcrecpp::RE spec_re("SPEC:(\\d+):(XE|X|YC|Y|C)([.].*)?");
575579

576580
if (!spec_per_re.FullMatch(pvStr, &period, &spec, &axis, &field))
577581
{
@@ -588,8 +592,8 @@ bool parseSpecPV(const std::string& pvStr, int& spec, int& period, std::string&
588592
bool parseMonitorPV(const std::string& pvStr, int& mon, int& period, std::string& axis, std::string& field)
589593
{
590594
//Assumes period then monitor
591-
pcrecpp::RE monitor_per_re("MON:(\\d+):(\\d+):(X|YC|Y|C|S)([.].*)?");
592-
pcrecpp::RE monitor_re("MON:(\\d+):(X|YC|Y|C|S)([.].*)?");
595+
pcrecpp::RE monitor_per_re("MON:(\\d+):(\\d+):(XE|X|YC|Y|C|S)([.].*)?");
596+
pcrecpp::RE monitor_re("MON:(\\d+):(XE|X|YC|Y|C|S)([.].*)?");
593597
if (!monitor_per_re.FullMatch(pvStr, &period, &mon, &axis, &field))
594598
{
595599
if (!monitor_re.FullMatch(pvStr, &mon, &axis, &field))

isisdaeApp/src/exServer.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,12 +290,42 @@ class NORDPV : public exScalarPV {
290290
NORDPV ( exServer & cas, pvInfo &setup,
291291
bool preCreateFlag, bool scanOnIn, T& nord );
292292
virtual bool getNewValue(smartGDDPointer& pDD);
293+
protected:
294+
void setNORD(const T& nord) { m_nord = nord; }
293295
private:
294296
T& m_nord;
295297
NORDPV & operator = ( const NORDPV & );
296298
NORDPV ( const NORDPV & );
297299
};
298300

301+
template <typename T>
302+
class NORDSPECPV : public NORDPV<T>
303+
{
304+
public:
305+
NORDSPECPV ( exServer & cas, pvInfo &setup,
306+
bool preCreateFlag, bool scanOnIn, T& nord, int spec, bool is_edges );
307+
virtual bool getNewValue(smartGDDPointer& pDD);
308+
private:
309+
bool m_is_edges;
310+
int m_spec;
311+
NORDSPECPV & operator = ( const NORDSPECPV & );
312+
NORDSPECPV ( const NORDSPECPV & );
313+
};
314+
315+
template <typename T>
316+
class NORDMONPV : public NORDPV<T>
317+
{
318+
public:
319+
NORDMONPV ( exServer & cas, pvInfo &setup,
320+
bool preCreateFlag, bool scanOnIn, T& nord, int mon, bool is_edges );
321+
virtual bool getNewValue(smartGDDPointer& pDD);
322+
private:
323+
bool m_is_edges;
324+
int m_mon;
325+
NORDMONPV & operator = ( const NORDMONPV & );
326+
NORDMONPV ( const NORDMONPV & );
327+
};
328+
299329
class CountsPV : public exScalarPV {
300330
public:
301331
CountsPV ( exServer & cas, pvInfo &setup,

isisdaeApp/src/isisdaeDriver.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,6 +1125,7 @@ isisdaeDriver::isisdaeDriver(isisdaeInterface* iface, const char *portName, int
11251125

11261126
createParam(P_BeamCurrentString, asynParamFloat64, &P_BeamCurrent);
11271127
createParam(P_TotalUAmpsString, asynParamFloat64, &P_TotalUAmps);
1128+
createParam(P_TotalUAmpsPeriodString, asynParamFloat64, &P_TotalUAmpsPeriod);
11281129
createParam(P_MonitorFromString, asynParamFloat64, &P_MonitorFrom);
11291130
createParam(P_MonitorToString, asynParamFloat64, &P_MonitorTo);
11301131
createParam(P_MEventsString, asynParamFloat64, &P_MEvents);
@@ -1409,22 +1410,26 @@ void isisdaeDriver::updateRunStatus()
14091410
{
14101411
m_RunStatus = rs;
14111412
}
1412-
long frames = m_iface->getGoodFrames();
14131413
unsigned long tc = m_iface->getTotalCounts();
14141414
epicsTime tc_ts(epicsTime::getCurrent());
1415-
double uah = m_iface->getGoodUAH();
1416-
// long p_frames = m_iface->getGoodFramesPeriod(); // this currently only works in period card mode
1417-
// double p_uah = m_iface->getGoodUAHPeriod();
1415+
long frames = m_iface->getGoodFrames();
1416+
long p_frames = m_iface->getGoodFramesPeriod();
14181417
long r_frames = m_iface->getRawFrames();
1419-
double r_uah = 0.0;
1418+
long p_r_frames = m_iface->getRawFramesPeriod();
1419+
double uah = m_iface->getGoodUAH();
1420+
double p_uah = m_iface->getGoodUAHPeriod();
1421+
double r_uah = m_iface->getRawUAH();
1422+
double p_r_uah = m_iface->getRawUAHPeriod();
14201423
if (no_check_frame_uamp == NULL || *no_check_frame_uamp == '\0')
14211424
{
14221425
check_frame_uamp("good", frames, uah, fu_state);
14231426
check_frame_uamp("raw", r_frames, r_uah, r_fu_state);
1424-
// check_frame_uamp("period good", p_frames, p_uah, p_fu_state);
1427+
check_frame_uamp("period good", p_frames, p_uah, p_fu_state);
14251428
}
14261429
setDoubleParam(P_GoodUAH, uah);
1427-
// setDoubleParam(P_GoodUAHPeriod, p_uah);
1430+
setDoubleParam(P_GoodUAHPeriod, p_uah);
1431+
setDoubleParam(P_TotalUAmps, r_uah);
1432+
setDoubleParam(P_TotalUAmpsPeriod, p_r_uah);
14281433
setIntegerParam(P_TotalCounts, tc);
14291434
setDoubleParam(P_MEvents, static_cast<double>(tc) / 1.0e6);
14301435
double tdiff = static_cast<double>(tc_ts - old_tc_ts);
@@ -1445,10 +1450,11 @@ void isisdaeDriver::updateRunStatus()
14451450
old_frames = frames;
14461451
}
14471452
setIntegerParam(P_GoodFramesTotal, frames);
1448-
// setIntegerParam(P_GoodFramesPeriod, p_frames);
1453+
setIntegerParam(P_GoodFramesPeriod, p_frames);
1454+
setIntegerParam(P_RawFramesPeriod, p_r_frames);
14491455
setIntegerParam(P_RawFramesTotal, r_frames);
14501456
setIntegerParam(P_RunStatus, m_RunStatus);
1451-
///@todo need to update P_RawFramesPeriod, P_RunDurationTotal, P_TotalUAmps, P_RunDurationPeriod, P_MonitorCounts
1457+
///@todo need to update P_RunDurationTotal, P_RunDurationPeriod, P_MonitorCounts
14521458
}
14531459

14541460
// zero counters st start of run, done early before actual readbacks
@@ -1457,6 +1463,7 @@ void isisdaeDriver::zeroRunCounters(bool do_callbacks)
14571463
setDoubleParam(P_GoodUAH, 0.0);
14581464
setDoubleParam(P_GoodUAHPeriod, 0.0);
14591465
setDoubleParam(P_TotalUAmps, 0.0);
1466+
setDoubleParam(P_TotalUAmpsPeriod, 0.0);
14601467
setIntegerParam(P_TotalCounts, 0);
14611468
setIntegerParam(P_GoodFramesTotal, 0);
14621469
setIntegerParam(P_GoodFramesPeriod, 0);

isisdaeApp/src/isisdaeDriver.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ class isisdaeDriver : public ADDriver
9090
int P_PeriodSequence; // long
9191
int P_BeamCurrent; // double
9292
int P_TotalUAmps; // double
93+
int P_TotalUAmpsPeriod; // double
9394
int P_MonitorFrom; // double
9495
int P_MonitorTo; // double
9596
int P_MEvents; // double
@@ -265,6 +266,7 @@ class isisdaeDriver : public ADDriver
265266
#define P_PeriodSequenceString "PERIODSEQ"
266267
#define P_BeamCurrentString "BEAMCURRENT"
267268
#define P_TotalUAmpsString "TOTALUAMPS"
269+
#define P_TotalUAmpsPeriodString "TOTALUAMPSPD"
268270
#define P_MonitorFromString "MONITORFROM"
269271
#define P_MonitorToString "MONITORTO"
270272
#define P_MEventsString "MEVENTS"

0 commit comments

Comments
 (0)