Ignore:
Timestamp:
05/18/11 16:00:41 (13 years ago)
Author:
lyard
Message:
added configurable grouping and did some cosmetics to the code (removed tabs)
File:
1 edited

Legend:

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

    r10725 r10741  
    3535//! @param numDataBytes the number of bytes taken by the variable
    3636//
    37 void Fits::AddStandardColumn(Description& desc, std::string dataFormat, void* dataPointer, long unsigned int numDataBytes)
     37void Fits::AddStandardColumn(Description& desc, string dataFormat, void* dataPointer, long unsigned int numDataBytes)
    3838{
    3939        //check if entry already exist
    40         for (std::vector<Description>::iterator it=fStandardColDesc.begin(); it != fStandardColDesc.end(); it++)
     40        for (vector<Description>::iterator it=fStandardColDesc.begin(); it != fStandardColDesc.end(); it++)
    4141                if (it->name == desc.name)
    4242                        return;
     
    5454//! @param numDataBytes the number of bytes taken by the DIM data.
    5555//     
    56 void Fits::InitDataColumns(std::vector<Description> desc, std::vector<std::string>& dataFormat, void* dataPointer, int numDataBytes)
     56void Fits::InitDataColumns(vector<Description> desc, vector<string>& dataFormat, void* dataPointer, int numDataBytes)
    5757{//we will copy this information here. It duplicates the data, which is not great, but it is the easiest way of doing it right now
    5858        if (desc.size() == dataFormat.size())
     
    6565                for (unsigned int i=0;i<dataFormat.size();i++)
    6666                {
    67                         std::stringstream stt;
     67                        stringstream stt;
    6868                        stt << "Data" << i;
    6969                        fDataColDesc.push_back(Description(stt.str(), "comment", "unit"));
     
    8383//! @param out a pointer to the MessageImp that should be used to log errors
    8484//
    85 void Fits::Open(const std::string& fileName, const std::string& tableName, FITS* file, int* fitsCounter, MessageImp* out)//std::ostream& out)
     85void Fits::Open(const string& fileName, const string& tableName, FITS* file, int* fitsCounter, MessageImp* out)//ostream& out)
    8686{               
    8787//      if (fMess)
     
    9898                catch (CCfits::FitsError e)
    9999                {                       
    100                         std::stringstream str;
     100                        stringstream str;
    101101                        str << "Could not open FITS file " << fileName << " reason: " << e.message();
    102102                        fMess->Error(str);
     
    115115        //concatenate the standard and data columns
    116116        //do it the inneficient way first: its easier and faster to code.
    117         std::vector<std::string> allNames;
    118         std::vector<std::string> allDataTypes;
    119         std::vector<std::string> allUnits;
     117        vector<string> allNames;
     118        vector<string> allDataTypes;
     119        vector<string> allUnits;
    120120        fTotalNumBytes = 0;
    121121        for (unsigned int i=0;i<fStandardColDesc.size();i++)
     
    133133                else
    134134                {
    135                         std::stringstream stt;
     135                        stringstream stt;
    136136                        stt << "Data" << i;
    137137                        allNames.push_back(stt.str());
     
    145145        try
    146146        {
    147                 std::string factTableName = "FACT-" + tableName;
     147                string factTableName = "FACT-" + tableName;
    148148                fTable = fFile->addTable(factTableName, 0, allNames, allDataTypes, allUnits);
    149149                fTable->makeThisCurrent();
     
    159159                        }       
    160160                        //read the table binary data.
    161                         std::vector<string> colName;
     161                        vector<string> colName;
    162162                        bTable->readData(true, colName);
    163163
    164164                        //double check that the data was indeed read from the disk. Go through the fTable instead as colName is empty (yes, it is !)
    165                         std::map<std::string, Column*> cMap = fTable->column();
    166                         std::map<std::string, Column*>::iterator cMapIt;
     165                        map<string, Column*> cMap = fTable->column();
     166                        map<string, Column*>::iterator cMapIt;
    167167
    168168                        for (cMapIt = cMap.begin(); cMapIt != cMap.end(); cMapIt++)
     
    179179        catch(CCfits::FitsError e)
    180180        {
    181                 std::stringstream str;
     181                stringstream str;
    182182                str << "Could not open or create FITS table " << tableName << " in  file " << fileName << " reason: " << e.message();
    183183                fMess->Error(str);
     
    190190                WriteHeaderKeys();
    191191}
     192// --------------------------------------------------------------------------
     193//
     194//!This writes a single header key in the currently open file.
     195//!@param name the key
     196//!@param value the key value
     197//!@param a comment explaining the meaning of the key
    192198template <typename T>
    193199void Fits::WriteSingleHeaderKey(string name, T value, string comment)
     
    199205        catch (CCfits::FitsError e)
    200206        {
    201                 std::stringstream str;
     207                stringstream str;
    202208                str << "Could not add header keys in file " << fFileName << " reason: " << e.message();
    203209                fMess->Error(str);
     
    212218        if (!fTable)
    213219                return;
    214         std::string name;
    215         std::string comment;
    216        
    217 //      float floatValue;
    218 //      double doubleValue;
    219         std::string stringValue;
     220        string name;
     221        string comment;
     222
     223        string stringValue;
    220224
    221225        WriteSingleHeaderKey("EXTREL", 1.0f, "Release Number");
     
    230234        WriteSingleHeaderKey("TIMEREF", "UTC", "Time reference frame");
    231235        WriteSingleHeaderKey("MJDREF", fRefMjD, "Modified Julian Date of origin");
     236    WriteSingleHeaderKey("TSTOP", fEndMjD, "Time of the last receied data");
    232237}
    233238// --------------------------------------------------------------------------
     
    239244{
    240245
    241 //      try
    242 //      {
    243246        fTable->makeThisCurrent();
    244247        int status(0);
    245248        if (fits_insert_rows(fTable->fitsPointer(), fNumRows, 1, &status))
    246249        {
    247                 std::stringstream str;
     250                stringstream str;
    248251                str << "Could not insert row in file " << fFileName << ". cfitsio error code: " << status;
    249252                fMess->Error(str);
    250253        }
    251 //              fTable->insertRows(fNumRows);
    252 //      }
    253 //      catch(CCfits::FitsError e)
    254 //      {
    255 //              std::stringstream str;
    256 //              str << "Could not insert row in file " << fFileName << " reason: " << e.message();
    257 //              fMess->Error(str);
    258 //      }
    259254        fNumRows++;
    260255
     
    273268        {
    274269                const char * charSrc = static_cast<char*>(fStandardPointers[i]);
    275 
    276270                reverse_copy(charSrc, charSrc+fStandardNumBytes[i], &fCopyBuffer[shift]);
    277 //              for (int j=0; j<fStandardNumBytes[i]; j++)
    278 //                      fCopyBuffer[shift+j] = static_cast<char*>(fStandardPointers[i])[fStandardNumBytes[i]-(j+1)];
    279271                shift+= fStandardNumBytes[i];   
    280272        }
     
    284276                         
    285277        //data copied to buffer, can write to fits
    286 //      int status = 0;
    287         //TODO check the status after the write operation
    288278        fits_write_tblbytes(fFile->fitsPointer(), fNumRows, 1, fTotalNumBytes, fCopyBuffer, &status);
    289279        if (status)
     
    291281                char text[30];//max length of cfitsio error strings (from doc)
    292282                fits_get_errstatus(status, text);
    293                 std::stringstream str;
     283                stringstream str;
    294284                str << "Error while writing FITS row in " << fFileName << ". Message: " << text << " [" << status << "]";
    295285                fMess->Error(str);     
    296286        }
    297         //This forces the writting of each row to the disk. Otherwise all rows are written when the file is closed.
    298         ///TODO check whether this consumes too much resources or not. If it does, flush every N write operations instead
    299 /*      try
    300         {
    301                 fFile->flush();
    302         }
    303         catch (CCfits::FitsError e)
    304         {
    305                 std::stringstream str;
    306                 str << "Error while flushing bytes to disk. File: " << fFileName << " reason: " << e.message();
    307                 fMess->Error(str);     
    308         }
    309 */}
     287}
    310288// --------------------------------------------------------------------------
    311289//
     
    335313
    336314// --------------------------------------------------------------------------
    337 //
     315//! Returns the size on the disk of the Fits file being written.
    338316int Fits::GetWrittenSize()
    339317{
Note: See TracChangeset for help on using the changeset viewer.