Changeset 10271 for trunk/FACT++
- Timestamp:
- 03/30/11 15:43:05 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/dataLogger.cc
r10265 r10271 45 45 #include "Time.h" 46 46 #include "StateMachineDim.h" 47 #include "WindowLog.h" 48 #include "Configuration.h" 47 49 #include "ServiceList.h" 48 50 #include "Converter.h" 49 51 #include "MessageImp.h" 52 #include "LocalControl.h" 50 53 51 54 //#define HAS_FITS … … 72 75 } localstates_t; 73 76 74 DataLogger();77 DataLogger(std::ostream &out); 75 78 ~DataLogger(); 76 79 … … 274 277 //!Setup the allows states, configs and transitions for the data logger 275 278 // 276 DataLogger::DataLogger( ) : StateMachineDim(std::cout, "DATA_LOGGER")279 DataLogger::DataLogger(std::ostream &out) : StateMachineDim(out, "DATA_LOGGER") 277 280 { 278 281 //initialize member data … … 281 284 fRunNumber = 12345; 282 285 //Give a name to this machine's specific states 283 AddStateName(kSM_DailyOpen, "Daily_File_Openened");284 AddStateName(kSM_WaitingRun, "Waiting_Run_Number");285 AddStateName(kSM_Logging, "Logging data");286 AddStateName(kSM_BadDailyConfig, " Folder_For_Daily_Logging_Badly_Configured");287 AddStateName(kSM_BadRunConfig, "Folder_For_Run_Logging_Badly Configured");286 AddStateName(kSM_DailyOpen, "DailyFileOpen"); 287 AddStateName(kSM_WaitingRun, "WaitForRun"); 288 AddStateName(kSM_Logging, "Logging"); 289 AddStateName(kSM_BadDailyConfig, "ErrDailyFolder"); 290 AddStateName(kSM_BadRunConfig, "ErrRunFolder"); 288 291 289 292 /*Add the possible transitions for this machine*/ … … 596 599 } 597 600 } 601 598 602 // -------------------------------------------------------------------------- 599 603 // … … 635 639 header << fMs << " " << I->getTimestamp() << " "; 636 640 637 Converter conv(std::cout, I->getFormat(), I->getData(), I->getSize()); 638 639 if (conv.Ptr() == NULL) 640 return; 641 642 std::string text(conv.Ptr()); 643 641 const Converter conv(Out(), I->getFormat()); 642 643 std::string text = conv.GetString(I->getData(), I->getSize()); 644 if (!conv.valid() || text.empty()!=conv.empty()) 645 { 646 Error("Couldn't properly parse the data... ignored."); 647 return; 648 } 649 644 650 if (text.empty()) 645 return; 651 return; 652 653 //replace bizarre characters by white space 654 replace(text.begin(), text.end(), '\n', '\\'); 655 replace_if(text.begin(), text.end(), std::ptr_fun<int, int>(&std::iscntrl), ' '); 646 656 647 657 if (fDailyReportFile.is_open()) … … 649 659 if (fRunReportFile.is_open()) 650 660 fRunReportFile << header.str(); 651 652 //replace bizarre characters by white space 653 for (unsigned int i=0; i<text.size(); i++) 654 { 655 if (text[i] == '\n') 656 text[i] = '\\'; 657 else 658 if (iscntrl(text[i])) 659 text[i] = ' '; 660 } 661 if (fDailyReportFile.is_open()) 661 662 if (fDailyReportFile.is_open()) 662 663 fDailyReportFile << text << std::endl; 663 664 if (fRunReportFile.is_open()) … … 692 693 //! @returns 693 694 //! the new state. Currently, always the current state 694 // 695 //DEPREC I guess that this function should not be any longer 695 //! 696 //! @deprecated 697 //! I guess that this function should not be any longer 698 // 696 699 int DataLogger::LogMessagePlease(const Event& evt) 697 700 { … … 706 709 707 710 // std::string text = ToString(evt.GetFormat().c_str(), evt.GetData(), evt.GetSize()); 708 Converter conv(std::cout, evt.GetFormat().c_str(), evt.GetData(), evt.GetSize()); 709 if (conv.Ptr() == NULL) 710 return GetCurrentState(); 711 712 std::string text(conv.Ptr()); 713 714 if (!text.empty()) 715 { 716 if (fDailyLogFile.is_open()) 717 fDailyLogFile << header; 718 if (fRunLogFile.is_open()) 719 fRunLogFile << header; 720 721 //replace bizarre characters by white space 722 for (unsigned int i=0; i<text.size(); i++) 723 { 724 if (text[i] == '\n') 725 text[i] = '\\'; 726 else 727 if (iscntrl(text[i])) 728 text[i] = ' '; 729 } 730 if (fDailyLogFile.is_open()) 731 fDailyLogFile << text; 732 if (fRunLogFile.is_open()) 733 fRunLogFile << text; 734 } 735 736 return GetCurrentState(); 711 const Converter conv(Out(), evt.GetFormat()); 712 713 std::string text = conv.GetString(evt.GetData(), evt.GetSize()); 714 if (!conv.valid() || text.empty()!=conv.empty()) 715 { 716 Error("Couldn't properly parse the data... ignored."); 717 return GetCurrentState(); 718 } 719 720 if (text.empty()) 721 return GetCurrentState(); 722 723 //replace bizarre characters by white space 724 replace(text.begin(), text.end(), '\n', '\\'); 725 replace_if(text.begin(), text.end(), std::ptr_fun<int, int>(&std::iscntrl), ' '); 726 727 if (fDailyLogFile.is_open()) 728 fDailyLogFile << header; 729 if (fRunLogFile.is_open()) 730 fRunLogFile << header; 731 732 if (fDailyLogFile.is_open()) 733 fDailyLogFile << text; 734 if (fRunLogFile.is_open()) 735 fRunLogFile << text; 736 737 return GetCurrentState(); 737 738 } 738 739 // -------------------------------------------------------------------------- … … 897 898 // sub.runFile.InitCol("MilliSec", "int", &fMs); 898 899 sub.runFile.InitCol("QoS", "int", &fQuality); 899 900 Converter::FormatList flist = Converter::Convert(std::cout, std::string(format)); 901 900 901 const Converter::FormatList flist = Converter::Compile(Out(), format); 902 903 // Compilation failed 904 if (fList.empty() || fList.back().first.second!=0) 905 { 906 Error("Compilation of format string failed."); 907 return; 908 } 909 902 910 //we've got a nice structure describing the format of this service's messages. 903 911 //Let's create the appropriate FITS columns … … 1055 1063 1056 1064 // -------------------------------------------------------------------------- 1057 // 1058 int main() 1059 { 1060 //No more Dim Checking ?? 1061 // if (!CheckDim()) 1062 // return -1; 1063 1064 DataLogger log; 1065 while (!log.fExitRequested) 1066 { 1067 usleep(10); 1068 } 1069 return 0; 1070 1071 } 1065 1066 int RunDim(Configuration &conf) 1067 { 1068 WindowLog wout; 1069 1070 //log.SetWindow(stdscr); 1071 if (conf.Has("log")) 1072 if (!wout.OpenLogFile(conf.Get<std::string>("log"))) 1073 wout << kRed << "ERROR - Couldn't open log-file " << conf.Get<std::string>("log") << ": " << strerror(errno) << std::endl; 1074 1075 // Start io_service.Run to use the StateMachineImp::Run() loop 1076 // Start io_service.run to only use the commandHandler command detaching 1077 DataLogger logger(wout); 1078 1079 while (1) 1080 usleep(1); 1081 1082 return 0; 1083 } 1084 1085 template<class T> 1086 int RunShell(Configuration &conf) 1087 { 1088 static T shell(conf.GetName().c_str(), conf.Get<int>("console")!=1); 1089 1090 WindowLog &win = shell.GetStreamIn(); 1091 WindowLog &wout = shell.GetStreamOut(); 1092 1093 if (conf.Has("log")) 1094 if (!wout.OpenLogFile(conf.Get<std::string>("log"))) 1095 win << kRed << "ERROR - Couldn't open log-file " << conf.Get<std::string>("log") << ": " << strerror(errno) << std::endl; 1096 1097 DataLogger io_service(wout); 1098 1099 shell.SetReceiver(io_service); 1100 shell.Run(); // Run the shell 1101 1102 return 0; 1103 } 1104 1105 void SetupConfiguration(Configuration &conf) 1106 { 1107 const std::string n = conf.GetName()+".log"; 1108 1109 po::options_description config("Program options"); 1110 config.add_options() 1111 ("dns", var<std::string>("localhost"), "Dim nameserver host name (Overwites DIM_DNS_NODE environment variable)") 1112 ("log,l", var<std::string>(n), "Write log-file") 1113 ("console,c", var<int>(), "Use console (0=shell, 1=simple buffered, X=simple unbuffered)") 1114 ; 1115 1116 conf.AddEnv("dns", "DIM_DNS_NODE"); 1117 1118 conf.AddOptions(config); 1119 } 1120 1121 int main(int argc, char* argv[]) 1122 { 1123 Configuration conf(argv[0]); 1124 SetupConfiguration(conf); 1125 1126 po::variables_map vm; 1127 try 1128 { 1129 vm = conf.Parse(argc, argv); 1130 } 1131 #if BOOST_VERSION > 104000 1132 catch (po::multiple_occurrences &e) 1133 { 1134 std::cout << "Error: " << e.what() << " of '" << e.get_option_name() << "' option." << std::endl; 1135 std::cout << std::endl; 1136 return -1; 1137 } 1138 #endif 1139 catch (std::exception &e) 1140 { 1141 std::cout << "Error: " << e.what() << std::endl; 1142 std::cout << std::endl; 1143 1144 return -1; 1145 } 1146 1147 if (conf.HasHelp() || conf.HasPrint()) 1148 return -1; 1149 1150 // To allow overwriting of DIM_DNS_NODE set 0 to 1 1151 setenv("DIM_DNS_NODE", conf.Get<std::string>("dns").c_str(), 1); 1152 1153 try 1154 { 1155 // No console access at all 1156 if (!conf.Has("console")) 1157 return RunDim(conf); 1158 1159 // Cosole access w/ and w/o Dim 1160 if (conf.Get<int>("console")==0) 1161 return RunShell<LocalShell>(conf); 1162 else 1163 return RunShell<LocalConsole>(conf); 1164 } 1165 catch (std::exception& e) 1166 { 1167 cerr << "Exception: " << e.what() << endl; 1168 return -1; 1169 } 1170 1171 return 0; 1172 }
Note:
See TracChangeset
for help on using the changeset viewer.