Changeset 10990 for trunk/FACT++/src


Ignore:
Timestamp:
06/10/11 19:27:14 (13 years ago)
Author:
tbretz
Message:
Restructured some code; unified some functions; adapted some logging messages; removed the constants for the commands.
File:
1 edited

Legend:

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

    r10974 r10990  
    243243    ///boolean to know whether we should close and reopen daily files or not
    244244    bool fDailyFileDayChangedAlready;
    245 public:
    246     /***************************************************
    247      * STATIC COMMAND NAMES
    248      ***************************************************/
    249     ///Define all the static names
    250     static const char* fConfigDay;
    251     static const char* fConfigRun;
    252     static const char* fConfigRunNumber;
    253     static const char* fConfigLog;
    254     static const char* fTransStart;
    255     static const char* fTransStop;
    256     static const char* fTransStartRun;
    257     static const char* fTransStopRun;
    258     static const char* fTransReset;
    259     static const char* fTransWait;
    260     static const char* fRunNumberInfo; ///< This is the name of the dimInfo received to specify the run number. It must be updated once the final name will be defined
    261     static const char* fPrintCommand;
    262     static const char* fDebugOnOff;
    263     static const char* fStatsPeriod;
    264     static const char* fStartStopOpenedFiles;
    265     static const char* fStartStopNumSubsAndFits;
    266     static const char* fSetRunTimeOutDelay;
     245
    267246private:
    268247    /***************************************************
     
    277256    ///Reporting method for the services info received
    278257    void ReportPlease(DimInfo* I, SubscriptionType& sub); 
     258
     259    int ConfigureFileName(string &target, const string &type, const EventImp &evt);
    279260    ///Configuration of the nightly file path
    280261    int ConfigureNightlyFileName(const Event& evt);
     
    366347    ///creates a group fits file based on a list of files to be grouped
    367348    void CreateFitsGrouping(map<string, vector<string> >& filesToGroup, int runNumber);
     349
     350    bool OpenStream(shared_ptr<ofstream> stream, const string &filename);
    368351    ///Open the relevant text files related to a particular run
    369352    int OpenRunFile(RunNumberType& run);
     
    565548void DataLogger::CheckForOfstreamError(ofstream& out)
    566549{
    567     if (!out.good())
    568     {
    569         Error("An error occured while writing to a text file. Closing it");
    570         if (out.is_open())
    571             out.close();
    572         SetCurrentState(kSM_WriteError);
    573     }
     550    if (out.good())
     551        return;
     552
     553    Error("An error occured while writing to a text file. Closing it");
     554    if (out.is_open())
     555        out.close();
     556    SetCurrentState(kSM_WriteError);
    574557}
    575558// --------------------------------------------------------------------------
     
    858841}
    859842
    860 //static members initialization
    861 //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 ?
    862 const char* DataLogger::fConfigDay = "CONFIG_DAY";
    863 const char* DataLogger::fConfigRun = "CONFIG_RUN";
    864 const char* DataLogger::fConfigRunNumber = "CONFIG_RUN_NUMBER";
    865 const char* DataLogger::fConfigLog = "LOG";
    866 const char* DataLogger::fTransStart = "START";
    867 const char* DataLogger::fTransStop = "STOP";
    868 const char* DataLogger::fTransStartRun = "START_RUN";
    869 const char* DataLogger::fTransStopRun = "STOP_RUN";
    870 const char* DataLogger::fTransReset = "RESET";
    871 const char* DataLogger::fTransWait = "WAIT_RUN_NUMBER";
    872 const char* DataLogger::fRunNumberInfo = "RUN_NUMBER";
    873 const char* DataLogger::fPrintCommand = "PRINT";
    874 const char* DataLogger::fDebugOnOff = "DEBUG";
    875 const char* DataLogger::fStatsPeriod = "STATS_PERIOD";
    876 const char* DataLogger::fStartStopOpenedFiles = "OPENED_FILES_SRVC";
    877 const char* DataLogger::fStartStopNumSubsAndFits = "NUM_SUBS_SRVC";
    878 const char* DataLogger::fSetRunTimeOutDelay = "RUN_TIMEOUT";
    879 
    880843// --------------------------------------------------------------------------
    881844//
     
    944907    AddStateName(kSM_BadNightlyConfig, "ErrNightlyFolder", "The folder for the nighly summary files is invalid.");
    945908    AddStateName(kSM_BadRunConfig,     "ErrRunFolder",     "The folder for the run files is invalid.");
    946     AddStateName(kSM_WriteError, "ErrWrite", "An error occured while writing to a file.");
    947 
    948     /*Add the possible transitions for this machine*/
    949     AddEvent(kSM_NightlyOpen, fTransStart, kSM_Ready, kSM_BadNightlyConfig)
    950             (boost::bind(&DataLogger::StartPlease, this))
    951             ("Start the nightly logging. Nightly file location must be specified already");
    952 
    953     AddEvent(kSM_Ready, fTransStop, kSM_NightlyOpen, kSM_WaitingRun, kSM_Logging, kSM_WriteError)
    954             (boost::bind(&DataLogger::GoToReadyPlease, this))
    955             ("Stop all data logging, close all files.");
    956 
    957     AddEvent(kSM_Logging, fTransStartRun, kSM_WaitingRun, kSM_BadRunConfig)
    958             (boost::bind(&DataLogger::StartRunPlease, this))
    959             ("Start the run logging. Run file location must be specified already.");
    960 
    961     AddEvent(kSM_WaitingRun, fTransStopRun, kSM_Logging)
    962             (boost::bind(&DataLogger::StopRunPlease, this))
    963             ("Wait for a run to be started, open run-files as soon as a run number arrives.");
    964 
    965     AddEvent(kSM_Ready, fTransReset, kSM_Error, kSM_BadNightlyConfig, kSM_BadRunConfig, kSM_WriteError)
    966             (boost::bind(&DataLogger::GoToReadyPlease, this))
    967             ("Transition to exit error states. Closes the nightly file if already opened.");
    968 
    969     AddEvent(kSM_WaitingRun, fTransWait, kSM_NightlyOpen)
    970             (boost::bind(&DataLogger::NightlyToWaitRunPlease, this));
    971 
    972     /*Add the possible configurations for this machine*/
    973     AddEvent(fConfigDay, "C", kSM_Ready, kSM_BadNightlyConfig)
    974             (boost::bind(&DataLogger::ConfigureNightlyFileName, this, _1))
    975             ("Configure the folder for the nightly files."
    976              "|Path[string]:Absolute or relative path name where the nightly files should be stored.");
    977 
    978     AddEvent(fConfigRun, "C", kSM_Ready, kSM_BadNightlyConfig, kSM_NightlyOpen, kSM_WaitingRun, kSM_BadRunConfig)
    979             (boost::bind(&DataLogger::ConfigureRunFileName, this, _1))
    980             ("Configure the folder for the run files."
    981              "|Path[string]:Absolute or relative path name where the run files should be stored.");
    982 
    983     AddEvent(fConfigRunNumber, "X", kSM_Ready, kSM_NightlyOpen, kSM_WaitingRun, kSM_BadRunConfig, kSM_Logging)
    984             (boost::bind(&DataLogger::ConfigureRunNumber, this, _1))
    985             ("Configure the run number. Cannot be done in logging state");
    986 
    987      //Provide a print command
    988      ostringstream str;
    989      str <<     kSM_Ready << " " << kSM_NightlyOpen << " " << kSM_WaitingRun << " " << kSM_Logging << " " << kSM_BadNightlyConfig << " " << kSM_WriteError;
    990      str << " " << kSM_BadRunConfig;
    991      AddEvent(fPrintCommand, str.str().c_str(), "")
    992              (boost::bind(&DataLogger::PrintStatePlease, this, _1))
    993              ("Print information about the internal status of the data logger.");
     909    AddStateName(kSM_WriteError,       "ErrWrite",          "An error occured while writing to a file.");
     910
     911    // Add the possible transitions for this machine
     912    AddEvent(kSM_NightlyOpen, "START", kSM_Ready, kSM_BadNightlyConfig)
     913        (boost::bind(&DataLogger::StartPlease, this))
     914        ("Start the nightly logging. Nightly file location must be specified already");
     915
     916    AddEvent(kSM_Ready, "STOP", kSM_NightlyOpen, kSM_WaitingRun, kSM_Logging, kSM_WriteError)
     917        (boost::bind(&DataLogger::GoToReadyPlease, this))
     918        ("Stop all data logging, close all files.");
     919
     920    AddEvent(kSM_Logging, "START_RUN", kSM_WaitingRun, kSM_BadRunConfig)
     921        (boost::bind(&DataLogger::StartRunPlease, this))
     922        ("Start the run logging. Run file location must be specified already.");
     923
     924    AddEvent(kSM_WaitingRun, "STOP_RUN", kSM_Logging)
     925        (boost::bind(&DataLogger::StopRunPlease, this))
     926        ("Wait for a run to be started, open run-files as soon as a run number arrives.");
     927
     928    AddEvent(kSM_Ready, "RESET", kSM_Error, kSM_BadNightlyConfig, kSM_BadRunConfig, kSM_WriteError)
     929        (boost::bind(&DataLogger::GoToReadyPlease, this))
     930        ("Transition to exit error states. Closes the any open file.");
     931
     932    AddEvent(kSM_WaitingRun, "WAIT_FOR_RUN_NUMBER", kSM_NightlyOpen)
     933        (boost::bind(&DataLogger::NightlyToWaitRunPlease, this))
     934        ("Go to waiting for run number state. In this state with any received run-number a new file is opened.");
     935
     936    // Add the possible configurations for this machine
     937    AddEvent("SET_NIGHTLY_FOLDER", "C", kSM_Ready, kSM_BadNightlyConfig)
     938        (boost::bind(&DataLogger::ConfigureNightlyFileName, this, _1))
     939        ("Configure the base folder for the nightly files."
     940         "|Path[string]:Absolute or relative path name where the nightly files should be stored.");
     941
     942    AddEvent("SET_RUN_FOLDER", "C", kSM_Ready, kSM_BadNightlyConfig, kSM_NightlyOpen, kSM_WaitingRun, kSM_BadRunConfig)
     943        (boost::bind(&DataLogger::ConfigureRunFileName, this, _1))
     944        ("Configure the base folder for the run files."
     945         "|Path[string]:Absolute or relative path name where the run files should be stored.");
     946
     947    AddEvent("SET_RUN_NUMBER", "X", kSM_Ready, kSM_NightlyOpen, kSM_WaitingRun, kSM_BadRunConfig, kSM_Logging)
     948        (boost::bind(&DataLogger::ConfigureRunNumber, this, _1))
     949        ("Configure the run number. Cannot be done in logging state");
     950
     951     // Provide a print command
     952     AddEvent("PRINT")
     953            (boost::bind(&DataLogger::PrintStatePlease, this, _1))
     954            ("Print information about the internal status of the data logger.");
    994955
    995956     OpenFileToDim fToDim;
     
    1020981     fNumSubAndFitsIsOn = true;
    1021982
    1022      //provide services control commands
    1023      AddEvent(fDebugOnOff, "B:1", kSM_NightlyOpen, kSM_Logging, kSM_WaitingRun, kSM_Ready)
    1024              (boost::bind(&DataLogger::SetDebugOnOff, this, _1))
    1025              ("Switch debug mode on off. Debug mode prints ifnormation about every service written to a file."
    1026               "|Enable[bool]:Enable of disable debug mode (yes/no).");
    1027 
    1028      AddEvent(fStatsPeriod, "F", kSM_NightlyOpen, kSM_Logging, kSM_WaitingRun, kSM_Ready)
    1029              (boost::bind(&DataLogger::SetStatsPeriod, this, _1))
    1030              ("Interval in which the data-logger statistics service (STATS) is updated."
    1031               "Interval[s]:Floating point value in seconds.");
    1032 
    1033      AddEvent(fStartStopOpenedFiles, "B:1", kSM_NightlyOpen, kSM_Logging, kSM_WaitingRun, kSM_Ready)
    1034               (boost::bind(&DataLogger::SetOpenedFilesOnOff ,this, _1))
    1035               ("Switch off the service which distributes information about the open files.");
    1036 
    1037      AddEvent(fStartStopNumSubsAndFits, "B:1", kSM_NightlyOpen, kSM_Logging, kSM_WaitingRun, kSM_Ready)
    1038              (boost::bind(&DataLogger::SetNumSubsAndFitsOnOff, this, _1))
    1039              ("Switch off the service which distributes information about the number of subscriptions and open files.");
    1040 
    1041      AddEvent(fSetRunTimeOutDelay, "L:1", kSM_Ready, kSM_NightlyOpen, kSM_Logging, kSM_WaitingRun)
    1042              (boost::bind(&DataLogger::SetRunTimeoutDelay, this, _1))
    1043              ("Set the timeout delay for old run numbers.");
     983     // provide services control commands
     984     AddEvent("SET_DEUG_MODE", "B:1", kSM_NightlyOpen, kSM_Logging, kSM_WaitingRun, kSM_Ready)
     985         (boost::bind(&DataLogger::SetDebugOnOff, this, _1))
     986         ("Switch debug mode on or off. Debug mode prints ifnormation about every service written to a file."
     987          "|Enable[bool]:Enable of disable debug mode (yes/no).");
     988
     989     AddEvent("SET_STATISTICS_UPDATE_INTERVAL", "F", kSM_NightlyOpen, kSM_Logging, kSM_WaitingRun, kSM_Ready)
     990         (boost::bind(&DataLogger::SetStatsPeriod, this, _1))
     991         ("Interval in which the data-logger statistics service (STATS) is updated."
     992          "Interval[s]:Floating point value in seconds.");
     993
     994     AddEvent("ENABLE_FILENAME_SERVICES", "B:1", kSM_NightlyOpen, kSM_Logging, kSM_WaitingRun, kSM_Ready)
     995         (boost::bind(&DataLogger::SetOpenedFilesOnOff ,this, _1))
     996         ("Switch service which distributes information about the open files on or off."
     997          "|Enable[bool]:Enable of disable filename services (yes/no).");
     998
     999     AddEvent("ENABLE_NUMSUBS_SERVICE", "B:1", kSM_NightlyOpen, kSM_Logging, kSM_WaitingRun, kSM_Ready)
     1000         (boost::bind(&DataLogger::SetNumSubsAndFitsOnOff, this, _1))
     1001         ("Switch the service which distributes information about the number of subscriptions and open files on or off."
     1002          "|Enable[bool]:Enable of disable NUM_SUBS service (yes/no).");
     1003
     1004     AddEvent("SET_RUN_TIMEOUT", "L:1", kSM_Ready, kSM_NightlyOpen, kSM_Logging, kSM_WaitingRun)
     1005         (boost::bind(&DataLogger::SetRunTimeoutDelay, this, _1))
     1006         ("Set the timeout delay for old run numbers."
     1007          "|timeout[min]:Time out in minutes after which files for expired runs are closed.");
    10441008
    10451009     fDestructing = false;
     
    11971161        return;
    11981162
    1199     CheckForRunNumber(I);
     1163    // FIXME: Here we have to check if we have received the
     1164    //        service with the run-number.
     1165    //        CheckForRunNumber(I); has been removed because we have to
     1166    //        subscribe to this service anyway and hence we have the pointer
     1167    //        (no need to check for the name)
    12001168
    12011169    ReportPlease(I, y->second);
     
    12071175    TrimOldRunNumbers();
    12081176}
     1177
     1178bool DataLogger::OpenStream(shared_ptr<ofstream> stream, const string &filename)
     1179{
     1180    if (stream->is_open())
     1181    {
     1182        ostringstream str;
     1183        str << filename << " was already open when trying to open it.";
     1184        Error(str);
     1185        return false;
     1186    }
     1187
     1188    errno = 0;
     1189    stream->open(filename.c_str(), ios_base::out | ios_base::app);
     1190    if (errno != 0)
     1191    {
     1192        ostringstream str;
     1193        str << "Unable to open " << filename << ": " << strerror(errno) << " (errno=" << errno << ")";
     1194        Error(str);
     1195        return false;
     1196    }
     1197
     1198    if (!stream->is_open())
     1199    {
     1200        ostringstream str;
     1201        str << "File " << filename << " not open as it ought to be.";
     1202        Error(str);
     1203        return false;
     1204    }
     1205
     1206    return true;
     1207}
     1208
    12091209// --------------------------------------------------------------------------
    12101210//
     
    12151215{
    12161216#ifdef RUN_LOGS
    1217     if (run.logFile->is_open())
    1218     {
    1219         ostringstream str;
    1220         str << "Log file " << run.logName << " was already open when trying to open it in OpenRunFile";
    1221         Error(str);
     1217    // open log file
     1218    run.logName = CompileFileName(fRunFilePath, run.runNumber, "", "log");
     1219    if (!OpenStream(run.logFile, run.logName))
    12221220        return -1;
    1223     }
    1224     run.logName = CompileFileName(fRunFilePath, run.runNumber, "", "log");
    1225 
    1226     errno = 0;
    1227     run.logFile->open(run.logName.c_str(), ios_base::out | ios_base::app);
    1228     if (errno != 0)
    1229     {
    1230         ostringstream str;
    1231         str << "Unable to open log-file " << run.logName << ": " << strerror(errno) << " (errno=" << errno << ")";
    1232         Error(str);
    1233     }
    12341221#endif
    1235     //open report file
     1222
     1223    // open report file
    12361224    run.reportName = CompileFileName(fRunFilePath, run.runNumber, "", "rep");
    1237     if (run.reportFile->is_open())
    1238     {
    1239         ostringstream str;
    1240         str << "Report file " << run.reportName << " was already open when trying to open it in OpenRunFile";
    1241         Error(str);
     1225    if (!OpenStream(run.reportFile, run.reportName))
    12421226        return -1;
    1243     }
    1244 
    1245     errno = 0;
    1246     run.reportFile->open(run.reportName.c_str(), ios_base::out | ios_base::app);
    1247     if (errno != 0)
    1248     {
    1249         ostringstream str;
    1250         str << "Unable to open rep-file " << run.reportName << ": " << strerror(errno) << " (errno=" << errno << ")";
    1251         Error(str);
    1252     }
    1253 
    1254 #ifdef RUN_LOGS
    1255     if (!run.logFile->is_open() || !run.reportFile->is_open())
    1256 #else
    1257     if (!run.reportFile->is_open())
    1258 #endif
    1259     {
    1260         ostringstream str;
    1261         str << "Something went wrong while openning files ";
    1262 #ifdef RUN_LOGS
    1263         str << run.logName << " and ";
    1264 #endif
    1265         str << run.reportName;
    1266         Error(str);
    1267         return -1;
    1268     }
     1227
    12691228    //get the size of the newly opened file.
    12701229#ifdef RUN_LOGS
     
    13221281void DataLogger::CheckForRunNumber(DimInfo* I)
    13231282{
    1324     if (strstr(I->getName(), fRunNumberInfo) != NULL)
     1283    if (strstr(I->getName(), "SET_RUN_NUMBER") != NULL)
    13251284    {//assumes that the run number is an integer
    13261285        //check if some run number entries can be deleted leave one so that two remain after adding the new one
     
    14511410        catch (const runtime_error &e)
    14521411        {
    1453             Out() << kRed << e.what() << endl;
    14541412            ostringstream str;
    1455             str << "Could not properly parse the data for service " << sub.dimInfo->getName();
    1456             str << " reason: " << e.what() << ". Entry ignored";
     1413            str << "Parsing service " << sub.dimInfo->getName();
     1414            str << " failed: " << e.what();
    14571415            Error(str);
    14581416            return;
     
    14851443    else
    14861444    {//write entry to both Nightly and run logs
    1487         string n = I->getName();
    14881445        ostringstream msg;
    1489         msg << n << ": " << I->getString();
     1446        msg << I->getName() << ": " << I->getString();
    14901447
    14911448        if (fNightlyLogFile.is_open())
    14921449        {
    1493             MessageImp nightlyMess(fNightlyLogFile);
    1494             nightlyMess.Write(cTime, msg.str().c_str(), fQuality);
     1450            MessageImp(fNightlyLogFile).Write(cTime, msg.str().c_str(), fQuality);
    14951451            CheckForOfstreamError(fNightlyLogFile);
    14961452        }
    14971453        if (targetRunFile && targetRunFile->is_open())
    14981454        {
    1499             MessageImp runMess(*targetRunFile);
    1500             runMess.Write(cTime, msg.str().c_str(), fQuality);
     1455            MessageImp(*targetRunFile).Write(cTime, msg.str().c_str(), fQuality);
    15011456            CheckForOfstreamError(*targetRunFile);
    15021457        }
     
    16351590int DataLogger::SetDebugOnOff(const Event& evt)
    16361591{
    1637     bool backupDebug = fDebugIsOn;
     1592    const bool backupDebug = fDebugIsOn;
     1593
    16381594    fDebugIsOn = evt.GetBool();
     1595
    16391596    if (fDebugIsOn == backupDebug)
    1640         Warn("Warning: debug mode was already in the requested state");
    1641     else
    1642     {
    1643         ostringstream str;
    1644         str << "Debug mode is now " << fDebugIsOn;
    1645         Message(str);
    1646     }
     1597        Message("Debug mode was already in the requested state.");
     1598
     1599    ostringstream str;
     1600    str << "Debug mode is now " << fDebugIsOn;
     1601    Message(str);
     1602
    16471603    return GetCurrentState();
    16481604}
     
    16571613int DataLogger::SetStatsPeriod(const Event& evt)
    16581614{
    1659     float backupDuration = fStatsPeriodDuration;
     1615    const float backupDuration = fStatsPeriodDuration;
     1616
    16601617    fStatsPeriodDuration = evt.GetFloat();
     1618
    16611619    if (fStatsPeriodDuration < 0)
    16621620    {
     
    16671625    if (!finite(fStatsPeriodDuration))// != fStatsPeriodDuration)
    16681626    {
    1669         Error("Provided duration does not appear to be a valid float. discarding it.");
     1627        Error("Provided duration does not appear to be a valid float. Discarding it.");
    16701628        fStatsPeriodDuration = backupDuration;
    16711629        return GetCurrentState();   
    16721630    }
    16731631    if (backupDuration == fStatsPeriodDuration)
    1674         Warn("Warning: statistics period was not modified: supplied value already in use");
     1632        Warn("Statistics period not modified. Supplied value already in use.");
     1633
     1634    if (fStatsPeriodDuration == 0.0f)
     1635        Message("Statistics are now OFF");
    16751636    else
    16761637    {
    1677         if (fStatsPeriodDuration == 0.0f)
    1678             Message("Statistics are now OFF");
    1679         else
    1680         {
    1681             ostringstream str;
    1682             str << "Statistics period is now " << fStatsPeriodDuration << " seconds";
    1683             Message(str);
    1684         }   
    1685     }
     1638        ostringstream str;
     1639        str << "Statistics period is now " << fStatsPeriodDuration << " seconds";
     1640        Message(str);
     1641    }
     1642
    16861643    return GetCurrentState();
    16871644}
     
    16961653int DataLogger::SetOpenedFilesOnOff(const Event& evt)
    16971654{
    1698     bool backupOpened = fOpenedFilesIsOn;
     1655    const bool backupOpened = fOpenedFilesIsOn;
     1656
    16991657    fOpenedFilesIsOn = evt.GetBool();
     1658
    17001659    if (fOpenedFilesIsOn == backupOpened)
    1701         Warn("Warning: opened files service mode was already in the requested state");
    1702     else
    1703     {
    1704         ostringstream str;
    1705         str << "Opened files service mode is now " << fOpenedFilesIsOn;
    1706         Message(str);
    1707     }
     1660        Message("Opened files service mode was already in the requested state.");
     1661
     1662    ostringstream str;
     1663    str << "Opened files service mode is now " << fOpenedFilesIsOn;
     1664    Message(str);
     1665
    17081666    return GetCurrentState();
    1709    
    1710 }
     1667}
     1668
    17111669// --------------------------------------------------------------------------
    17121670//
     
    17201678{
    17211679    const bool backupSubs = fNumSubAndFitsIsOn;
     1680
    17221681    fNumSubAndFitsIsOn = evt.GetBool();
    17231682
    17241683    if (fNumSubAndFitsIsOn == backupSubs)
    1725         Warn("Warning: Number of subscriptions service mode was already in the requested state");
    1726     else
    1727     {
    1728         ostringstream str;
    1729         str << "Number of subscriptions service mode is now " << fNumSubAndFitsIsOn;
    1730         Message(str);
    1731     }
     1684        Message("Number of subscriptions service mode was already in the requested state");
     1685
     1686    ostringstream str;
     1687    str << "Number of subscriptions service mode is now " << fNumSubAndFitsIsOn;
     1688    Message(str);
     1689
    17321690    return GetCurrentState();
    17331691}
     
    17481706    {
    17491707        fRunNumberTimeout = backupTimeout;
    1750         Error("timeout delays for old run numbers must be greater than 0. Ignored.");
     1708        Error("Timeout delays for old run numbers must be greater than 0. Ignored.");
    17511709        return GetCurrentState();
    17521710    }
    17531711
    17541712    if (fRunNumberTimeout == backupTimeout)
    1755         Warn("Warning: given timeout for old run numbers is same value as previous one");
    1756     else
    1757     {
    1758         ostringstream str;
    1759         str  << "Timeout delay for old run numbers is now " << fRunNumberTimeout;
    1760         Message(str);
    1761     }
     1713        Message("New timeout for old run numbers is same value as previous one.");
     1714
     1715    ostringstream str;
     1716    str  << "Timeout delay for old run numbers is now " << fRunNumberTimeout;
     1717    Message(str);
     1718
    17621719    return GetCurrentState();
    17631720}
     1721
     1722int DataLogger::ConfigureFileName(string &target, const string &type, const EventImp &evt)
     1723{
     1724    if (!evt.GetText())
     1725    {
     1726        Error("Empty "+type+" folder given. Please specify a valid path.");
     1727        return GetCurrentState();
     1728    }
     1729
     1730    const string givenPath = evt.GetText();
     1731    if (!DoesPathExist(givenPath))
     1732    {
     1733        Error("Provided "+type+" path '"+givenPath+"' is not a valid folder. Ignored");
     1734        return GetCurrentState();
     1735    }
     1736
     1737    Message("New "+type+" folder specified: "+givenPath);
     1738
     1739    target = givenPath;
     1740
     1741    return GetCurrentState();
     1742}
     1743
    17641744// --------------------------------------------------------------------------
    17651745//
     
    17721752int DataLogger::ConfigureNightlyFileName(const Event& evt)
    17731753{
    1774     if (evt.GetText() != NULL)
    1775     {
    1776         string givenPath = string(evt.GetText());
    1777         if (!DoesPathExist(givenPath))
    1778         {
    1779             Error("Provided path is not a valid folder. Ignored");
    1780             return GetCurrentState();
    1781         }
    1782         fNightlyFilePath = givenPath;
    1783         Message("New Nightly folder specified: " + fNightlyFilePath);
    1784     }
    1785     else
    1786         Error("Empty Nightly folder given. Please specify a valid path.");
    1787 
    1788     return GetCurrentState();
    1789 }
     1754    return ConfigureFileName(fNightlyFilePath, "nightly", evt);
     1755}
     1756
    17901757// --------------------------------------------------------------------------
    17911758//
     
    17971764int DataLogger::ConfigureRunFileName(const Event& evt)
    17981765{
    1799     if (evt.GetText() == NULL)
    1800     {
    1801         Error("Empty Nightly folder given. Please specify a valid path");
    1802         return GetCurrentState();
    1803     }
    1804 
    1805     const string givenPath = string(evt.GetText());
    1806     if (!DoesPathExist(givenPath))
    1807     {
    1808         Error("Provided path is not a valid folder. Ignored");
    1809         return GetCurrentState();
    1810     }
    1811 
    1812     fRunFilePath = givenPath;
    1813     Message("New Run folder specified: " + fRunFilePath);
    1814 
    1815     return GetCurrentState();
    1816 }
     1766    return ConfigureFileName(fRunFilePath, "run", evt);
     1767}
     1768
    18171769// --------------------------------------------------------------------------
    18181770//
     
    18521804    if (name.size()+1 > FILENAME_MAX)
    18531805    {
    1854         Error("Provided file name '" + name + "' is longer than allowed file name length");
     1806        Error("Provided file name '" + name + "' is longer than allowed file name length.");
     1807        return;
    18551808    }
    18561809
     
    24352388    {
    24362389        const long timeout = conf.Get<long>("runtimeout");
    2437         if (timeout != 0)
    2438             fRunNumberTimeout = timeout;
    2439         else
     2390        if (timeout <= 0)
     2391        {
    24402392            Error("Time out delay for old run numbers should be greater than 0 minute");
     2393            return false;
     2394        }
     2395        fRunNumberTimeout = timeout;
    24412396    }
    24422397    return true;
     
    25472502        "SERVICE_LIST services offered by any server and DIS_DNS/SERVICE_LIST "
    25482503        "will skip DIS_DNS/SERVICE_LIST.\n"
    2549         "\n"
    2550         "The commands offered by the dataLoger are the following: \n";
    2551     cout << setw(20) << DataLogger::fConfigDay << " : specify the path where to put the nightly files\n";
    2552     cout << setw(20) << DataLogger::fConfigRun << " : specify the path where to put the run files\n";
    2553     cout << setw(20) << DataLogger::fConfigRunNumber << " : specify the run number\n";
    2554     cout << setw(20) << DataLogger::fConfigLog << " : log a particular message\n";
    2555     cout << setw(20) << DataLogger::fTransStart << " : start the nightly logging\n";
    2556     cout << setw(20) << DataLogger::fTransStop << " : stop the nightly logging\n";
    2557     cout << setw(20) << DataLogger::fTransStartRun << " : start the run logging\n";
    2558     cout << setw(20) << DataLogger::fTransStopRun << " : stop the run logging\n";
    2559     cout << setw(20) << DataLogger::fTransReset << " : stop any logging and/or recover from an error state\n";
    2560     cout << setw(20) << DataLogger::fTransWait << " : go to the wait for run number state\n";
    2561     cout << setw(20) << DataLogger::fPrintCommand << " : print the current state of the logger to the shell\n";
    2562     cout << setw(20) << DataLogger::fDebugOnOff << " : turn on or off the debug mode\n";
    2563     cout << setw(20) << DataLogger::fStatsPeriod << " : set the periodicity of the statistics. 0 disable them\n";
    2564     cout << endl;
    2565 }
     2504        << endl;
     2505}
     2506
    25662507// --------------------------------------------------------------------------
    25672508void SetupConfiguration(Configuration &conf)
Note: See TracChangeset for help on using the changeset viewer.