- Timestamp:
- 06/10/12 14:51:43 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/smartfact.cc
r14140 r14145 422 422 423 423 int64_t fFadControlNumEvents; 424 int64_t fFadControlStartRun; 424 425 int32_t fFadControlDrsStep; 425 426 vector<uint32_t> fFadControlDrsRuns; 426 427 427 428 deque<float> fFtmControlTriggerRateHist; 428 bool fFtmControlNewRunStarted; 429 uint32_t fFtmControlNewRunStarted; 430 uint32_t fFtmControlTriggerRateTooLow; 429 431 430 432 float fFtmPatchThresholdMed; … … 526 528 527 529 template<class T> 528 void WriteBinaryVec(const EventImp &d, const string &fname, const vector<T> &vec, double scale, double offset=0)530 void WriteBinaryVec(const Time &tm, const string &fname, const vector<T> &vec, double scale, double offset=0, const string &title="") 529 531 { 530 532 if (vec.size()==0) 531 533 return; 532 534 533 const Statistics stat(vec[0]);534 535 535 ostringstream out; 536 out << d.GetJavaDate() << '\n';536 out << tm.JavaDate() << '\n'; 537 537 out << offset << '\n'; 538 538 out << offset+scale << '\n'; 539 539 out << setprecision(3); 540 out << stat.min << '\n'; 541 out << stat.med << '\n'; 542 out << stat.max << '\x7f'; 540 if (!title.empty()) 541 out << title << '\x7f'; 542 else 543 { 544 const Statistics stat(vec[0]); 545 out << stat.min << '\n'; 546 out << stat.med << '\n'; 547 out << stat.max << '\x7f'; 548 } 543 549 for (auto it=vec.begin(); it!=vec.end(); it++) 544 550 { … … 565 571 566 572 template<class T> 573 void WriteBinaryVec(const EventImp &d, const string &fname, const vector<T> &vec, double scale, double offset=0, const string &title="") 574 { 575 WriteBinaryVec(d.GetTime(), fname, vec, scale, offset, title); 576 } 577 578 template<class T> 579 void WriteBinary(const Time &tm, const string &fname, const T &t, double scale, double offset=0) 580 { 581 WriteBinaryVec(tm, fname, vector<T>(&t, &t+1), scale, offset); 582 } 583 584 template<class T> 567 585 void WriteBinary(const EventImp &d, const string &fname, const T &t, double scale, double offset=0) 568 586 { 569 WriteBinaryVec(d , fname, vector<T>(&t, &t+1), scale, offset);587 WriteBinaryVec(d.GetTime(), fname, vector<T>(&t, &t+1), scale, offset); 570 588 } 571 589 … … 716 734 if (fMcpConfigurationState==MCP::State::kTakingData && d.GetQoS()==MCP::State::kIdle) 717 735 { 718 //...and no script is running just play a simple 'tick' 719 if (fDimControl.state()<-2) 736 // ...and no script is running just play a simple 'tick' 737 // ...and a script is running just play a simple 'tick' 738 if (/*fDimControl.state()<-2 &&*/ fDimControl.scriptdepth==0) 720 739 SetAudio("dong"); 721 722 // ...and a script is running just play a simple 'tick' 723 if (fDimControl.state()>=-2) 740 else 724 741 SetAudio("losticks"); 725 742 726 743 ostringstream out; 727 out << d.GetTimeAsStr("%H:%M:%S") << " <#dark green>" << d.Ptr<char>(16);744 out << d.GetTimeAsStr("%H:%M:%S") << " <#darkred>" << d.Ptr<char>(16); 728 745 if (!fDriveControlSourceName.empty()) 729 746 out << " [" << fDriveControlSourceName << ']'; 747 out << " (N=" << fFadControlNumEvents << ')'; 730 748 out << "</#><br/>"; 731 749 fMcpConfigurationHist.push_back(out.str()); … … 738 756 739 757 ostringstream out; 740 out << d.GetTimeAsStr("%H:%M:%S") << " <#dark red>" << fMcpConfigurationName;758 out << d.GetTimeAsStr("%H:%M:%S") << " <#darkgreen>" << fMcpConfigurationName; 741 759 if (!fDriveControlSourceName.empty()) 742 760 out << " [" << fDriveControlSourceName << ']'; 761 if (fFadControlStartRun>0) 762 out << " (Run " << fFadControlStartRun << ')'; 743 763 out << "</#><br/>"; 744 764 fMcpConfigurationHist.push_back(out.str()); … … 1175 1195 } 1176 1196 1197 int HandleFadStartRun(const EventImp &d) 1198 { 1199 if (!CheckDataSize(d, "FadControl:StartRun", 16)) 1200 { 1201 fFadControlStartRun = -1; 1202 return GetCurrentState(); 1203 } 1204 1205 fFadControlStartRun = d.Get<int64_t>(); 1206 1207 return GetCurrentState(); 1208 } 1209 1177 1210 int HandleFadDrsRuns(const EventImp &d) 1178 1211 { … … 1246 1279 { 1247 1280 if (!CheckDataSize(d, "FtmControl:TriggerRates", 24+160+640+8)) 1281 { 1282 fFtmControlTriggerRateTooLow = 0; 1248 1283 return GetCurrentState(); 1284 } 1249 1285 1250 1286 const double crate = d.Get<float>(20); // Camera rate … … 1253 1289 if (crate<0) 1254 1290 { 1255 fFtmControlNewRunStarted = true; 1291 fFtmControlNewRunStarted = 0; 1292 fFtmControlTriggerRateTooLow = 0; 1256 1293 return GetCurrentState(); 1257 1294 } 1258 fFtmControlNewRunStarted = false; 1259 1260 const float *brates = d.Ptr<float>(24); // Board rate 1261 const float *prates = d.Ptr<float>(24+160); // Patch rate 1295 1296 // At the end of a run sometimes the trigger rate drops (the 1297 // service is trasmitted) before the run is 'officially' finished 1298 // by the MCP. Hence, we get a warning. So we have to require 1299 // two consecutive low rates. 1300 if (crate<0.1) 1301 fFtmControlTriggerRateTooLow++; 1302 else 1303 fFtmControlTriggerRateTooLow=0; 1304 1305 fFtmControlNewRunStarted++; 1306 1307 const float *brates = d.Ptr<float>(24); // Board rate 1308 const float *prates = d.Ptr<float>(24+40*sizeof(float)); // Patch rate 1262 1309 1263 1310 // Store a history of the last 60 entries … … 1576 1623 out << HTML::kWhite << '\t' << fFtmBoardThresholdMed << '\n'; 1577 1624 out << HTML::kWhite << '\t' << fFtmPatchThresholdMed << '\n'; 1578 out << HTML::kWhite << '\t' << pow(10, fRateScanDataHist[0].back()) << '\n';1579 out << HTML::kWhite << '\t' << max<< '\n';1625 out << HTML::kWhite << '\t' << floor(pow(10, fRateScanDataHist[0].back())+.5) << '\n'; 1626 out << HTML::kWhite << '\t' << floor(max+.5) << '\n'; 1580 1627 1581 1628 ofstream(fPath+"/ratescan.data") << out.str(); … … 1721 1768 } 1722 1769 1770 #ifdef HAVE_NOVA 1771 pair<vector<float>, pair<Time, float>> GetVisibility(ln_equ_posn *src, ln_lnlat_posn *observer, double jd) 1772 { 1773 jd = floor(jd); 1774 1775 const double jd0 = fmod(fSun.fSetAstronomical.JD(), 1); 1776 const double jd1 = fmod(fSun.fRiseAstronomical.JD(), 1); 1777 1778 ln_equ_posn moon; 1779 ln_equ_posn *pos = src ? src : &moon; 1780 1781 double max = 0; 1782 double maxjd = jd0; 1783 1784 1785 vector<float> alt; 1786 for (double h=0; h<1; h+=1./(24*12)) 1787 { 1788 if (src==0) 1789 ln_get_lunar_equ_coords(jd+h, &moon); 1790 1791 ln_hrz_posn hrz; 1792 ln_get_hrz_from_equ(pos, observer, jd+h, &hrz); 1793 1794 if (h>jd0 && h<jd1 && hrz.alt>15) 1795 alt.push_back(hrz.alt); 1796 1797 if (hrz.alt>max) 1798 { 1799 max = hrz.alt; 1800 maxjd = jd+h; 1801 } 1802 } 1803 1804 if (max<15) 1805 return make_pair(vector<float>(), make_pair(Time(), 0)); 1806 1807 return make_pair(alt, make_pair(maxjd, maxjd>jd0+jd&&maxjd<jd1+jd?max:0)); 1808 } 1809 #endif 1810 1723 1811 void UpdateAstronomy() 1724 1812 { … … 1762 1850 1763 1851 if (!fMoon.visible) 1764 out << HTML::kWhite << "\t—\ n";1852 out << HTML::kWhite << "\t—\t\n"; 1765 1853 else 1766 1854 { … … 1779 1867 } 1780 1868 1781 ostringstream out2 ;1869 ostringstream out2, out3; 1782 1870 out2 << setprecision(3); 1783 1871 out2 << now.JavaDate() << '\n'; 1872 out3 << now.JavaDate() << '\n'; 1873 1874 map<Time, pair<string, float>> culmination; 1875 vector<vector<float>> alt; 1876 1877 #ifdef HAVE_NOVA 1878 ln_lnlat_posn observer; 1879 observer.lng = lon; 1880 observer.lat = lat; 1881 1882 const pair<vector<float>, pair<Time, float>> vism = GetVisibility(0, &observer, now.JD()); 1883 if (vism.first.size()>0) 1884 { 1885 alt.push_back(vism.first); 1886 culmination[vism.second.first] = make_pair("Moon", vism.second.second); 1887 } 1888 #endif 1784 1889 1785 1890 #ifdef HAVE_SQL … … 1791 1896 out << HTML::kWhite << '\t'; 1792 1897 out2 << HTML::kWhite << '\t'; 1898 out3 << HTML::kWhite << '\t'; 1793 1899 1794 1900 for (vector<mysqlpp::Row>::const_iterator v=res.begin(); v<res.end(); v++) … … 1798 1904 const double dec = (*v)[2]; 1799 1905 #ifdef HAVE_NOVA 1800 ln_lnlat_posn observer;1801 observer.lng = lon;1802 observer.lat = lat;1803 1804 1906 ln_equ_posn pos; 1805 1907 pos.ra = ra*15; … … 1808 1910 ln_hrz_posn hrz; 1809 1911 ln_get_hrz_from_equ(&pos, &observer, now.JD(), &hrz); 1912 1913 const pair<vector<float>, pair<Time, float>> vis = GetVisibility(&pos, &observer, now.JD()); 1914 if (vis.first.size()>0) 1915 { 1916 alt.push_back(vis.first); 1917 culmination[vis.second.first] = make_pair(name, vis.second.second); 1918 } 1919 1920 //out3 << vis.second.first << "/" << vis.second.second << " "; 1810 1921 1811 1922 string col = HTML::kWhite; … … 1835 1946 out << "</tr>"; 1836 1947 } 1948 1949 for (auto it=culmination.begin(); it!=culmination.end(); it++) 1950 { 1951 if (it!=culmination.begin()) 1952 out3 << ", "; 1953 out3 << "<B>" << it->second.first << "</B>"; 1954 if (it->second.second>0) 1955 out3 << " [" << nearbyint(90-it->second.second) << "°]"; 1956 } 1957 1958 ostringstream title; 1959 title << "Alt "; 1960 title << fSun.fSetAstronomical.GetAsStr("%H:%M"); 1961 title << " / "; 1962 title << ((fSun.fRiseAstronomical-fSun.fSetAstronomical)/20).minutes(); 1963 title << "' / "; 1964 title << fSun.fRiseAstronomical.GetAsStr("%H:%M"); 1965 1837 1966 out << '\n'; 1838 1967 out2 << '\n'; 1968 out3 << '\n'; 1839 1969 out << HTML::kWhite << '\t' << Time()-now << '\n'; 1840 1970 out2 << HTML::kWhite << '\t' << Time()-now << '\n'; 1971 1972 WriteBinaryVec(now, "hist-visibility", alt, 75, 15, title.str()); 1841 1973 } 1842 1974 catch (const exception &e) … … 1846 1978 out << HTML::kWhite << '\t' << "ERROR - "+string(e.what()) << '\n'; 1847 1979 out2 << HTML::kWhite << '\t' << "ERROR - "+string(e.what()) << '\n'; 1980 out3 << HTML::kWhite << '\t' << "ERROR - "+string(e.what()) << '\n'; 1848 1981 } 1849 1982 #endif … … 1851 1984 ofstream(fPath+"/moon.data") << out.str(); 1852 1985 ofstream(fPath+"/source-list.data") << out2.str(); 1986 ofstream(fPath+"/visibility.data") << out3.str(); 1853 1987 } 1854 1988 … … 1925 2059 "Sensor temperature exceeds outside temperature by more than 8°C"); 1926 2060 1927 if (fFtmControlTriggerRateHist.size()>0 && !fFtmControlNewRunStarted) 1928 { 1929 newerr |= SetError(fFtmControlTriggerRateHist.size()>0 && fFtmControlTriggerRateHist.back()<0.01 && fDimMcp.state()==MCP::State::kTakingData, 1930 "Trigger rate below 10mHz during data taking"); 1931 } 2061 newerr |= SetError(fFtmControlNewRunStarted>0 && fFtmControlTriggerRateTooLow>1 && fDimMcp.state()==MCP::State::kTakingData, 2062 "Trigger rate below 100mHz during data taking"); 1932 2063 1933 2064 newerr |= SetError(fDimTimeCheck.state()==1, … … 2116 2247 if (fDimDNS.online() && fDimDriveControl.state()>=Drive::State::kArmed) // Armed, Moving, Tracking 2117 2248 { 2118 const double dev = fDriveControlTrackingDevHist.size()>0 ? fDriveControlTrackingDevHist.back() : 0;2249 const uint32_t dev = fDriveControlTrackingDevHist.size()>0 ? round(fDriveControlTrackingDevHist.back()) : 0; 2119 2250 const State rc = fDimDriveControl.description(); 2120 2251 string col = HTML::kGreen; … … 2167 2298 } 2168 2299 } 2169 2170 2300 if (fDimDNS.online() && fDimDriveControl.state()==0x100) // Armed, Moving, Tracking 2171 2301 out << " [ERR]"; … … 2213 2343 { 2214 2344 string col = HTML::kGreen; 2215 if (fFtmControlTriggerRateHist.size()>0 && !fFtmControlNewRunStarted)2345 if (fFtmControlTriggerRateHist.size()>0 && fFtmControlNewRunStarted>0) 2216 2346 { 2217 2347 if (fFtmControlTriggerRateHist.back()<15) … … 2437 2567 Subscribe("FAD_CONTROL/EVENTS") 2438 2568 (bind(&StateMachineSmartFACT::HandleFadEvents, this, placeholders::_1)); 2569 Subscribe("FAD_CONTROL/START_RUN") 2570 (bind(&StateMachineSmartFACT::HandleFadStartRun, this, placeholders::_1)); 2439 2571 Subscribe("FAD_CONTROL/DRS_RUNS") 2440 2572 (bind(&StateMachineSmartFACT::HandleFadDrsRuns, this, placeholders::_1));
Note:
See TracChangeset
for help on using the changeset viewer.