Ignore:
Timestamp:
06/09/11 17:13:03 (13 years ago)
Author:
lyard
Message:
added WriteError state
File:
1 edited

Legend:

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

    r10954 r10955  
    199199        kSM_BadNightlyConfig = 0x101, ///< the folder specified for Nightly logging does not exist or has bad permissions
    200200        kSM_BadRunConfig = 0x102, ///<  the folder specified for the run logging does not exist or has wrong permissions or no run number
     201        kSM_WriteError = 0x103, ///< Denotes that an error occured while writing a file (text or fits).
    201202    } localstates_t;
    202203   
     
    297298    ///from NightlyOpen to waiting transition
    298299    int NightlyToWaitRunPlease();
     300    /// from writing to error
     301    std::string SetCurrentState(int state, const char *txt="", const std::string &cmd="");
    299302#ifdef HAVE_FITS
    300303    ///Open fits files
     
    560563        if (out.is_open())
    561564            out.close();
     565        SetCurrentState(kSM_WriteError);
    562566    }
    563567}
     
    928932    AddStateName(kSM_BadNightlyConfig, "ErrNightlyFolder", "The folder for the nighly summary files is invalid.");
    929933    AddStateName(kSM_BadRunConfig,     "ErrRunFolder",     "The folder for the run files is invalid.");
     934    AddStateName(kSM_WriteError, "ErrWrite", "An error occured while writing to a file.");
    930935
    931936    /*Add the possible transitions for this machine*/
     
    934939            ("Start the nightly logging. Nightly file location must be specified already");
    935940
    936     AddEvent(kSM_Ready, fTransStop, kSM_NightlyOpen, kSM_WaitingRun, kSM_Logging)
     941    AddEvent(kSM_Ready, fTransStop, kSM_NightlyOpen, kSM_WaitingRun, kSM_Logging, kSM_WriteError)
    937942            (boost::bind(&DataLogger::GoToReadyPlease, this))
    938943            ("Stop all data logging, close all files.");
     
    946951            ("Wait for a run to be started, open run-files as soon as a run number arrives.");
    947952
    948     AddEvent(kSM_Ready, fTransReset, kSM_Error, kSM_BadNightlyConfig, kSM_BadRunConfig, kSM_Error)
     953    AddEvent(kSM_Ready, fTransReset, kSM_Error, kSM_BadNightlyConfig, kSM_BadRunConfig, kSM_WriteError)
    949954            (boost::bind(&DataLogger::GoToReadyPlease, this))
    950955            ("Transition to exit error states. Closes the nightly file if already opened.");
     
    970975     //Provide a print command
    971976     ostringstream str;
    972      str <<     kSM_Ready << " " << kSM_NightlyOpen << " " << kSM_WaitingRun << " " << kSM_Logging << " " << kSM_BadNightlyConfig;
     977     str <<     kSM_Ready << " " << kSM_NightlyOpen << " " << kSM_WaitingRun << " " << kSM_Logging << " " << kSM_BadNightlyConfig << " " << kSM_WriteError;
    973978     str << " " << kSM_BadRunConfig;
    974979     AddEvent(fPrintCommand, str.str().c_str(), "")
     
    13091314
    13101315    //create the converter for that service
    1311     if (sub.fConv && isItaReport)
     1316    if ((!sub.fConv.get()) && isItaReport)
    13121317    {
    13131318        //trick the converter in case of 'C'. why do I do this ? well simple: the converter checks that the right number
     
    18511856            fOpenedNightlyFits[fileNameOnly].push_back(serviceName);
    18521857
    1853         sub.nightlyFile.Open(partialName, serviceName, NULL, &fNumSubAndFitsData.numOpenFits, this, 0);//Out());
    1854 
     1858        if (!sub.nightlyFile.Open(partialName, serviceName, NULL, &fNumSubAndFitsData.numOpenFits, this, 0))
     1859        {
     1860            SetCurrentState(kSM_WriteError);
     1861            return;
     1862        }
    18551863        //notify the opening
    18561864        string baseFileName = CompileFileName(fNightlyFilePath, "", "");
     
    18891897            }
    18901898
    1891         if (hasGrouping && cRunNumber->runFitsFile)
     1899        if (hasGrouping && (!cRunNumber->runFitsFile.get()))
    18921900            try
    18931901            {
     
    19061914        NotifyOpenedFile(baseFileName, 7, fOpenedRunFiles);// + '_' + serviceName, 4);
    19071915        if (hasGrouping)
    1908             sub.runFile.Open(partialName, serviceName, (cRunNumber->runFitsFile).get(), &fNumSubAndFitsData.numOpenFits, this, sub.runNumber);//Out());
     1916        {
     1917            if (!sub.runFile.Open(partialName, serviceName, (cRunNumber->runFitsFile).get(), &fNumSubAndFitsData.numOpenFits, this, sub.runNumber))
     1918            {
     1919                SetCurrentState(kSM_WriteError);
     1920                return;
     1921            }
     1922        }
    19091923        else
    1910             sub.runFile.Open(partialName, serviceName, NULL, &fNumSubAndFitsData.numOpenFits, this, sub.runNumber);//Out());
    1911 
     1924        {
     1925            if (sub.runFile.Open(partialName, serviceName, NULL, &fNumSubAndFitsData.numOpenFits, this, sub.runNumber))
     1926            {
     1927                SetCurrentState(kSM_WriteError);
     1928                return;
     1929            }
     1930        }
    19121931       if (fNumSubAndFitsIsOn)
    19131932           fNumSubAndFits->updateService();
     
    20102029        if (sub.nightlyFile.IsOpen())
    20112030        {
    2012             sub.nightlyFile.Write(sub.fConv.get());
    2013             if (fDebugIsOn)
    2014             {
    2015                 Debug("Writing to nightly FITS " + sub.nightlyFile.fFileName);
    2016             }
    2017         }
     2031            if (!sub.nightlyFile.Write(sub.fConv.get()))
     2032                SetCurrentState(kSM_WriteError);
     2033         }
    20182034        if (sub.runFile.IsOpen())
    20192035        {
    2020             sub.runFile.Write(sub.fConv.get());
    2021             if (fDebugIsOn)
    2022             {
    2023                 Debug("Writing to Run FITS " + sub.runFile.fFileName);   
    2024             }
     2036            if (!sub.runFile.Write(sub.fConv.get()))
     2037                SetCurrentState(kSM_WriteError);
    20252038        }
    20262039}
    20272040#endif //if has_fits
     2041
     2042std::string DataLogger::SetCurrentState(int state, const char *txt, const std::string &cmd)
     2043{
     2044    if (state == kSM_WriteError && GetCurrentState() == kSM_WriteError)
     2045        return "";
     2046    return StateMachineImp::SetCurrentState(state, txt, cmd);
     2047}
    20282048// --------------------------------------------------------------------------
    20292049//
Note: See TracChangeset for help on using the changeset viewer.