Skip to content

Commit 2c27b4f

Browse files
authored
Merge pull request #336 from jacomago/empty-waveform
Handle Empty waveforms more elegantly
2 parents dc040bb + 9a0e588 commit 2c27b4f

File tree

8 files changed

+52
-147
lines changed

8 files changed

+52
-147
lines changed

src/main/org/epics/archiverappliance/data/VectorValue.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public VectorValue(List<T> vals) {
3030
*/
3131
@Override
3232
public Number getValue() {
33+
if (values.isEmpty()) return Double.NaN;
3334
return values.get(0);
3435
}
3536

src/main/org/epics/archiverappliance/engine/ArchiveEngine.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.epics.archiverappliance.engine.metadata.MetaGet;
2828
import org.epics.archiverappliance.engine.model.ArchiveChannel;
2929
import org.epics.archiverappliance.engine.model.DeltaArchiveChannel;
30-
import org.epics.archiverappliance.engine.model.Enablement;
3130
import org.epics.archiverappliance.engine.model.MonitoredArchiveChannel;
3231
import org.epics.archiverappliance.engine.model.SampleMode;
3332
import org.epics.archiverappliance.engine.model.ScannedArchiveChannel;
@@ -111,12 +110,12 @@ private static ArchiveChannel addChannel(final String name, final Writer writer,
111110
// Create new channel
112111
if (sample_mode.isMonitor()) {
113112
if (sample_mode.getDelta() > 0) {
114-
channel = new DeltaArchiveChannel(name, writer, Enablement.Enabling, buffer_capacity, last_sampleTimestamp, pvSamplingPeriod, sample_mode.getDelta(), configservice, archdbrtype, controlPVname, JCACommandThreadID, usePVAccess);
113+
channel = new DeltaArchiveChannel(name, writer, buffer_capacity, last_sampleTimestamp, pvSamplingPeriod, sample_mode.getDelta(), configservice, archdbrtype, controlPVname, JCACommandThreadID, usePVAccess);
115114
} else {
116-
channel = new MonitoredArchiveChannel(name, writer, Enablement.Enabling, buffer_capacity, last_sampleTimestamp, pvSamplingPeriod, configservice, archdbrtype, controlPVname, JCACommandThreadID, usePVAccess);
115+
channel = new MonitoredArchiveChannel(name, writer, buffer_capacity, last_sampleTimestamp, pvSamplingPeriod, configservice, archdbrtype, controlPVname, JCACommandThreadID, usePVAccess);
117116
}
118117
} else {
119-
channel = new ScannedArchiveChannel(name, writer, Enablement.Enabling, buffer_capacity, last_sampleTimestamp, pvSamplingPeriod, configservice, archdbrtype, controlPVname, JCACommandThreadID, usePVAccess);
118+
channel = new ScannedArchiveChannel(name, writer, buffer_capacity, last_sampleTimestamp, pvSamplingPeriod, configservice, archdbrtype, controlPVname, JCACommandThreadID, usePVAccess);
120119
}
121120

122121
configservice.getEngineContext().getChannelList().put(channel.getName(), channel);

src/main/org/epics/archiverappliance/engine/model/ArchiveChannel.java

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import org.epics.archiverappliance.config.ConfigService;
2222
import org.epics.archiverappliance.config.PVNames;
2323
import org.epics.archiverappliance.data.DBRTimeEvent;
24-
import org.epics.archiverappliance.data.SampleValue;
2524
import org.epics.archiverappliance.engine.membuf.ArrayListEventStream;
2625
import org.epics.archiverappliance.engine.pv.EPICS_V3_PV;
2726
import org.epics.archiverappliance.engine.pv.EPICS_V4_PV;
@@ -109,10 +108,6 @@ public abstract class ArchiveChannel {
109108
* The name of the PV that control archiving of this PV.
110109
*/
111110
private final String controlPVname;
112-
/**
113-
* How channel affects its groups
114-
*/
115-
private final Enablement enablement;
116111
/**
117112
* The writer/storage plugin that receives the samples.
118113
* We place samples into SampleBufffer and then the write thread comes along periodically and flushes these samples into this storageplugin.
@@ -148,10 +143,6 @@ public abstract class ArchiveChannel {
148143
* initial sample into the archive with current time stamp.
149144
*/
150145
private boolean need_first_sample = true;
151-
/**
152-
* Is this channel currently enabled?
153-
*/
154-
private boolean enabled = true;
155146

156147
/**
157148
* Is this channel currently paused? The source of truth for this is the PVTypeInfo in the database.
@@ -176,7 +167,6 @@ public abstract class ArchiveChannel {
176167
*
177168
* @param name pv's name
178169
* @param writer the writer for this pv
179-
* @param enablement start or stop archiving this pv when channel is created
180170
* @param buffer_capacity the sample buffer's capacity for this pv
181171
* @param last_archived_timestamp the last time stamp when this pv was archived
182172
* @param configservice the configservice of new archiver
@@ -190,7 +180,6 @@ public abstract class ArchiveChannel {
190180
public ArchiveChannel(
191181
final String name,
192182
final Writer writer,
193-
final Enablement enablement,
194183
final int buffer_capacity,
195184
final Instant last_archived_timestamp,
196185
final ConfigService configservice,
@@ -203,7 +192,6 @@ public ArchiveChannel(
203192
this.SERVER_IOC_DRIFT_SECONDS = Integer.parseInt(configservice.getInstallationProperties().getProperty("org.epics.archiverappliance.engine.epics.server_ioc_drift_seconds", "1800"));
204193
this.controlPVname = controlPVname;
205194
this.writer = writer;
206-
this.enablement = enablement;
207195
this.last_archived_timestamp = last_archived_timestamp;
208196
this.pvMetrics = new PVMetrics(name, controlPVname, System.currentTimeMillis() / 1000, archdbrtype);
209197
this.buffer = new SampleBuffer(name, buffer_capacity, archdbrtype, this.pvMetrics);
@@ -217,7 +205,6 @@ public void pvValueUpdate(final PV pv, final DBRTimeEvent temptimeevent) {
217205
// PV already suppresses updates after 'stop', but check anyway
218206
if (is_running) {
219207
try {
220-
if (enablement != Enablement.Passive) handleEnablement(temptimeevent);
221208

222209
handleNewValue(temptimeevent);
223210
} catch (Exception e) {
@@ -406,18 +393,6 @@ public final String getName() {
406393
return name;
407394
}
408395

409-
/** @return How channel affects its groups */
410-
public final Enablement getEnablement() {
411-
return enablement;
412-
}
413-
414-
/**
415-
* @return <code>true</code> if channel is currently enabled
416-
*/
417-
public final boolean isEnabled() {
418-
return enabled;
419-
}
420-
421396
/**
422397
* @return Short description of sample mechanism
423398
*/
@@ -436,7 +411,6 @@ public final void start() throws Exception {
436411
if (is_running) return;
437412

438413
is_running = true;
439-
enabled = true;
440414
need_first_sample = true;
441415
pvMetrics.setEnable(true);
442416
pv.start();
@@ -451,7 +425,6 @@ public final void stop() throws Exception {
451425
if (!is_running) return;
452426

453427
is_running = false;
454-
enabled = false;
455428
pv.stop();
456429
pvMetrics.setEnable(false);
457430
}
@@ -480,28 +453,6 @@ public void reset() {
480453
}
481454
}
482455

483-
/**
484-
* Enable or disable groups based on received value
485-
*
486-
* @param temptimeevent DBRTimeEvent
487-
* @throws Exception &emsp;
488-
*/
489-
private void handleEnablement(final DBRTimeEvent temptimeevent) throws Exception {
490-
if (enablement == Enablement.Passive) throw new Exception("Not to be called when passive");
491-
492-
SampleValue sampleValue = temptimeevent.getSampleValue();
493-
final double number = ValueUtil.getDouble(sampleValue);
494-
final boolean yes = number > 0.0;
495-
496-
// Do we enable or disable based on that value?
497-
final boolean enable = (enablement == Enablement.Enabling) == yes;
498-
try {
499-
if (enable) updateEnabledState();
500-
} catch (Exception e) {
501-
logger.error("exception in handleEnablement", e);
502-
}
503-
}
504-
505456
/**
506457
* Called for each value received from PV.
507458
* <p>
@@ -518,8 +469,6 @@ protected boolean handleNewValue(final DBRTimeEvent timeevent) throws Exception
518469
latestDBRTimeEvent = timeevent;
519470
}
520471

521-
if (!enabled) return false;
522-
523472
// Did we recover from write errors?
524473
if (need_write_error_sample && !SampleBuffer.isInErrorState()) {
525474
need_write_error_sample = false;
@@ -627,18 +576,6 @@ protected final void addValueToBuffer(final DBRTimeEvent timeevent) {
627576
if (SampleBuffer.isInErrorState()) need_write_error_sample = true;
628577
}
629578

630-
/**
631-
* Update the enablement state in case of change
632-
*
633-
*/
634-
private void updateEnabledState() {
635-
// Any change?
636-
if (enabled) return;
637-
638-
enabled = true;
639-
640-
// In case this arrived after shutdown, don't log it.
641-
}
642579

643580
@Override
644581
public String toString() {

src/main/org/epics/archiverappliance/engine/model/DeltaArchiveChannel.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ public class DeltaArchiveChannel extends ArchiveChannel {
3636
* @param name
3737
* Name of the channel (PV)
3838
* @param writer &emsp;
39-
* @param enablement
40-
* How channel affects its groups
4139
* @param buffer_capacity
4240
* Size of sample buffer
4341
* @param last_timeestamp &emsp;
@@ -54,12 +52,12 @@ public class DeltaArchiveChannel extends ArchiveChannel {
5452
* On error in PV setup
5553
*/
5654
public DeltaArchiveChannel(final String name, final Writer writer,
57-
final Enablement enablement, final int buffer_capacity,
55+
final int buffer_capacity,
5856
final Instant last_timeestamp, final double period_estimate,
5957
final double delta, final ConfigService configservice,
6058
final ArchDBRTypes archdbrtype, final String controlPVname,
6159
final int commandThreadID, final boolean usePVAccess) throws Exception {
62-
super(name, writer, enablement, buffer_capacity, last_timeestamp,
60+
super(name, writer, buffer_capacity, last_timeestamp,
6361
configservice, archdbrtype, controlPVname, commandThreadID, usePVAccess);
6462
this.delta = delta;
6563
this.period_estimate = period_estimate;
@@ -85,7 +83,7 @@ protected boolean handleNewValue(final DBRTimeEvent timeevent) {
8583
//
8684
logger.error("Exception handing new value", e1);
8785
}
88-
if (isEnabled() && isBeyondDelta(timeevent)) {
86+
if (isBeyondDelta(timeevent)) {
8987
// Activator.getLogger().log(Level.FINE,
9088
// "Wrote sample for {0}: {1}", new Object[] { getName(), value });
9189
try {

src/main/org/epics/archiverappliance/engine/model/Enablement.java

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/main/org/epics/archiverappliance/engine/model/MonitoredArchiveChannel.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ public class MonitoredArchiveChannel extends ArchiveChannel {
3232
/** @see ArchiveChannel#ArchiveChannel
3333
* @param name pv's name
3434
* @param writer the writer for this pv
35-
* @param enablement start or stop archiving this pv when channel is created
3635
* @param buffer_capacity the sample buffer's capacity for this pv
3736
* @param last_archived_timestamp the last time stamp when this pv was archived
3837
* @param period_estimate &emsp;
@@ -44,12 +43,12 @@ public class MonitoredArchiveChannel extends ArchiveChannel {
4443
* @throws Exception error when creating archive channel for this pv
4544
*/
4645
public MonitoredArchiveChannel(final String name, final Writer writer,
47-
final Enablement enablement, final int buffer_capacity,
46+
final int buffer_capacity,
4847
final Instant last_archived_timestamp,
4948
final double period_estimate, final ConfigService configservice,
5049
final ArchDBRTypes archdbrtype, final String controlPVname,
5150
final int commandThreadID, final boolean usePVAccess) throws Exception {
52-
super(name, writer, enablement, buffer_capacity,
51+
super(name, writer, buffer_capacity,
5352
last_archived_timestamp, configservice, archdbrtype,
5453
controlPVname, commandThreadID, usePVAccess);
5554
this.period_estimate = period_estimate;
@@ -74,14 +73,11 @@ protected boolean handleNewValue(final DBRTimeEvent timeevent) {
7473
} catch (Exception e) {
7574
logger.error("exception in handleNewValue for pv" + this.getName(), e);
7675
}
77-
if (isEnabled()) {
78-
try {
79-
addValueToBuffer(timeevent);
80-
} catch (Exception e) {
81-
logger.error("exception in handleNewValue for pv " + this.getName(), e);
82-
}
83-
return true;
76+
try {
77+
addValueToBuffer(timeevent);
78+
} catch (Exception e) {
79+
logger.error("exception in handleNewValue for pv " + this.getName(), e);
8480
}
85-
return false;
81+
return true;
8682
}
8783
}

src/main/org/epics/archiverappliance/engine/model/ScannedArchiveChannel.java

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ public class ScannedArchiveChannel extends ArchiveChannel implements Runnable {
3737
/** @see ArchiveChannel#ArchiveChannel
3838
* @param name pv's name
3939
* @param writer the writer for this pv
40-
* @param enablement start or stop archiving this pv when channel is created
4140
* @param buffer_capacity the sample buffer's capacity for this pv
4241
* @param last_timeestamp the last time stamp when this pv was archived
4342
* @param scan_period &emsp;
@@ -49,12 +48,12 @@ public class ScannedArchiveChannel extends ArchiveChannel implements Runnable {
4948
* @throws Exception error when creating archive channel for this pv
5049
*/
5150
public ScannedArchiveChannel(final String name, final Writer writer,
52-
Enablement enablement, final int buffer_capacity,
51+
final int buffer_capacity,
5352
final Instant last_timeestamp, final double scan_period,
5453
final ConfigService configservice, final ArchDBRTypes archdbrtype,
5554
final String controlPVname, final int commandThreadID, final boolean usePVAccess)
5655
throws Exception {
57-
super(name, writer, enablement, buffer_capacity, last_timeestamp,
56+
super(name, writer, buffer_capacity, last_timeestamp,
5857
configservice, archdbrtype, controlPVname, commandThreadID, usePVAccess);
5958
this.scan_period = scan_period;
6059
this.pvMetrics.setSamplingPeriod(scan_period);
@@ -89,32 +88,30 @@ protected boolean handleNewValue(final DBRTimeEvent timeevent) throws Exception
8988
logger.error("exception in handleNewValue for pv" + this.getName(), e);
9089
}
9190

92-
if (isEnabled()) {
93-
try {
94-
if (latestDBRTimeEvent == null) {
95-
return true;
96-
}
97-
// Is it a new value?
98-
if (isMatchingTimeStamp(lastDBRTimeEvent, latestDBRTimeEvent)) {
99-
return true;
100-
}
91+
try {
92+
if (latestDBRTimeEvent == null) {
93+
return true;
94+
}
95+
// Is it a new value?
96+
if (isMatchingTimeStamp(lastDBRTimeEvent, latestDBRTimeEvent)) {
97+
return true;
98+
}
10199

102-
if(isLessThanScanPeriod(lastDBRTimeEvent, latestDBRTimeEvent)) {
103-
// logger.debug("Latest event is less than scan periond; skipping for " + this.getName());
104-
// We however keep track of the server time when we got a handle event for comparision in the SCAN thread.
105-
this.serverTimeForStragglingScanValuesMillis = System.currentTimeMillis();
106-
return true;
107-
} else {
108-
// logger.debug("Latest event is more than scan periond; recording for " + this.getName());
109-
addValueToBuffer(latestDBRTimeEvent);
110-
}
111-
112-
} catch (Exception e) {
113-
logger.error("exception in handleNewValue for pv " + this.getName(), e);
100+
if(isLessThanScanPeriod(lastDBRTimeEvent, latestDBRTimeEvent)) {
101+
// logger.debug("Latest event is less than scan periond; skipping for " + this.getName());
102+
// We however keep track of the server time when we got a handle event for comparision in the SCAN thread.
103+
this.serverTimeForStragglingScanValuesMillis = System.currentTimeMillis();
104+
return true;
105+
} else {
106+
// logger.debug("Latest event is more than scan periond; recording for " + this.getName());
107+
addValueToBuffer(latestDBRTimeEvent);
114108
}
115-
return true;
109+
110+
} catch (Exception e) {
111+
logger.error("exception in handleNewValue for pv " + this.getName(), e);
116112
}
117-
return false;
113+
return true;
114+
118115
}
119116
}
120117

@@ -125,7 +122,6 @@ protected boolean handleNewValue(final DBRTimeEvent timeevent) throws Exception
125122
@Override
126123
public void run() {
127124
synchronized(this) {
128-
if (isEnabled()) {
129125
try {
130126
if (latestDBRTimeEvent == null || this.serverTimeForStragglingScanValuesMillis <= 0) {
131127
// logger.debug("Latest event/straggling time is null " + this.getName());
@@ -149,8 +145,7 @@ public void run() {
149145
logger.error("exception in handleNewValue for pv " + this.getName(), e);
150146
}
151147
return;
152-
}
153-
return;
148+
154149
}
155150
}
156151

0 commit comments

Comments
 (0)