Changeset 10971 for trunk/FACT++/src/dataLogger.cc
- Timestamp:
- 06/10/11 08:52:28 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/dataLogger.cc
r10968 r10971 221 221 ///run numbers 222 222 list<RunNumberType> fRunNumber; 223 ///old run numbers time-out delay (in minutes) 224 long fRunNumberTimeout; 223 225 ///previous run number. to check if changed while logging 224 226 int fPreviousRunNumber; … … 236 238 ///full name of the nightly report file 237 239 string fFullNightlyReportFileName; 238 ///variables for computing statistics239 DataLoggerStats fStatVar;240 240 ///variable to track when the statistic were last calculated 241 241 double fPreviousStatsUpdateTime; 242 242 double fPreviousOldRunNumberCheck; 243 ///mutex to make sure that the Stats are not accessed while updating244 mutex fStatsMutex;245 243 ///boolean to know whether we should close and reopen daily files or not 246 244 bool fDailyFileDayChangedAlready; … … 266 264 static const char* fStartStopOpenedFiles; 267 265 static const char* fStartStopNumSubsAndFits; 266 static const char* fSetRunTimeOutDelay; 268 267 private: 269 268 /*************************************************** … … 315 314 void ServicesMonitoring(); 316 315 inline void NotifyOpenedFile(const string &name, int type, DimDescribedService* service); 316 ///variables for computing statistics 317 DataLoggerStats fStatVar; 318 ///mutex to make sure that the Stats are not accessed while updating 319 // mutex fStatsMutex; 317 320 ///services notification thread 318 boost::thread fMonitoringThread;321 // boost::thread fMonitoringThread; 319 322 ///end of the monitoring 320 bool fContinueMonitoring;323 // bool fContinueMonitoring; 321 324 ///stores the size of each file that is or was open 322 325 map<string, long> fFileSizesMap; … … 329 332 DimDescribedService* fOpenedRunFiles; 330 333 DimDescribedService* fNumSubAndFits; 334 DimDescribedService* fStatsMonitoring; 331 335 NumSubAndFitsType fNumSubAndFitsData; 332 336 ///Small function for calculating the total size written so far … … 351 355 int SetOpenedFilesOnOff(const Event& evt); 352 356 int SetNumSubsAndFitsOnOff(const Event& evt); 357 int SetRunTimeoutDelay(const Event& evt); 353 358 354 359 ///boolean to prevent DIM update while desctructing the dataLogger … … 772 777 bool DataLogger::calculateTotalSizeWritten(DataLoggerStats& statVar, bool isPrinting) 773 778 { 774 if (!isPrinting) 775 fStatsMutex.lock(); 779 //mutex 780 // if (!isPrinting) 781 // fStatsMutex.lock(); 776 782 #ifdef HAVE_FITS 777 783 if (isPrinting) … … 841 847 statVar.sizeWritten -= fBaseSizeRun; 842 848 843 if (!isPrinting) 844 fStatsMutex.unlock(); 849 //mutex 850 // if (!isPrinting) 851 // fStatsMutex.unlock(); 845 852 846 853 return shouldWarn; … … 865 872 const char* DataLogger::fStartStopOpenedFiles = "OPENED_FILES_SRVC"; 866 873 const char* DataLogger::fStartStopNumSubsAndFits = "NUM_SUBS_SRVC"; 874 const char* DataLogger::fSetRunTimeOutDelay = "RUN_TIMEOUT"; 867 875 868 876 // -------------------------------------------------------------------------- … … 871 879 // 872 880 // 881 /* 873 882 void DataLogger::ServicesMonitoring() 874 883 { … … 911 920 } 912 921 } 913 922 */ 914 923 // -------------------------------------------------------------------------- 915 924 // … … 1015 1024 AddEvent(fStatsPeriod, "F", kSM_NightlyOpen, kSM_Logging, kSM_WaitingRun, kSM_Ready) 1016 1025 (boost::bind(&DataLogger::SetStatsPeriod, this, _1)) 1017 ("Interval in which the data-logger stati tistics service (STATS) is updated."1026 ("Interval in which the data-logger statistics service (STATS) is updated." 1018 1027 "Interval[s]:Floating point value in seconds."); 1019 1028 … … 1025 1034 (boost::bind(&DataLogger::SetNumSubsAndFitsOnOff, this, _1)) 1026 1035 ("Switch off the service which distributes information about the number of subscriptions and open files."); 1036 1037 AddEvent(fSetRunTimeOutDelay, "L:1", kSM_Ready, kSM_NightlyOpen, kSM_Logging, kSM_WaitingRun) 1038 (boost::bind(&DataLogger::SetRunTimeoutDelay, this, _1)) 1039 ("Set the timeout delay for old run numbers."); 1027 1040 1028 1041 fDestructing = false; … … 1034 1047 fPreviousStatsUpdateTime = Time().Mjd(); 1035 1048 fPreviousOldRunNumberCheck = Time().Mjd(); 1036 fContinueMonitoring = true; 1037 fMonitoringThread = boost::thread(boost::bind(&DataLogger::ServicesMonitoring, this)); 1049 fPreviousSize = 0; 1050 1051 struct statvfs vfs; 1052 if (!statvfs(fNightlyFilePath.c_str(), &vfs)) 1053 fStatVar.freeSpace = vfs.f_bsize*vfs.f_bavail; 1054 else 1055 fStatVar.freeSpace = -1; 1056 1057 fStatsMonitoring = new DimDescribedService(GetName() + "/STATS", "X:3", fStatVar, "Add description here"); 1058 1059 //mutex 1060 // fContinueMonitoring = true; 1061 // fMonitoringThread = boost::thread(boost::bind(&DataLogger::ServicesMonitoring, this)); 1038 1062 fBaseSizeNightly = 0; 1039 1063 fBaseSizeRun = 0; 1040 1064 fDailyFileDayChangedAlready = true; 1065 fRunNumberTimeout = 1; 1041 1066 if(fDebugIsOn) 1042 1067 { … … 1061 1086 fServiceSubscriptions.clear(); 1062 1087 //exit the monitoring loop 1063 fContinueMonitoring = false; 1064 1065 fMonitoringThread.join();1088 //mutex 1089 // fContinueMonitoring = false; 1090 // fMonitoringThread.join(); 1066 1091 //clear any remaining run number (should remain only one) 1067 1092 while (fRunNumber.size() > 0) … … 1136 1161 fPreviousSize = fStatVar.sizeWritten; 1137 1162 fPreviousStatsUpdateTime = cTime.Mjd(); 1138 } 1139 if ((cTime.Mjd() - fPreviousOldRunNumberCheck)*24*60*60 > 10.0) 1140 { 1141 while (fRunNumber.size() > 1 && (cTime - fRunNumber.back().time) > boost::posix_time::time_duration(0,0,10,0)) 1163 //update the service. No need to check if data has been written, because some must have been, otherwise we would not have hit this piece of code 1164 fStatsMonitoring->updateService(); 1165 1166 if(fDebugIsOn) 1167 { 1168 ostringstream str; 1169 str << "Size written: " << fStatVar.sizeWritten/1000 << " kB; writing rate: "; 1170 str << fStatVar.writingRate/1000 << " kB/s; free space: "; 1171 str << fStatVar.freeSpace/(1000*1000) << " MB"; 1172 Debug(str); 1173 } 1174 } 1175 if ((cTime.Mjd() - fPreviousOldRunNumberCheck)*24*60 >= fRunNumberTimeout) 1176 { 1177 while (fRunNumber.size() > 1 && (cTime - fRunNumber.back().time) > boost::posix_time::minutes(fRunNumberTimeout)) 1142 1178 { 1143 1179 RemoveOldestRunNumber(); … … 1487 1523 str << " <none>"; 1488 1524 Message(str); 1525 //timeout value 1526 str.str(""); 1527 str << "Timeout delay for old run numbers: " << fRunNumberTimeout << " minute(s)"; 1528 Message(str); 1489 1529 1490 1530 //print all the open files. … … 1663 1703 ostringstream str; 1664 1704 str << "Number of subscriptions service mode is now " << fNumSubAndFitsIsOn; 1705 Message(str); 1706 } 1707 return GetCurrentState(); 1708 } 1709 // -------------------------------------------------------------------------- 1710 // 1711 //! set the timeout delay for old run numbers 1712 //! @param evt 1713 //! the current event. contains the timeout delay long value 1714 //! @returns 1715 //! the new state. Which, in that case, is the current state 1716 //! 1717 int DataLogger::SetRunTimeoutDelay(const Event& evt) 1718 { 1719 const long backupTimeout = fRunNumberTimeout; 1720 fRunNumberTimeout = evt.GetXtra(); 1721 1722 if (fRunNumberTimeout == 0) 1723 { 1724 fRunNumberTimeout = backupTimeout; 1725 Error("timeout delays for old run numbers must be greater than 0. Ignored."); 1726 return GetCurrentState(); 1727 } 1728 1729 if (fRunNumberTimeout == backupTimeout) 1730 Warn("Warning: given timeout for old run numbers is same value as previous one"); 1731 else 1732 { 1733 ostringstream str; 1734 str << "Timeout delay for old run numbers is now " << fRunNumberTimeout; 1665 1735 Message(str); 1666 1736 } … … 2314 2384 fBlackList.insert("DIS_DNS/"); 2315 2385 2386 //set the black list 2316 2387 if (conf.Has("block")) 2317 2388 { … … 2321 2392 } 2322 2393 2394 //set the white list 2323 2395 if (conf.Has("allow")) 2324 2396 { … … 2332 2404 const vector<string> vec = conf.Get<vector<string>>("group"); 2333 2405 fGrouping.insert(vec.begin(), vec.end()); 2406 } 2407 2408 //set the old run numbers timeout delay 2409 if (conf.Has("runtimeout")) 2410 { 2411 const long timeout = conf.Get<long>("runtimeout"); 2412 if (timeout != 0) 2413 fRunNumberTimeout = timeout; 2414 else 2415 Error("Time out delay for old run numbers should be greater than 0 minute"); 2334 2416 } 2335 2417 return true; … … 2475 2557 ("debug", po_bool(), "Debug mode. Print clear text of received service reports to log-stream") 2476 2558 ("group,g", vars<string>(), "Grouping of services into a single run-Fits") 2559 ("runtimeout", var<long>(), "Time out delay for old run numbers") 2477 2560 ; 2478 2561
Note:
See TracChangeset
for help on using the changeset viewer.