00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 var SmartLaunch = SmartLaunch || {};
00031
00032 if (typeof Debug == 'undefined')
00033 throw('ERROR: Debug is undefined! Must include Debug.js before SmartLaunch.js');
00034 else if (typeof Globals == 'undefined')
00035 throw('ERROR: Globals is undefined! Must include Globals.js before SmartLaunch.js');
00036
00037 SmartLaunch.MENU_PRIMARY_COLOR = "rgb(220, 187, 165)";
00038 SmartLaunch.MENU_SECONDARY_COLOR = "rgb(130, 51, 51)";
00039
00040
00041 SmartLaunch.launcher;
00042 SmartLaunch.doShowContexts = false;
00043 SmartLaunch.subsystems = [];
00044
00045
00046
00047
00048 SmartLaunch.systemToContextMap = {};
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00065
00068 SmartLaunch.create = function() {
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098 var _CHECKBOX_H = 40;
00099 var _CHECKBOX_MIN_W = 240;
00100 var _CHECKBOX_MAX_W = 540;
00101 var _LAUNCH_MIN_W = 525;
00102 var _MARGIN = 40;
00103
00104
00105 var _needEventListeners = true;
00106
00107 var _subsetBasePath = "XDAQContextConfiguration";
00108
00109 var _systemStatusArray = [];
00110 var _contextRecords = [];
00111
00112
00113
00114
00115 var _state = "";
00116 var _inTransition = false;
00117 var _wasInTransition = false;
00118 var _timeInState = 0;
00119 var _transitionPercentComplete = 0;
00120 var _runNumber;
00121 var _transitionName = "";
00122
00123 var _fsmName, _fsmWindowName;
00124 var _getStateTimer = 0;
00125 var _runFSMTimer = 0;
00126
00127 var _running = false;
00128 var _runStatusDiv;
00129
00132
00133 SmartLaunch.launcher = this;
00134 Debug.log("SmartLaunch.launcher constructed");
00135
00136 init();
00137 Debug.log("SmartLaunch.launcher initialized");
00138
00139
00140
00141
00142 function init()
00143 {
00144 Debug.log("Smart Launch init ");
00145 DesktopContent.tooltip("Smart Launch",
00146 "Welcome to the Smart Launch user interface. "+
00147 "Select which pieces of the configuration you want to enable, and then press the launch button!" +
00148 "\n\n" +
00149 "Once the pieces you want are enabled, press the run button!"
00150 );
00151
00152
00153 ConfigurationAPI.getSubsetRecords(
00154 _subsetBasePath,
00155 "",
00156 localGetContextRecordsHandler
00157 );
00158
00159
00160 window.clearTimeout(_getStateTimer);
00161 _getStateTimer = window.setTimeout(getCurrentState,1000);
00162
00163 return;
00164
00166 function localGetContextRecordsHandler(records)
00167 {
00168
00169 console.log(records);
00170 _contextRecords = records;
00171
00172
00173 createElements();
00174
00175 if(_needEventListeners)
00176 {
00177 window.addEventListener("resize",redrawWindow);
00178 _needEventListeners = false;
00179 }
00180
00181
00182 readEnabledSubsystems();
00183 }
00184
00185
00186 }
00187
00188
00189
00190
00191 function createElements()
00192 {
00193 Debug.log("createElements");
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214 var cel,el,al,sl;
00215
00216 cel = document.getElementById("content");
00217 if(!cel)
00218 {
00219 cel = document.createElement("div");
00220 cel.setAttribute("id","content");
00221 }
00222
00223
00224 cel.innerHTML = "";
00225
00226
00227 {
00228
00229
00230
00231 sl = document.createElement("div");
00232 sl.setAttribute("id","subsystemDiv");
00233 el = document.createElement("div");
00234 el.setAttribute("id","subsystemDivContainer");
00235 sl.appendChild(el);
00236 cel.appendChild(sl);
00237
00238
00239
00240
00241 al = document.createElement("a");
00242 al.setAttribute("id","launchLink");
00243 al.onclick = function()
00244 {
00245 Debug.log("clicked launch");
00246 SmartLaunch.launcher.launch();
00247 };
00248
00249 el = document.createElement("div");
00250 el.setAttribute("id","launchDiv");
00251 el.innerHTML = "Launch";
00252 al.appendChild(el);
00253 cel.appendChild(al);
00254
00255
00256 al = document.createElement("a");
00257 al.setAttribute("id","runLink");
00258 al.onclick = function()
00259 {
00260 Debug.log("clicked run");
00261 SmartLaunch.launcher.run();
00262 };
00263
00264 el = document.createElement("div");
00265 el.setAttribute("id","runDiv");
00266 el.innerHTML = "Run";
00267 al.appendChild(el);
00268 cel.appendChild(al);
00269
00270
00271 sl = document.createElement("div");
00272 sl.setAttribute("id","runStatusDiv");
00273 sl.style.top = "10px";
00274 cel.appendChild(sl);
00275
00276 }
00277
00278
00279
00280
00281
00282
00283 document.body.appendChild(cel);
00284
00285
00286 }
00287
00288
00289
00290
00291 function readEnabledSubsystems()
00292 {
00293 try
00294 {
00295 Debug.log("readEnabledSubsystems");
00296
00297 var recordsArray = [];
00298
00299 for(var i=0; i<SmartLaunch.subsystems.length; ++i)
00300 {
00301 for(var j=0; j<SmartLaunch.systemToContextMap[SmartLaunch.subsystems[i]].length; ++j)
00302 recordsArray.push(SmartLaunch.systemToContextMap[SmartLaunch.subsystems[i]][j]);
00303 }
00304 if(SmartLaunch.doShowContexts)
00305 for(var i=0; i<_contextRecords.length; ++i)
00306 recordsArray.push(_contextRecords[i]);
00307
00308 console.log("recordsArray",recordsArray);
00309
00310 ConfigurationAPI.getFieldValuesForRecords(
00311 _subsetBasePath,
00312 recordsArray,
00313 ["Status"],
00314 localStatusForRecordsHandler
00315 );
00316 return;
00317 }
00318 catch(e)
00319 {
00320 Debug.log("There was error reading the status of the configuration subsystems (" +
00321 "were the subsystem variables setup properly?): " +
00322 e, Debug.HIGH_PRIORITY);
00323 return;
00324 }
00325
00327 function localStatusForRecordsHandler(recFieldValues)
00328 {
00329 Debug.log("localStatusForRecordsHandler value-length=" + recFieldValues.length)
00330 var statusArray = [];
00331 for(var i in recFieldValues)
00332 statusArray.push(
00333 recFieldValues[i].fieldValue == "On"?true:false);
00334
00335 console.log("statusArray",statusArray);
00336
00337 _systemStatusArray = [];
00338 var k=0;
00339 for(var i=0; i<SmartLaunch.subsystems.length; ++i)
00340 {
00341 _systemStatusArray.push(true);
00342 for(var j=0; j<SmartLaunch.systemToContextMap[SmartLaunch.subsystems[i]].length; ++j,++k)
00343 if(!statusArray[k])
00344 _systemStatusArray[i] = false;
00345 }
00346 if(SmartLaunch.doShowContexts)
00347 for(var i=0; i<_contextRecords.length; ++i, ++k)
00348 _systemStatusArray.push(statusArray[k]);
00349
00350 console.log("_systemStatusArray",_systemStatusArray);
00351
00352 redrawWindow();
00353
00354 }
00355
00356
00357 }
00358
00359
00360
00361
00362
00363 function redrawWindow()
00364 {
00365
00366
00367
00368 var w = window.innerWidth | 0;
00369 var h = window.innerHeight | 0;
00370
00371 if(w < _LAUNCH_MIN_W)
00372 w = _LAUNCH_MIN_W;
00373 if(h < _LAUNCH_MIN_W)
00374 h = _LAUNCH_MIN_W;
00375
00376 Debug.log("redrawWindow to " + w + " - " + h);
00377
00378 var sdiv = document.getElementById("subsystemDiv");
00379 var ldiv = document.getElementById("launchDiv");
00380 var rdiv = document.getElementById("runDiv");
00381 _runStatusDiv = runStatusDiv = document.getElementById("runStatusDiv");
00382
00383 var chkH = _CHECKBOX_H;
00384 var chkW = (w/3)|0;
00385 if(chkW < _CHECKBOX_MIN_W) chkW = _CHECKBOX_MIN_W;
00386 if(chkW > _CHECKBOX_MAX_W) chkW = _CHECKBOX_MAX_W;
00387
00388 var sdivH = 66 + chkH*SmartLaunch.subsystems.length;
00389
00390 if(SmartLaunch.doShowContexts)
00391 {
00392 sdivH += 66 + chkH*_contextRecords.length;
00393 }
00394 if(sdivH > 2/3*h)
00395 sdivH = 2/3*h;
00396 if(sdivH < 100)
00397 sdivH = 100;
00398
00399 var sdivW = chkW;
00400
00401 var sdivX = _MARGIN;
00402 var sdivY = (h-sdivH)/2;
00403 if(sdivY < _MARGIN)
00404 sdivY = _MARGIN;
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419 var ldivX = _MARGIN + chkW;
00420 var ldivSz = h/2;
00421 if(ldivSz > w - ldivX - _MARGIN*3)
00422 ldivSz = w - ldivX - _MARGIN*3;
00423 ldivSz *= 0.9;
00424 var ldivY = (h-ldivSz)/2 - ldivSz/2;
00425 var lratio = 180/300;
00426
00427 var rdivX = _MARGIN + chkW;
00428 var rdivSz = ldivSz;
00429 var rdivY = ldivY + ldivSz;
00430 var rratio = 180/300;
00431
00432
00433
00434 {
00435 var str = "";
00436 var statusIndex = 0;
00437
00438 var hideableSubsystems = SmartLaunch.subsystems.length && SmartLaunch.doShowContexts;
00439 var hideableContexts = SmartLaunch.subsystems.length;
00440
00441 if(SmartLaunch.subsystems.length)
00442 {
00443 if(hideableSubsystems)
00444 str += "<a onclick='SmartLaunch.launcher.toggleCheckboxDiv(0);' title='Hide/Show Subsystems'>";
00445 str += "<h3>Subsystems</h3>";
00446 if(hideableSubsystems)
00447 str += "</a>";
00448
00449 str += "<div id='ssCheckboxDiv'>";
00450 for(var i=0;i<SmartLaunch.subsystems.length;++i,++statusIndex)
00451 {
00452 str += "<div class='ssCheckbox' style='height:" + chkH + "px;" +
00453 "' >";
00454 str += "<div class='pretty p-icon p-round p-smooth' onclick='SmartLaunch.launcher.handleCheckbox(" +
00455 statusIndex + ");' >";
00456 str += " <input type='checkbox' class='subsystemCheckboxes' " +
00457 (_systemStatusArray[statusIndex]?"checked":"") +
00458 "/>";
00459 str += "<div class='state p-success'>";
00460 str += "<i class='icon mdi mdi-check'></i>";
00461 str += "<label>" + SmartLaunch.subsystems[i] + "</label>";
00462 str += "</div>";
00463 str += "</div>";
00464 str += "</div>";
00465 str += "<div id='clearDiv'></div>";
00466 }
00467 str += "</div>";
00468 }
00469 else if(!SmartLaunch.doShowContexts)
00470 {
00471 str += "No subsystem configuration definition found.";
00472 }
00473
00474
00475 if(SmartLaunch.doShowContexts)
00476 {
00477 if(hideableContexts)
00478 str += "<a onclick='SmartLaunch.launcher.toggleCheckboxDiv(1);' title='Hide/Show Contexts'>";
00479 str += "<h3>Individual Contexts</h3>";
00480 if(hideableContexts)
00481 str += "</a>";
00482
00483 if(!_contextRecords.length)
00484 str += "No contexts found.";
00485
00486
00487 str += "<div id='ctxCheckboxDiv'>";
00488 for(var i=0; i<_contextRecords.length; ++i,++statusIndex)
00489 {
00490 str += "<div class='ssCheckbox' style='height:" + chkH + "px;" +
00491 "' >";
00492 str += "<div class='pretty p-icon p-round p-smooth' onclick='SmartLaunch.launcher.handleCheckbox(" +
00493 statusIndex + ");' >";
00494 str += " <input type='checkbox' class='subsystemCheckboxes' " +
00495 (_systemStatusArray[statusIndex]?"checked":"") +
00496 "/>";
00497 str += "<div class='state p-success'>";
00498 str += "<i class='icon mdi mdi-check'></i>";
00499 str += "<label>" + _contextRecords[i] + "</label>";
00500 str += "</div>";
00501 str += "</div>";
00502 str += "</div>";
00503 str += "<div id='clearDiv'></div>";
00504 }
00505 str += "</div>"
00506 }
00507
00508
00509 sdiv.style.left = (sdivX-20) + "px";
00510 sdiv.style.top = sdivY + "px";
00511 sdiv.style.height = sdivH + "px";
00512 sdiv.style.width = sdivW + "px";
00513 sdiv.style.display = "block";
00514
00515
00516 sdiv = document.getElementById("subsystemDivContainer");
00517 sdiv.style.left = (sdivX-20) + "px";
00518 sdiv.style.top = sdivY + "px";
00519 sdiv.style.height = sdivH + "px";
00520 sdiv.style.width = sdivW + "px";
00521 sdiv.innerHTML = "";
00522 sdiv.innerHTML = str;
00523 sdiv.style.display = "block";
00524 }
00525
00526
00527 {
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541 ldiv.style.left = (ldivX + (w - ldivX - _MARGIN*2 - ldivSz)/2) + "px";
00542 ldiv.style.top = (ldivY+((ldivSz-ldivSz*lratio)/2)) + "px";
00543
00544 ldiv.style.width = ldivSz + "px";
00545 ldiv.style.paddingTop = (ldivSz*lratio/2 - 36/2) + "px";
00546 ldiv.style.paddingBottom = (ldivSz*lratio/2- 36/2) + "px";
00547
00548
00549
00550 ldiv.style.borderRadius = ldivSz + "px/" + (ldivSz*200/300) + "px";
00551 ldiv.style.fontSize = ldivSz/10 + "px";
00552
00553 ldiv.style.display = "block";
00554 }
00555
00556
00557
00558 {
00559
00560 rdiv.style.left = (rdivX + (w - rdivX - _MARGIN*2 - rdivSz)/2) + "px";
00561 rdiv.style.top = (rdivY+((rdivSz-rdivSz*rratio)/2)) + "px";
00562
00563 rdiv.style.width = rdivSz + "px";
00564 rdiv.style.paddingTop = (rdivSz*rratio/2 - 36/2) + "px";
00565 rdiv.style.paddingBottom = (rdivSz*rratio/2- 36/2) + "px";
00566
00567
00568
00569 rdiv.style.borderRadius = rdivSz + "px/" + (rdivSz*200/300) + "px";
00570 rdiv.style.fontSize = rdivSz/10 + "px";
00571
00572 rdiv.style.display = "block";
00573
00574
00575 runStatusDiv.style.left = (rdivX + _MARGIN + (w - rdivX - _MARGIN*2 - rdivSz)/2) + "px";
00576 runStatusDiv.style.top = (h/2 - 50) + "px";
00577 runStatusDiv.style.width = (rdivSz + _MARGIN) + "px";
00578 runStatusDiv.style.fontSize = rdivSz/15 + "px";
00579 }
00580
00581 }
00582
00583
00584
00585
00586 function getCurrentState()
00587 {
00588 window.clearTimeout(_getStateTimer);
00589
00590 DesktopContent.XMLHttpRequest("Request?RequestType=getCurrentState" +
00591 "&fsmName=" + _fsmName,
00592 "",
00593 localGetStateHandler,
00594 0,
00595 0,0,false,
00596 true , true );
00597
00598
00599 function localGetStateHandler(req,id,err)
00600 {
00601 if(!req)
00602 {
00603 Debug.log("Error: " + err, Debug.HIGH_PRIORITY);
00604 return;
00605 }
00606
00607
00608 _state = DesktopContent.getXMLValue(req,"current_state");
00609 _inTransition = DesktopContent.getXMLValue(req,"in_transition") == "1";
00610 _timeInState = DesktopContent.getXMLValue(req,"time_in_state") | 0;
00611 _runNumber = DesktopContent.getXMLValue(req,"run_number");
00612 _transitionPercentComplete = DesktopContent.getXMLValue(req,"transition_progress") | 0;
00613
00614 if(_transitionPercentComplete > 100)
00615 {
00616
00617 _transitionPercentComplete = 100;
00618 }
00619
00620
00621
00622
00623
00624
00625
00626 displayState();
00627
00628
00629
00630 window.clearTimeout(_getStateTimer);
00631 _getStateTimer = window.setTimeout(getCurrentState,1000);
00632 }
00633 }
00634
00635
00636
00637
00638 function displayState()
00639 {
00640
00641
00642
00643
00644
00645 if(_state == "Running")
00646 {
00647 if(!_running)
00648 {
00649 _running = true;
00650 document.getElementById("runDiv").innerHTML = "Stop";
00651 }
00652 }
00653 else
00654 {
00655 if(_running)
00656 {
00657 _running = false;
00658 document.getElementById("runDiv").innerHTML = "Run";
00659 }
00660 }
00661
00662
00663 let str = "";
00664 str += "<table cellspacing='0' cellpadding='0'>";
00665
00666
00667 if(_inTransition)
00668 str += "<tr><td style='font-weight: bold; padding-right:20px;'>Transition:</td><td>" +
00669 _transitionName + "</td></tr>";
00670 else
00671 str += "<tr><td style='font-weight: bold; padding-right:20px;'>Current State:</td><td>" +
00672 _state + "</td></tr>";
00673
00674
00675
00676
00677 if(
00678 _runNumber)
00679 {
00680
00681 let i = _runNumber.lastIndexOf(' ');
00682 if(i >= 0)
00683 {
00684 let hdr = _runNumber.substr(0,i);
00685 let num = _runNumber.substr(i+1);
00686 stateStr = "Running <br> " + _runNumber;
00687 str += "<tr><td style='font-weight: bold; padding-right:20px;'>" +
00688 hdr + "</td><td>" +
00689 num + "</td></tr>";
00690 }
00691 }
00692
00693
00694
00695
00696 let progressStr = "";
00697 if(_inTransition)
00698 {
00699 progressStr = _transitionPercentComplete + " %";
00700
00701 str += "<tr><td style='font-weight: bold; padding-right:20px;'>Progress:</td><td>" +
00702 progressStr + "</td></tr>";
00703
00704 if(!_wasInTransition)
00705 _wasInTransition = true;
00706 }
00707 else if(_wasInTransition)
00708 {
00709
00710 _wasInTransition = false;
00711 progressStr = 100 + " %";
00712
00713 str += "<tr><td style='font-weight: bold; padding-right:20px;'>Transitioning:</td><td>" +
00714 progressStr + "</td></tr>";
00715 }
00716 else
00717 {
00718
00719 let tstr = "";
00720 var hours = (_timeInState/60.0/60.0)|0;
00721 var mins = ((_timeInState%(60*60))/60.0)|0;
00722 var secs = _timeInState%60;
00723
00724 tstr += hours + ":";
00725 if(mins < 10) tstr += "0";
00726 tstr += mins + ":";
00727 if(secs < 10) tstr += "0";
00728 tstr += secs ;
00729
00730 str += "<tr><td style='font-weight: bold; padding-right:20px;'>Time-in-State:</td><td>" + tstr + "</td></tr>";
00731 }
00732
00733 try
00734 {
00735 _runStatusDiv.innerHTML = str;
00736
00737 _runStatusDiv.style.display = "block";
00738 }
00739 catch(e) {console.log(e);}
00740 }
00741
00742
00743
00744 this.launch = function()
00745 {
00746 Debug.log("launch");
00747 DesktopContent.popUpVerification(
00748 "Are you sure you want to relaunch otsdaq?",
00749 localLaunch,
00750 0,"#efeaea",0,"#770000");
00751
00752
00753 function localLaunch()
00754 {
00755 Debug.log("localLaunch");
00756
00757 var checkboxes = document.getElementsByClassName('subsystemCheckboxes');
00758 console.log("checkboxes",checkboxes);
00759 var checkedArray = [];
00760 for(var i=0;i<checkboxes.length;++i)
00761 checkedArray.push(checkboxes[i].checked);
00762 console.log("checkedArray",checkedArray);
00763
00764 var recordsArray = [];
00765 var valuesArray = [];
00766
00767
00768
00769 if(SmartLaunch.doShowContexts)
00770 {
00771
00772 for(var i=0; i<_contextRecords.length; ++i)
00773 {
00774 recordsArray.push(_contextRecords[i]);
00775 valuesArray.push(checkedArray[SmartLaunch.subsystems.length+i]?
00776 "1":"0");
00777 }
00778 }
00779 else
00780 {
00781
00782 for(var i=0; i<SmartLaunch.subsystems.length; ++i)
00783 {
00784 for(var j=0; j<SmartLaunch.systemToContextMap[SmartLaunch.subsystems[i]].length; ++j)
00785 {
00786 recordsArray.push(SmartLaunch.systemToContextMap[SmartLaunch.subsystems[i]][j]);
00787 valuesArray.push(checkedArray[i]?"1":"0");
00788
00789 }
00790 }
00791 }
00792 console.log("recordsArray",recordsArray);
00793 console.log("valuesArray",valuesArray);
00794
00795 var recordIndex = 0;
00796 var localModifiedTables = undefined;
00797
00798 localSetSequenceOfRecords();
00799
00800
00801 function localSetSequenceOfRecords()
00802 {
00803 ConfigurationAPI.setFieldValuesForRecords(
00804 _subsetBasePath,
00805 recordsArray[recordIndex],
00806 "Status",
00807 valuesArray[recordIndex],
00808 function(modifiedTables)
00809 {
00810 Debug.log("recordIndex = " + recordIndex);
00811
00812 if(modifiedTables.length == 0)
00813 {
00814 Debug.log("Something went very wrong. Notify administrators.",
00815 Debug.HIGH_PRIORITY);
00816 return;
00817 }
00818
00819 ++recordIndex;
00820 if(recordIndex == recordsArray.length)
00821 {
00822 Debug.log("Done with sequence.");
00823
00824
00825 ConfigurationAPI.saveModifiedTables(modifiedTables,
00827 function(savedTables, savedGroups, savedAliases)
00828 {
00829 if(!savedTables.length)
00830 {
00831 Debug.log("Something went very wrong. Notify administrators.",
00832 Debug.HIGH_PRIORITY);
00833 return;
00834 }
00835
00836 Debug.log("Successfully applied subsystem selections!", Debug.INFO_PRIORITY);
00837
00838
00839
00840 Debug.log("Relaunching ots...");
00841 SmartLaunch.launcher.gatewayLaunchOts();
00842
00843
00844 });
00845 return;
00846 }
00847
00848 console.log("setFieldValuesForRecords modifiedTables",modifiedTables);
00849 localModifiedTables = modifiedTables;
00850 localSetSequenceOfRecords();
00851
00852 }
00853 ,localModifiedTables);
00854 }
00855 }
00856 }
00857
00858
00859
00860 this.gatewayLaunchOts = function()
00861 {
00862 Debug.log("Relaunching otsdaq!",Debug.INFO_PRIORITY);
00863
00864
00865 window.clearTimeout(_getStateTimer);
00866
00867
00868 DesktopContent._blockSystemCheckMailbox.innerHTML = "1";
00869 window.setTimeout(localDelayedLaunch,1000);
00870
00871
00872
00873 function localDelayedLaunch()
00874 {
00875 DesktopContent.XMLHttpRequest("Request?" +
00876 "RequestType=gatewayLaunchOTS",
00877 "",
00878 function(req)
00879 {
00880 Debug.log("gatewayLaunchOts handler ");
00881
00882
00883 var countDown = 10;
00884 localCountDown();
00885
00886 function localCountDown()
00887 {
00888 Debug.log("Waiting " + countDown + " seconds for startup sequence...",
00889 Debug.INFO_PRIORITY);
00890
00891 window.setTimeout(function() {
00892 Debug.log("localCountDown handler ");
00893 --countDown;
00894 if(countDown == 0)
00895 {
00896
00897 DesktopContent._blockSystemCheckMailbox.innerHTML = "";
00898 init();
00899 Debug.log("And we are back!",Debug.INFO_PRIORITY);
00900 return;
00901 }
00902 localCountDown();
00903 },
00904 1000);
00905 }
00906
00907 },
00908 0,
00909 0,0,true,
00910 true , true );
00911 }
00912
00913 }
00914
00915
00916
00917
00918 this.run = function()
00919 {
00920 Debug.log("run");
00921
00922 var timeoutCount = 0;
00923 var operativeWord = "starting";
00924 var lastState = "";
00925
00926 if(_running)
00927 {
00928 DesktopContent.popUpVerification(
00929 "Are you sure you want to stop the run?",
00930 localStop,
00931 0,"#efeaea",0,"#770000");
00932
00933
00934 function localStop()
00935 {
00936 Debug.log("localStop");
00937
00938 operativeWord = "stopping";
00939 localRun();
00940 }
00941 return;
00942 }
00943
00944 DesktopContent.popUpVerification(
00945 "Are you sure you want to start a run?",
00946 localRun,
00947 0,"#efeaea",0,"#770000");
00948
00949
00950 function localRun()
00951 {
00952 Debug.log("localRun");
00953
00954 window.clearTimeout(_runFSMTimer);
00955
00956 ++timeoutCount;
00957 if(timeoutCount > 60)
00958 {
00959 Debug.log("Timeout reached! Giving up on " + operativeWord + " the run.", Debug.HIGH_PRIORITY);
00960 return;
00961 }
00962
00963 if(_inTransition)
00964 {
00965 window.clearTimeout(_getStateTimer);
00966 _getStateTimer = window.setTimeout(getCurrentState,1000);
00967
00968 window.clearTimeout(_runFSMTimer);
00969 _runFSMTimer = window.setTimeout(localRun,1000);
00970 return;
00971 }
00972
00973 if(lastState == _state)
00974 {
00975 Debug.log("State machine is not progressing! Stuck in '" +
00976 _state + ".' Giving up on " + operativeWord + " the run.", Debug.HIGH_PRIORITY);
00977 return;
00978 }
00979
00980 lastState = _state;
00981
00982 let transitionPostData = "";
00983
00984 if(_state == "Initial")
00985 {
00986 _transitionName = "Initialize";
00987 }
00988 else if(_state == "Failed")
00989 {
00990 if(timeoutCount > 1)
00991 {
00992
00993 Debug.log("Fault encountered! Giving up on " + operativeWord + " the run.", Debug.HIGH_PRIORITY);
00994 return;
00995 }
00996 _transitionName = "Halt";
00997 }
00998 else if(_state == "Halted")
00999 {
01000 _transitionName = "Configure";
01001
01002 transitionPostData = "ConfigurationAlias=" + "defaultSystemAlias";
01003 }
01004 else if(_state == "Configured")
01005 {
01006 if(operativeWord == "stopping")
01007 {
01008
01009 Debug.log("<i>otsdaq</i> has now Stopped! " +
01010 _runNumber + ".", Debug.INFO_PRIORITY);
01011 return;
01012 }
01013
01014 _transitionName = "Start";
01015 }
01016 else if(_state == "Paused")
01017 {
01018 _transitionName = "Start";
01019 }
01020 else if(_state == "Running")
01021 {
01022 if(operativeWord == "stopping")
01023 {
01024 _transitionName = "Stop";
01025 }
01026 else
01027 {
01028
01029 Debug.log("<i>otsdaq</i> is now Running! " +
01030 _runNumber + ".", Debug.INFO_PRIORITY);
01031 return;
01032 }
01033 }
01034 else
01035 {
01036 Debug.log("Unknown action for current state '" + _state + "'..." +
01037 "Giving up on " + operativeWord + " the run.", Debug.HIGH_PRIORITY);
01038 return;
01039 }
01040
01041 _inTransition = true;
01042 _transitionPercentComplete = 0;
01043
01044 displayState();
01045
01046 Debug.log("_transitionName = " + _transitionName +
01047 " transitionPostData = " + transitionPostData);
01048
01049 DesktopContent.XMLHttpRequest("StateMachineXgiHandler?StateMachine=" +
01050 _transitionName +
01051 "&fsmName=" + _fsmName +
01052 "&fsmWindowName=" + _fsmWindowName,
01053 transitionPostData,
01054
01055 function(req)
01056 {
01057
01058 var success = DesktopContent.getXMLValue(req,"state_tranisition_attempted") == "1";
01059 if(!success)
01060 {
01061 var err = DesktopContent.getXMLValue(req,"state_tranisition_attempted_err");
01062 if(err)
01063 Debug.log(err,Debug.HIGH_PRIORITY);
01064 Debug.log("Server indicated failure to attempt state transition. " +
01065 "Giving up on " + operativeWord + " the run.",Debug.HIGH_PRIORITY);
01066 return;
01067 }
01068
01069
01070 window.clearTimeout(_runFSMTimer);
01071 _runFSMTimer = window.setTimeout(localRun,3000);
01072 },
01073 0,
01074 0,0,false,
01075 true );
01076
01077 }
01078
01079 }
01080
01081
01082
01083 this.toggleCheckboxDiv = function(i)
01084 {
01085 Debug.log("toggleCheckboxDiv(i) " + i);
01086
01087 var el;
01088 if(i == 0)
01089 {
01090 el = document.getElementById("ssCheckboxDiv");
01091 el.style.display = (el.style.display == "none")?"block":"none";
01092 }
01093 else if(i == 1)
01094 {
01095 el = document.getElementById("ctxCheckboxDiv");
01096 el.style.display = (el.style.display == "none")?"block":"none";
01097 }
01098 else throw("Invalid index checkbox div " + i);
01099 }
01100
01101
01102
01103 this.handleCheckbox = function(c)
01104 {
01105 Debug.log("handleCheckbox(c) " + c);
01106
01107 var checkboxes = document.getElementsByClassName('subsystemCheckboxes');
01108 console.log("checkboxes",checkboxes);
01109 var checkedArray = [];
01110 for(var i=0;i<checkboxes.length;++i)
01111 checkedArray.push(checkboxes[i].checked);
01112 console.log("checkedArray",checkedArray);
01113
01114 Debug.log("set to " + checkedArray[c]);
01115
01116
01117 var contextEnabledMap = {};
01118 for(var i=0; i<_contextRecords.length; ++i)
01119 contextEnabledMap[_contextRecords[i]] = [checkedArray[SmartLaunch.subsystems.length+i],
01120 SmartLaunch.subsystems.length+i];
01121
01122
01123 if(c < SmartLaunch.subsystems.length)
01124 {
01125
01126 for(var j=0; j<SmartLaunch.systemToContextMap[SmartLaunch.subsystems[c]].length; ++j)
01127 {
01128
01129 contextEnabledMap[
01130 SmartLaunch.systemToContextMap[SmartLaunch.subsystems[c]][j]
01131 ][0] = checkedArray[c];
01132
01133 checkboxes[contextEnabledMap[
01134 SmartLaunch.systemToContextMap[SmartLaunch.subsystems[c]][j]
01135 ][1]].checked = checkedArray[c];
01136 }
01137 }
01138 else
01139 {
01140
01141
01142
01143 contextEnabledMap[_contextRecords[c - SmartLaunch.subsystems.length]][0] = checkedArray[c];
01144
01145 }
01146 console.log("contextEnabledMap",contextEnabledMap);
01147
01148
01149
01150 for(var i=0;i<SmartLaunch.subsystems.length;++i)
01151 {
01152 if(i==c) continue;
01153
01154 var enabled = true;
01155
01156 for(var j=0; j<SmartLaunch.systemToContextMap[SmartLaunch.subsystems[i]].length; ++j)
01157 {
01158 if(!contextEnabledMap[
01159 SmartLaunch.systemToContextMap[SmartLaunch.subsystems[i]][j]][0])
01160 {
01161 enabled = false;
01162 break;
01163 }
01164 }
01165
01166
01167 checkboxes[i].checked = enabled;
01168 }
01169
01170
01171 }
01172
01173
01174 }
01175
01176
01177
01178
01179
01180
01181
01182
01183
01184
01185