Changeset 10675 for trunk/FACT++/src/dataLogger.cc
- Timestamp:
- 05/12/11 12:17:37 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/dataLogger.cc
r10648 r10675 143 143 ///run number (-1 means no run number specified) 144 144 int fRunNumber; 145 ///previous run number. to check if changed while logging 146 int fPreviousRunNumber; 145 147 ///Current Service Quality 146 148 int fQuality; 147 149 ///Modified Julian Date 148 150 double fMjD; 149 151 public: 150 152 ///Define all the static names 151 153 static const char* fConfigDay; … … 165 167 static const char* fStartStopOpenedFiles; 166 168 static const char* fStartStopNumSubsAndFits; 169 private: 167 170 //overloading of DIM's infoHandler function 168 171 void infoHandler(); … … 315 318 inline void NotifyOpenedFile(std::string name, int type, DimDescribedService* service); 316 319 public: 317 void setBlackWhiteList(const std::string& , bool); 320 // void setBlackWhiteList(const std::string& , bool); 321 void Setup(Configuration& conf); 322 318 323 private: 319 324 std::set<std::string> fGreyList; … … 330 335 ///boolean to prevent DIM update while desctructing the dataLogger 331 336 bool fDestructing; 337 338 ///Small function for calculating the total size written so far 339 void calculateTotalSizeWritten(DataLoggerStats& statVar, bool& shouldWarn, bool isPrinting); 332 340 }; //DataLogger 333 341 342 void DataLogger::calculateTotalSizeWritten(DataLoggerStats& statVar, bool& shouldWarn, bool isPrinting) 343 { 344 #ifdef HAS_FITS 345 if (isPrinting) 346 { 347 stringstream str; 348 str.str(""); 349 str << "There are " << fNumSubAndFitsData.numOpenFits << " FITS files open:"; 350 Message(str.str()); 351 } 352 SubscriptionsListType::iterator x; 353 std::map<std::string, SubscriptionType>::iterator y; 354 bool runFileDone = false; 355 for (x=fServiceSubscriptions.begin(); x != fServiceSubscriptions.end(); x++) 356 { 357 for (y=x->second.begin(); y != x->second.end(); y++) 358 { 359 if (y->second.runFile.IsOpen() && !runFileDone) 360 { 361 fFileSizesMap[y->second.runFile.fFileName] = y->second.runFile.GetWrittenSize(); 362 if (isPrinting) 363 Message("-> "+y->second.runFile.fFileName); 364 #ifdef ONE_FITS_ONLY 365 runFileDone = true; 366 #endif 367 } 368 if (y->second.nightlyFile.IsOpen()) 369 { 370 fFileSizesMap[y->second.nightlyFile.fFileName] = y->second.nightlyFile.GetWrittenSize(); 371 if (isPrinting) 372 Message("-> "+y->second.nightlyFile.fFileName); 373 } 374 } 375 } 376 #else 377 if (isPrinting) 378 Message("FITS output disabled at compilation"); 379 #endif 380 struct stat st; 381 //gather log and report files sizes on disk 382 if (fNightlyLogFile.is_open()) 383 { 384 stat(fFullNightlyLogFileName.c_str(), &st); 385 fFileSizesMap[fFullNightlyLogFileName] = st.st_size; 386 } 387 if (fNightlyReportFile.is_open()) 388 { 389 stat(fFullNightlyReportFileName.c_str(), &st); 390 fFileSizesMap[fFullNightlyReportFileName] = st.st_size; 391 } 392 if (fRunLogFile.is_open()) 393 { 394 stat(fFullRunLogFileName.c_str(), &st); 395 fFileSizesMap[fFullRunLogFileName] = st.st_size; 396 } 397 if (fRunReportFile.is_open()) 398 { 399 stat(fFullRunReportFileName.c_str(), &st); 400 fFileSizesMap[fFullRunReportFileName] = st.st_size; 401 } 402 struct statvfs vfs; 403 if (!statvfs(fNightlyFileName.c_str(), &vfs)) 404 { 405 statVar.freeSpace = vfs.f_bsize*vfs.f_bavail; 406 shouldWarn = false; 407 } 408 else 409 { 410 stringstream str; 411 str.str(""); 412 str << "Unable to retrieve stats for " << fNightlyFileName << ". Reason: " << strerror(errno) << " [" << errno << "]"; 413 if (!shouldWarn) 414 Error(str); 415 shouldWarn = true; 416 statVar.freeSpace = -1; 417 } 418 //sum up all the file sizes. past and present 419 statVar.sizeWritten = 0; 420 for (std::map<std::string, long>::iterator it=fFileSizesMap.begin(); it != fFileSizesMap.end(); it++) 421 statVar.sizeWritten += it->second; 422 statVar.sizeWritten -= fBaseSizeNightly; 423 statVar.sizeWritten -= fBaseSizeRun; 424 } 334 425 //static members initialization 335 426 //since I do not check the transition/config names any longer, indeed maybe these could be hard-coded... but who knows what will happen in the future ? … … 381 472 sleep(fStatsPeriodDuration); 382 473 //update the fits files sizes 474 calculateTotalSizeWritten(statVar, statWarning, false);/* 383 475 #ifdef HAS_FITS 384 476 SubscriptionsListType::iterator x; … … 445 537 statVar.sizeWritten -= fBaseSizeNightly; 446 538 statVar.sizeWritten -= fBaseSizeRun; 539 */ 447 540 if (fStatsPeriodDuration == 0.0f) 448 541 continue; … … 481 574 fNightlyFileName = ".";//"/home/lyard/log";// 482 575 fRunFileName = ".";//"/home/lyard/log"; 483 fRunNumber = 12345; 576 fRunNumber = -1; 577 fPreviousRunNumber = fRunNumber; 484 578 #ifdef HAS_FITS 485 579 #ifdef ONE_RUN_FITS_ONLY … … 545 639 546 640 //Provide a print command 547 AddConfiguration(fPrintCommand, kSM_NightlyOpen, kSM_Logging, kSM_WaitingRun, kSM_BadNightlyConfig, kSM_BadRunConfig) 641 stringstream str; 642 str << kSM_Ready << " " << kSM_NightlyOpen << " " << kSM_WaitingRun << " " << kSM_Logging << " " << kSM_BadNightlyConfig; 643 str << " " << kSM_BadRunConfig; 644 645 AddConfiguration(fPrintCommand, str.str().c_str(), "") 646 // AddConfiguration(fPrintCommand, kSM_NightlyOpen, kSM_Logging, kSM_WaitingRun, kSM_BadNightlyConfig, kSM_BadRunConfig) 548 647 (boost::bind(&DataLogger::PrintStatePlease, this, _1)) 549 648 ("Print information about the internal status of the data logger."); … … 583 682 584 683 //services parameters 585 fDebugIsOn = false;684 fDebugIsOn = true;//false; 586 685 fStatsPeriodDuration = 1.0f; 587 686 fOpenedFilesIsOn = true; … … 793 892 return; 794 893 795 894 DimInfo* I = getInfo(); 796 895 SubscriptionsListType::iterator x; 797 896 std::map<std::string, SubscriptionType>::iterator y; … … 843 942 844 943 CheckForRunNumber(I); 944 945 if (fPreviousRunNumber != fRunNumber) 946 {//run number has changed. close and reopen run files. 947 StopRunPlease(); 948 StartRunPlease(); 949 fPreviousRunNumber = fRunNumber; 950 } 951 845 952 ReportPlease(I, y->second); 846 953 … … 1183 1290 else 1184 1291 Message("Run Report.........CLOSED"); 1292 bool statWarning = false; 1293 DataLoggerStats statVar; 1294 calculateTotalSizeWritten(statVar, statWarning, false);/* 1185 1295 #ifdef HAS_FITS 1186 1296 str.str(""); … … 1254 1364 statVar.sizeWritten -= fBaseSizeNightly; 1255 1365 statVar.sizeWritten -= fBaseSizeRun; 1366 */ 1256 1367 Message("-----------------STATS-------------------"); 1257 1368 str.str(""); … … 1261 1372 str << "Disk free space: " << statVar.freeSpace << " bytes."; 1262 1373 Message(str.str()); 1263 1374 str.str(""); 1375 str << "Statistics are updated every " << fStatsPeriodDuration << " seconds"; 1376 if (fStatsPeriodDuration != 0) 1377 Message(str); 1378 else 1379 Message("Statistics updates are currently disabled"); 1264 1380 Message("------------DIM SUBSCRIPTIONS------------"); 1265 1381 … … 1274 1390 Message("-> "+it2->first); 1275 1391 } 1276 Message("-----------------------------------------"); 1277 1392 if (fIsBlackList) 1393 Message("------------BLOCK LIST-------------------"); 1394 else 1395 if (fGreyList.size() != 0) 1396 Message("------------ALLOW LIST-------------------"); 1397 for (set<string>::iterator it=fGreyList.begin(); it != fGreyList.end(); it++) 1398 Message(*it); 1278 1399 return GetCurrentState(); 1279 1400 } … … 1778 1899 } 1779 1900 //attempt to open run file with current parameters 1780 if (fRunNumber == -1)1781 return kSM_BadRunConfig;1901 // if (fRunNumber == -1) 1902 // return kSM_BadRunConfig; 1782 1903 std::stringstream sRun; 1783 1904 sRun << fRunNumber; … … 1870 1991 if (!fRunLogFile.is_open() || !fRunReportFile.is_open()) 1871 1992 return kSM_FatalError; 1872 1873 fRunLogFile.close(); 1874 fRunReportFile.close(); 1993 if (fRunLogFile.is_open()) 1994 fRunLogFile.close(); 1995 if (fRunReportFile.is_open()) 1996 fRunReportFile.close(); 1875 1997 #ifdef HAS_FITS 1876 1998 for (SubscriptionsListType::iterator i = fServiceSubscriptions.begin(); i != fServiceSubscriptions.end(); i++) … … 1962 2084 } 1963 2085 2086 void DataLogger::Setup(Configuration& conf) 2087 { 2088 //Set the block or allow list 2089 fGreyList.clear(); 2090 if (conf.Has("block")) 2091 { 2092 vector<string> vec = conf.Get<vector<string>>("block"); 2093 if (vec.size() != 0) 2094 { 2095 fIsBlackList = true; 2096 if (fDebugIsOn) 2097 Debug("Setting BLOCK list:"); 2098 } 2099 else if (conf.Has("allow")) 2100 { 2101 vec = conf.Get<vector<string>>("allow"); 2102 if (vec.size() != 0) 2103 { 2104 fIsBlackList = false; 2105 if (fDebugIsOn) 2106 Debug("Setting ALLOW list:"); 2107 } 2108 } 2109 for (vector<string>::iterator it=vec.begin(); it != vec.end(); it++) 2110 { 2111 fGreyList.insert(*it); 2112 if (fDebugIsOn) 2113 Debug(" " + *it); 2114 } 2115 } 2116 } 2117 /* 1964 2118 void DataLogger::setBlackWhiteList(const std::string& black, bool isBlack) 1965 2119 { … … 1980 2134 fIsBlackList = isBlack; 1981 2135 } 1982 2136 */ 1983 2137 // -------------------------------------------------------------------------- 1984 2138 … … 2022 2176 DataLogger logger(wout); 2023 2177 2024 if (conf.Has("black-list")) 2025 { if (conf.Get<std::string>("black-list") != "") 2026 logger.setBlackWhiteList(conf.Get<std::string>("black-list"), true); 2027 else if (conf.Has("white-list")) 2028 { 2029 if (conf.Get<std::string>("white-list") != "") 2030 logger.setBlackWhiteList(conf.Get<std::string>("white-list"), false); 2031 } 2032 } 2178 logger.Setup(conf); 2179 2033 2180 shell.SetReceiver(logger); 2034 2181 … … 2065 2212 "All actions are supposed to arrive as DimCommands. Using the -c " 2066 2213 "option, a local shell can be initialized. With h or help a short " 2067 "help message about the us uage can be brought to the screen.\n"2214 "help message about the usage can be brought to the screen.\n" 2068 2215 "\n" 2069 2216 "Usage: dataLogger [-c type] [OPTIONS]\n" … … 2077 2224 /* Additional help text which is printed after the configuration 2078 2225 options goes here */ 2226 cout << "\n" 2227 "The Block option has priority over the allow." 2228 " i.e. if both are present, only the block list is kept." 2229 "If only a server name or service without its server prefix is given " 2230 "then all the services of that server, or all the services that correspond to the given suffix" 2231 " are ignored or considered." 2232 "\n" 2233 "For example, block=DIS_DNS will skip all the services offered by the DIS_DNS server. " 2234 "while block=SERVICE_LIST will skip all the SERVICE_LIST services offered by any server." 2235 "\n" 2236 " The Commands offered by the dataLoger are the following: \n"; 2237 cout << DataLogger::fConfigDay << " specify the path where to put the nightly files\n"; 2238 cout << DataLogger::fConfigRun << " specify the path where to put the run files\n"; 2239 cout << DataLogger::fConfigRunNumber << " specify the run number\n"; 2240 cout << DataLogger::fConfigLog << " log a particular message\n"; 2241 cout << DataLogger::fTransStart << " start the nightly logging\n"; 2242 cout << DataLogger::fTransStop << " stop the nightly logging\n"; 2243 cout << DataLogger::fTransStartRun << " start the run logging\n"; 2244 cout << DataLogger::fTransStopRun << " stop the run logging\n"; 2245 cout << DataLogger::fTransReset << " stop any logging and/or recover from an error state\n"; 2246 cout << DataLogger::fTransWait << " go to the wait for run number state\n"; 2247 cout << DataLogger::fPrintCommand << " print the current state of the logger to the shell\n"; 2248 cout << DataLogger::fDebugOnOff << " turn on or off the debug mode\n"; 2249 cout << DataLogger::fStatsPeriod << " set the periodicity of the statistics. 0 disable them\n"; 2250 cout << endl; 2251 2079 2252 } 2080 2253 … … 2088 2261 ("log,l", var<string>(n), "Write log-file") 2089 2262 ("console,c", var<int>(), "Use console (0=shell, 1=simple buffered, X=simple unbuffered)") 2090 ("bl ack-list,b", var<string>(""), "Black-list of services")2091 (" white-list,w", var<string>(""), "White-list of services")2263 ("block,b", vars<string>(), "Black-list of services") 2264 ("allow,a", vars<string>(), "White-list of services") 2092 2265 ; 2093 2266
Note:
See TracChangeset
for help on using the changeset viewer.