-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMagnetDataProcessorFESA_26042018.java
More file actions
242 lines (164 loc) · 8.62 KB
/
Copy pathMagnetDataProcessorFESA_26042018.java
File metadata and controls
242 lines (164 loc) · 8.62 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
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.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.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 Set<Device> frsDevices;
private final static String[] propertyname = { "DCValue", "DCMode", "Status", "Acquisition", "Acquisition",
"Status", "Status" };
private final static String[] propertyfield = { "current", "mode", "status", "current", "voltage", "detailedStatus",
"detailedStatus_labels" };
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 String[] fieldValue = new String[propertyname.length]; // to be changed into generic object
// private final static ObservableList<Magnet> magnetData = FXCollections.observableArrayList();
private final List<String[]> 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 DeviceUpdateFESA duf;
// private final String magData[][] = getMagnetData();
// String temp_magData[][];
MagnetDataProcessorFESA() {
}
public static MagnetDataProcessorFESA getInstance() {
return INSTANCE;
}
public void setBeamChain(final BeamProductionChain chain) {
this.chain = chain;
// setDevices();
// setFrsDevices();
}
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);
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();
// final Set<Parameter> parameters = new HashSet<>();
for (final Device device : myDevices) {
duf = new DeviceUpdateFESA(device.getName().substring(8));
// final ParametersRequestBuilder builder_ = new ParametersRequestBuilder();
// builder_.setDevices(frsDevices);
// builder_.setParameterTypeNames(Arrays.asList(new String[] { "I", "BL" }));
// System.out.println("*** Device Properties ***");
// System.out.println(device.getName());
for (int p = 0; p < propertyname.length; p++) {
try {
parameterName = Parameters.buildParameterName(device.getName().substring(8), propertyname[p]);
System.out.println("Parameter Name " + parameterName);
parameter = ParameterFactory.newInstance().newParameter(parameterName);
System.out.println("Parameter " + parameter);
ParameterValue = parameter.getValue(MULTIPLEXED_SELECTOR);
// ParameterValue = parameter.getValue(NULL_SELECTOR);
System.out.println(ParameterValue);
mapParameterValue = (MapParameterValue) ParameterValue.getValue();
System.out.println(mapParameterValue.getNames());
System.out.println("***MAP PARAMETER VALUE***");
System.out.println(mapParameterValue);
// System.exit(0);
if (p < 5) {
fieldValue[p] = mapParameterValue.getString(propertyfield[p]);
// System.out.println("Property: " + propertyname[p] + " " + "Field Value: " + fieldValue);
} else {
// Implement boolean part
// fieldValue[p] = mapParameterValue.getBooleans(propertyfield[p]);
}
// temp_magData[deviceCounter][p] = fieldValue[p];
////
// duf.getParameterValue(MULTIPLEXED_SELECTOR, propertyname[p]);
duf.subscribe(MULTIPLEXED_SELECTOR, propertyname[p]);
} catch (final ParameterException e) {
// Acquisition/current get null value if magnets are off or BeamProductionChain is not running
// See Jutta's mail 23/4/2018 - 12:54
if (p == 3 && fieldValue[p] == null) {
fieldValue[p] = "99.99";
}
// Acquisition/voltage (Hall Probe) get null value if magnets are off or BeamProductionChain is not
// running
if (p == 4 && fieldValue[p] == null) {
fieldValue[p] = "99.99";
}
// LOGGER.error(e.getMessage());
// System.out.println("ERROR************************************************");
}
}
if (Boolean.getBoolean(fieldValue[2])) {
magDataList.add(new String[] { device.getName().substring(8), fieldValue[0], fieldValue[1],
fieldValue[2], fieldValue[4] });
} else {
magDataList.add(new String[] { device.getName().substring(8), fieldValue[3], fieldValue[1],
fieldValue[2], fieldValue[4] });
}
System.out.println("******FESA******");
for (int i = 0; i < magDataList.size(); i++) {
System.out.println(magDataList.get(i)[0] + " - " + magDataList.get(i)[1] + " - " + magDataList.get(i)[2]
+ " - " + magDataList.get(i)[3] + " - " + magDataList.get(i)[4]);
}
// magnetData.add(new Magnet(device.getName(), Integer.parseInt(fieldValue[2]),
// Boolean.valueOf(fieldValue[1]),
// Double.parseDouble(fieldValue[0]), 0.0, 0.0, 0.0, 0.0, false));
// System.out.println("*** End of Decvie Properties ***");
}
// System.out.println(magData.length);
// System.out.println("************DATA");
// System.out.println(magDataList.get(0)[0]);
// System.out.println(magData.length);
// System.out.println("************DATA");
// getParameterValue(propertyname1, MULTIPLEXED_SELECTOR);
// System.exit(0);
}
public List<String[]> getMagnetData() {
return magDataList;
}
// public ObservableList<Magnet> getMagnetData() {
// return magnetData;
// }
}