Changeset 16049
- Timestamp:
- 05/22/13 22:36:30 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/scripts/Main.js
r15482 r16049 24 24 //this is just the class implementation of 'Observation' 25 25 include('scripts/Observation_class.js'); 26 27 /*28 // this file just contains the definition of29 // the variable observations, which builds our nightly schedule, hence the filename30 include('scripts/schedule.js');31 32 // make Observation objects from user input and check if 'date' is increasing.33 for (var i=0; i<observations.length; i++)34 {35 observations[i] = new Observation(observations[i]);36 37 // check if the start date given by the user is increasing.38 if (i>0 && observations[i].start <= observations[i-1].start)39 {40 throw new Error("Start time '"+ observations[i].start.toUTCString()+41 "' in row "+i+" exceeds start time in row "+(i-1));42 }43 }44 */45 46 26 include('scripts/getSchedule.js'); 47 27 … … 106 86 */ 107 87 108 // ---------------------------------------------------------------- 109 110 // ================================================================ 111 // Code related to monitoring the fad system 112 // ================================================================ 113 114 var sub_incomplete = new Subscription("FAD_CONTROL/INCOMPLETE"); 115 116 var incomplete = 0; 117 118 sub_incomplete.onchange = function(evt) 119 { 120 if (!evt.data) 121 return; 122 123 var inc = evt.obj['incomplete']; 124 if (!inc || inc>0xffffffffff) 125 return; 126 127 if (incomplete>0) 128 return; 129 130 if (dim.state("MCP").name!="TakingData") 131 return; 132 133 incomplete = inc; 134 135 console.out("", "Incomplete event detected, sending MCP/STOP"); 136 dim.send("MCP/STOP"); 137 } 138 139 140 // ================================================================ 141 // Code related to taking data 142 // ================================================================ 143 144 var sub_connections = new Subscription("FAD_CONTROL/CONNECTIONS"); 145 146 var startrun = new Subscription("FAD_CONTROL/START_RUN"); 147 startrun.get(5000); 148 149 /** 150 * reconnect to problematic FADs 151 * 152 * Dis- and Reconnects to FADs, found to be problematic by call-back function 153 * onchange() to have a different CONNECTION value than 66 or 67. 154 * 155 * @returns 156 * a boolean is returned. 157 * reconnect returns true if: 158 * * nothing needed to be reset --> no problems found by onchange() 159 * * the reconnection went fine. 160 * 161 * reconnect *never returns false* so far. 162 * 163 * @example 164 * if (!sub_connections.reconnect()) 165 * exit(); 166 */ 167 function reconnect(list, txt) 168 { /* 169 var reset = [ ]; 170 171 for (var i=0; i<list.length; i++) 172 { 173 console.out(" FAD %2d".$(list[i])+" lost during "+txt); 174 reset.push(parseInt(list[i]/10)); 175 } 176 177 reset = reset.filter(function(elem,pos){return reset.indexOf(elem)==pos;}); 178 179 console.out(""); 180 console.out(" FADs belong to crate(s): "+reset); 181 console.out(""); 182 */ 183 console.out(""); 184 console.out("Trying automatic reconnect ["+txt+"]..."); 185 186 for (var i=0; i<list.length; i++) 187 { 188 console.out(" ...disconnect "+list[i]); 189 dim.send("FAD_CONTROL/DISCONNECT", list[i]); 190 } 191 192 console.out(" ...waiting for 3s"); 193 v8.sleep(3000); 194 195 for (var i=0; i<list.length; i++) 196 { 197 console.out(" ...reconnect "+list[i]); 198 dim.send("FAD_CONTROL/CONNECT", list[i]); 199 } 200 201 console.out(" ...waiting for 1s"); 202 v8.sleep(1000); 203 console.out(" ...checking connection"); 204 dim.wait("FAD_CONTROL", "Connected", 3000); 205 console.out(""); 206 } 207 208 function takeRun(type, count, time) 209 { 210 if (!count) 211 count = -1; 212 if (!time) 213 time = -1; 214 215 var nextrun = startrun.get().obj['next']; 216 console.out(" Take run %3d".$(nextrun)+": N="+count+" T="+time+"s ["+type+"]"); 217 218 // FIXME: Replace by callback? 219 // 220 // DN: I believe instead of waiting for 'TakingData' one could split this 221 // up into two checks with an extra condition: 222 // if type == 'data': 223 // wait until ThresholdCalibration starts: 224 // --> this time should be pretty identical for each run 225 // if this takes longer than say 3s: 226 // there might be a problem with one/more FADs 227 // 228 // wait until "TakingData": 229 // --> this seems to take even some minutes sometimes... 230 // (might be optimized rather soon, but still in the moment...) 231 // if this takes way too long: 232 // there might be something broken, 233 // so maybe a very high time limit is ok here. 234 // I think there is not much that can go wrong, 235 // when the Thr-Calib has already started. Still it might be nice 236 // If in the future RateControl is written so to find out that 237 // in case the threshold finding algorithm does 238 // *not converge as usual* 239 // it can complain, and in this way give a hint, that the weather 240 // might be a little bit too bad. 241 // else: 242 // wait until "TakingData": 243 // --> in a non-data run this time should be pretty short again 244 // if this takes longer than say 3s: 245 // there might be a problem with one/more FADs 246 // 247 248 // Use this if you use the rate control to calibrate by rates 249 //if (!dim.wait("MCP", "TakingData", -300000) ) 250 //{ 251 // throw new Error("MCP took longer than 5 minutes to start TakingData"+ 252 // "maybe this idicates a problem with one of the FADs?"); 253 //} 254 255 // Here we could check and handle fad losses 256 257 incomplete = 0; 258 259 for (var n=0; n<3; n++) 260 { 261 dim.send("MCP/START", time?time:-1, count?count:-1, type); 262 try 263 { 264 dim.wait("MCP", "TakingData", 15000); 265 break; 266 } 267 catch (e) 268 { 269 console.out(""); 270 console.out("MCP: "+dim.state("MCP").name); 271 console.out("FAD_CONTROL: "+dim.state("FAD_CONTROL").name); 272 console.out("FTM_CONTROL: "+dim.state("FTM_CONTROL").name); 273 console.out(""); 274 275 if (dim.state("MCP").name!="Configuring3" || 276 dim.state("FAD_CONTROL").name!="Configuring2") 277 throw e; 278 279 console.out(""); 280 console.out("Waiting for fadctrl to get configured timed out... checking for in-run FAD loss."); 281 282 var con = sub_connections.get(); 283 var stat = con.obj['status']; 284 285 console.out("Sending MCP/RESET"); 286 dim.send("MCP/RESET"); 287 288 dim.wait("FTM_CONTROL", "Idle", 3000); 289 dim.wait("FAD_CONTROL", "Connected", 3000); 290 dim.wait("MCP", "Idle", 3000); 291 292 var list = []; 293 for (var i=0; i<40; i++) 294 if (stat[i]!=0x43) 295 list.push(i); 296 297 reconnect(list, "configuration"); 298 299 if (n==2) 300 throw e; 301 302 dim.wait("MCP", "Idle", 3000); 303 } 304 } 305 306 dim.wait("MCP", "Idle", time>0 ? time*1250 : undefined); // run time plus 25% 307 308 if (incomplete) 309 { 310 console.out(""); 311 console.out("MCP: "+dim.state("MCP").name); 312 console.out("FAD_CONTROL: "+dim.state("FAD_CONTROL").name); 313 console.out("FTM_CONTROL: "+dim.state("FTM_CONTROL").name); 314 315 dim.wait("MCP", "Idle", 3000); 316 dim.wait("FTM_CONTROL", "Idle", 3000); 317 318 // Necessary to allow the disconnect, reconnect 319 dim.send("FAD_CONTROL/CLOSE_OPEN_FILES"); 320 dim.wait("FAD_CONTROL", "Connected", 3000); 321 322 var list = []; 323 for (var i=0; i<40; i++) 324 if (incomplete&(1<<i)) 325 list.push(i); 326 327 reconnect(list, "data taking"); 328 329 return false; 330 331 //throw new Error("In-run FAD loss detected."); 332 } 333 334 //console.out(" Take run: end"); 335 336 // DN: currently reconnect() never returns false 337 // .. but it can fail of course. 338 //if (!sub_connections.reconnect()) 339 // exit(); 340 341 return true;//sub_connections.reconnect(); 342 } 343 344 // ---------------------------------------------------------------- 88 // ================================================================ 89 // Code to perform the DRS calib sequence 90 // ================================================================ 345 91 346 92 function doDrsCalibration(where) … … 454 200 455 201 var delta = evt.obj['DeltaBias']; 202 203 // It seems this can happen when the feedback was newly started. Why? 204 // What is the correct solution? 205 if (!delta) 206 return; 456 207 457 208 var avg = 0; … … 606 357 //v8.timeout(5*60000, func, this); 607 358 while ((this.cnt==undefined || this.get().counter<=this.cnt+10) && (!this.voltageStep || this.voltageStep>0.02)) 608 v8.sleep( );359 v8.sleep(100); 609 360 610 361 console.out(" Feedback wait: end [dV=%.3f, cnt=%d, %.2fs]".$(this.voltageStep, this.get().counter, (new Date()-now)/1000)); … … 781 532 include('scripts/Startup.js'); 782 533 534 // ================================================================ 535 // Code related to monitoring the fad system 536 // ================================================================ 537 538 // This code is here, because scripts/Startup.js needs the 539 // same subscriptions... to be revised. 540 var sub_incomplete = new Subscription("FAD_CONTROL/INCOMPLETE"); 541 var sub_connections = new Subscription("FAD_CONTROL/CONNECTIONS"); 542 var sub_startrun = new Subscription("FAD_CONTROL/START_RUN"); 543 sub_startrun.get(5000); 544 545 include('scripts/takeRun.js'); 546 783 547 // ---------------------------------------------------------------- 784 548 // Check that everything we need is availabel to receive commands
Note:
See TracChangeset
for help on using the changeset viewer.