Changeset 13621 for trunk/FACT++/src
- Timestamp:
- 05/09/12 16:17:10 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/smartfact.cc
r13609 r13621 83 83 float fFtmControlTriggerRateCam; 84 84 deque<float> fFtmControlTriggerRateHist; 85 86 uint64_t fRateScanDataId; 87 deque<float> fRateScanDataHist; 85 88 86 89 // ------------- Initialize variables before the Dim stuff ------------ … … 182 185 DimStampedInfo fDimFtmControlTriggerRates; 183 186 187 DimStampedInfo fDimRateScanData; 188 184 189 DimStampedInfo *fDimFadControlEventData; 185 190 … … 224 229 for (uint64_t i=0; i<t.size(); i++) 225 230 { 226 float range = nearbyint(128*(t[i] +offset)/scale); // [-2V; 2V]231 float range = nearbyint(128*(t[i]-offset)/scale); // [-2V; 2V] 227 232 if (range>127) 228 233 range=127; … … 240 245 // ------------------------------------------------------------------- 241 246 247 struct Statistics 248 { 249 float min; 250 float max; 251 float med; 252 float avg; 253 //float rms; 254 255 template<class T> 256 Statistics(const T &t) 257 { 258 min = *min_element(t.begin(), t.end()); 259 max = *max_element(t.begin(), t.end()); 260 avg = accumulate (t.begin(), t.end(), 0.)/t.size(); 261 262 const size_t p = t.size()/2; 263 264 T copy(t); 265 nth_element(copy.begin(), copy.begin()+p, copy.end()); 266 med = copy[p]; 267 } 268 }; 269 242 270 void HandleMcpConfiguration(const DimData &d) 243 271 { … … 256 284 void WriteWeather(const DimData &d, const string &name, int i, float min, float max) 257 285 { 258 const auto fmin = min_element(fMagicWeatherHist[i].begin(), fMagicWeatherHist[i].end()); 259 const auto fmax = max_element(fMagicWeatherHist[i].begin(), fMagicWeatherHist[i].end()); 260 const float favg = accumulate (fMagicWeatherHist[i].begin(), fMagicWeatherHist[i].end(), 0.)/fMagicWeatherHist[i].size(); 286 const Statistics stat(fMagicWeatherHist[i]); 261 287 262 288 ostringstream out; … … 265 291 266 292 out << "#ffffff\t" << fMagicWeatherHist[i].back() << '\n'; 267 out << "#ffffff\t" << *fmin << '\n';268 out << "#ffffff\t" << favg << '\n';269 out << "#ffffff\t" << *fmax << '\n';293 out << "#ffffff\t" << stat.min << '\n'; 294 out << "#ffffff\t" << stat.avg << '\n'; 295 out << "#ffffff\t" << stat.max << '\n'; 270 296 271 297 ofstream("www/"+name+".txt") << out.str(); 272 298 273 WriteBinary("magicweather-"+name+"-hist", fMagicWeatherHist[i], max-min, -min);299 WriteBinary("magicweather-"+name+"-hist", fMagicWeatherHist[i], max-min, min); 274 300 } 275 301 … … 287 313 } 288 314 315 static const char *dir[] = 316 { 317 "N", "NNE", "NE", "ENE", 318 "E", "ESE", "SE", "SSE", 319 "S", "SSW", "SW", "WSW", 320 "W", "WNW", "NW", "NNW" 321 }; 322 323 const uint16_t idx = uint16_t(floor(fmod(fMagicWeatherHist[kDir].back()+360+11.25, 360)/22.5)); 324 289 325 ostringstream out; 290 326 out << uint64_t(d.time.UnixTime()*1000) << '\n'; 291 292 for (int i=0; i<7; i++) 327 for (int i=0; i<6; i++) 293 328 out << "#ffffff\t" << fMagicWeatherHist[i].back() << '\n'; 329 out << "#ffffff\t" << dir[idx] << '\n'; 330 294 331 295 332 ofstream("www/magicweather.txt") << out.str(); … … 320 357 }; 321 358 322 const uint16_t i = uint16_t(floor(fmod(az+360+11.25, 360)/22 ));359 const uint16_t i = uint16_t(floor(fmod(az+360+11.25, 360)/22.5)); 323 360 fDriveControlPointingAz = dir[i]; 324 361 … … 404 441 fBiasControlVoltageVec.assign(d.ptr<float>(), d.ptr<float>()+320); 405 442 406 vector<float> v(fBiasControlVoltageVec); 407 sort(v.begin(), v.end()); 408 409 fBiasControlVoltageMed = (v[159]+v[160])/2; 410 411 //const char *ptr = d.ptr<char>(); 412 //ofstream fout("www/biascontrol-voltage.bin"); 413 //fout.write(ptr, 320*sizeof(float)); 443 const Statistics stat(fBiasControlVoltageVec); 444 445 fBiasControlVoltageMed = stat.med; 414 446 415 447 vector<float> val(320, 0); … … 417 449 { 418 450 const int idx = (fPixelMap.hv(i).hw()/9)*2+fPixelMap.hv(i).group(); 419 val[i ] = v[i];451 val[idx] = fBiasControlVoltageVec[i]; 420 452 } 421 453 422 454 WriteBinary("biascontrol-voltage", val, 75); 455 456 ostringstream out; 457 out << setprecision(3); 458 out << uint64_t(d.time.UnixTime()*1000) << '\n'; 459 out << kHtmlWhite << '\t' << stat.min << '\n'; 460 out << kHtmlWhite << '\t' << stat.med << '\n'; 461 out << kHtmlWhite << '\t' << stat.avg << '\n'; 462 out << kHtmlWhite << '\t' << stat.max << '\n'; 463 ofstream("www/voltage.txt") << out.str(); 464 423 465 } 424 466 … … 443 485 { 444 486 const int idx = (fPixelMap.hv(i).hw()/9)*2+fPixelMap.hv(i).group(); 445 val[idx] = v[i]; //max(v[i*2], v[i*2+1]);487 val[idx] = v[i]; 446 488 } 447 489 … … 449 491 WriteBinary("biascontrol-current", val, 1000); 450 492 451 // Now sort them to determine the median 452 sort(v.begin(), v.end()); 493 const Statistics stat(v); 453 494 454 495 // Exclude the three crazy channels 455 fBiasControlCurrentMed = (v[159]+v[160])/2;456 fBiasControlCurrentMax = v[316];496 fBiasControlCurrentMed = stat.med; 497 fBiasControlCurrentMax = stat.max; 457 498 458 499 // Store a history of the last 60 entries … … 463 504 // write the history to a file 464 505 WriteBinary("biascontrol-current-hist", fBiasControlCurrentHist, 1000); 506 507 ostringstream out; 508 out << setprecision(3); 509 out << uint64_t(d.time.UnixTime()*1000) << '\n'; 510 out << kHtmlWhite << '\t' << stat.min << '\n'; 511 out << kHtmlWhite << '\t' << stat.med << '\n'; 512 out << kHtmlWhite << '\t' << stat.avg << '\n'; 513 out << kHtmlWhite << '\t' << stat.max << '\n'; 514 ofstream("www/current.txt") << out.str(); 465 515 } 466 516 … … 494 544 out << "#ffffff\t" << fFtmControlTriggerRateCam << '\n'; 495 545 496 ofstream fout("www/trigger.txt"); 497 fout << out.str(); 546 ofstream("www/trigger.txt") << out.str(); 547 548 const Statistics bstat(vector<float>(brates, brates+40)); 549 const Statistics pstat(vector<float>(prates, prates+160)); 550 551 out.str(""); 552 out << uint64_t(d.time.UnixTime()*1000) << '\n'; 553 out << kHtmlWhite << '\t' << bstat.min << '\n'; 554 out << kHtmlWhite << '\t' << bstat.med << '\n'; 555 out << kHtmlWhite << '\t' << bstat.avg << '\n'; 556 out << kHtmlWhite << '\t' << bstat.max << '\n'; 557 ofstream("www/boardrates.txt") << out.str(); 558 559 out.str(""); 560 out << uint64_t(d.time.UnixTime()*1000) << '\n'; 561 out << kHtmlWhite << '\t' << pstat.min << '\n'; 562 out << kHtmlWhite << '\t' << pstat.med << '\n'; 563 out << kHtmlWhite << '\t' << pstat.avg << '\n'; 564 out << kHtmlWhite << '\t' << pstat.max << '\n'; 565 ofstream("www/patchrates.txt") << out.str(); 566 567 498 568 } 499 569 … … 521 591 switch (d.qos) 522 592 { 523 case 0: WriteBinary("fadcontrol-eventdata", max, 2000, 1000); break;524 case 1: WriteBinary("fadcontrol-eventdata", max, 2000, 0); break;525 default: WriteBinary("fadcontrol-eventdata", max, 250, 0); break;593 case 0: WriteBinary("fadcontrol-eventdata", max, 2000, -1000); break; 594 case 1: WriteBinary("fadcontrol-eventdata", max, 2000, 0); break; 595 default: WriteBinary("fadcontrol-eventdata", max, 250, 0); break; 526 596 } 527 597 } … … 566 636 fFscControlTemperatureHist.pop_front(); 567 637 568 const auto beg = fFscControlTemperatureHist.begin(); 569 const auto end = fFscControlTemperatureHist.end(); 570 571 const auto fmin = min_element(beg, end); 572 const auto fmax = max_element(beg, end); 573 const float favg = accumulate (beg, end, 0)/fFscControlTemperatureHist.size(); 638 const Statistics stat(fFscControlTemperatureHist); 574 639 575 640 ostringstream out; 576 641 out << setprecision(3); 577 642 out << uint64_t(d.time.UnixTime()*1000) << '\n'; 578 out << "#ffffff\t" << min << '\n';579 out << "#ffffff\t" << avg << '\n';580 out << "#ffffff\t" << max << '\n';581 out << "#ffffff\t" << *fmin << '\n';582 out << "#ffffff\t" << favg<< '\n';583 out << "#ffffff\t" << *fmax << '\n';643 out << "#ffffff\t" << min << '\n'; 644 out << "#ffffff\t" << avg << '\n'; 645 out << "#ffffff\t" << max << '\n'; 646 out << "#ffffff\t" << stat.min << '\n'; 647 out << "#ffffff\t" << stat.avg << '\n'; 648 out << "#ffffff\t" << stat.max << '\n'; 584 649 585 650 ofstream("www/fsc.txt") << out.str(); … … 587 652 WriteBinary("fsccontrol-temperature-hist", 588 653 fFscControlTemperatureHist, 30); 589 590 654 } 591 655 … … 610 674 } 611 675 676 void HandleRateScanData(const DimData &d) 677 { 678 if (!CheckDataSize(d, "RateScan:Data", 24+200*40)) 679 return; 680 681 const uint64_t id = d.get<uint64_t>(); 682 const float rate = log10(d.get<float>(20)); 683 684 if (fRateScanDataId!=id) 685 { 686 fRateScanDataHist.clear(); 687 fRateScanDataId = id; 688 } 689 fRateScanDataHist.push_back(rate); 690 691 WriteBinary("ratescan-hist", fRateScanDataHist, 10, -1); 692 } 612 693 613 694 // ------------------------------------------------------------------- … … 619 700 return; 620 701 621 if (HandleService(curr, fDimMcpConfiguration, &StateMachineSmartFACT:: HandleMcpConfiguration))702 if (HandleService(curr, fDimMcpConfiguration, &StateMachineSmartFACT::configuHandleMcpConfiguration)) 622 703 return; 623 704 if (HandleService(curr, fDimMagicWeatherData, &StateMachineSmartFACT::HandleMagicWeatherData)) … … 642 723 return; 643 724 if (HandleService(curr, fDimFscControlHumidity, &StateMachineSmartFACT::HandleFscControlHumidity)) 725 return; 726 if (HandleService(curr, fDimRateScanData, &StateMachineSmartFACT::HandleRateScanData)) 644 727 return; 645 728 } … … 768 851 if (fMcpConfigurationMaxEvents>0 || fMcpConfigurationState==12) 769 852 out << ']'; 770 771 772 853 } 773 854 else … … 919 1000 public: 920 1001 StateMachineSmartFACT(ostream &out=cout) : StateMachineDim(out, "SMART_FACT"), 1002 fMcpConfigurationMaxTime(0), 1003 fMcpConfigurationMaxEvents(0), 1004 fRateScanDataId(0), 921 1005 //--- 922 1006 fDimMcp ("MCP"), … … 951 1035 fDimFtmControlTriggerRates("FTM_CONTROL/TRIGGER_RATES", (void*)NULL, 0, this), 952 1036 //- 953 f McpConfigurationMaxEvents(0),954 fMcpConfigurationMaxTime(0),1037 fDimRateScanData ("RATE_SCAN/DATA", (void*)NULL, 0, this), 1038 //- 955 1039 fDimFadControlEventData(0) 956 1040 {
Note:
See TracChangeset
for help on using the changeset viewer.