Changeset 11290 for trunk


Ignore:
Timestamp:
07/08/11 09:34:29 (13 years ago)
Author:
lyard
Message:
Moved the files statistics to a separate class and improved transitions
Location:
trunk/FACT++/src
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/Fits.cc

    r11283 r11290  
    347347//          fFile = NULL;
    348348            WriteSingleHeaderKey("TSTOP", fEndMjD, "Time of the last receied data");
    349 //          fFile->flush();
    350349            delete fFile;
    351350
  • trunk/FACT++/src/datalogger.cc

    r11270 r11290  
    3737  }
    3838  \enddot
     39
     40  For questions or bug report, please contact Etienne Lyard (etienne.lyard@unige.ch) or Thomas Bretz.
    3941 */
    4042 //****************************************************************
     
    6769#endif
    6870
     71#include "FilesStatisticsService.h"
     72
    6973//Dim structures
    7074///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//};
    7680///distributes the number of opened subscriptions and fits files
    7781struct NumSubAndFitsType {
     
    230234    string fFullNightlyReportFileName;
    231235    ///variable to track when the statistic were last calculated
    232     Time fPreviousStatsUpdateTime;
     236//    Time fPreviousStatsUpdateTime;
    233237    Time fPreviousOldRunNumberCheck;
    234238    ///boolean to know whether we should close and reopen daily files or not
    235239    bool fDailyFileDayChangedAlready;
    236 
     240    FilesStatisticsService fFilesStats;
    237241private:
    238242    /***************************************************
     
    269273    ///from NightlyOpen to waiting transition
    270274    int NightlyToWaitRunPlease();
     275    ///from wait for run number to nightly open
     276    int BackToNightlyOpenPlease();
    271277#ifdef HAVE_FITS
    272278    ///Open fits files
     
    285291    inline void NotifyOpenedFile(const string &name, int type, DimDescribedService* service);
    286292    ///variables for computing statistics
    287     DataLoggerStats fStatVar;
     293//    DataLoggerStats fStatVar;
    288294    ///stores the size of each file that is or was open
    289     map<string, long> fFileSizesMap;
     295//    map<string, long> fFileSizesMap;
    290296    ///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;
    294300    ///Service for opened files
    295301    DimDescribedService* fOpenedNightlyFiles;
    296302    DimDescribedService* fOpenedRunFiles;
    297303    DimDescribedService* fNumSubAndFits;
    298     DimDescribedService* fStatsMonitoring;
     304//    DimDescribedService* fStatsMonitoring;
    299305    NumSubAndFitsType fNumSubAndFitsData;
    300306    ///Small function for calculating the total size written so far
    301     bool calculateTotalSizeWritten(DataLoggerStats& statVar, bool isPrinting);
     307//    bool calculateTotalSizeWritten(DataLoggerStats& statVar, bool isPrinting);
    302308
    303309    /***************************************************
     
    362368//    string CheckIfDirIsDot(const string& dir);
    363369    ///Remembers the size of newly opened files. for statistic purposes
    364     bool RememberFileOrigSizePlease(string& fileName, bool nightly);
     370//    bool RememberFileOrigSizePlease(string& fileName, bool nightly);
    365371    ///Checks if the input osftream is in error state, and if so close it.
    366372    bool CheckForOfstreamError(ofstream& out, bool isDailyStream);
     
    371377    bool DoesPathExist(string path);
    372378    ///Check if the statistics service should be updated, and if so, do it
    373     void UpdateStatisticsService();
     379//    void UpdateStatisticsService();
    374380    ///Check if old run numbers can be trimmed, and if so, do it
    375381    void TrimOldRunNumbers();
     
    592598//! @param nightly whether this is a run or nightly file, so that its size is added to the correct member variable
    593599//
    594 bool DataLogger::RememberFileOrigSizePlease(string& fileName, bool nightly)
    595 {
     600//bool DataLogger::RememberFileOrigSizePlease(string& fileName, bool nightly)
     601//{
    596602    //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     else
    603         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//}
    607613
    608614// --------------------------------------------------------------------------
     
    820826//! @param isPrinting whether this function was called from the PRINT command or not. If so, displays relevant information
    821827//
     828/*
    822829bool DataLogger::calculateTotalSizeWritten(DataLoggerStats& statVar, bool isPrinting)
    823830{
     
    891898    return shouldWarn;
    892899}
    893 
     900*/
    894901// --------------------------------------------------------------------------
    895902//
     
    899906//!Setup the allows states, configs and transitions for the data logger
    900907//
    901 DataLogger::DataLogger(ostream &out) : StateMachineDim(out, "DATA_LOGGER")
     908DataLogger::DataLogger(ostream &out) : StateMachineDim(out, "DATA_LOGGER"),
     909                                       fFilesStats("DATA_LOGGER", this)
    902910{
    903911    //initialize member data
     
    935943        ("Transition to exit error states. Closes the any open file.");
    936944
    937     AddEvent(kSM_WaitingRun, "WAIT_FOR_RUN_NUMBER", kSM_NightlyOpen)
     945    AddEvent(kSM_WaitingRun, "WAIT_FOR_RUN_NUMBER", kSM_NightlyOpen, kSM_Ready)
    938946        (boost::bind(&DataLogger::NightlyToWaitRunPlease, this))
    939947        ("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.");
    940952
    941953    // Add the possible configurations for this machine
     
    10151027
    10161028     //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();
    10211033     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      else
    1028          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;
    10341046     fDailyFileDayChangedAlready = true;
    10351047     fRunNumberTimeout = 60; //default run-timeout set to 1 minute
     
    10661078    delete fOpenedRunFiles;
    10671079    delete fNumSubAndFits;
    1068     delete fStatsMonitoring;
     1080//    delete fStatsMonitoring;
    10691081
    10701082    if (fDebugIsOn)
     
    10771089//! checks if the statistic service should be updated, and if so, do it
    10781090//
    1079 void DataLogger::UpdateStatisticsService()
     1091/*void DataLogger::UpdateStatisticsService()
    10801092{
    10811093    //update the fits files sizes
     
    11041116        Debug(str);
    11051117    }
    1106 }
     1118}*/
    11071119// --------------------------------------------------------------------------
    11081120//
     
    11921204//    dim_unlock();
    11931205    //update the fits files sizes
    1194     UpdateStatisticsService();
     1206 //   UpdateStatisticsService();
    11951207
    11961208    //remove old run numbers
     
    12521264    //get the size of the newly opened file.
    12531265#ifdef RUN_LOGS
    1254     RememberFileOrigSizePlease(run.logName, false);
     1266    fFilesStats.FileOpened(run.logName);
     1267//    RememberFileOrigSizePlease(run.logName, false);
    12551268#endif
    1256     RememberFileOrigSizePlease(run.reportName, false);
    1257 
     1269//    RememberFileOrigSizePlease(run.reportName, false);
     1270    fFilesStats.FileOpened(run.reportName);
    12581271    //TODO this notification scheme might be messed up now.... fix it !
    12591272    const string baseFileName = CompileFileNameWithPath(fRunFilePath, run.runNumber, "", "");
     
    16021615    }
    16031616
    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
    16071626    Message("----------------- STATS ------------------");
    16081627    str.str("");
     
    19301949    }
    19311950    //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);
    19381959    //notify that a new file has been opened.
    19391960    const string baseFileName = CompileFileNameWithPath(fNightlyFilePath, "", "");
     
    19922013            AllocateFITSBuffers(sub);
    19932014        //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)
    19952017            fOpenedNightlyFits[fileNameOnly].push_back(serviceName);
    19962018
     
    20272049        }
    20282050        //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)
    20302053            cRunNumber->openedFits[fileNameOnly].push_back(serviceName);
    20312054        else
     
    24552478//
    24562479//! 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
     2483int 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
    24572501//! Does nothing really.
    24582502//!    @returns
    24592503//!        kSM_WaitingRun
    2460 int DataLogger::NightlyToWaitRunPlease()
     2504int DataLogger::BackToNightlyOpenPlease()
    24612505{
    24622506    if (fDebugIsOn)
    24632507    {
    2464         Debug("Going to Wait Run Number state...");   
    2465     }
    2466     return kSM_WaitingRun;   
     2508        Debug("Going to NightlyOpen state...");
     2509    }
     2510    return kSM_NightlyOpen;
    24672511}
    24682512// --------------------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.