Changeset 11308


Ignore:
Timestamp:
07/10/11 13:49:31 (13 years ago)
Author:
tbretz
Message:
Updated name and usage of new statistics class; adapted and fixed new program options; updated includes; changed run-timeout to milliseconds.
File:
1 edited

Legend:

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

    r11292 r11308  
    4242 //****************************************************************
    4343#include <unistd.h>      //for getting stat of opened files
    44 #include <sys/statvfs.h> //for getting disk free space
    45 #include <sys/stat.h>    //for getting files sizes
     44//#include <sys/statvfs.h> //for getting disk free space
     45//#include <sys/stat.h>    //for getting files sizes
    4646#include <fstream>
    4747
     
    5151#include "Dim.h"
    5252#include "Event.h"
    53 #include "Time.h"
    5453#include "StateMachineDim.h"
    55 #include "WindowLog.h"
    5654#include "Configuration.h"
    57 #include "ServiceList.h"
    5855#include "Converter.h"
    59 #include "MessageImp.h"
    60 #include "DimDescriptionService.h"
     56#include "DimWriteStatistics.h"
    6157
    6258#include "Description.h"
    63 
    64 //#include "DimServiceInfoList.h"
    6559#include "DimNetwork.h"
    6660
     
    6862#include "Fits.h"
    6963#endif
    70 
    71 #include "FilesStatisticsService.h"
    7264
    7365//Dim structures
     
    217209    list<RunNumberType> fRunNumber;
    218210    ///old run numbers time-out delay (in seconds)
    219     long fRunNumberTimeout;
     211    uint32_t fRunNumberTimeout;
    220212    ///previous run number. to check if changed while logging
    221213    int fPreviousRunNumber;
     
    238230    ///boolean to know whether we should close and reopen daily files or not
    239231    bool fDailyFileDayChangedAlready;
    240     FilesStatisticsService fFilesStats;
     232
     233    DimWriteStatistics fFilesStats;
    241234private:
    242235    /***************************************************
     
    907900//
    908901DataLogger::DataLogger(ostream &out) : StateMachineDim(out, "DATA_LOGGER"),
    909                                        fFilesStats("DATA_LOGGER", this)
     902                                       fFilesStats("DATA_LOGGER", *this)
    910903{
    911904    //initialize member data
     
    1004997          "|Enable[bool]:Enable of disable debug mode (yes/no).");
    1005998
    1006      AddEvent("SET_STATISTICS_UPDATE_INTERVAL", "F", kSM_NightlyOpen, kSM_Logging, kSM_WaitingRun, kSM_Ready)
     999     AddEvent("SET_STATISTICS_UPDATE_INTERVAL", "S:1", kSM_NightlyOpen, kSM_Logging, kSM_WaitingRun, kSM_Ready)
    10071000         (boost::bind(&DataLogger::SetStatsPeriod, this, _1))
    10081001         ("Interval in which the data-logger statistics service (STATS) is updated."
    1009           "|Interval[s]:Floating point value in seconds.");
     1002          "|Interval[ms]:Value in milliseconds (<=0: no update).");
    10101003
    10111004     AddEvent("ENABLE_FILENAME_SERVICES", "B:1", kSM_NightlyOpen, kSM_Logging, kSM_WaitingRun, kSM_Ready)
     
    11251118    const Time cTime = Time();
    11261119
    1127     if ((cTime - fPreviousOldRunNumberCheck).total_seconds() < fRunNumberTimeout)
     1120    if (cTime - fPreviousOldRunNumberCheck < boost::posix_time::milliseconds(fRunNumberTimeout))
    11281121        return;
    11291122
    1130     while (fRunNumber.size() > 1 && (cTime - fRunNumber.back().time) > boost::posix_time::seconds(fRunNumberTimeout))
     1123    while (fRunNumber.size() > 1 && (cTime - fRunNumber.back().time) > boost::posix_time::milliseconds(fRunNumberTimeout))
    11311124    {
    11321125         RemoveOldestRunNumber();
     
    15941587    //timeout value
    15951588    str.str("");
    1596     str << "Timeout delay for old run numbers: " << fRunNumberTimeout << " seconds";
     1589    str << "Timeout delay for old run numbers: " << fRunNumberTimeout << " ms";
    15971590    Message(str);
    15981591
     
    16151608    }
    16161609
    1617     FileStatisticsData statVar;
    1618     fFilesStats.GetTotalSizeWritten(statVar);
     1610    const DimWriteStatistics::Stats statVar = fFilesStats.GetTotalSizeWritten();
    16191611 //   /*const bool statWarning =*/ calculateTotalSizeWritten(statVar, true);
    16201612#ifdef HAVE_FITS
     
    17381730    }
    17391731*/
    1740     fFilesStats.SetStatPeriod(evt.GetFloat());
     1732    fFilesStats.SetUpdateInterval(evt.GetShort());
    17411733    return GetCurrentState();
    17421734}
     
    17981790int DataLogger::SetRunTimeoutDelay(const Event& evt)
    17991791{
    1800     const long backupTimeout = fRunNumberTimeout;
    1801     fRunNumberTimeout = evt.GetXtra();
    1802 
    1803     if (fRunNumberTimeout == 0)
    1804     {
    1805         fRunNumberTimeout = backupTimeout;
    1806         Error("Timeout delays for old run numbers must be greater than 0. Ignored.");
     1792    if (evt.GetUInt() == 0)
     1793    {
     1794        Error("Timeout delays for old run numbers must be greater than 0... ignored.");
    18071795        return GetCurrentState();
    18081796    }
    18091797
    1810     if (fRunNumberTimeout == backupTimeout)
     1798    if (fRunNumberTimeout == evt.GetUInt())
    18111799        Message("New timeout for old run numbers is same value as previous one.");
    18121800
     1801    fRunNumberTimeout = evt.GetUInt();
     1802
    18131803    ostringstream str;
    1814     str  << "Timeout delay for old run numbers is now " << fRunNumberTimeout << " seconds";
     1804    str  << "Timeout delay for old run numbers is now " << fRunNumberTimeout << " ms";
    18151805    Message(str);
    18161806
     
    19591949//    fBaseSizeRun = 0;
    19601950//    fPreviousSize = 0;
    1961     fFilesStats.Reset();
     1951//    fFilesStats.Reset();
    19621952    fFilesStats.FileOpened(fFullNightlyLogFileName);
    19631953    fFilesStats.FileOpened(fFullNightlyReportFileName);
     
    25382528    {
    25392529        const vector<string> vec = conf.Get<vector<string>>("block");
    2540 
    25412530        fBlackList.insert(vec.begin(), vec.end());
    25422531    }
     
    25572546
    25582547    //set the old run numbers timeout delay
    2559     if (conf.Has("runtimeout"))
    2560     {
    2561         const long timeout = conf.Get<long>("runtimeout");
    2562         if (timeout <= 0)
    2563         {
    2564             Error("Time out delay for old run numbers should be greater than 0 minute");
     2548    if (conf.Has("run-timeout"))
     2549    {
     2550        const uint32_t timeout = conf.Get<uint32_t>("run-timeout");
     2551        if (timeout == 0)
     2552        {
     2553            Error("Time out delay for old run numbers must not be 0.");
    25652554            return 1;
    25662555        }
     
    25692558
    25702559    //configure the run files directory
    2571     if (conf.Has("run_folder"))
     2560    if (conf.Has("destination-folder"))
    25722561     {
    2573          const string folder = conf.Get<string>("run_folder");
    2574          if (fFilesStats.SetCurrentFolder(folder))
    2575              fRunFilePath = folder;
    2576          else
    2577              Error("Folder " + folder + " given through configuration seems invalid. Ignoring it");
    2578     }
    2579 
    2580     //configure the nightly files directory
    2581     if (conf.Has("nightly_folder"))
    2582     {
    2583         const string folder = conf.Get<string>("nightly_folder");
    2584         if (fFilesStats.SetCurrentFolder(folder))
    2585             fNightlyFilePath = folder;
    2586         else
    2587             Error("Folder " + folder + " given through configuration seems invalid. Ignoring it");
    2588     }
    2589 
    2590     //check if we have overwritten badly the directory being watched for free space
    2591     if (conf.Has("run_folder") && !conf.Has("nightly_folder"))
    2592     {//we've set the run folder for free space. we've decided it should be the nightly one. thus override it
    2593         fFilesStats.SetCurrentFolder(fNightlyFilePath);
     2562         const string folder = conf.Get<string>("destination-folder");
     2563         if (!fFilesStats.SetCurrentFolder(folder))
     2564             return 2;
     2565
     2566         fRunFilePath     = folder;
     2567         fNightlyFilePath = folder;
    25942568    }
    25952569
    25962570    //configure the interval between statistics updates
    2597     if (conf.Has("stats_interval"))
    2598     {
    2599         const float interval = conf.Get<float>("stats_interval");
    2600         fFilesStats.SetStatPeriod(interval);
    2601     }
     2571    if (conf.Has("stats-interval"))
     2572        fFilesStats.SetUpdateInterval(conf.Get<int16_t>("stats-interval"));
    26022573
    26032574    //configure if the filenames service is on or off
    2604     if (conf.Has("filename_service"))
    2605     {
    2606         fOpenedFilesIsOn = conf.Get<bool>("filename_service");
    2607     }
     2575    fOpenedFilesIsOn = !conf.Get<bool>("no-filename-service");
    26082576
    26092577    //configure if the number of subscriptions and fits files is on or off.
    2610     if (conf.Has("numsubs_service"))
    2611     {
    2612         fNumSubAndFitsIsOn = conf.Get<bool>("numsubs_service");
    2613     }
     2578    fNumSubAndFitsIsOn = !conf.Get<bool>("no-numsubs-service");
    26142579
    26152580    return -1;
     
    27692734    po::options_description configs("DataLogger options");
    27702735    configs.add_options()
    2771         ("block,b", vars<string>(), "Black-list of services")
    2772         ("allow,a", vars<string>(), "White-list of services")
    2773         ("debug",   po_bool(),      "Debug mode. Print clear text of received service reports to log-stream")
    2774         ("group,g", vars<string>(), "Grouping of services into a single run-Fits")
    2775         ("runtimeout", var<long>(), "Time out delay for old run numbers")
    2776         ("nightly_folder", var<string>(), "Base path for the nightly files")
    2777         ("run_folder", var<string>(), "Base path for the run files")
    2778         ("stats_interval", var<float>(), "Interval in seconds between two files statistics update")
    2779         ("filename_service", po_bool(), "Should the filename service be enabled?")
    2780         ("numsubs_service", po_bool(), "Should the number of subscriptions service be enabled?")
     2736        ("block,b",             vars<string>(),  "Black-list of services")
     2737        ("allow,a",             vars<string>(),  "White-list of services")
     2738        ("debug",               po_bool(),       "Debug mode. Print clear text of received service reports to log-stream")
     2739        ("group,g",             vars<string>(),  "Grouping of services into a single run-Fits")
     2740        ("run-timeout",         var<uint32_t>(), "Time out delay for old run numbers in milliseconds")
     2741        ("destination-folder",  var<string>(),   "Base path for the nightly files")
     2742        ("stats-interval",      var<int16_t>(),  "Interval in seconds between two files statistics update")
     2743        ("no-filename-service", po_bool(),       "Should the filename service be enabled?")
     2744        ("no-numsubs-service",  po_bool(),       "Should the number of subscriptions service be enabled?")
    27812745        ;
    27822746
Note: See TracChangeset for help on using the changeset viewer.