-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDriveDataProcessorFESA_18022019.java
More file actions
245 lines (169 loc) · 7.25 KB
/
DriveDataProcessorFESA_18022019.java
File metadata and controls
245 lines (169 loc) · 7.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
package de.gsi.csco.ap.app_drivestat.utils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import cern.accsoft.commons.domain.particletransfers.ParticleTransfer;
import cern.japc.AcquiredParameterValue;
import cern.japc.MapParameterValue;
import cern.japc.Parameter;
import cern.japc.ParameterException;
import cern.japc.Parameters;
import cern.japc.Selector;
import cern.japc.factory.ParameterFactory;
import cern.japc.factory.SelectorFactory;
import cern.lsa.client.DeviceService;
import cern.lsa.client.Services;
import cern.lsa.domain.devices.Device;
import cern.lsa.domain.devices.DeviceMetaTypeEnum;
import cern.lsa.domain.devices.factory.DevicesRequestBuilder;
import cern.lsa.domain.settings.BeamProductionChain;
import cern.lsa.domain.settings.Contexts;
/**
* @author fschirru
*/
public class DriveDataProcessorFESA {
private static final DriveDataProcessorFESA INSTANCE = new DriveDataProcessorFESA();
private static final DeviceUserNameGenerator dung = DeviceUserNameGenerator.getInstance();
private static final Selector MULTIPLEXED_SELECTOR = SelectorFactory.newSelector("FAIR.SELECTOR.ALL");
private static final String[] DRIVE_TYPES = new String[] { "DS", "PLA" };
private static final String[] propertyname = { "POSIABSI", "CONSTANT", "CONSTANT", "POSITI" };
// private final static String[] propertyname = { "POSIABSS", "CONSTANT",
// "CONSTANT", "POSITI" };
private static final String[] propertyfield = { "data_pos", "minPosition", "maxPosition", "position" };
// private final static String[] propertyfield = { "pos", "minPosition",
// "maxPosition", "position" };
private static final DeviceComparator dc = new DeviceComparator();
private static String parameterName;
private static Parameter parameter;
private static AcquiredParameterValue ParameterValue;
private static MapParameterValue mapParameterValue;
private static Object[] fieldValue = new Object[propertyname.length];
private final List<Device> mySortedDevices = new ArrayList<>();
private final List<Object[]> driveDataList = new ArrayList<>();
private BeamProductionChain chain;
private Set<Device> myDevices = new HashSet<>();
private final DeviceService deviceService = Services.getDeviceService();
private Set<ParticleTransfer> particleTransfers;
private int p; // the property number
public DriveDataProcessorFESA() {
}
public static DriveDataProcessorFESA getInstance() {
return INSTANCE;
}
public void setBeamChain(final BeamProductionChain chain) {
this.chain = chain;
}
public void setDevices() {
final Set<String> drive_Types = new HashSet<>();
Collections.addAll(drive_Types, DRIVE_TYPES);
particleTransfers = Contexts.getParticleTransfersFromBeamProcesses(chain.getDrivableBeamProcesses());
// Filter on drives per particleTransfers and types
final DevicesRequestBuilder devicesRequestBuilder = new DevicesRequestBuilder();
devicesRequestBuilder.setParticleTransfers(particleTransfers);
devicesRequestBuilder.setMetaType(DeviceMetaTypeEnum.ACTUAL);
devicesRequestBuilder.setDeviceTypeNames(drive_Types);
myDevices = deviceService.findDevices(devicesRequestBuilder.build());
getDevicesData();
}
// get data from hardware
public void getDevicesData() {
// Clear list to avoid summing up of items while changing the chain
driveDataList.clear();
mySortedDevices.clear();
for (final Device device : myDevices) {
if (dung.isDeviceNameExisting(device.getName())) {
// Data processing according to the device type
if (device.getDeviceType().getName().equals("DS")) {
for (int p = 0; p < 3; p++) {
try {
parameterName = Parameters.buildParameterName(device.getName(), propertyname[p]);
parameter = ParameterFactory.newInstance().newParameter(parameterName);
ParameterValue = parameter.getValue(MULTIPLEXED_SELECTOR);
mapParameterValue = (MapParameterValue) ParameterValue.getValue();
// acquire the value of the considered property of
// the related device.
fieldValue[p] = mapParameterValue.getString(propertyfield[p]);
} catch (final ParameterException e) {
System.out.println(e);
fieldValue[p] = "0";
}
}
fieldValue[3] = "0"; // by default for DS devices
}
if (device.getDeviceType().getName().equals("PLA")) {
for (int p = 3; p < 4; p++) {
try {
parameterName = Parameters.buildParameterName(device.getName(), propertyname[p]);
parameter = ParameterFactory.newInstance().newParameter(parameterName);
ParameterValue = parameter.getValue(MULTIPLEXED_SELECTOR);
mapParameterValue = (MapParameterValue) ParameterValue.getValue();
// acquire the value of the considered property of
// the related device.
fieldValue[p] = mapParameterValue.getString(propertyfield[p]);
} catch (final ParameterException e) {
System.out.println(e);
fieldValue[p] = "0";
}
}
fieldValue[0] = "0"; // by default for PLA devices
fieldValue[1] = "0"; // by default for PLA devices
fieldValue[2] = "0"; // by default for PLA devices
}
// Once the device has been recognized and data acquired
// the latter will be stored in the driveDataList for
// visualization in the main table
try {
driveDataList.add(new Object[] { device.getName(), fieldValue[0], fieldValue[1], fieldValue[2],
fieldValue[3] });
mySortedDevices.add(device);
} catch (final Exception e) {
System.out.println(e);
System.exit(0);
}
} // End if deviceNameExists
} // End for Device
// retrieveDataFromFESA();
mySortedDevices.sort(dc); /*- Perform a sort respect device actual position */
}
public List<Object[]> getDriveData() {
return driveDataList;
}
public List<Device> getSortedDevices() {
return mySortedDevices;
}
// test method to check all devices processed within the getDeviceData
// method
public void retrieveDataFromFESA() {
System.out.println("******FESA DATA******" + "Size: " + driveDataList.size());
for (int i = 0; i < driveDataList.size(); i++) {
try {
System.out.println(driveDataList.get(i)[0] + " - " + driveDataList.get(i)[1] + " - "
+ driveDataList.get(i)[2] + " - " + driveDataList.get(i)[3] + " - " + driveDataList.get(i)[4]);
} catch (final Exception e) {
System.out.println(e);
System.exit(0);
}
}
}
public void generateDeviceSubscriptions() {
/*- for "DS" devices the only property to be updated is p = 0 while for "PLA" p = 3 */
for (final Device device : myDevices) {
if (dung.isDeviceNameExisting(device.getName())) {
final DeviceUpdateFESA duf = new DeviceUpdateFESA(device.getName());
if (device.getDeviceType().getName().equals("DS")) {
p = 0;
} else {
p = 3; // case "PLA" device
}
try {
duf.subscribe(MULTIPLEXED_SELECTOR, propertyname[p]);
} catch (final Exception e) {
System.out.println("Exception: " + e);
System.exit(0);
}
} // end if filter on device user-friendly names
}
}
}