Changeset 16786


Ignore:
Timestamp:
06/10/13 11:54:29 (11 years ago)
Author:
tbretz
Message:
Make sure no threshold is set initially below the limit (the limit is set to ThresholdMin, so Thresholdreference is not really the correct reference here); directly use fThreshold for the dim commands, therefore replaced uint16 by int32; only send threshold if they have changed; improved output
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/ratecontrol.cc

    r16778 r16786  
    9494    }
    9595
    96     vector<uint16_t> fThresholds;
     96    vector<uint32_t> fThresholds;
    9797
    9898    void PrintThresholds(const FTM::DimStaticData &sdata)
    9999    {
    100         //if (!fVerbose)
    101         //    return;
     100        if (!fVerbose)
     101            return;
    102102
    103103        if (fThresholds.empty())
     
    105105
    106106        Out() << "Min. DAC=" << fThresholdMin << endl;
    107 
    108         int t=0;
    109         for (t=0; t<160; t++)
    110             if (sdata.fThreshold[t]!=fThresholds[t])
    111                 break;
    112 
    113         if (t==160)
    114             return;
    115107
    116108        for (int j=0; j<10; j++)
     
    119111            {
    120112                for (int i=0; i<4; i++)
    121                     if (fThresholds[i+k*4+j*16]!=fThresholdMin)
    122                         Out() << setw(3) << fThresholds[i+k*4+j*16] << " ";
     113                {
     114                    const int p = i + k*4 + j*16;
     115
     116                    if (fThresholds[p]!=fThresholdMin)
     117                        Out() << setw(3) << fThresholds[p];
    123118                    else
    124                         Out() << " -  ";
     119                        Out() << " - ";
     120
     121                    if (fThresholds[p]!=sdata.fThreshold[p])
     122                        Out() << "!";
     123                    else
     124                        Out() << " ";
     125                }
     126
    125127                Out() << "   ";
    126128            }
     
    131133
    132134    // RETUNR VALUE
    133     int32_t Step(int idx, float step)
    134     {
    135         uint16_t diff = fThresholds[idx]+int16_t(truncf(step));
     135    bool Step(int idx, float step)
     136    {
     137        uint32_t diff = fThresholds[idx]+int16_t(truncf(step));
    136138        if (diff<fThresholdMin)
    137139            diff=fThresholdMin;
     140        if (diff>0xffff)
     141            diff = 0xffff;
    138142
    139143        if (diff==fThresholds[idx])
    140             return -1;
     144            return false;
    141145
    142146        if (fVerbose)
    143147        {
    144             Out() << idx/40 << "|" << (idx/4)%10 << "|" << idx%4;
     148            Out() << "Apply: Patch " << setw(3) << idx << " [" << idx/40 << "|" << (idx/4)%10 << "|" << idx%4 << "]";
    145149            Out() << (step>0 ? " += " : " -= ");
    146             Out() << fabs(step) << " (" << diff << ")" << endl;
    147         }
    148 
    149         //const uint32_t val[2] = { idx,  diff };
    150         //Dim::SendCommandNB("FTM_CONTROL/SET_THRESHOLD", val);
    151 
     150            Out() << fabs(step) << " (old=" << fThresholds[idx] << ", new=" << diff << ")" << endl;
     151        }
     152
     153        fThresholds[idx] = diff;
    152154        fBlock[idx/4] = true;
    153155
    154         return diff;
     156        return true;
    155157    }
    156158
     
    176178        sort(devp.begin(), devp.end());
    177179
    178         double mb = (medb[19]+medb[20])/2;
    179         double mp = (medp[79]+medp[80])/2;
    180 
    181         double db = devb[27];
    182         double dp = devp[109];
     180        const double mb = (medb[19]+medb[20])/2;
     181        const double mp = (medp[79]+medp[80])/2;
     182
     183        const double db = devb[27];
     184        const double dp = devp[109];
    183185
    184186        // If any is zero there is something wrong
     
    187189
    188190        if (fVerbose)
    189             Out() << Tools::Form("Board: Med=%3.1f +- %3.1f   Patch: Med=%3.1f +- %3.1f", mb, db, mp, dp) << endl;
    190 
    191         vector<int32_t> newth(160, -1);
     191            Out() << Tools::Form("Boards: Med=%3.1f +- %3.1f Hz   Patches: Med=%3.1f +- %3.1f Hz", mb, db, mp, dp) << endl;
     192
     193        bool changed = false;
    192194
    193195        for (int i=0; i<40; i++)
     
    205207            {
    206208                if (fVerbose)
    207                     Out() << "B" << i << ": " << dif << endl;
     209                    Out() << "Board " << setw(3) << i << ": " << dif << " dev away from med" << endl;
    208210
    209211                float max = sdata.fPatchRate[i*4];
     
    229231                    const float step = (log10(sdata.fPatchRate[i*4+j])-log10(mp+3.5*dp))/0.039;
    230232                    //  * (dif-5)/dif
    231                     newth[i*4+j] = Step(i*4+j, step);
     233                    changed |= Step(i*4+j, step);
    232234                    continue;
    233235                }
     
    237239                {
    238240                    const float step = (log10(sdata.fPatchRate[i*4+j])-log10(mp+3.5*dp))/0.039;
    239                     newth[i*4+j] = Step(i*4+j, step);
     241                    changed |= Step(i*4+j, step);
    240242                    continue;
    241243                }
    242244
    243245                const float step =  -1.5*(log10(mp+dp)-log10(mp))/0.039;
    244                 newth[i*4+j] = Step(i*4+j, step);
     246                changed |= Step(i*4+j, step);
    245247            }
    246248        }
    247249
    248         // WARNING: By _not_ updating fThresholds here, we assume
    249         // the the returned static data block is received before the
    250         // next update. If not, we will just skip these patches (block
    251         // condition) and send the same update next time again.
    252         if (std::count(newth.begin(), newth.end(), -1)!=160)
    253             Dim::SendCommandNB("FTM_CONTROL/SET_SELECTED_THRESHOLDS", newth);
     250        if (changed)
     251            Dim::SendCommandNB("FTM_CONTROL/SET_SELECTED_THRESHOLDS", fThresholds);
    254252    }
    255253
     
    532530            avg2 += vec[i];
    533531
    534             if (vec[i]-avg>3.5*avg_dev)
     532            if (vec[i]>avg+3.5*avg_dev)
    535533            {
    536                 fThresholds[i] = max(uint16_t(40.5*pow(vec[i], 0.642)+164), fThresholdReference);
     534                fThresholds[i] = max(uint16_t(40.5*pow(vec[i], 0.642)+164), fThresholdMin);
    537535
    538536                counter++;
     
    542540
    543541
    544         vector<int32_t> val(160, fThresholdMin);
    545         std::copy(fThresholds.begin(), fThresholds.end(), val.begin());
    546         Dim::SendCommandNB("FTM_CONTROL/SET_ALL_THRESHOLDS", val);
     542        Dim::SendCommandNB("FTM_CONTROL/SET_ALL_THRESHOLDS", fThresholds);
    547543
    548544
Note: See TracChangeset for help on using the changeset viewer.