-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDriveDataProcessorFESA_15022019.java
More file actions
400 lines (286 loc) · 12.4 KB
/
DriveDataProcessorFESA_15022019.java
File metadata and controls
400 lines (286 loc) · 12.4 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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
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;
import cern.lsa.domain.settings.DrivableBeamProcess;
import cern.lsa.domain.settings.type.BeamProcessTypeCategory;
import de.gsi.aco.sv.japc.FAIRSelectorBuilder;
// for library loggers
// import org.slf4j.Logger;
// import org.slf4j.LoggerFactory;
// for application loggers
// import de.gsi.cs.co.ap.common.gui.elements.logger.AppLogger;
/**
* @author fschirru
*/
public class DriveDataProcessorFESA {
// You can choose a logger (needed imports are given in the import section
// as comments):
// for libraries:
// private static final Logger LOGGER =
// LoggerFactory.getLogger(DriveDataProcessorFESA.class);
// for applications:
// private static final AppLogger LOGGER = AppLogger.getLogger();
/**
* @author fschirru
*/
private static final DriveDataProcessorFESA INSTANCE = new DriveDataProcessorFESA();
private final DriveDataProcessorLSA ddpLSA = DriveDataProcessorLSA.getInstance();
private final DeviceUserNameGenerator dung = DeviceUserNameGenerator.getInstance();
private final static String[] propertyname = { "POSIABSI", "CONSTANT", "CONSTANT", "POSITI" };
// private final static String[] propertyname = { "POSIABSS", "CONSTANT",
// "CONSTANT", "POSITI" };
private final static String[] propertyfield = { "data_pos", "minPosition", "maxPosition", "position" };
// private final static String[] propertyfield = { "pos", "minPosition",
// "maxPosition", "position" };
private static final Selector MULTIPLEXED_SELECTOR = SelectorFactory.newSelector("FAIR.SELECTOR.ALL");
// private static String devicename = "GTH4QD21";
private static String parameterName;
private static Parameter parameter;
private static AcquiredParameterValue ParameterValue;
private static MapParameterValue mapParameterValue;
private static Object[] fieldValue = new Object[propertyname.length]; // to
// be
// changed
// into
// generic
// object
private Set<Device> myDSdevices = new HashSet<>(); // The list containing
// the DS devices
private Set<Device> myPLAdevices = new HashSet<>(); // The list containing
// the PLA devices
private final List<Object[]> driveDataList = new ArrayList<>(); // to be
// changed
// into
// generic
// object
private BeamProductionChain chain;
private Set<Device> myDevices = new HashSet<>();
private final DevicesRequestBuilder builder = new DevicesRequestBuilder();
private final DeviceService deviceService = Services.getDeviceService();
private Set<ParticleTransfer> particleTransfers;
DriveDataProcessorFESA() {
}
public static DriveDataProcessorFESA getInstance() {
return INSTANCE;
}
public void setBeamChain(final BeamProductionChain chain) {
this.chain = chain;
}
public void setFrsDevices() {
myDevices = ddpLSA.getStaticDevices();
// System.out.println(myDevices.size());
getDevicesData();
}
public void setDevices() {
// Find all the devices belonging to the selected chainstatic list of
// FRS devices
final DevicesRequestBuilder devicesRequestBuilder_DS = new DevicesRequestBuilder();
final DevicesRequestBuilder devicesRequestBuilder_PLA = new DevicesRequestBuilder();
particleTransfers = Contexts.getParticleTransfersFromBeamProcesses(chain.getDrivableBeamProcesses());
devicesRequestBuilder_DS.setParticleTransfers(particleTransfers);
devicesRequestBuilder_DS.setMetaType(DeviceMetaTypeEnum.ACTUAL);
devicesRequestBuilder_DS.setDeviceTypeName("DS"); // StepperMotor Drive
devicesRequestBuilder_PLA.setParticleTransfers(particleTransfers);
devicesRequestBuilder_PLA.setMetaType(DeviceMetaTypeEnum.ACTUAL);
devicesRequestBuilder_PLA.setDeviceTypeName("PLA"); // Pneumatic Drives
myDSdevices = deviceService.findDevices(devicesRequestBuilder_DS.build());
myPLAdevices = deviceService.findDevices(devicesRequestBuilder_PLA.build());
System.out.println("DS: " + myDSdevices.size());
System.out.println("PLA: " + myPLAdevices.size());
myDevices.addAll(myDSdevices);
myDevices.addAll(myPLAdevices);
System.out.println("*********");
System.out.println(myDevices);
System.out.println("*********");
System.out.println("FESA myDevice DIM " + myDevices.size());
getDevicesData();
}
public void getDevicesData() {
// Clear list to avoid summing up of items while changing the chain
driveDataList.clear();
for (final Device device : myDevices) {
if (dung.isDeviceNameExisting(device.getName())) {
// System.out.println("Name of device: " + device.getName());
// final Selector newMULTIPLEXED_SELECTOR = getSelector(device);
// System.out.println(device.getName());
// System.out.println(newMULTIPLEXED_SELECTOR);
// System.out.println("TYPE " +
// getDeviceType(device.getName()));
// Data processing according to the device type
if (getDeviceType(device.getName()).equals("DS")) {
for (int p = 0; p < 3; p++) {
try {
// parameterName =
// Parameters.buildParameterName(device.getName().substring(8),
// propertyname[p]); // if setFRSDevice is used
parameterName = Parameters.buildParameterName(device.getName(), propertyname[p]);
parameter = ParameterFactory.newInstance().newParameter(parameterName);
// ParameterValue =
// parameter.getValue(newMULTIPLEXED_SELECTOR);
ParameterValue = parameter.getValue(MULTIPLEXED_SELECTOR);
mapParameterValue = (MapParameterValue) ParameterValue.getValue();
// System.out.println(parameterName);
// System.out.println(mapParameterValue);
// 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 (getDeviceType(device.getName()).equals("PLA")) {
for (int p = 3; p < 4; p++) {
try {
// parameterName =
// Parameters.buildParameterName(device.getName().substring(8),
// propertyname[p]); // if setFRSDevice is used
parameterName = Parameters.buildParameterName(device.getName(), propertyname[p]);
parameter = ParameterFactory.newInstance().newParameter(parameterName);
// ParameterValue =
// parameter.getValue(newMULTIPLEXED_SELECTOR);
ParameterValue = parameter.getValue(MULTIPLEXED_SELECTOR);
mapParameterValue = (MapParameterValue) ParameterValue.getValue();
// System.out.println(parameterName);
// System.out.println(mapParameterValue);
// 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
}
/*
* System.out.println("DATA ACQUIRED");
* System.out.println(device.getName().substring(8));
* System.out.println(fieldValue[0]);
* System.out.println(fieldValue[1]);
* System.out.println(fieldValue[2]);
* System.out.println(fieldValue[3]);
*/
// Add processed device to the list
// Use device.getName().substr(8) if setFrsDevice is used!!!
try {
driveDataList.add(new Object[] { device.getName(), fieldValue[0], fieldValue[1], fieldValue[2],
fieldValue[3] });
} catch (final Exception e) {
System.out.println(e);
System.exit(0);
}
} // End if deviceNameExists
} // End for Device
// retrieveDataFromFESA();
}
public List<Object[]> getDriveData() {
return driveDataList;
}
// test method to check all devices processed within the getDeviceData
// method
public void retrieveDataFromFESA() {
System.out.println("******FESA DATA******");
System.out.println(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);
}
}
// System.exit(0);
}
public void generateDeviceSubscriptions() {
for (final Device device : myDevices) {
if (dung.isDeviceNameExisting(device.getName())) {
if (getDeviceType(device.getName()).equals("DS")) {
// final DeviceUpdateFESA duf = new
// DeviceUpdateFESA(device.getName().substring(8));
final DeviceUpdateFESA duf = new DeviceUpdateFESA(device.getName());
// final Selector newMULTIPLEXED_SELECTOR =
// getSelector(device);
for (int p = 0; p < 1; p++) { // CONSTANT property does not
// need to be updated!
// for (int p = 0; p < 3; p++) {
try {
duf.subscribe(MULTIPLEXED_SELECTOR, propertyname[p]);
// duf.subscribe(newMULTIPLEXED_SELECTOR,
// propertyname[p]);
} catch (final Exception e) {
System.out.println("Exception: " + e);
System.exit(0);
}
} // for property
}
if (getDeviceType(device.getName()).equals("PLA")) {
// final DeviceUpdateFESA duf = new
// DeviceUpdateFESA(device.getName().substring(8));
final DeviceUpdateFESA duf = new DeviceUpdateFESA(device.getName());
// final Selector newMULTIPLEXED_SELECTOR =
// getSelector(device);
for (int p = 3; p < 4; p++) {
try {
// duf.subscribe(newMULTIPLEXED_SELECTOR,
// propertyname[p]);
duf.subscribe(MULTIPLEXED_SELECTOR, propertyname[p]);
} catch (final Exception e) {
System.out.println("Exception: " + e);
System.exit(0);
}
} // for property
}
} // end if filter on device user friendly names
}
}
private Selector getSelector(final Device device) {
final Set<ParticleTransfer> particleTransfersForDevice = device.getAcceleratorZone().getParticleTransfers();
if (particleTransfersForDevice.size() > 1) {
throw new IllegalStateException("There was more then one particle transfer found for device "
+ device.getName() + " but it should be only one.");
}
final List<DrivableBeamProcess> chainBeamProcesses = chain.getDrivableBeamProcesses();
final ParticleTransfer particleTransferForDevice = particleTransfersForDevice.iterator().next();
final List<DrivableBeamProcess> beamProcessesForDevice = Contexts.filterBeamProcesses(chainBeamProcesses,
particleTransferForDevice, BeamProcessTypeCategory.FUNCTION_BEAM_IN);
final Selector selector = FAIRSelectorBuilder.parse(beamProcessesForDevice.get(0).getUser()).build();
return selector;
}
private String getDeviceType(final String deviceName) {
String deviceType = "";
for (int i = 0; i < ddpLSA.getDriveData().size(); i++) {
// if
// (deviceName.substring(8).equals(ddpLSA.getDriveData().get(i)[0]))
// {
if (deviceName.equals(ddpLSA.getDriveData().get(i)[0])) {
deviceType = ddpLSA.getDriveData().get(i)[1].toString();
}
}
return deviceType;
}
}