-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMagnetDataProcessorFESA_31082018_MS.java
More file actions
421 lines (309 loc) · 15.3 KB
/
Copy pathMagnetDataProcessorFESA_31082018_MS.java
File metadata and controls
421 lines (309 loc) · 15.3 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
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
package de.gsi.cs.co.ap.my_test_project.utils;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import cern.accsoft.commons.domain.particletransfers.ParticleTransfer;
import cern.colt.Arrays;
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.SubscriptionHandle;
import cern.japc.factory.ParameterFactory;
import cern.japc.factory.SelectorFactory;
import cern.japc.group.support.SysoutFailSafeParameterValueListener;
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.BeamProcess;
import cern.lsa.domain.settings.BeamProductionChain;
import cern.lsa.domain.settings.Contexts;
import cern.lsa.domain.settings.DrivableBeamProcess;
import cern.lsa.domain.settings.factory.ParametersRequestBuilder;
import cern.lsa.domain.settings.type.BeamProcessTypeCategory;
import cern.lsa.gui.fx.FilteredListView;
import de.gsi.aco.sv.japc.FAIRSelectorBuilder;
import de.gsi.cs.co.lsa.domain.GsiTimingDomain;
public class MagnetDataProcessorFESA {
/**
* @author fschirru
*/
private static final MagnetDataProcessorFESA INSTANCE = new MagnetDataProcessorFESA();
private final MagnetDataProcessorLSA mdpLSA = MagnetDataProcessorLSA.getInstance();
private Set<Device> frsDevices;
private final static String[] propertyname = { "Acquisition", "Acquisition", "DCValue", "DCMode", "Status",
"Status", "Status", "DCValueAcq", "DCValueAcq" };
private final static String[] propertyfield = { "current", "voltage", "current", "mode", "status", "detailedStatus",
"detailedStatus_labels", "current", "voltage" };
// 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 static String[] fieldValue_labels = new String[24];
// private final static ObservableList<Magnet> magnetData = FXCollections.observableArrayList();
private final List<Object[]> magDataList = new ArrayList<>(); // to be changed into generic object
private BeamProductionChain chain;
private final DeviceService deviceService = Services.getDeviceService();
private final DevicesRequestBuilder builder = new DevicesRequestBuilder();
private Set<Device> myDevices;
private Set<ParticleTransfer> particleTransfers;
MagnetDataProcessorFESA() {
}
public static MagnetDataProcessorFESA getInstance() {
return INSTANCE;
}
public void setBeamChain(final BeamProductionChain chain) {
this.chain = chain;
}
public void setFrsDevices() {
System.out.println("*********");
System.out.println("*********");
myDevices = mdpLSA.getStaticDevices();
// System.out.println("frsDevices Dim: " + frsDevices.size());
System.out.println(myDevices.size());
System.out.println(myDevices);
// System.exit(0);
getDevicesData();
}
public void setDevices() {
particleTransfers = Contexts.getParticleTransfersFromBeamProcesses(chain.getDrivableBeamProcesses());
builder.setParticleTransfers(particleTransfers);
builder.setMetaType(DeviceMetaTypeEnum.ACTUAL);
builder.setDeviceTypeName("BasicPS");
myDevices = deviceService.findDevices(builder.build());
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
magDataList.clear();
for (final Device device : myDevices) {
final Selector newMULTIPLEXED_SELECTOR = getSelector(device);
// final Selector newMULTIPLEXED_SELECTOR = SelectorFactory.newSelector("FAIR.SELECTOR.ALL");
System.out.println(device.getName());
System.out.println(newMULTIPLEXED_SELECTOR);
for (int p = 0; p < propertyname.length; p++) {
// if (p != 1) {
try {
parameterName = Parameters.buildParameterName(device.getName().substring(8), propertyname[p]);
parameter = ParameterFactory.newInstance().newParameter(parameterName);
ParameterValue = parameter.getValue(newMULTIPLEXED_SELECTOR);
mapParameterValue = (MapParameterValue) ParameterValue.getValue();
// acquire the value of the considered property of the related device.
// The first five properties are numbers and retrieved as strings
if (p < 5) {
if (p != 1) {
fieldValue[p] = mapParameterValue.getString(propertyfield[p]);
System.out.println(fieldValue[p]);
System.out.println(p);
} else { // voltage treated only for Dipoles!
if (device.getName().substring(8).equals("GTS3MU1")
|| device.getName().substring(8).equals("GTS3MU2")
|| device.getName().substring(8).equals("GTS4MU1")
|| device.getName().substring(8).equals("GHFSMU1")
|| device.getName().substring(8).equals("GTS5MU1")
|| device.getName().substring(8).equals("GTS6MU1")
|| device.getName().substring(8).equals("GTS7MU1")) {
fieldValue[p] = mapParameterValue.getString(propertyfield[p]);
System.out.println(fieldValue[p]);
System.out.println(p);
} else {
fieldValue[p] = 0.0; // Assign null value to all other devices (quadrupoles ect)
}
}
}
if (p == 5) {
fieldValue[p] = mapParameterValue.getBooleans(propertyfield[p]);
}
if (p == 6) {
fieldValue[p] = mapParameterValue.getStrings(propertyfield[p]);
}
if (p == 7) { // DCValueAcq current
fieldValue[p] = mapParameterValue.getStrings(propertyfield[p]);
}
if (p == 8) { // DCValueAcq voltage
fieldValue[p] = mapParameterValue.getStrings(propertyfield[p]);
}
} catch (final ParameterException e) {
// Assign an arbitrary value to the Acquisition/current of the related device.
if (fieldValue[0] == null) {
fieldValue[0] = "0.55";
}
if (fieldValue[1] == null) {
fieldValue[1] = "0.55";
}
if (fieldValue[3] == null) {
fieldValue[3] = "false";
}
if (fieldValue[4] == null) {
fieldValue[4] = "11";
}
if (fieldValue[7] == null) {
fieldValue[7] = "0.55";
}
if (fieldValue[8] == null) {
fieldValue[8] = "0.55";
}
/*
* if (fieldValue[5] == null) {
*
* fieldValue[5] = new String[] { "false", "false", "false" };
* }
*
* if (fieldValue[6] == null) {
*
* fieldValue[6] = new String[] { "Error", "Error", "Error" };
* }
*/
}
// } else {
/*
* try {
*
* parameterName = Parameters.buildParameterName(device.getName().substring(8), propertyname[p]);
* parameter = ParameterFactory.newInstance().newParameter(parameterName);
* ParameterValue = parameter.getValue(newMULTIPLEXED_SELECTOR);
* mapParameterValue = (MapParameterValue) ParameterValue.getValue();
* // fieldValue[1] = mapParameterValue.getString(propertyfield[1]); //to add
*
* fieldValue[1] = 0.0;
*
* } catch (final ParameterException e) {
*
* System.out.println(device.getName());
* System.out.println(newMULTIPLEXED_SELECTOR);
* fieldValue[p] = 0.5;
* // fieldValue[p] = 0.0; // Assign a temporary value for the HallProbe of the related device
* System.out.println(e);
* // System.exit(0);
*
* }
*/
// fieldValue[1] = 0.0; // Assign a temporary value for the HallProbe of the related device
// end if p
// }
} // End for property
/*
* 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]);
* System.out.println(fieldValue[4]);
* System.out.println(fieldValue[5]);
* System.out.println(fieldValue[6]);
*
* System.out.println(n);
* n++;
*/
try {
// Add processed device to the list
magDataList.add(new Object[] { device.getName().substring(8), fieldValue[0], fieldValue[1],
fieldValue[7/* 2 */], fieldValue[3], fieldValue[4], fieldValue[5], fieldValue[6] });
} catch (final Exception e) {
System.out.println("**********");
System.out.println(device.getName().substring(8));
System.out.println(e);
System.exit(0);
}
// System.exit(0);
} // End for Device
// retrieveDataFromFESA();
}
public List<Object[]> getMagnetData() {
return magDataList;
}
// test method to check all devices processed within the getDeviceData method
public void retrieveDataFromFESA() {
System.out.println("******FESA DATA******");
System.out.println(magDataList.get(0)[5]);
System.out.println(magDataList.size());
for (int i = 0; i < magDataList.size(); i++) {
try {
System.out.println(magDataList.get(i)[0] + " - " + magDataList.get(i)[1] + " - " + magDataList.get(i)[2]
+ " - " + magDataList.get(i)[3] + " - " + magDataList.get(i)[4] + " - " + " - "
+ Arrays.toString((boolean[]) fieldValue[5]) + Arrays.toString((String[]) fieldValue[6]));
} catch (final Exception e) {
System.out.println(e);
System.exit(0);
}
}
// System.exit(0);
}
public void generateDeviceSubscriptions() {
for (final Device device : myDevices) {
final DeviceUpdateFESA duf = new DeviceUpdateFESA(device.getName().substring(8));
final Selector newMULTIPLEXED_SELECTOR = getSelector(device);
/*
* if (device.getName().substring(8).equals("GTS2QT12")) {
*
* System.out.println(newMULTIPLEXED_SELECTOR);
* System.exit(0);
* }
*/
for (int p = 0; p < propertyname.length; p++) {
try {
duf.subscribe(newMULTIPLEXED_SELECTOR, propertyname[p]);
} catch (final Exception e) {
System.out.println("Exception: " + e);
System.exit(0);
}
} // for property
/*
* // Treat special devices equipped with HallProbe
* if (device.getName().substring(8).equals("GTS7MU1") || device.getName().substring(8).equals("GTS3MU1")
* || device.getName().substring(8).equals("GHFSMU1")
* || device.getName().substring(8).equals("GTS6MU1")) {
*
* try {
*
* final DeviceUpdateFESA duf_0 = new DeviceUpdateFESA(device.getName().substring(8) + "_0");
*
* // start subscription of the considered property (HallProbe) of the related device
* duf_0.subscribe(newMULTIPLEXED_SELECTOR, propertyname[1]);
*
* } catch (final Exception e) {
*
* System.out.println("Exception: " + e);
* System.exit(0);
* }
* }
*/
}
}
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();
/*
* if (chain.getName().contains("HFS")) {
*
* System.out.println(selector);
* System.out.println(chainBeamProcesses);
* System.out.println("END " + device);
* System.out.println(beamProcessesForDevice);
* System.exit(0);
* }
*/
return selector;
}
}