Changeset 10955 for trunk/FACT++


Ignore:
Timestamp:
06/09/11 17:13:03 (13 years ago)
Author:
lyard
Message:
added WriteError state
Location:
trunk/FACT++/src
Files:
3 edited

Legend:

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

    r10947 r10955  
    8484//! @param runNumber the runNumber for which this file is opened. 0 means nightly file.
    8585//
    86 void Fits::Open(const string& fileName, const string& tableName, FITS* file, int* fitsCounter, MessageImp* out, int runNumber)
     86bool Fits::Open(const string& fileName, const string& tableName, FITS* file, int* fitsCounter, MessageImp* out, int runNumber)
    8787{               
    8888//      if (fMess)
     
    104104                        fMess->Error(str);
    105105                        fFile = NULL;
    106                         return;
     106                        return false;
    107107                }       
    108108                fOwner = true;
     
    166166            {
    167167                fMess->Error("The table " + factTableName + " could not be created nor loaded. skipping it");
    168                 return;
     168                Close();
     169                return false;
    169170            }
    170171            fTable->makeThisCurrent();
     
    177178                        {
    178179                                fMess->Error("The table " + factTableName + " could not be converted to a binary table. skipping");
    179                                 return;
     180                                Close();
     181                                return false;
    180182                        }       
    181183                        //read the table binary data.
     
    192194                                {
    193195                                        fMess->Error("Column " + cMapIt->first + "Could not be read back from the disk");
    194                                         return;
     196                                        Close();
     197                                        return false;
    195198                                }       
    196199                        }
     
    205208                fMess->Error(str);
    206209                fTable = NULL;
     210                Close();
     211                return false;
    207212        }
    208213                       
     
    210215        fRefMjD = 0;//* static_cast<double*>(fStandardPointers[0]);
    211216        if (!updating)
    212                 WriteHeaderKeys();
     217                return WriteHeaderKeys();
     218
     219        return true;
    213220}
    214221// --------------------------------------------------------------------------
     
    219226//!@param a comment explaining the meaning of the key
    220227template <typename T>
    221 void Fits::WriteSingleHeaderKey(string name, T value, string comment)
     228bool Fits::WriteSingleHeaderKey(string name, T value, string comment)
    222229{
    223230        try
     
    230237                str << "Could not add header keys in file " << fFileName << " reason: " << e.message();
    231238                fMess->Error(str);
    232         }
     239                return false;
     240        }
     241        return true;
    233242}
    234243// --------------------------------------------------------------------------
     
    236245//! This writes the standard header
    237246//
    238 void Fits::WriteHeaderKeys()
     247bool Fits::WriteHeaderKeys()
    239248{
    240249        if (!fTable)
    241                 return;
     250                return false;
    242251        string name;
    243252        string comment;
     
    245254        string stringValue;
    246255
    247         WriteSingleHeaderKey("EXTREL", 1.0f, "Release Number");
    248         WriteSingleHeaderKey("TELESCOP", "FACT", "Telescope that acquired this data");
    249         WriteSingleHeaderKey("ORIGIN", "ISDC", "Institution that wrote the file");
    250         WriteSingleHeaderKey("CREATOR", "FACT++ DataLogger", "Program that wrote this file");
     256        if (!WriteSingleHeaderKey("EXTREL", 1.0f, "Release Number")) return false;
     257        if (!WriteSingleHeaderKey("TELESCOP", "FACT", "Telescope that acquired this data")) return false;
     258        if (!WriteSingleHeaderKey("ORIGIN", "ISDC", "Institution that wrote the file")) return false;
     259        if (!WriteSingleHeaderKey("CREATOR", "FACT++ DataLogger", "Program that wrote this file")) return false;
    251260        stringValue = Time().GetAsStr();
    252261        stringValue[10]= 'T';
    253         WriteSingleHeaderKey("DATE", stringValue, "File creation data");
    254         WriteSingleHeaderKey("TIMESYS", "TT", "Time frame system");
    255         WriteSingleHeaderKey("TIMEUNIT", "d", "Time unit");
    256         WriteSingleHeaderKey("TIMEREF", "UTC", "Time reference frame");
    257         WriteSingleHeaderKey("MJDREF", fRefMjD, "Modified Julian Date of origin");
    258     WriteSingleHeaderKey("TSTOP", fEndMjD, "Time of the last receied data");
     262        if (!WriteSingleHeaderKey("DATE", stringValue, "File creation data")) return false;
     263        if (!WriteSingleHeaderKey("TIMESYS", "TT", "Time frame system")) return false;
     264        if (!WriteSingleHeaderKey("TIMEUNIT", "d", "Time unit")) return false;
     265        if (!WriteSingleHeaderKey("TIMEREF", "UTC", "Time reference frame")) return false;
     266        if (!WriteSingleHeaderKey("MJDREF", fRefMjD, "Modified Julian Date of origin")) return false;
     267        if (!WriteSingleHeaderKey("TSTOP", fEndMjD, "Time of the last receied data")) return false;
     268    return true;
    259269}
    260270// --------------------------------------------------------------------------
     
    263273//! @param conv the converter corresponding to the service being logged
    264274//
    265 void Fits::Write(Converter* conv)
     275bool Fits::Write(Converter* conv)
    266276{
    267277    //first copy the standard variables to the copy buffer
     
    284294        str << fFileName << ": " << e.what();
    285295        fMess->Error(str);
    286         return;
     296        return false;
    287297    }
    288298
     
    295305        str << "Inserting row into " << fFileName << " failed (fits_insert_rows, rc=" << status << ")";
    296306        fMess->Error(str);
    297         // FIXME: What is a proper action here?
     307        Close();
     308        return false;
    298309    }
    299310
     
    310321
    311322    //data copied to buffer, can write to fits
    312     fits_write_tblbytes(fFile->fitsPointer(), fNumRows, 1, fTotalNumBytes, fCopyBuffer, &status);
    313     if (status)
     323    if (fits_write_tblbytes(fFile->fitsPointer(), fNumRows, 1, fTotalNumBytes, fCopyBuffer, &status))
    314324    {
    315325        char text[30];//max length of cfitsio error strings (from doc)
     
    318328        str << "Writing FITS row " << fNumRows << " in " << fFileName << ": " << text << " (file_write_tblbytes, rc=" << status << ")";
    319329        fMess->Error(str);
    320         // FIXME: What is a proper action here?
    321     }
     330        Close();
     331        return false;
     332    }
     333    return true;
    322334}
    323335
  • trunk/FACT++/src/Fits.h

    r10934 r10955  
    5050                double fRefMjD;
    5151                ///Write the FITS header keys
    52                 void WriteHeaderKeys();
     52                bool WriteHeaderKeys();
    5353public:
    5454                ///Name of the openned file. For querying stats
     
    9494
    9595                ///Opens a FITS file
    96         void Open(const string& fileName, const string& tableName, CCfits::FITS* file, int* fitsCounter, MessageImp* out, int runNumber);//ostream& out);
     96        bool Open(const string& fileName, const string& tableName, CCfits::FITS* file, int* fitsCounter, MessageImp* out, int runNumber);//ostream& out);
    9797
    9898                ///Write one line of data. Use the given converter.
    99                 void Write(Converter* conv);
     99                bool Write(Converter* conv);
    100100               
    101101                ///Close the currently opened file.
     
    106106private:
    107107                template <typename T>
    108                 void WriteSingleHeaderKey(string name, T value, string comment);
     108                bool WriteSingleHeaderKey(string name, T value, string comment);
    109109
    110110};//Fits
  • 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.