Ignore:
Timestamp:
03/13/13 11:09:52 (12 years ago)
Author:
tbretz
Message:
Some code cleanup; added throwing an execption if an underflow condition has been detected.
File:
1 edited

Legend:

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

    r15038 r15048  
    6060if (!runs)
    6161    throw new Error("Could not connect to FAD_CONTROL/DRS_RUNS");
    62 /*
    63 runs = {
    64     "name"    : "FAD_CONTROL/DRS_RUNS",
    65     "format"  : "I:1;I:3",
    66     "qos"     : 0,
    67     "size"    : 16,
    68     "counter" : 0,
    69     "time"    : new Date("2012-11-20T05:23:52.804Z"),
    70     "data"    : [300,[148,149,154]]
    71   };
    72 */
    7362
    7463// Wait for agilent to be online with state information
     
    8574console.out(" * Last power cycle:   "+power);
    8675console.out(" * Last DRS calib set: "+(runs.data?runs.time:"none"));
    87 //console.out(JSON.stringify(dim.state("AGILENT_CONTROL")));
    8876
    8977
    9078if (1)//diff>8 && now.getHours()>16 || runs.time<power)
    9179{
     80    console.out("Checking send.");
     81    checkSend(["FAD_CONTROL", "MCP", "RATE_CONTROL"]);
     82    console.out("Checking send: done");
     83
    9284    //console.out("Most probablay the camera has not been checked for underflows yet.");
    93 
    94     // Wait for dim.send to be ready
    95     // FIXME: timeout
    96     while (!dim.send("FAD_CONTROL"))
    97         v8.sleep();
    98 
    99     // FAD_CONTROL/RAW_DATA:
    100     //  roi,roi_tm,num_fad,num_ftm,type,num_boards,error,
    101     //  dummy,time,time_board,start_pix,start_tm,adc
    102 
    103     // FAD_CONTROL/EVENT_DATA
    104     // avg,rms,max,pos
    10585
    10686    var service_event = new Subscription("FAD_CONTROL/EVENT_DATA");
    10787    var event = service_event.get(5000, false);
    108     //if (!event)
    109     //    throw new Error("Could not connect to FAD_CONTROL/EVENT_DATA");
    11088
    11189    var event_counter = event.counter;
     
    125103    console.out("Event received: "+(new Date()-d)+"ms");
    126104
    127     console.out("Stop run");
    128105    dim.send("MCP/STOP");
    129     while (!dim.send("RATE_CONTROL"))
    130     {
    131         v8.sleep(800);
    132         console.out("waiting for RATE_CONTROL to send the necessary format information");
    133     }
     106
     107    event = service_event.get(0, false);
     108    service_event.close();
     109
     110    console.out("Run stopped.");
     111
    134112    dim.send("RATE_CONTROL/STOP"); // GlobalThresholdSet -> Connected
    135113    dim.wait("MCP", "Idle", 3000);
    136114
    137     var nn = runs.data && runs.data[0]>0 ? runs.data[1].reduce(Func.max) : -1;
     115    var nn = run.data && runs.data.length>0 && runs.obj['roi']>0 ? runs.obj['run'][1].reduce(Func.max) : -1;
    138116    if (nn>0)
    139117    {
     
    154132    }
    155133
    156     //console.out(JSON.stringify(service_drs.get(0, false)));
    157 
    158     event = service_event.get(0, false);
    159 
    160     service_event.close();
    161 
    162134    var hist = Hist2D(16, -2048.5, 2048.5, 11, -10, 100);
    163135
     136    var data = event.obj;
     137
    164138    for (var i=0; i<1440; i++)
    165         hist.fill(event.data[0][i], isNaN(event.data[1][i])?-1:event.data[1][i]);
     139        hist.fill(data.avg[i], isNaN(data.rms[i])?-1:data.rms[i]);
    166140
    167     //console.out(("%78s".$("")).replace(/ /g, "-"));
    168141    hist.print();
    169     //console.out(("%78s".$("")).replace(/ /g, "-"));
    170142
    171     // Could also be <512
    172     var stat0 = Func.stat(event.data[0], function(val) { if (val<0) console.out(" VAL="+val); return val<0; });
    173     var stat1 = Func.stat(event.data[1]);
     143    var stat0 = Func.stat(data.avg, function(val) { if (val<0) console.out(" VAL="+val); return val<0; });
     144    var stat1 = Func.stat(data.rms);
    174145
    175146    console.out("Avg[min]=%.1f".$(stat0.min));
     
    182153    console.out("Rms[max]=%.1f".$(stat1.max));
    183154    console.out(("%78s\n".$("")).replace(/ /g, "="));
     155
     156    //      OK                            UNDERFLOW
     157    // ------------------------------------------------------
     158    // Avg[min]=722.0                Avg[min]=-380.0
     159    // Avg[avg]=815.9 +- 45.9        Avg[avg]= 808.0 +- 102.0
     160    // Avg[max]=930.5                Avg[max]= 931.1
     161    // Avg[cnt]=0                    Avg[cnt]= 9
     162
     163    // Rms[min]=14.0                 Rms[min]=13.9
     164    // Rms[avg]=16.5 +- 1.6          Rms[avg]=18.8 +- 26.8
     165    // Rms[max]=44.0                 Rms[max]=382.1
     166
     167    if (stat0.count==0)
     168        return;
     169
     170    if (stat0.count>8)
     171        throw new Error("Underflow condition detected in about "+stat0.count/9+" DRS.");
     172
     173    log.warn("There is probably an underflow condition in one DRS... please check manually.");
    184174}
    185175
Note: See TracChangeset for help on using the changeset viewer.