1 | 'use strict';
|
---|
2 |
|
---|
3 | // ================================================================
|
---|
4 | // Code related to monitoring the fad system
|
---|
5 | // ================================================================
|
---|
6 |
|
---|
7 | var incomplete = 0;
|
---|
8 |
|
---|
9 | sub_incomplete.onchange = function(evt)
|
---|
10 | {
|
---|
11 | if (!evt.data)
|
---|
12 | return;
|
---|
13 |
|
---|
14 | var inc = evt.obj['incomplete'];
|
---|
15 | if (!inc || inc>0xffffffffff)
|
---|
16 | return;
|
---|
17 |
|
---|
18 | if (incomplete>0)
|
---|
19 | return;
|
---|
20 |
|
---|
21 | if (dim.state("MCP").name!="TakingData")
|
---|
22 | return;
|
---|
23 |
|
---|
24 | console.out("");
|
---|
25 | dim.log("Incomplete event ["+inc+","+incomplete+"] detected, sending MCP/STOP");
|
---|
26 |
|
---|
27 | incomplete = inc;
|
---|
28 | dim.send("MCP/STOP");
|
---|
29 | }
|
---|
30 |
|
---|
31 | // ================================================================
|
---|
32 | // Code related to taking data
|
---|
33 | // ================================================================
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * reconnect to problematic FADs
|
---|
37 | *
|
---|
38 | * Dis- and Reconnects to FADs, found to be problematic by call-back function
|
---|
39 | * onchange() to have a different CONNECTION value than 66 or 67.
|
---|
40 | *
|
---|
41 | * @returns
|
---|
42 | * a boolean is returned.
|
---|
43 | * reconnect returns true if:
|
---|
44 | * * nothing needed to be reset --> no problems found by onchange()
|
---|
45 | * * the reconnection went fine.
|
---|
46 | *
|
---|
47 | * reconnect *never returns false* so far.
|
---|
48 | *
|
---|
49 | * @example
|
---|
50 | * if (!sub_connections.reconnect())
|
---|
51 | * exit();
|
---|
52 | */
|
---|
53 | function reconnect(list, txt)
|
---|
54 | { /*
|
---|
55 | var reset = [ ];
|
---|
56 |
|
---|
57 | for (var i=0; i<list.length; i++)
|
---|
58 | {
|
---|
59 | console.out(" FAD %2d".$(list[i])+" lost during "+txt);
|
---|
60 | reset.push(parseInt(list[i]/10));
|
---|
61 | }
|
---|
62 |
|
---|
63 | reset = reset.filter(function(elem,pos){return reset.indexOf(elem)==pos;});
|
---|
64 |
|
---|
65 | console.out("");
|
---|
66 | console.out(" FADs belong to crate(s): "+reset);
|
---|
67 | console.out("");
|
---|
68 | */
|
---|
69 | console.out("");
|
---|
70 | dim.log("Trying automatic reconnect ["+txt+",n="+list.length+"]...");
|
---|
71 |
|
---|
72 | if (list.length>3)
|
---|
73 | throw new Error("Too many boards to be reconnected. Please check what happened.");
|
---|
74 |
|
---|
75 | for (var i=0; i<list.length; i++)
|
---|
76 | {
|
---|
77 | console.out(" ...disconnect "+list[i]);
|
---|
78 | dim.send("FAD_CONTROL/DISCONNECT", list[i]);
|
---|
79 | }
|
---|
80 |
|
---|
81 | console.out(" ...waiting for 3s");
|
---|
82 | v8.sleep(3000);
|
---|
83 |
|
---|
84 | for (var i=0; i<list.length; i++)
|
---|
85 | {
|
---|
86 | console.out(" ...reconnect "+list[i]);
|
---|
87 | dim.send("FAD_CONTROL/CONNECT", list[i]);
|
---|
88 | }
|
---|
89 |
|
---|
90 | console.out(" ...waiting for 1s");
|
---|
91 |
|
---|
92 | // Wait for one second to bridge possible pending connects
|
---|
93 | v8.sleep(1000);
|
---|
94 |
|
---|
95 | console.out(" ...checking connection");
|
---|
96 |
|
---|
97 | // Wait for FAD_CONTROL to realize that all boards are connected
|
---|
98 | // FIXME: Wait for '40' boards being connected instead
|
---|
99 | try
|
---|
100 | {
|
---|
101 | dim.wait("FAD_CONTROL", "Connected", 3000);
|
---|
102 | }
|
---|
103 | catch (e)
|
---|
104 | {
|
---|
105 | if (dim.state("FAD_CONTROL").name!="Connecting")
|
---|
106 | {
|
---|
107 | console.out("");
|
---|
108 | console.out(" + FAD_CONTROL: "+dim.state("FAD_CONTROL").name);
|
---|
109 | console.out("");
|
---|
110 | throw e;
|
---|
111 | }
|
---|
112 |
|
---|
113 | var crates = [];
|
---|
114 | for (var i=0; i<list.length; i++)
|
---|
115 | crates[list[i]/4] = true;
|
---|
116 |
|
---|
117 | include('scripts/crateReset.js');
|
---|
118 | crateReset(crates);
|
---|
119 | }
|
---|
120 |
|
---|
121 | // Wait also for MCP to have all boards connected again
|
---|
122 | dim.wait("MCP", "Idle", 3000);
|
---|
123 |
|
---|
124 | dim.log("Automatic reconnect successfull.");
|
---|
125 | console.out("");
|
---|
126 | }
|
---|
127 |
|
---|
128 | function takeRun(type, count, time)
|
---|
129 | {
|
---|
130 | if (!count)
|
---|
131 | count = -1;
|
---|
132 | if (!time)
|
---|
133 | time = -1;
|
---|
134 |
|
---|
135 | var nextrun = sub_startrun.get().obj['next'];
|
---|
136 | dim.log("Take run %3d".$(nextrun)+": N="+count+" T="+time+"s ["+type+"]");
|
---|
137 |
|
---|
138 | // FIXME: Replace by callback?
|
---|
139 | //
|
---|
140 | // DN: I believe instead of waiting for 'TakingData' one could split this
|
---|
141 | // up into two checks with an extra condition:
|
---|
142 | // if type == 'data':
|
---|
143 | // wait until ThresholdCalibration starts:
|
---|
144 | // --> this time should be pretty identical for each run
|
---|
145 | // if this takes longer than say 3s:
|
---|
146 | // there might be a problem with one/more FADs
|
---|
147 | //
|
---|
148 | // wait until "TakingData":
|
---|
149 | // --> this seems to take even some minutes sometimes...
|
---|
150 | // (might be optimized rather soon, but still in the moment...)
|
---|
151 | // if this takes way too long:
|
---|
152 | // there might be something broken,
|
---|
153 | // so maybe a very high time limit is ok here.
|
---|
154 | // I think there is not much that can go wrong,
|
---|
155 | // when the Thr-Calib has already started. Still it might be nice
|
---|
156 | // If in the future RateControl is written so to find out that
|
---|
157 | // in case the threshold finding algorithm does
|
---|
158 | // *not converge as usual*
|
---|
159 | // it can complain, and in this way give a hint, that the weather
|
---|
160 | // might be a little bit too bad.
|
---|
161 | // else:
|
---|
162 | // wait until "TakingData":
|
---|
163 | // --> in a non-data run this time should be pretty short again
|
---|
164 | // if this takes longer than say 3s:
|
---|
165 | // there might be a problem with one/more FADs
|
---|
166 | //
|
---|
167 |
|
---|
168 | // Use this if you use the rate control to calibrate by rates
|
---|
169 | //if (!dim.wait("MCP", "TakingData", -300000) )
|
---|
170 | //{
|
---|
171 | // throw new Error("MCP took longer than 5 minutes to start TakingData"+
|
---|
172 | // "maybe this idicates a problem with one of the FADs?");
|
---|
173 | //}
|
---|
174 |
|
---|
175 | // Here we could check and handle fad losses
|
---|
176 |
|
---|
177 | incomplete = 0;
|
---|
178 |
|
---|
179 | var start = true;
|
---|
180 |
|
---|
181 | for (var n=0; n<3; n++)
|
---|
182 | {
|
---|
183 | if (start)
|
---|
184 | dim.send("MCP/START", time, count, type);
|
---|
185 |
|
---|
186 | try
|
---|
187 | {
|
---|
188 | dim.wait("MCP", "TakingData", 15000);
|
---|
189 | break;
|
---|
190 | }
|
---|
191 | catch (e)
|
---|
192 | {
|
---|
193 | if (dim.state("MCP").name=="TriggerOn" &&
|
---|
194 | dim.state("FAD_CONTROL").name=="Connected" &&
|
---|
195 | dim.state("FTM_CONTROL").name=="TriggerOn")
|
---|
196 | {
|
---|
197 | console.out("");
|
---|
198 | console.out("Waiting for TakingData timed out. Everything looks ok, but file not yet open... waiting once more.");
|
---|
199 | start = false;
|
---|
200 | continue;
|
---|
201 | }
|
---|
202 |
|
---|
203 | start = true;
|
---|
204 |
|
---|
205 | console.out("");
|
---|
206 | console.out(" + MCP: "+dim.state("MCP").name);
|
---|
207 | console.out(" + FAD_CONTROL: "+dim.state("FAD_CONTROL").name);
|
---|
208 | console.out(" + FTM_CONTROL: "+dim.state("FTM_CONTROL").name);
|
---|
209 | console.out("");
|
---|
210 |
|
---|
211 | if (dim.state("MCP").name!="Configuring3" ||
|
---|
212 | (dim.state("FAD_CONTROL").name!="Configuring1" &&
|
---|
213 | dim.state("FAD_CONTROL").name!="Configuring2"))
|
---|
214 | throw e;
|
---|
215 |
|
---|
216 | console.out("");
|
---|
217 | console.out("Waiting for fadctrl to get configured timed out... checking for in-run FAD loss.");
|
---|
218 |
|
---|
219 | var con = sub_connections.get();
|
---|
220 | var stat = con.obj['status'];
|
---|
221 |
|
---|
222 | console.out("Sending MCP/RESET");
|
---|
223 | dim.send("MCP/RESET");
|
---|
224 |
|
---|
225 | dim.wait("FTM_CONTROL", "Valid", 3000);
|
---|
226 | dim.wait("FAD_CONTROL", "Connected", 3000);
|
---|
227 | dim.wait("MCP", "Idle", 3000);
|
---|
228 |
|
---|
229 | var list = [];
|
---|
230 | for (var i=0; i<40; i++)
|
---|
231 | if (stat[i]!=0x43)
|
---|
232 | list.push(i);
|
---|
233 |
|
---|
234 | reconnect(list, "configuration");
|
---|
235 |
|
---|
236 | if (n==2)
|
---|
237 | throw e;
|
---|
238 |
|
---|
239 | //dim.wait("MCP", "Idle", 3000);
|
---|
240 | }
|
---|
241 | }
|
---|
242 |
|
---|
243 | dim.wait("MCP", "Idle", time>0 ? time*1250 : undefined); // run time plus 25%
|
---|
244 |
|
---|
245 | if (incomplete)
|
---|
246 | {
|
---|
247 | console.out("");
|
---|
248 | console.out(" - MCP: "+dim.state("MCP").name);
|
---|
249 | console.out(" - FAD_CONTROL: "+dim.state("FAD_CONTROL").name);
|
---|
250 | console.out(" - FTM_CONTROL: "+dim.state("FTM_CONTROL").name);
|
---|
251 |
|
---|
252 | dim.wait("FTM_CONTROL", "Valid", 3000);
|
---|
253 | dim.wait("FAD_CONTROL", "Connected", 3000);
|
---|
254 | dim.wait("MCP", "Idle", 3000);
|
---|
255 |
|
---|
256 | var str = incomplete.toString(2);
|
---|
257 | var len = str.length;
|
---|
258 |
|
---|
259 | var list = [];
|
---|
260 | for (var i=0; i<str.length; i++)
|
---|
261 | if (str[str.length-i-1]=='1')
|
---|
262 | list.push(i);
|
---|
263 |
|
---|
264 | reconnect(list, "data taking");
|
---|
265 |
|
---|
266 | return false;
|
---|
267 | }
|
---|
268 |
|
---|
269 | // FIXME: What if the ext1 is not enabled in the configuration?
|
---|
270 | if (type=="data")
|
---|
271 | {
|
---|
272 | var dim_trg = new Subscription("FAD_CONTROL/TRIGGER_COUNTER");
|
---|
273 | var counter = dim_trg.get(3000);
|
---|
274 |
|
---|
275 | // The check on physics and pedestal triggers is to ensure that
|
---|
276 | // there was at least a chance to receive any event (e.g. in case
|
---|
277 | // of an interrupt this might not be the case)
|
---|
278 | if (counter.qos!=111 &&
|
---|
279 | (counter.data['N_trg']>1000 || counter.data['N_ped']>5) &&
|
---|
280 | counter.data['N_ext1']==0) // 'o' for open
|
---|
281 | throw new Error("No ext1 triggers received during data taking... please check the reason and report in the logbook.");
|
---|
282 | dim_trg.close();
|
---|
283 | }
|
---|
284 |
|
---|
285 | return true;
|
---|
286 | }
|
---|