-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMagnetDataProcessorFESA_magstat_04042019.java
More file actions
419 lines (304 loc) · 12.9 KB
/
Copy pathMagnetDataProcessorFESA_magstat_04042019.java
File metadata and controls
419 lines (304 loc) · 12.9 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
package de.gsi.cs.co.ap.app.magstat.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.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.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;
public class MagnetDataProcessorFESA {
/**
* @author fschirru
*/
private static final MagnetDataProcessorFESA INSTANCE = new MagnetDataProcessorFESA();
private final MagnetDataProcessorLSA mdpLSA = MagnetDataProcessorLSA.getInstance();
private final RetrieveDeviceSelector rdSel = RetrieveDeviceSelector.getInstance();
private static final String[] MAGNET_TYPES = new String[] { "BasicPS", "BasicHvPS" };
// private Set<Device> frsDevices;
private final static String[] propertynameSelector = { "Acquisition", "DCValue", "DCMode", "Status", "DCValueAcq" };
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<Device> mySortedDevices = new ArrayList<>();
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;
private List<SubscriptionHandle> list_of_subscriptions = new ArrayList<>();
private boolean subscription_exists;
// private final DeviceUpdateFESA duFESA = DeviceUpdateFESA.getInstance();
public MagnetDataProcessorFESA() {
}
public static MagnetDataProcessorFESA getInstance() {
return INSTANCE;
}
public void setBeamChain(final BeamProductionChain chain) {
this.chain = chain;
}
public void setFrsDevices() {
myDevices = mdpLSA.getStaticDevices();
getDevicesData();
}
public void setDevices() {
// If we use this method from the main controller
// it has to be used later without .substring(8)
// in the for loop (parameterName) because
// devices from FESA are not LOGICAL type!!!!
// Otherwise app can not run
// I need to think for a generic solution both for
// setDevices and setFrsDevices
final Set<String> magnet_Types = new HashSet<>();
Collections.addAll(magnet_Types, MAGNET_TYPES);
particleTransfers = Contexts.getParticleTransfersFromBeamProcesses(chain.getDrivableBeamProcesses());
builder.setParticleTransfers(particleTransfers);
builder.setMetaType(DeviceMetaTypeEnum.ACTUAL);
// builder.setDeviceTypeName("BasicPS");
builder.setDeviceTypeNames(magnet_Types);
myDevices = deviceService.findDevices(builder.build());
getDevicesData();
}
public void getDevicesData() {
// Clear list to avoid summing up of items while changing the chain
magDataList.clear();
System.out.println("Chain selected: " + chain.getName());
rdSel.setBeamChain(chain);
for (final Device device : myDevices) {
final Selector newMULTIPLEXED_SELECTOR = rdSel.getSelector(device);
/*- set temporary values to avoid app from crashing due to lack of data */
fieldValue[0] = "-0.0";
fieldValue[1] = "-0.0";
// fieldValue[2] = "
fieldValue[3] = "false";
fieldValue[4] = "-0.0";
// fieldValue[5] =
// fieldValue[6] =
fieldValue[7] = "-0.0";
fieldValue[8] = "-0.0";
/*- temporary to propertyname.length-2 to deal with the DCValueAcq separately */
for (int p = 0; p < propertyname.length - 2; p++) {
System.out.println("P VALUE " + p);
// if (p != 1) {
try {
parameterName = Parameters.buildParameterName(device.getName().substring(8), propertyname[p]);
// System.out.println("**** " + parameterName);
parameter = ParameterFactory.newInstance().newParameter(parameterName);
System.out.println(parameter);
System.out.println(newMULTIPLEXED_SELECTOR);
// To get data from real hardware and not test devices, on
// the
// Run Configurations we need to specify
// "cmwpro00a.acc.gsi.de:5021"
// By chance may work with "cmwdev00a.acc.gsi.de:5021" but
// pro should be used.
// Applications which are deployed look directly into
// "cmwpro00a.acc.gsi.de:5021"
// Since this application is not yet deployed we need to
// give the link manually
// in the "Run Configurations"
// Otherwise, an error (null value) leads to SetOnFAIL in
// the app.
// The next line gives setOnFail and to solve it
// the pom file must be resaved.
// Otherwise it should cleaned the maven repository
// with rm -rf .m2/repository
// eclipse will load all again automatically
// Also better Maven->Update Project
/*- If the selector is wrong, this line throws an exception */
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 {
/*- Assign null value to all other devices (quadrupoles ect) */
fieldValue[p] = 0.0;
}
}
}
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.getString("current");
}
if (p == 8) { // DCValueAcq voltage
fieldValue[p] = mapParameterValue.getStrings(propertyfield[p]);
}
} catch (final ParameterException e) {
System.out.println(e);
}
} // End for property
// Add processed device to the list
try {
magDataList.add(new Object[] { device.getName().substring(8), fieldValue[0], fieldValue[1],
fieldValue[7/* 2 */], fieldValue[3], fieldValue[4], fieldValue[5], fieldValue[6] });
// DCModeValAcq blocked
// magDataList.add(new Object[] { device.getName().substring(8),
// fieldValue[0], fieldValue[1], 0.0,
// fieldValue[3], fieldValue[4], fieldValue[5], fieldValue[6]
// });
} catch (final Exception e) {
System.out.println(e);
System.exit(0);
}
} // End for Device
// retrieveDataFromFESA();
}
public List<Object[]> getMagnetData() {
return magDataList;
}
public List<Device> getSortedDevices() {
return mySortedDevices;
}
public void setListOfSubscriptions(final List<SubscriptionHandle> subscriptions) {
list_of_subscriptions = subscriptions;
}
// 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() {
/*
* System.out.println("List Sub " + list_of_subscriptions.size());
*
* for (int s = 0; s < list_of_subscriptions.size(); s++) {
*
* System.out.println( list_of_subscriptions.get(s).getParameter() + " "
* + list_of_subscriptions.get(s).getSelector());
*
* }
*/
rdSel.setBeamChain(chain);
for (final Device device : myDevices) {
final Selector newMULTIPLEXED_SELECTOR = rdSel.getSelector(device);
/*- temporary to propertynameSelector.length-1 to deal with the DCValueAcq separately */
for (int p = 0; p < propertynameSelector.length; p++) {
subscription_exists = false;
final String parametername = Parameters.buildParameterName(device.getName().substring(8),
propertynameSelector[p]);
Parameter parameter = null;
try {
parameter = ParameterFactory.newInstance().newParameter(parametername);
} catch (final ParameterException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
/*- Check if subscription is already initialized for a particular parameter and selector */
for (int s = 0; s < list_of_subscriptions.size(); s++) {
// System.out.println(s);
// System.out.println("Current parameter: " + parameter);
// System.out.println("Current Selector: " +
// newMULTIPLEXED_SELECTOR);
// System.out.println(list_of_subscriptions.get(s).getParameter());
// System.out.println(list_of_subscriptions.get(s).getSelector());
if (list_of_subscriptions.get(s).getParameter() == parameter) {
if (list_of_subscriptions.get(s).getSelector().equals(newMULTIPLEXED_SELECTOR)) {
System.out.println("Subscription already initialized! Index: " + s);
System.out.println(
"Restarting monitoring..." + "Parameter " + parameter.getName() + " Index: " + s);
subscription_exists = true;
try {
list_of_subscriptions.get(s).startMonitoring();
} catch (final ParameterException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
break;
}
}
}
if (!subscription_exists) {
System.out.println("A new instance has been created for " + device.getName());
// final DeviceUpdateFESA duf = new
// DeviceUpdateFESA(device.getName().substring(8));
final DeviceUpdateFESA duf = new DeviceUpdateFESA(device.getName().substring(8));
// duf.setDeviceName(device.getName().substring(8));
try {
duf.subscribe(newMULTIPLEXED_SELECTOR, propertynameSelector[p]);
} catch (final Exception e) {
System.out.println("Exception: " + e);
System.exit(0);
}
}
} // for property
}
}
public void closeDeviceSubscriptions() {
for (int s = 0; s < list_of_subscriptions.size(); s++) {
list_of_subscriptions.get(s).stopMonitoring();
System.out.println("Subscription stopped. Index " + s);
}
}
}