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/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
Note: See TracChangeset for help on using the changeset viewer.