Changeset 13699
- Timestamp:
- 05/13/12 14:29:38 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/smartfact.cc
r13693 r13699 48 48 Time fLastUpdate; 49 49 50 string fPath; 51 50 52 // ----------------------------- Data storage ------------------------- 51 53 … … 84 86 deque<float> fFtmControlTriggerRateHist; 85 87 88 vector<float> fFtmPatchThresholds; 89 86 90 uint64_t fRateScanDataId; 87 91 deque<float> fRateScanDataHist; … … 100 104 string server; 101 105 pair<Time, int> info; 106 string msg; 102 107 103 108 DimStampedInfo dim; … … 117 122 info = make_pair(Time(tsec, tms*1000), 118 123 disconnected ? -2 : dim.getQuality()); 124 125 msg = disconnected ? "" : dim.getString(); 119 126 } 120 127 … … 146 153 return "Offline"; 147 154 148 ostringstream msg;149 msg<< "V" << info.second/100 << 'r' << info.second%100;150 return msg.str();155 ostringstream out; 156 out << "V" << info.second/100 << 'r' << info.second%100; 157 return out.str(); 151 158 } 152 159 }; … … 186 193 187 194 DimStampedInfo fDimFtmControlTriggerRates; 195 DimStampedInfo fDimFtmControlStaticData; 188 196 189 197 DimStampedInfo fDimRateScanData; … … 241 249 const char *ptr = reinterpret_cast<char*>(val.data()); 242 250 243 ofstream fout( "www/"+fname+".bin");251 ofstream fout(fPath+"/"+fname+".bin"); 244 252 fout << offset << '\n'; 245 253 fout << offset+scale << '\n'; … … 309 317 out << "#ffffff\t" << stat.max << '\n'; 310 318 311 ofstream( "www/"+name+".txt") << out.str();319 ofstream(fPath+"/"+name+".txt") << out.str(); 312 320 313 321 WriteBinary("magicweather-"+name+"-hist", fMagicWeatherHist[i], max-min, min); … … 344 352 345 353 346 ofstream( "www/magicweather.txt") << out.str();354 ofstream(fPath+"/magicweather.txt") << out.str(); 347 355 348 356 WriteWeather(d, "temp", kTemp, -5, 35); … … 381 389 out << az << '\n'; 382 390 383 ofstream( "www/drive-pointing.txt") << out.str();391 ofstream(fPath+"/drive-pointing.txt") << out.str(); 384 392 } 385 393 … … 389 397 return; 390 398 391 const double zd = d.get<double>( 4*8) * M_PI / 180;392 const double dzd = d.get<double>( 6*8) * M_PI / 180;393 const double daz = d.get<double>( 7*8) * M_PI / 180;399 const double zd = d.get<double>(3*8) * M_PI / 180; 400 const double dzd = d.get<double>(5*8) * M_PI / 180; 401 const double daz = d.get<double>(6*8) * M_PI / 180; 394 402 395 403 // Correct: … … 399 407 const double dev = cos(dzd) - sin(zd+dzd)*sin(zd)*(1.-cos(daz)); 400 408 fDriveControlTrackingDev = acos(dev) * 180 / M_PI * 3600; 409 401 410 if (fDriveControlTrackingDev<0.01) 402 411 fDriveControlTrackingDev=0; … … 428 437 out << "#ffffff\t" << wang << '\n'; 429 438 430 ofstream( "www/drive.txt") << out.str();439 ofstream(fPath+"/drive.txt") << out.str(); 431 440 } 432 441 … … 448 457 return; 449 458 459 const float *ptr = d.ptr<float>(); 450 460 vector<float> dev(ptr+416, ptr+416+320); 451 461 … … 471 481 out << kHtmlWhite << '\t' << stat.max << '\n'; 472 482 ofstream("www/feedback.txt") << out.str(); 473 474 483 } 475 484 … … 495 504 } 496 505 497 WriteBinary("biascontrol-voltage", val, 75); 506 if (fDimBiasControl.state()==BIAS::kVoltageOn) 507 WriteBinary("biascontrol-voltage", val, 10, 65); 508 else 509 WriteBinary("biascontrol-voltage", val, 75); 498 510 499 511 ostringstream out; … … 504 516 out << kHtmlWhite << '\t' << stat.avg << '\n'; 505 517 out << kHtmlWhite << '\t' << stat.max << '\n'; 506 ofstream( "www/voltage.txt") << out.str();518 ofstream(fPath+"/voltage.txt") << out.str(); 507 519 508 520 } … … 518 530 v[i] = d.ptr<uint16_t>()[i] * 5000./4096; 519 531 532 const bool cal = fFeedbackCalibration.size()>0 && fBiasControlVoltageVec.size()>0; 533 520 534 // Calibrate the data (subtract offset) 521 if ( fFeedbackCalibration.size()>0 && fBiasControlVoltageVec.size()>0)535 if (cal) 522 536 for (int i=0; i<320; i++) 537 { 523 538 v[i] -= fBiasControlVoltageVec[i]/fFeedbackCalibration[i]*1e6; 539 v[i] /= fPixelMap.hv(i).group() ? 5 : 4; 540 } 524 541 525 542 // Get the maximum of each patch … … 532 549 533 550 // Write the 160 patch values to a file 534 WriteBinary("biascontrol-current", val, 500);551 WriteBinary("biascontrol-current", val, 100); 535 552 536 553 const Statistics stat(v, 0, 3); … … 542 559 // Store a history of the last 60 entries 543 560 fBiasControlCurrentHist.push_back(fBiasControlCurrentMed); 544 if (fBiasControlCurrentHist.size()> 60)561 if (fBiasControlCurrentHist.size()>360) 545 562 fBiasControlCurrentHist.pop_front(); 546 563 547 564 // write the history to a file 548 WriteBinary("biascontrol-current-hist", fBiasControlCurrentHist, 500); 565 WriteBinary("biascontrol-current-hist", fBiasControlCurrentHist, 100); 566 567 const string col0 = cal ? kHtmlGreen : kHtmlWhite; 568 569 string col1 = col0; 570 string col2 = col0; 571 string col3 = col0; 572 string col4 = col0; 573 574 if (cal && stat.min>65) 575 col1 = kYellow; 576 if (cal && stat.min>80) 577 col1 = kRed; 578 579 if (cal && stat.med>65) 580 col2 = kYellow; 581 if (cal && stat.med>80) 582 col2 = kRed; 583 584 if (cal && stat.avg>65) 585 col3 = kYellow; 586 if (cal && stat.avg>80) 587 col3 = kRed; 588 589 if (cal && stat.max>65) 590 col4 = kYellow; 591 if (cal && stat.max>80) 592 col4 = kRed; 549 593 550 594 ostringstream out; 551 595 out << setprecision(3); 552 596 out << d.time.JavaDate() << '\n'; 553 out << kHtmlWhite << '\t' << stat.min << '\n'; 554 out << kHtmlWhite << '\t' << stat.med << '\n'; 555 out << kHtmlWhite << '\t' << stat.avg << '\n'; 556 out << kHtmlWhite << '\t' << stat.max << '\n'; 557 ofstream("www/current.txt") << out.str(); 597 out << col0 << '\t' << (cal?"yes":"no") << '\n'; 598 out << col1 << '\t' << stat.min << '\n'; 599 out << col2 << '\t' << stat.med << '\n'; 600 out << col3 << '\t' << stat.avg << '\n'; 601 out << col4 << '\t' << stat.max << '\n'; 602 ofstream(fPath+"/current.txt") << out.str(); 558 603 } 559 604 … … 591 636 out << "#ffffff\t" << fFtmControlTriggerRateCam << '\n'; 592 637 593 ofstream( "www/trigger.txt") << out.str();638 ofstream(fPath+"/trigger.txt") << out.str(); 594 639 595 640 const Statistics bstat(vector<float>(brates, brates+40)); … … 602 647 out << kHtmlWhite << '\t' << bstat.avg << '\n'; 603 648 out << kHtmlWhite << '\t' << bstat.max << '\n'; 604 ofstream( "www/boardrates.txt") << out.str();649 ofstream(fPath+"/boardrates.txt") << out.str(); 605 650 606 651 out.str(""); … … 610 655 out << kHtmlWhite << '\t' << pstat.avg << '\n'; 611 656 out << kHtmlWhite << '\t' << pstat.max << '\n'; 612 ofstream("www/patchrates.txt") << out.str(); 657 ofstream(fPath+"/patchrates.txt") << out.str(); 658 } 659 660 void HandleFtmControlStaticData(const DimData &d) 661 { 662 if (!CheckDataSize(d, "FtmControl:StaticData", 740)) 663 return; 664 665 const uint16_t *ptr = d.ptr<uint16_t>(260); 666 vector<uint16_t> vec(ptr, ptr+160); 667 668 WriteBinary("ftmcontrol-thresholds", vec, 1000); 669 670 const Statistics stat(vec); 671 672 ostringstream out; 673 out << d.time.JavaDate() << '\n'; 674 out << kHtmlWhite << '\t' << stat.min << '\n'; 675 out << kHtmlWhite << '\t' << stat.med << '\n'; 676 out << kHtmlWhite << '\t' << stat.avg << '\n'; 677 out << kHtmlWhite << '\t' << stat.max << '\n'; 678 ofstream(fPath+"/thresholds.txt") << out.str(); 613 679 } 614 680 … … 694 760 out << "#ffffff\t" << stat.max << '\n'; 695 761 696 ofstream( "www/fsc.txt") << out.str();762 ofstream(fPath+"/fsc.txt") << out.str(); 697 763 698 764 WriteBinary("fsccontrol-temperature-hist", … … 765 831 return; 766 832 if (HandleService(curr, fDimFtmControlTriggerRates, &StateMachineSmartFACT::HandleFtmControlTriggerRates)) 833 return; 834 if (HandleService(curr, fDimFtmControlStaticData, &StateMachineSmartFACT::HandleFtmControlStaticData)) 767 835 return; 768 836 if (HandleService(curr, *fDimFadControlEventData, &StateMachineSmartFACT::HandleFadControlEventData)) … … 828 896 const State rc = GetState(state); 829 897 898 if (rc.index==-2 && state.state()>-2) 899 { 900 ostringstream out; 901 out << kWhite << '\t' << state.state() << '\n'; 902 return out.str(); 903 } 904 830 905 //ostringstream msg; 831 906 //msg << kHtmlWhite << '\t' << rc.name << " [" << rc.index << "]\n"; … … 884 959 { 885 960 if (fMcpConfigurationState==12) 886 out << fMcpConfigurationMaxTime-(Time()-fMcpConfigurationRunStart).total_seconds() << 's'; 961 { 962 963 const uint32_t dt = (Time()-fMcpConfigurationRunStart).total_seconds(); 964 if (dt>fMcpConfigurationMaxTime) 965 out << "---"; 966 else 967 out << fMcpConfigurationMaxTime-dt << 's'; 968 } 887 969 else 888 970 out << "[" << fMcpConfigurationMaxTime << "s]"; … … 987 1069 { 988 1070 string col = fBiasControlVoltageMed>3?kHtmlGreen:kHtmlWhite; 989 if (fBiasControlCurrentMax> 280)1071 if (fBiasControlCurrentMax>65) 990 1072 col = kHtmlYellow; 991 if (fBiasControlCurrentMax> 350)1073 if (fBiasControlCurrentMax>80) 992 1074 col = kHtmlRed; 993 1075 994 if (fFeedbackCalibration.size()==0) 995 col = kHtmlBlue; 1076 // Bias in overcurrent => Red 996 1077 if (fDimBiasControl.state()==BIAS::kOverCurrent) 997 1078 col = kHtmlRed; 998 1079 1080 // MCP in ReadyForDatataking/Configuring/Configured/TriggerOn/TakingData 1081 // and Bias not in "data-taking state' => Red 1082 if (fDimMcp.state()>5 && 1083 (fDimBiasControl.state()==BIAS::kVoltageOn || 1084 fDimBiasControl.state()==BIAS::kVoltageOff)) 1085 col = kHtmlRed; 1086 1087 const bool cal = fFeedbackCalibration.size(); 1088 1089 // Feedback is currently calibrating => Blue 999 1090 if (fDimFeedback.state()==13) 1000 1091 { … … 1007 1098 out << col << '\t'; 1008 1099 out << fBiasControlCurrentMed << '\t'; 1009 out << fBiasControlCurrentMax << '\t'; 1100 if (cal) 1101 out << fBiasControlCurrentMax; 1102 else 1103 out << "— "; 1104 out << '\t'; 1010 1105 } 1011 1106 out << fBiasControlVoltageMed << '\n'; … … 1017 1112 // ------------------------------------------ 1018 1113 1019 ofstream( "www/fact.txt") << out.str();1114 ofstream(fPath+"/fact.txt") << out.str(); 1020 1115 1021 1116 // ========================================== … … 1031 1126 1032 1127 out << GetStateHtml(fDimMcp, 4); 1033 out << GetStateHtml(fDimControl, 0);1128 out << kHtmlWhite << '\t' << (fDimControl.state()>-2?fDimControl.msg:"---") << "\n"; 1034 1129 out << GetStateHtml(fDimDataLogger, 1); 1035 1130 out << GetStateHtml(fDimDriveControl, 2); … … 1045 1140 } 1046 1141 1047 ofstream( "www/status.txt") << out.str();1142 ofstream(fPath+"/status.txt") << out.str(); 1048 1143 1049 1144 return kStateRunning; … … 1052 1147 public: 1053 1148 StateMachineSmartFACT(ostream &out=cout) : StateMachineDim(out, "SMART_FACT"), 1149 fPath("www/smartfact/data"), 1054 1150 fMcpConfigurationMaxTime(0), 1055 1151 fMcpConfigurationMaxEvents(0), … … 1088 1184 //--- 1089 1185 fDimFtmControlTriggerRates("FTM_CONTROL/TRIGGER_RATES", (void*)NULL, 0, this), 1186 fDimFtmControlStaticData ("FTM_CONTROL/STATIC_DATA", (void*)NULL, 0, this), 1090 1187 //- 1091 1188 fDimRateScanData ("RATE_SCAN/DATA", (void*)NULL, 0, this), … … 1121 1218 } 1122 1219 1220 // First move all the dim services to another class so that 1221 // they can be instatiated all at once _after_ path was set 1222 //fPath = conf.Get<string>("path"); 1223 1123 1224 // Pixel map is needed to deal with this service 1124 1225 fDimFadControlEventData=new DimStampedInfo("FAD_CONTROL/EVENT_DATA", (void*)NULL, 0, this); … … 1142 1243 po::options_description control("Smart FACT"); 1143 1244 control.add_options() 1144 ("pixel-map-file", var<string>("FACTmapV5a.txt"), "Pixel mapping file. Used here to get the default reference voltage.") 1245 ("pixel-map-file", var<string>("FACTmapV5a.txt"), "Pixel mapping file. Used here to get the default reference voltage") 1246 ("path", var<string>("www/smartfact"), "Output path for the data-files") 1145 1247 ; 1146 1248
Note:
See TracChangeset
for help on using the changeset viewer.