Ignore:
Timestamp:
04/04/13 14:11:50 (11 years ago)
Author:
tbretz
Message:
Unified the checkState during data taking; improved some log-output; some little bug fixes
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/scripts/Main.js

    r15146 r15252  
    109109service_con.onchange = function(evt)
    110110{
     111    return;
     112
    111113    // This happens, but why?
    112114    if (!evt.obj['status'])
     
    229231    catch (e)
    230232    {
     233        console.out("");
     234        console.out("MCP:         "+dim.state("MCP").name);
     235        console.out("FAD_CONTROL: "+dim.state("FAD_CONTROL").name);
     236        console.out("FTM_CONTROL: "+dim.state("FTM_CONTROL").name);
     237        console.out("");
     238
    231239        if (dim.state("MCP").name=="Configuring3" &&
    232240            dim.state("FAD_CONTROL").name=="Configuring2")
    233241        {
    234             conssole.out("");
    235             conssole.out("Waiting for fadctrl to get configured timed out... checking for FAD loss.");
    236             conssole.out("");
     242            console.out("");
     243            console.out("Waiting for fadctrl to get configured timed out... checking for FAD loss.");
     244            console.out("");
    237245
    238246            var con  = service_con.get();
     
    245253                {
    246254                    console.out("  FAD %2d".$(i)+" not in Configured state.");
    247                     reset.push(i/10);
     255                    reset.push(parseInt(i/10));
    248256                }
    249257
     
    253261            {
    254262                console.out("");
    255                 console.out("  FADs belong to crates "+reset);
     263                console.out("  FADs belong to crate(s): "+reset);
     264                console.out("");
    256265            }
    257266        }
    258267
     268        console.out("Sending MCP/RESET");
    259269        dim.send("MCP/RESET");
    260270
     
    264274    }
    265275
    266     if (time>0)
    267         dim.wait("MCP", "Idle", time*1250); // run time plus 25%
    268     else
    269         dim.wait("MCP", "Idle");
     276    dim.wait("MCP", "Idle", time>0 ? time*1250 : undefined); // run time plus 25%
    270277
    271278    //console.out("  Take run: end");
     
    281288// ----------------------------------------------------------------
    282289
    283 function doDrsCalibration()
    284 {
    285     //console.out("  DRS cal: start");
     290function doDrsCalibration(where)
     291{
     292    console.out("  Take DRS calibration ["+where+"]");
     293
    286294    service_feedback.voltageOff();
     295
     296    var tm = new Date();
    287297
    288298    while (1)
     
    315325    }
    316326
    317     //dim.send("RATE_CONTROL/STOP"); // get out of GlobalThresholdSet
    318     //dim.wait("RATE_CONTROL", "Connected", 3000);
    319 
    320     //console.out("  DRS cal: end");
     327    console.out("  DRS calibration done [%.1f]".$((new Date()-tm)/1000));
    321328}
    322329
     
    336343    var isClosed = dim.state("LID_CONTROL").name=="Closed";
    337344
     345    var tm = new Date();
     346
    338347    // Wait for lid to be open
    339348    if (isClosed)
     
    345354
    346355    if (isClosed)
    347         console.out("  Open lid: done");
     356        console.out("  Open lid: done [%.1fs]".$((new Date()-tm)/1000));
    348357}
    349358
     
    351360{
    352361    var isOpen = dim.state("LID_CONTROL").name=="Open";
     362
     363    var tm = new Date();
    353364
    354365    // Wait for lid to be open
     
    361372
    362373    if (isOpen)
    363         console.out("  Close lid: end");
     374        console.out("  Close lid: end [%.1fs]".$((new Date()-tm)/1000));
    364375}
    365376
     
    535546include('scripts/Startup.js');//Startup();
    536547
    537 /*
    538 include('scripts/CheckStates.js');
    539 
    540 var table =
    541 [
    542  [ "TNG_WEATHER"   ],
    543  [ "MAGIC_WEATHER" ],
    544  [ "CHAT"          ],
    545  [ "SMART_FACT"     ],
    546  [ "FSC_CONTROL",     [ "Connected"                    ] ],
    547  [ "MCP",             [ "Idle"                         ] ],
    548  [ "TIME_CHECK",      [ "Valid"                        ] ],
    549  [ "PWR_CONTROL",     [ "SystemOn"                     ] ],
    550  [ "AGILENT_CONTROL", [ "VoltageOn"                    ] ],
    551  [ "BIAS_CONTROL",    [ "VoltageOff"                   ] ],
    552  [ "FEEDBACK",        [ "CurrentControl", "CurrentCtrlIdle", "Connected" ] ],
    553  [ "RATE_SCAN",       [ "Connected"                    ] ],
    554  [ "RATE_CONTROL",    [ "Connected"                    ] ],
    555  [ "LID_CONTROL",     [ "Open", "Closed"               ] ],
    556  [ "DRIVE_CONTROL",   [ "Armed", "Tracking", "OnTrack" ] ],
    557  [ "FTM_CONTROL",     [ "Idle", "TriggerOn"            ] ],
    558  [ "FAD_CONTROL",     [ "Connected", "WritingData"     ] ],
    559  [ "DATA_LOGGER",     [ "NightlyFileOpen", "WaitForRun", "Logging" ] ],
    560 ];
    561 
    562 console.out("Checking states.");
    563 if (!checkStates(table, 10000))
    564 {
    565     throw new Error"Something unexpected has happened. Although the startup-",
    566             "procedure has finished, not all servers are in the state",
    567             "in which they ought to be. Please, try to find out what",
    568             "happened...");
    569 }
    570 
    571 console.out("Checking states: done.");
    572 */
    573548// ----------------------------------------------------------------
    574549
     
    622597    console.out("Shutdown: start");
    623598
     599    dim.send("FEEDBACK/STOP");
     600    dim.send("FEEDBACK/ENABLE_OUTPUT", false);
    624601    dim.send("FTM_CONTROL/STOP_TRIGGER");
    625602    service_feedback.voltageOff();
     
    659636    console.out("");
    660637    console.out("Shutdown procedure seems to be finished...");
    661     console.out("  Telescope at Zd="+report.obj['Zd']+"deg Az="+report.obj['Az']+"deg");
     638    console.out("  Telescope at Zd=%.1fdeg Az=%.1fdeg".$(report.obj['Zd'], report.obj['Az']));
    662639    console.out("  Please make sure the park position was reached");
    663640    console.out("  and the telescope is not moving anymore.");
     
    743720        if (run<0)
    744721        {
    745             Startup();   // -> Bias On/Off?, Lid open/closed?
    746             CloseLid();
     722            //Startup();   // -> Bias On/Off?, Lid open/closed?
     723            //CloseLid();
    747724        }
    748725
     
    768745    }
    769746
    770     console.out("\n"+(new Date()).toUTCString()+": Current measurement: "+obs[sub]);
    771 
    772     // Check if obs.task is one of the one-time-tasks
    773     switch (obs[sub].task)
    774     {
    775     case "STARTUP":
    776         console.out("  STARTUP", "");
    777         Startup();  // BiasOn/Off?, Lid open/close?
    778         CloseLid();
    779 
    780         console.out("  Take DRS calibration [startup]");
    781         doDrsCalibration();  // -> VoltageOff
    782         console.out("  DRS calibration done.");
    783 
    784         service_feedback.voltageOn();
    785         service_feedback.waitForVoltageOn();
    786 
    787         // Before we can switch to 3000 we have to make the right DRS calibration
    788         console.out("  Take single p.e. run.");
    789         while (!takeRun("pedestal", 5000));
    790 
    791         service_feedback.voltageOff();
    792 
    793         //dim.send("RATE_CONTROL/STOP"); // get out of GlobalThresholdSet
    794         //dim.wait("RATE_CONTROL", "Connected", 3000);
    795 
    796         console.out("  Waiting for first scheduled observation.","");
    797         sub++;
    798         continue;
    799 
    800     case "SHUTDOWN":
    801         console.out("  SHUTDOWN","");
    802         Shutdown();
    803 
    804         console.out("  Waiting for next startup.", "");
    805         sub++;
    806         continue;
    807 
    808     case "IDLE":
    809         v8.sleep(1000);
    810         continue;
    811 
    812     case "DRSCALIB":
    813         console.out("  DRSCALIB", "");
    814 
    815         console.out("  Take DRS calibration [drscalib]");
    816         doDrsCalibration();  // -> VoltageOff
    817         console.out("  DRS calibration done.");
    818 
    819         //dim.send("RATE_CONTROL/STOP"); // get out of GlobalThresholdSet
    820         //dim.wait("RATE_CONTROL", "Connected", 3000);
    821 
    822         sub++;
    823         continue;
    824 
    825     case "SINGLEPE":
    826 
    827         // FIXME: Check whether a DRS calib is necessary.
    828 
    829         service_feedback.voltageOn();
    830         service_feedback.waitForVoltageOn();
    831 
    832         // Before we can switch to 3000 we have to make the right DRS calibration
    833         console.out("  Take single p.e. run.");
    834         while (!takeRun("pedestal", 5000));
    835 
    836         service_feedback.voltageOff();
    837 
    838         //dim.send("RATE_CONTROL/STOP"); // get out of GlobalThresholdSet
    839         //dim.wait("RATE_CONTROL", "Connected", 3000);
    840 
    841         sub++;
    842         continue;
    843 
    844     case "RATESCAN":
    845         console.out("  RATESCAN  ");
    846         /*
    847         if (dim.state("FTM_CONTROL").name=="TriggerOn")
    848         {
    849             dim.send("FTM_CONTROL/STOP_TRIGGER");
    850             dim.wait("FTM_CONTROL", "Idle", 3000);
    851         }*/
    852 
    853         // This is a workaround to make sure that we really catch
    854         // the new state and not the old one
    855         dim.send("DRIVE_CONTROL/STOP");
    856         dim.wait("DRIVE_CONTROL", "Armed", 5000);
    857 
    858         OpenLid();
    859 
    860         service_feedback.voltageOn();
    861 
    862         if (obs.source != undefined)
    863             dim.send("DRIVE_CONTROL/TRACK_ON", obs[sub].source);
    864         else
    865             dim.send("DRIVE_CONTROL/TRACK", obs[sub].ra, obs[sub].dec);
    866 
    867         dim.wait("DRIVE_CONTROL", "OnTrack", 150000); // 110s for turning and 30s for stabilizing
    868 
    869         service_feedback.waitForVoltageOn();
    870 
    871         // Checking if system is Ready for Data Taking, which is in this case
    872         // the same as Ready for RateScan.
    873         console.out("  Checking states [ratescan]");
    874         var table =
    875             [
    876              [ "TNG_WEATHER"   ],
    877              [ "MAGIC_WEATHER" ],
    878              [ "CHAT"          ],
    879              [ "SMART_FACT"    ],
    880              [ "DATA_LOGGER",     [ "NightlyFileOpen", "WaitForRun", "Logging" ] ],
    881              [ "FSC_CONTROL",     [ "Connected"                ] ],
    882              [ "MCP",             [ "Idle"                     ] ],
    883              [ "TIME_CHECK",      [ "Valid"                    ] ],
    884              [ "PWR_CONTROL",     [ "SystemOn"                 ] ],
    885              [ "AGILENT_CONTROL", [ "VoltageOn"                ] ],
    886              [ "BIAS_CONTROL",    [ "VoltageOn", "Ramping"     ] ],
    887              [ "FEEDBACK",        [ "CurrentControl"           ] ],
    888              [ "RATE_SCAN",       [ "Connected"                ] ],
    889              [ "RATE_CONTROL",    [ "Connected", "GlobalThresholdSet", "InProgress"  ] ],
    890              [ "LID_CONTROL",     [ "Open"                     ] ],
    891              [ "DRIVE_CONTROL",   [ "Tracking", "OnTrack"      ] ],
    892              [ "FTM_CONTROL",     [ "Idle", "TriggerOn"        ] ],
    893              [ "FAD_CONTROL",     [ "Connected", "WritingData" ] ],
    894             ];
    895 
    896         if (!checkStates(table))
    897         {
    898             throw new Error("Something unexpected has happened. One of the servers"+
    899                             "is in a state in which it should not be. Please,"+
    900                             "try to find out what happened...");
    901         }
    902 
    903         // Start rate scan
    904         dim.send("RATE_SCAN/START_THRESHOLD_SCAN", 50, 1000, -10);
    905 
    906         // Lets wait if the ratescan really starts... this might take a few
    907         // seconds because RATE_SCAN configures the ftm and is waiting for
    908         // it to be configured.
    909         dim.wait("RATE_SCAN", "InProgress", 10000);
    910         dim.wait("RATE_SCAN", "Connected", 2700000);
    911 
    912         // this line is actually some kind of hack.
    913         // after the Ratescan, no data is written to disk. I don't know why, but it happens all the time
    914         // So I decided to put this line here as a kind of patchwork....
    915         //dim.send("FAD_CONTROL/SET_FILE_FORMAT", 2);
    916 
    917         console.out("Ratescan done.");
    918         sub++;
    919         continue;
    920     }
    921 
    922     // ========================== case "DATA" ============================
    923 /*
    924     if (Sun.horizon("FACT").isUp)
    925     {
    926         console.out("  SHUTDOWN","");
    927         Shutdown();
    928         console.out("  Exit forced due to broken schedule", "");
    929         exit();
    930     }
    931 */
    932     // Calculate remaining time for this observation in minutes
    933     var remaining = nextObs==undefined ? 0 : (nextObs.start-new Date())/60000;
    934 
    935     // ------------------------------------------------------------
    936 
    937     // Checking for 'Ramping' in the BIAS_CONTROL is not ideal, but at the moment
    938     // it is not possible to distinguish between a real ramping and the short
    939     // ramping which takes place whenever the feedback updated the voltages.
    940 
    941     console.out("  Checking states [mainloop]");
     747    // A scheduled task was found, lets check if all servers are
     748    // still only and in reasonable states. If this is not the case,
     749    // something unexpected must have happend and the script is aborted.
     750    //console.out("  Checking states [general]");
    942751    var table =
    943752        [
     
    947756         [ "SMART_FACT"    ],
    948757         [ "DATA_LOGGER",     [ "NightlyFileOpen", "WaitForRun", "Logging" ] ],
    949          [ "FSC_CONTROL",     [ "Connected"                                ] ],
    950          [ "MCP",             [ "Idle"                                     ] ],
    951          [ "TIME_CHECK",      [ "Valid"                                    ] ],
    952          [ "PWR_CONTROL",     [ "SystemOn"                                 ] ],
    953          [ "AGILENT_CONTROL", [ "VoltageOn"                                ] ],
    954          [ "BIAS_CONTROL",    [ "VoltageOff", "VoltageOn", "Ramping"       ] ],
    955          [ "FEEDBACK",        [ "CurrentCtrlIdle", "CurrentControl"        ] ],
    956          [ "RATE_SCAN",       [ "Connected"                                ] ],
    957          [ "RATE_CONTROL",    [ "Connected", "GlobalThresholdSet", "InProgress" ] ],
    958          [ "LID_CONTROL",     [ "Open", "Closed"                           ] ],
    959          [ "DRIVE_CONTROL",   [ "Armed", "Tracking", "OnTrack"            ] ],
    960          [ "FTM_CONTROL",     [ "Idle", "TriggerOn"                        ] ],
    961          [ "FAD_CONTROL",     [ "Connected", "WritingData"                 ] ],
     758         [ "FSC_CONTROL",     [ "Connected"                ] ],
     759         [ "MCP",             [ "Idle"                     ] ],
     760         [ "TIME_CHECK",      [ "Valid"                    ] ],
     761         [ "PWR_CONTROL",     [ "SystemOn"                 ] ],
     762         [ "AGILENT_CONTROL", [ "VoltageOn"                ] ],
     763         [ "BIAS_CONTROL",    [ "VoltageOff", "VoltageOn", "Ramping" ] ],
     764         [ "FEEDBACK",        [ "CurrentControl", "CurrentCtrlIdle" ] ],
     765         [ "LID_CONTROL",     [ "Open", "Closed"           ] ],
     766         [ "DRIVE_CONTROL",   [ "Armed", "Tracking", "OnTrack" ] ],
     767         [ "FTM_CONTROL",     [ "Idle", "TriggerOn"        ] ],
     768         [ "FAD_CONTROL",     [ "Connected", "WritingData" ] ],
     769         [ "RATE_SCAN",       [ "Connected"                ] ],
     770         [ "RATE_CONTROL",    [ "Connected", "GlobalThresholdSet", "InProgress"  ] ],
    962771        ];
    963772
    964773    if (!checkStates(table))
    965774    {
    966         //dim.alarm("System inconsistent");
    967         //dim.alarm();
    968         throw new Error("Something unexpected has happened. One of the servers "+
    969                         "is in a state in which it should not be. Please, "+
     775        throw new Error("Something unexpected has happened. One of the servers"+
     776                        "is in a state in which it should not be. Please,"+
    970777                        "try to find out what happened...");
    971778    }
     779
     780    console.out("\n"+(new Date()).toUTCString()+": Current measurement: "+obs[sub]);
     781
     782    // Check if obs.task is one of the one-time-tasks
     783    switch (obs[sub].task)
     784    {
     785    case "STARTUP":
     786        console.out("  STARTUP", "");
     787        Startup();  // BiasOn/Off?, Lid open/close?
     788        CloseLid();
     789
     790        doDrsCalibration("startup");  // will switch the voltage off
     791
     792        service_feedback.voltageOn();
     793        service_feedback.waitForVoltageOn();
     794
     795        // Before we can switch to 3000 we have to make the right DRS calibration
     796        console.out("  Take single p.e. run.");
     797        while (!takeRun("pedestal", 5000));
     798
     799        service_feedback.voltageOff();
     800
     801        //dim.send("RATE_CONTROL/STOP"); // get out of GlobalThresholdSet
     802        //dim.wait("RATE_CONTROL", "Connected", 3000);
     803
     804        if (nextObs!=undefined && sub==obs.length-1)
     805            console.out("  Waiting for next observation scheduled for "+nextObs.start.toUTCString(),"");
     806        sub++;
     807        continue;
     808
     809    case "SHUTDOWN":
     810        console.out("  SHUTDOWN", "");
     811        Shutdown();
     812
     813        console.out("  Waiting for next startup.", "");
     814        sub++;
     815        continue;
     816
     817    case "IDLE":
     818        v8.sleep(1000);
     819        continue;
     820
     821    case "DRSCALIB":
     822        console.out("  DRSCALIB", "");
     823
     824        doDrsCalibration("drscalib");  // will switch the voltage off
     825
     826        if (nextObs!=undefined && sub==obs.length-1)
     827            console.out("  Waiting for next observation scheduled for "+nextObs.start.toUTCString(),"");
     828
     829        sub++;
     830        continue;
     831
     832    case "SINGLEPE":
     833        console.out("  SINGLE-PE", "");
     834
     835        // FIXME: Check whether a DRS calib is necessary.
     836
     837        // The lid must be closes
     838        CloseLid();
     839
     840        // The voltage must be on
     841        service_feedback.voltageOn();
     842        service_feedback.waitForVoltageOn();
     843
     844        // Before we can switch to 3000 we have to make the right DRS calibration
     845        console.out("  Take single p.e. run.");
     846        while (!takeRun("pedestal", 5000));
     847
     848        // It is unclear what comes next, so we better switch off the voltage
     849        // service_feedback.voltageOff();
     850
     851        if (nextObs!=undefined && sub==obs.length-1)
     852            console.out("  Waiting for next observation scheduled for "+nextObs.start.toUTCString(),"");
     853
     854        sub++;
     855        continue;
     856
     857    case "RATESCAN":
     858        console.out("  RATESCAN", "");
     859
     860        var tm1 = new Date();
     861
     862        // This is a workaround to make sure that we really catch
     863        // the new state and not the old one
     864        dim.send("DRIVE_CONTROL/STOP");
     865        dim.wait("DRIVE_CONTROL", "Armed", 5000);
     866
     867        // The lid must be open
     868        OpenLid();
     869
     870        // The voltage must be switched on
     871        service_feedback.voltageOn();
     872
     873        if (obs.source != undefined)
     874            dim.send("DRIVE_CONTROL/TRACK_ON", obs[sub].source);
     875        else
     876            dim.send("DRIVE_CONTROL/TRACK", obs[sub].ra, obs[sub].dec);
     877
     878        dim.wait("DRIVE_CONTROL", "OnTrack", 150000); // 110s for turning and 30s for stabilizing
     879
     880        service_feedback.waitForVoltageOn();
     881
     882        var tm2 = new Date();
     883
     884        // Start rate scan
     885        dim.send("RATE_SCAN/START_THRESHOLD_SCAN", 50, 1000, -10);
     886
     887        // Lets wait if the ratescan really starts... this might take a few
     888        // seconds because RATE_SCAN configures the ftm and is waiting for
     889        // it to be configured.
     890        dim.wait("RATE_SCAN", "InProgress", 10000);
     891        dim.wait("RATE_SCAN", "Connected", 2700000);
     892
     893        // this line is actually some kind of hack.
     894        // after the Ratescan, no data is written to disk. I don't know why, but it happens all the time
     895        // So I decided to put this line here as a kind of patchwork....
     896        //dim.send("FAD_CONTROL/SET_FILE_FORMAT", 2);
     897
     898        console.out("  Ratescan done [%.1fs, %.1fs]".$((tm2-tm1)/1000, (new Date()-tm2)/1000));
     899
     900        if (nextObs!=undefined && sub==obs.length-1)
     901            console.out("  Waiting for next observation scheduled for "+nextObs.start.toUTCString(),"");
     902
     903        sub++;
     904        continue;
     905    }
     906
     907    // ========================== case "DATA" ============================
     908/*
     909    if (Sun.horizon("FACT").isUp)
     910    {
     911        console.out("  SHUTDOWN","");
     912        Shutdown();
     913        console.out("  Exit forced due to broken schedule", "");
     914        exit();
     915    }
     916*/
     917    // Calculate remaining time for this observation in minutes
     918    var remaining = nextObs==undefined ? 0 : (nextObs.start-new Date())/60000;
     919
     920    // ------------------------------------------------------------
     921
     922    // Checking for 'Ramping' in the BIAS_CONTROL is not ideal, but at the moment
     923    // it is not possible to distinguish between a real ramping and the short
     924    // ramping which takes place whenever the feedback updated the voltages.
    972925
    973926    // ------------------------------------------------------------
     
    986939        console.out("  Last DRS calib: %.1fmin ago".$(diff));
    987940    else
    988         console.out("  No valid drs calibration");
     941        console.out("  No valid drs calibration available");
    989942
    990943    // Changine pointing position and take calibration...
     
    1023976
    1024977    if (drscal)
    1025     {
    1026         console.out("  Take DRS calibration [interleaved]");
    1027         doDrsCalibration();  // -> VoltageOff
    1028         console.out("  DRS calibration done.");
    1029     }
     978        doDrsCalibration("data");  // will turn voltage off
    1030979
    1031980    OpenLid();
Note: See TracChangeset for help on using the changeset viewer.