Changeset 14218
- Timestamp:
- 06/22/12 22:11:37 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/smartfact.cc
r14213 r14218 370 370 }; 371 371 372 // ------------------------- History classes ----------------------- 373 374 struct EventElement 375 { 376 Time time; 377 string msg; 378 379 EventElement(const Time &t, const string &s) : time(t), msg(s) { } 380 }; 381 382 class EventHist : public deque<EventElement> 383 { 384 const boost::posix_time::time_duration deltat; //boost::posix_time::pos_infin 385 const uint64_t max; 386 387 public: 388 EventHist(const boost::posix_time::time_duration &dt=boost::posix_time::hours(12), uint64_t mx=UINT64_MAX) : deltat(dt), max(mx) { } 389 390 void add(const string &s, const Time &t=Time()) 391 { 392 while (size()>0 && (front().time+deltat<t || size()>max)) 393 pop_front(); 394 395 push_back(EventElement(t, s)); 396 } 397 398 string get() const 399 { 400 ostringstream out; 401 402 string last = ""; 403 for (auto it=begin(); it!=end(); it++) 404 { 405 const string tm = it->time.GetAsStr("%H:%M:%S "); 406 out << (tm!=last?tm:"--:--:-- ") << it->msg << "<br/>"; 407 last = tm; 408 } 409 410 return out.str(); 411 } 412 string rget() const 413 { 414 ostringstream out; 415 416 for (auto it=rbegin(); it!=rend(); it++) 417 out << it->time.GetAsStr("%H:%M:%S ") << it->msg << "<br/>"; 418 419 return out.str(); 420 } 421 }; 422 372 423 // ------------------------- Internal variables ----------------------- 373 424 … … 385 436 // ----------------------------- Data storage ------------------------- 386 437 387 deque<string> fControlMessageHist; 388 int32_t fControlScriptDepth; 389 390 uint32_t fMcpConfigurationState; // For consistency 391 int64_t fMcpConfigurationMaxTime; 392 int64_t fMcpConfigurationMaxEvents; 393 string fMcpConfigurationName; 394 Time fMcpConfigurationRunStart; 395 Time fMcpConfigurationLastTime; 396 deque<string> fMcpConfigurationHist; 438 EventHist fControlMessageHist; 439 int32_t fControlScriptDepth; 440 441 uint32_t fMcpConfigurationState; // For consistency 442 int64_t fMcpConfigurationMaxTime; 443 int64_t fMcpConfigurationMaxEvents; 444 string fMcpConfigurationName; 445 Time fMcpConfigurationRunStart; 446 EventHist fMcpConfigurationHist; 397 447 398 448 bool fLastRunFinishedWithZeroEvents; … … 447 497 deque<float> fRateScanDataHist[41]; 448 498 449 set<string> fErrorList; 450 deque<string> fErrorHist; 451 deque<string> fChatHist; 452 Time fChatLastTime; 499 set<string> fErrorList; 500 EventHist fErrorHist; 501 EventHist fChatHist; 453 502 454 503 Sun fSun; … … 636 685 return; 637 686 638 const string time = d.GetTimeAsStr("%H:%M:%S "); 639 640 string str = " "; 641 for (auto it=fControlMessageHist.rbegin(); it!=fControlMessageHist.rend(); it++) 642 { 643 str = it->substr(0, time.length()); 644 if (str!="--:--:-- ") 645 break; 646 } 647 648 ostringstream tst; 649 tst << d.GetQoS(); 650 651 string msg; 652 msg += str==time ? "--:--:-- " : time; 653 msg += d.Ptr<char>(); 654 655 fControlMessageHist.push_back(msg); 687 fControlMessageHist.add(d.GetText(), d.GetTime()); 656 688 657 689 ostringstream out; … … 659 691 out << Header(d) << '\n'; 660 692 out << HTML::kWhite << '\t'; 661 662 out << "<->"; 663 for (auto it=fControlMessageHist.begin(); it!=fControlMessageHist.end(); it++) 664 out << *it << "<br/>"; 665 out << "</->"; 666 693 out << "<->" << fControlMessageHist.get() << "</->"; 667 694 out << '\n'; 668 695 … … 709 736 } 710 737 711 void HandleFscControlStateChange(const EventImp &d)712 {713 const int32_t &last = fDimFscControl.last.second;714 const int32_t &state = fDimFscControl.state();715 716 if (last==DimState::kOffline || state==DimState::kOffline)717 return;718 719 if (last<FSC::State::kConnected && state==FSC::State::kConnected)720 {721 AddMcpConfigurationHist(d, "<B>Camera swiched on</B>");722 SetAudio("startup");723 }724 725 if (last==FSC::State::kConnected && state<FSC::State::kConnected)726 {727 AddMcpConfigurationHist(d, "<B>Camera swiched off</B>");728 SetAudio("shutdown");729 }730 }731 732 738 void AddMcpConfigurationHist(const EventImp &d, const string &msg) 733 739 { 734 if (d.GetTime()>fMcpConfigurationLastTime+boost::posix_time::hours(12)) 735 fMcpConfigurationHist.clear(); 736 737 fMcpConfigurationLastTime = d.GetTime(); 738 fMcpConfigurationHist.push_back(d.GetTimeAsStr("%H:%M:%S ")+msg+"<br/>"); 740 fMcpConfigurationHist.add(msg, d.GetTime()); 739 741 740 742 ostringstream out; 741 743 out << d.GetJavaDate() << '\n'; 742 744 out << HTML::kWhite << '\t'; 743 for (auto it=fMcpConfigurationHist.rbegin(); it!=fMcpConfigurationHist.rend(); it++) 744 out << *it; 745 out << "<->" << fMcpConfigurationHist.rget() << "</->"; 745 746 out << '\n'; 746 747 747 748 ofstream(fPath+"/observations.data") << out.str(); 749 } 750 751 void HandleFscControlStateChange(const EventImp &d) 752 { 753 const int32_t &last = fDimFscControl.last.second; 754 const int32_t &state = fDimFscControl.state(); 755 756 if (last==DimState::kOffline || state==DimState::kOffline) 757 return; 758 759 if (last<FSC::State::kConnected && state==FSC::State::kConnected) 760 { 761 AddMcpConfigurationHist(d, "<B>Camera swiched on</B>"); 762 SetAudio("startup"); 763 } 764 765 if (last==FSC::State::kConnected && state<FSC::State::kConnected) 766 { 767 AddMcpConfigurationHist(d, "<B>Camera swiched off</B>"); 768 SetAudio("shutdown"); 769 } 748 770 } 749 771 … … 894 916 } 895 917 918 void HandleDriveControlStateChange(const EventImp &d) 919 { 920 const int32_t &last = fDimFscControl.last.second; 921 const int32_t &state = fDimFscControl.state(); 922 923 if (last==DimState::kOffline || state==DimState::kOffline) 924 return; 925 926 if (last<Drive::State::kArmed && state>=Drive::State::kArmed) 927 AddMcpConfigurationHist(d, "Drive connected"); 928 929 if (last>=Drive::State::kArmed && state<Drive::State::kArmed) 930 AddMcpConfigurationHist(d, "Drive disconnected"); 931 } 932 896 933 int HandleDrivePointing(const EventImp &d) 897 934 { … … 1320 1357 // by the MCP. Hence, we get a warning. So we have to require 1321 1358 // two consecutive low rates. 1322 if (*crate< 0.1)1359 if (*crate<1) 1323 1360 fFtmControlTriggerRateTooLow++; 1324 1361 else … … 1679 1716 return GetCurrentState(); 1680 1717 1681 if (d.GetTime()>fChatLastTime+boost::posix_time::hours(12))1682 fChatHist.clear();1683 1684 1718 if (Time()<d.GetTime()+boost::posix_time::minutes(1)) 1685 1719 SetAudio("message"); 1686 1720 1687 fChatLastTime = d.GetTime(); 1688 1689 string msg; 1690 msg += d.GetTimeAsStr("%H:%M:%S "); 1691 msg += d.Ptr<char>(); 1692 1693 fChatHist.push_front(msg); 1694 if (fChatHist.size()>80) 1695 fChatHist.pop_back(); 1721 fChatHist.add(d.GetText(), d.GetTime()); 1696 1722 1697 1723 ostringstream out; … … 1699 1725 out << Header(d) << '\n'; 1700 1726 out << HTML::kWhite << '\t'; 1701 1702 out << "<->"; 1703 for (auto it=fChatHist.begin(); it!=fChatHist.end(); it++) 1704 out << *it << "<br/>"; 1705 out << "</->"; 1706 1727 out << "<->" << fChatHist.rget() << "</->"; 1707 1728 out << '\n'; 1708 1729 … … 1810 1831 1811 1832 const bool isnew = fErrorList.insert(err).second; 1812 1813 1833 if (isnew) 1814 { 1815 ostringstream msg; 1816 msg << "<pre>" << Time().GetAsStr("%m-%d %H:%M") << "</pre> <->" << err << "</->"; 1817 if (find(fErrorHist.begin(), fErrorHist.end(), msg.str())==fErrorHist.end()) 1818 { 1819 fErrorHist.push_front(msg.str()); 1820 if (fErrorHist.size()>80) 1821 fErrorHist.pop_back(); 1822 } 1823 } 1834 fErrorHist.add(err); 1824 1835 1825 1836 return isnew; … … 2122 2133 2123 2134 newerr |= SetError(fFtmControlTriggerRateTooLow>2 && fDimMcp.state()==MCP::State::kTakingData, 2124 "Trigger rate below 1 00mHz during data taking");2135 "Trigger rate below 1Hz during data taking"); 2125 2136 2126 2137 newerr |= SetError(fDimTimeCheck.state()==1, … … 2170 2181 out << now.JavaDate() << '\n'; 2171 2182 out << HTML::kWhite << '\t'; 2172 for (auto it=fErrorHist.begin(); it!=fErrorHist.end(); it++) 2173 out << *it << "<br/>"; 2183 out << "<->" << fErrorHist.rget() << "<->"; 2174 2184 out << '\n'; 2175 2185 … … 2601 2611 2602 2612 fDimFscControl.SetCallback(bind(&StateMachineSmartFACT::HandleFscControlStateChange, this, placeholders::_1)); 2613 fDimDriveControl.SetCallback(bind(&StateMachineSmartFACT::HandleDriveControlStateChange, this, placeholders::_1)); 2603 2614 fDimControl.SetCallback(bind(&StateMachineSmartFACT::HandleControlStateChange, this, placeholders::_1)); 2604 2615 fDimControl.AddCallback("dotest.dim", bind(&StateMachineSmartFACT::HandleDoTest, this, placeholders::_1));
Note:
See TracChangeset
for help on using the changeset viewer.