Changeset 16786
- Timestamp:
- 06/10/13 11:54:29 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/ratecontrol.cc
r16778 r16786 94 94 } 95 95 96 vector<uint 16_t> fThresholds;96 vector<uint32_t> fThresholds; 97 97 98 98 void PrintThresholds(const FTM::DimStaticData &sdata) 99 99 { 100 //if (!fVerbose)101 //return;100 if (!fVerbose) 101 return; 102 102 103 103 if (fThresholds.empty()) … … 105 105 106 106 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;115 107 116 108 for (int j=0; j<10; j++) … … 119 111 { 120 112 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]; 123 118 else 124 Out() << " - "; 119 Out() << " - "; 120 121 if (fThresholds[p]!=sdata.fThreshold[p]) 122 Out() << "!"; 123 else 124 Out() << " "; 125 } 126 125 127 Out() << " "; 126 128 } … … 131 133 132 134 // RETUNR VALUE 133 int32_tStep(int idx, float step)134 { 135 uint 16_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)); 136 138 if (diff<fThresholdMin) 137 139 diff=fThresholdMin; 140 if (diff>0xffff) 141 diff = 0xffff; 138 142 139 143 if (diff==fThresholds[idx]) 140 return -1;144 return false; 141 145 142 146 if (fVerbose) 143 147 { 144 Out() << idx/40 << "|" << (idx/4)%10 << "|" << idx%4;148 Out() << "Apply: Patch " << setw(3) << idx << " [" << idx/40 << "|" << (idx/4)%10 << "|" << idx%4 << "]"; 145 149 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; 152 154 fBlock[idx/4] = true; 153 155 154 return diff;156 return true; 155 157 } 156 158 … … 176 178 sort(devp.begin(), devp.end()); 177 179 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]; 183 185 184 186 // If any is zero there is something wrong … … 187 189 188 190 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; 192 194 193 195 for (int i=0; i<40; i++) … … 205 207 { 206 208 if (fVerbose) 207 Out() << "B " << i << ": " << dif<< endl;209 Out() << "Board " << setw(3) << i << ": " << dif << " dev away from med" << endl; 208 210 209 211 float max = sdata.fPatchRate[i*4]; … … 229 231 const float step = (log10(sdata.fPatchRate[i*4+j])-log10(mp+3.5*dp))/0.039; 230 232 // * (dif-5)/dif 231 newth[i*4+j]= Step(i*4+j, step);233 changed |= Step(i*4+j, step); 232 234 continue; 233 235 } … … 237 239 { 238 240 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); 240 242 continue; 241 243 } 242 244 243 245 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); 245 247 } 246 248 } 247 249 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); 254 252 } 255 253 … … 532 530 avg2 += vec[i]; 533 531 534 if (vec[i] -avg>3.5*avg_dev)532 if (vec[i]>avg+3.5*avg_dev) 535 533 { 536 fThresholds[i] = max(uint16_t(40.5*pow(vec[i], 0.642)+164), fThreshold Reference);534 fThresholds[i] = max(uint16_t(40.5*pow(vec[i], 0.642)+164), fThresholdMin); 537 535 538 536 counter++; … … 542 540 543 541 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); 547 543 548 544
Note:
See TracChangeset
for help on using the changeset viewer.