Ignore:
Timestamp:
04/21/11 12:27:37 (14 years ago)
Author:
lyard
Message:
Added dataLogger services and use only one file for fits runs
File:
1 edited

Legend:

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

    r10380 r10442  
    1818#include "Time.h"
    1919#include "Converter.h"
     20
     21//for file stats
     22#include <sys/stat.h>
    2023
    2124using namespace std;
     
    3235void Fits::AddStandardColumn(Description& desc, std::string dataFormat, void* dataPointer, long unsigned int numDataBytes)
    3336{
     37        //check if entry already exist
     38        for (std::vector<Description>::iterator it=fStandardColDesc.begin(); it != fStandardColDesc.end(); it++)
     39                if (it->name == desc.name)
     40                        return;
    3441        fStandardColDesc.push_back(desc);
    3542        fStandardFormats.push_back(dataFormat);
     
    5360        else
    5461        {
     62                fDataColDesc.clear();
    5563                for (unsigned int i=0;i<dataFormat.size();i++)
    5664                {
     
    6977//! @param fileName the filename with complete or relative path of the file to open
    7078//! @param tableName the name of the table that will receive the logged data.
    71 //
    72 void Fits::Open(const std::string& fileName, const std::string& tableName)
     79//! @param file a pointer to an existing FITS file. If NULL, file will be opened and managed internally
     80//
     81void Fits::Open(const std::string& fileName, const std::string& tableName, FITS* file)
    7382{               
    74         try
    75         {
    76                 fFile = new FITS(fileName, RWmode::Write);
    77         }
    78         catch (FITS::CantOpen)
    79         {
    80                 std::ostringstream err;
    81                 err << "Could not open " << fileName << ".Skipping it.";
    82                 throw runtime_error(err.str());
    83         }       
     83        fFileName = fileName;
     84        if (file == NULL)
     85        {
     86                try
     87                {
     88                        fFile = new FITS(fileName, RWmode::Write);
     89                }
     90                catch (FITS::CantOpen)
     91                {
     92                        std::ostringstream err;
     93                        err << "Could not open " << fileName << ".Skipping it.";
     94                        throw runtime_error(err.str());
     95                }       
     96                fOwner = true;
     97        }
     98        else
     99        {
     100                fFile = file;
     101                fOwner = false;
     102        }
    84103        //concatenate the standard and data columns
    85104        //do it the inneficient way first: its easier and faster to code.
     
    206225void Fits::Write(Converter* conv)
    207226{
     227
     228        fTable->makeThisCurrent();
    208229        try
    209230        {
     
    240261
    241262        //This forces the writting of each row to the disk. Otherwise all rows are written when the file is closed.
     263        ///TODO check whether this consumes too much resources or not. If it does, flush every N write operations instead
    242264        fFile->flush();
    243265}
     
    252274//                      if (fTable != NULL)
    253275//                              delete fTable;
     276
    254277        std::string name = "TEND";
    255278        double doubleValue = fEndMjD;
    256279        std::string comment = "Time of the last received data";
    257280        fTable->addKey(name, doubleValue, comment);
    258 
    259         if (fFile != NULL)
     281       
     282        if (fFile != NULL && fOwner)
    260283                delete fFile;
    261284        fFile = NULL;
     
    264287        fCopyBuffer = NULL;
    265288}
     289
     290// --------------------------------------------------------------------------
     291//
     292//! This closes the currently openned FITS file.
     293//! it also updates the header to reflect the time of the last logged row
     294//     
     295int Fits::GetWrittenSize()
     296{
     297        if (!IsOpen())
     298                return 0;
     299               
     300        struct stat st;
     301        if (stat(fFileName.c_str(), &st))
     302                return 0;
     303        else
     304                return st.st_size;
     305}
Note: See TracChangeset for help on using the changeset viewer.