- Timestamp:
- 07/08/11 09:34:29 (13 years ago)
- Location:
- trunk/FACT++/src
- Files:
-
- 2 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/Fits.cc
r11283 r11290 347 347 // fFile = NULL; 348 348 WriteSingleHeaderKey("TSTOP", fEndMjD, "Time of the last receied data"); 349 // fFile->flush();350 349 delete fFile; 351 350 -
trunk/FACT++/src/datalogger.cc
r11270 r11290 37 37 } 38 38 \enddot 39 40 For questions or bug report, please contact Etienne Lyard (etienne.lyard@unige.ch) or Thomas Bretz. 39 41 */ 40 42 //**************************************************************** … … 67 69 #endif 68 70 71 #include "FilesStatisticsService.h" 72 69 73 //Dim structures 70 74 ///Distributes the writing statistics 71 struct DataLoggerStats {72 long sizeWritten;73 long freeSpace;74 long writingRate;75 };75 //struct DataLoggerStats { 76 // long sizeWritten; 77 // long freeSpace; 78 // long writingRate; 79 //}; 76 80 ///distributes the number of opened subscriptions and fits files 77 81 struct NumSubAndFitsType { … … 230 234 string fFullNightlyReportFileName; 231 235 ///variable to track when the statistic were last calculated 232 Time fPreviousStatsUpdateTime;236 // Time fPreviousStatsUpdateTime; 233 237 Time fPreviousOldRunNumberCheck; 234 238 ///boolean to know whether we should close and reopen daily files or not 235 239 bool fDailyFileDayChangedAlready; 236 240 FilesStatisticsService fFilesStats; 237 241 private: 238 242 /*************************************************** … … 269 273 ///from NightlyOpen to waiting transition 270 274 int NightlyToWaitRunPlease(); 275 ///from wait for run number to nightly open 276 int BackToNightlyOpenPlease(); 271 277 #ifdef HAVE_FITS 272 278 ///Open fits files … … 285 291 inline void NotifyOpenedFile(const string &name, int type, DimDescribedService* service); 286 292 ///variables for computing statistics 287 DataLoggerStats fStatVar;293 // DataLoggerStats fStatVar; 288 294 ///stores the size of each file that is or was open 289 map<string, long> fFileSizesMap;295 // map<string, long> fFileSizesMap; 290 296 ///total size of the opened files BEFORE they were opened by the logger 291 long fBaseSizeNightly;292 long fPreviousSize;293 long fBaseSizeRun;297 // long fBaseSizeNightly; 298 // long fPreviousSize; 299 // long fBaseSizeRun; 294 300 ///Service for opened files 295 301 DimDescribedService* fOpenedNightlyFiles; 296 302 DimDescribedService* fOpenedRunFiles; 297 303 DimDescribedService* fNumSubAndFits; 298 DimDescribedService* fStatsMonitoring;304 // DimDescribedService* fStatsMonitoring; 299 305 NumSubAndFitsType fNumSubAndFitsData; 300 306 ///Small function for calculating the total size written so far 301 bool calculateTotalSizeWritten(DataLoggerStats& statVar, bool isPrinting);307 // bool calculateTotalSizeWritten(DataLoggerStats& statVar, bool isPrinting); 302 308 303 309 /*************************************************** … … 362 368 // string CheckIfDirIsDot(const string& dir); 363 369 ///Remembers the size of newly opened files. for statistic purposes 364 bool RememberFileOrigSizePlease(string& fileName, bool nightly);370 // bool RememberFileOrigSizePlease(string& fileName, bool nightly); 365 371 ///Checks if the input osftream is in error state, and if so close it. 366 372 bool CheckForOfstreamError(ofstream& out, bool isDailyStream); … … 371 377 bool DoesPathExist(string path); 372 378 ///Check if the statistics service should be updated, and if so, do it 373 void UpdateStatisticsService();379 // void UpdateStatisticsService(); 374 380 ///Check if old run numbers can be trimmed, and if so, do it 375 381 void TrimOldRunNumbers(); … … 592 598 //! @param nightly whether this is a run or nightly file, so that its size is added to the correct member variable 593 599 // 594 bool DataLogger::RememberFileOrigSizePlease(string& fileName, bool nightly)595 {600 //bool DataLogger::RememberFileOrigSizePlease(string& fileName, bool nightly) 601 //{ 596 602 //get the size of the file we're about to open 597 if (fFileSizesMap.find(fileName) != fFileSizesMap.end())598 return false;599 600 if (nightly)601 fBaseSizeNightly += GetFileSize(fileName);602 else603 fBaseSizeRun += GetFileSize(fileName);604 fFileSizesMap[fileName] = 0;605 return true; 606 }603 // if (fFileSizesMap.find(fileName) != fFileSizesMap.end()) 604 // return false; 605 606 // if (nightly) 607 // fBaseSizeNightly += GetFileSize(fileName); 608 // else 609 // fBaseSizeRun += GetFileSize(fileName); 610 // fFileSizesMap[fileName] = 0; 611 // return true;// 612 //} 607 613 608 614 // -------------------------------------------------------------------------- … … 820 826 //! @param isPrinting whether this function was called from the PRINT command or not. If so, displays relevant information 821 827 // 828 /* 822 829 bool DataLogger::calculateTotalSizeWritten(DataLoggerStats& statVar, bool isPrinting) 823 830 { … … 891 898 return shouldWarn; 892 899 } 893 900 */ 894 901 // -------------------------------------------------------------------------- 895 902 // … … 899 906 //!Setup the allows states, configs and transitions for the data logger 900 907 // 901 DataLogger::DataLogger(ostream &out) : StateMachineDim(out, "DATA_LOGGER") 908 DataLogger::DataLogger(ostream &out) : StateMachineDim(out, "DATA_LOGGER"), 909 fFilesStats("DATA_LOGGER", this) 902 910 { 903 911 //initialize member data … … 935 943 ("Transition to exit error states. Closes the any open file."); 936 944 937 AddEvent(kSM_WaitingRun, "WAIT_FOR_RUN_NUMBER", kSM_NightlyOpen )945 AddEvent(kSM_WaitingRun, "WAIT_FOR_RUN_NUMBER", kSM_NightlyOpen, kSM_Ready) 938 946 (boost::bind(&DataLogger::NightlyToWaitRunPlease, this)) 939 947 ("Go to waiting for run number state. In this state with any received run-number a new file is opened."); 948 949 AddEvent(kSM_NightlyOpen, "BACK_TO_NIGHTLY_OPEN", kSM_WaitingRun) 950 (boost::bind(&DataLogger::BackToNightlyOpenPlease, this)) 951 ("Go from the wait for run to nightly open state."); 940 952 941 953 // Add the possible configurations for this machine … … 1015 1027 1016 1028 //start the monitoring service 1017 fStatVar.sizeWritten = 0;1018 fStatVar.freeSpace = 0;1019 fStatVar.writingRate = 0;1020 fPreviousStatsUpdateTime = Time().Mjd();1029 // fStatVar.sizeWritten = 0; 1030 // fStatVar.freeSpace = 0; 1031 // fStatVar.writingRate = 0; 1032 // fPreviousStatsUpdateTime = Time().Mjd(); 1021 1033 fPreviousOldRunNumberCheck = Time().Mjd(); 1022 fPreviousSize = 0;1023 1024 struct statvfs vfs;1025 if (!statvfs(fNightlyFilePath.c_str(), &vfs))1026 fStatVar.freeSpace = vfs.f_bsize*vfs.f_bavail;1027 else1028 fStatVar.freeSpace = -1;1029 1030 fStatsMonitoring = new DimDescribedService(GetName() + "/STATS", "X:3", fStatVar, "Add description here");1031 1032 fBaseSizeNightly = 0;1033 fBaseSizeRun = 0;1034 // fPreviousSize = 0; 1035 1036 // struct statvfs vfs; 1037 // if (!statvfs(fNightlyFilePath.c_str(), &vfs)) 1038 // fStatVar.freeSpace = vfs.f_bsize*vfs.f_bavail; 1039 // else 1040 // fStatVar.freeSpace = -1; 1041 1042 // fStatsMonitoring = new DimDescribedService(GetName() + "/STATS", "X:3", fStatVar, "Add description here"); 1043 1044 // fBaseSizeNightly = 0; 1045 // fBaseSizeRun = 0; 1034 1046 fDailyFileDayChangedAlready = true; 1035 1047 fRunNumberTimeout = 60; //default run-timeout set to 1 minute … … 1066 1078 delete fOpenedRunFiles; 1067 1079 delete fNumSubAndFits; 1068 delete fStatsMonitoring;1080 // delete fStatsMonitoring; 1069 1081 1070 1082 if (fDebugIsOn) … … 1077 1089 //! checks if the statistic service should be updated, and if so, do it 1078 1090 // 1079 void DataLogger::UpdateStatisticsService()1091 /*void DataLogger::UpdateStatisticsService() 1080 1092 { 1081 1093 //update the fits files sizes … … 1104 1116 Debug(str); 1105 1117 } 1106 } 1118 }*/ 1107 1119 // -------------------------------------------------------------------------- 1108 1120 // … … 1192 1204 // dim_unlock(); 1193 1205 //update the fits files sizes 1194 UpdateStatisticsService();1206 // UpdateStatisticsService(); 1195 1207 1196 1208 //remove old run numbers … … 1252 1264 //get the size of the newly opened file. 1253 1265 #ifdef RUN_LOGS 1254 RememberFileOrigSizePlease(run.logName, false); 1266 fFilesStats.FileOpened(run.logName); 1267 // RememberFileOrigSizePlease(run.logName, false); 1255 1268 #endif 1256 RememberFileOrigSizePlease(run.reportName, false);1257 1269 // RememberFileOrigSizePlease(run.reportName, false); 1270 fFilesStats.FileOpened(run.reportName); 1258 1271 //TODO this notification scheme might be messed up now.... fix it ! 1259 1272 const string baseFileName = CompileFileNameWithPath(fRunFilePath, run.runNumber, "", ""); … … 1602 1615 } 1603 1616 1604 DataLoggerStats statVar; 1605 /*const bool statWarning =*/ calculateTotalSizeWritten(statVar, true); 1606 1617 FileStatisticsData statVar; 1618 fFilesStats.GetTotalSizeWritten(statVar); 1619 // /*const bool statWarning =*/ calculateTotalSizeWritten(statVar, true); 1620 #ifdef HAVE_FITS 1621 str << "There are " << fNumSubAndFitsData.numOpenFits << " FITS files open:"; 1622 Message(str); 1623 #else 1624 Message("FITS output disabled at compilation"); 1625 #endif 1607 1626 Message("----------------- STATS ------------------"); 1608 1627 str.str(""); … … 1930 1949 } 1931 1950 //get the size of the newly opened file. 1932 fBaseSizeNightly = GetFileSize(fFullNightlyLogFileName); 1933 fBaseSizeNightly += GetFileSize(fFullNightlyReportFileName); 1934 fFileSizesMap.clear(); 1935 fBaseSizeRun = 0; 1936 fPreviousSize = 0; 1937 1951 // fBaseSizeNightly = GetFileSize(fFullNightlyLogFileName); 1952 // fBaseSizeNightly += GetFileSize(fFullNightlyReportFileName); 1953 // fFileSizesMap.clear(); 1954 // fBaseSizeRun = 0; 1955 // fPreviousSize = 0; 1956 fFilesStats.Reset(); 1957 fFilesStats.FileOpened(fFullNightlyLogFileName); 1958 fFilesStats.FileOpened(fFullNightlyReportFileName); 1938 1959 //notify that a new file has been opened. 1939 1960 const string baseFileName = CompileFileNameWithPath(fNightlyFilePath, "", ""); … … 1992 2013 AllocateFITSBuffers(sub); 1993 2014 //get the size of the file we're about to open 1994 if (RememberFileOrigSizePlease(partialName, true))//and remember that the file was opened (i.e. not an update) 2015 if (fFilesStats.FileOpened(partialName)) 2016 // if (RememberFileOrigSizePlease(partialName, true))//and remember that the file was opened (i.e. not an update) 1995 2017 fOpenedNightlyFits[fileNameOnly].push_back(serviceName); 1996 2018 … … 2027 2049 } 2028 2050 //get the size of the file we're about to open 2029 if (RememberFileOrigSizePlease(partialName, false))//and remember that the file was opened (i.e. not an update) 2051 if (fFilesStats.FileOpened(partialName)) 2052 // if (RememberFileOrigSizePlease(partialName, false))//and remember that the file was opened (i.e. not an update) 2030 2053 cRunNumber->openedFits[fileNameOnly].push_back(serviceName); 2031 2054 else … … 2455 2478 // 2456 2479 //! Implements the transition towards kSM_WaitingRun 2480 //! If current state is kSM_Ready, then tries to go to nightlyOpen state first. 2481 //! @returns 2482 //! kSM_WaitingRun or kSM_badNightlyConfig 2483 int DataLogger::NightlyToWaitRunPlease() 2484 { 2485 int cState = GetCurrentState(); 2486 if (cState == kSM_Ready) 2487 cState = StartPlease(); 2488 2489 if (cState != kSM_NightlyOpen) 2490 return GetCurrentState(); 2491 2492 if (fDebugIsOn) 2493 { 2494 Debug("Going to Wait Run Number state..."); 2495 } 2496 return kSM_WaitingRun; 2497 } 2498 // -------------------------------------------------------------------------- 2499 // 2500 //! Implements the transition from wait for run number to nightly open 2457 2501 //! Does nothing really. 2458 2502 //! @returns 2459 2503 //! kSM_WaitingRun 2460 int DataLogger:: NightlyToWaitRunPlease()2504 int DataLogger::BackToNightlyOpenPlease() 2461 2505 { 2462 2506 if (fDebugIsOn) 2463 2507 { 2464 Debug("Going to Wait Run Number state...");2465 } 2466 return kSM_ WaitingRun;2508 Debug("Going to NightlyOpen state..."); 2509 } 2510 return kSM_NightlyOpen; 2467 2511 } 2468 2512 // --------------------------------------------------------------------------
Note:
See TracChangeset
for help on using the changeset viewer.