Changeset 10725 for trunk


Ignore:
Timestamp:
05/17/11 14:30:27 (14 years ago)
Author:
lyard
Message:
Small changes asked by Thomas
Location:
trunk/FACT++/src
Files:
3 edited

Legend:

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

    r10696 r10725  
    8080//! @param tableName the name of the table that will receive the logged data.
    8181//! @param file a pointer to an existing FITS file. If NULL, file will be opened and managed internally
    82 //
    83 void Fits::Open(const std::string& fileName, const std::string& tableName, FITS* file, int* fitsCounter, std::ostream& out)
     82//! @param fitsCounter a pointer to the integer keeping track of the opened FITS files
     83//! @param out a pointer to the MessageImp that should be used to log errors
     84//
     85void Fits::Open(const std::string& fileName, const std::string& tableName, FITS* file, int* fitsCounter, MessageImp* out)//std::ostream& out)
    8486{               
    85         if (fMess)
    86                 delete fMess;
    87         fMess = new MessageImp(out);
    88        
     87//      if (fMess)
     88//              delete fMess;
     89//      fMess = new MessageImp(out);
     90        fMess = out;
    8991        fFileName = fileName;
    9092        if (file == NULL)
     
    183185        }
    184186                       
    185         fRefMjD = * static_cast<double*>(fStandardPointers[0]);
     187        //As requested by Roland, the reference MjD is 0.0
     188        fRefMjD = 0;//* static_cast<double*>(fStandardPointers[0]);
    186189        if (!updating)
    187190                WriteHeaderKeys();
     191}
     192template <typename T>
     193void Fits::WriteSingleHeaderKey(string name, T value, string comment)
     194{
     195        try
     196        {
     197                fTable->addKey(name, value, comment);
     198        }
     199        catch (CCfits::FitsError e)
     200        {
     201                std::stringstream str;
     202                str << "Could not add header keys in file " << fFileName << " reason: " << e.message();
     203                fMess->Error(str);
     204        }
    188205}
    189206// --------------------------------------------------------------------------
     
    198215        std::string comment;
    199216       
    200         float floatValue;
    201         double doubleValue;
     217//      float floatValue;
     218//      double doubleValue;
    202219        std::string stringValue;
    203         try
    204         {       
    205                 name = "EXTREL";
    206                 comment = "Release Number";
    207                 floatValue = 1.0f;
    208                 fTable->addKey(name, floatValue, comment);
    209                                
    210                 name = "BASETYPE";
    211                 comment = "Base type of the data structure";
    212                 stringValue = "??????";
    213                 fTable->addKey(name, stringValue, comment);
    214                                
    215                 name = "TELESCOP";
    216                 comment = "Telescope that acquired this data";
    217                 stringValue = "FACT";
    218                 fTable->addKey(name, stringValue, comment);
    219                                
    220                 name = "ORIGIN";
    221                 comment = "Institution that wrote the file";
    222                 stringValue = "ISDC";
    223                 fTable->addKey(name, stringValue, comment);
    224                                
    225                 name = "CREATOR";
    226                 comment = "Program that wrote this file";
    227                 stringValue = "FACT++_DataLogger";
    228                 fTable->addKey(name, stringValue, comment);
    229                                
    230                 name = "DATE";
    231                 stringValue = Time().GetAsStr();
    232                 stringValue[10] = 'T';
    233                 comment = "File creation date";
    234                 fTable->addKey(name, stringValue, comment);
    235                
    236                 name = "TIMESYS";
    237                 stringValue = "TT";
    238                 comment = "Time frame system";
    239                 fTable->addKey(name, stringValue, comment);
    240                
    241                 name = "TIMEUNIT";
    242                 stringValue = "d";
    243                 comment = "Time unit";
    244                 fTable->addKey(name, stringValue, comment);
    245                
    246                 name = "TIMEREF";
    247                 stringValue = "UTC";
    248                 comment = "Time reference frame";
    249                 fTable->addKey(name, stringValue, comment);
    250                        
    251                 name = "MJDREF";
    252                 doubleValue = fRefMjD;
    253                 comment = "Modified Julian Date of origin";
    254                 fTable->addKey(name, doubleValue, comment);
    255         }
    256         catch (CCfits::FitsError e)
    257         {
    258                 std::stringstream str;
    259                 str << "Could not add header keys in file " << fFileName << " reason: " << e.message();
    260                 fMess->Error(str);
    261         }                       
    262         //More ?
     220
     221        WriteSingleHeaderKey("EXTREL", 1.0f, "Release Number");
     222        WriteSingleHeaderKey("TELESCOP", "FACT", "Telescope that acquired this data");
     223        WriteSingleHeaderKey("ORIGIN", "ISDC", "Institution that wrote the file");
     224        WriteSingleHeaderKey("CREATOR", "FACT++ DataLogger", "Program that wrote this file");
     225        stringValue = Time().GetAsStr();
     226        stringValue[10]= 'T';
     227        WriteSingleHeaderKey("DATE", stringValue, "File creation data");
     228        WriteSingleHeaderKey("TIMESYS", "TT", "Time frame system");
     229        WriteSingleHeaderKey("TIMEUNIT", "d", "Time unit");
     230        WriteSingleHeaderKey("TIMEREF", "UTC", "Time reference frame");
     231        WriteSingleHeaderKey("MJDREF", fRefMjD, "Modified Julian Date of origin");
    263232}
    264233// --------------------------------------------------------------------------
     
    270239{
    271240
    272         try
    273         {
    274                 fTable->makeThisCurrent();
    275                 fTable->insertRows(fNumRows);
    276         }
    277         catch(CCfits::FitsError e)
    278         {
    279                 std::stringstream str;
    280                 str << "Could not insert row in file " << fFileName << " reason: " << e.message();
     241//      try
     242//      {
     243        fTable->makeThisCurrent();
     244        int status(0);
     245        if (fits_insert_rows(fTable->fitsPointer(), fNumRows, 1, &status))
     246        {
     247                std::stringstream str;
     248                str << "Could not insert row in file " << fFileName << ". cfitsio error code: " << status;
    281249                fMess->Error(str);
    282250        }
     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//      }
    283259        fNumRows++;
    284                        
     260
    285261        //the first standard variable is the current MjD
    286262        if (fEndMjD == 0)
    287263        {
    288                 std::string name = "TSTART";
    289                 double doubleValue = *static_cast<double*>(fStandardPointers[0]) - fRefMjD;
    290                 std::string comment = "Time of the first received data";
    291                 fTable->addKey(name, doubleValue, comment);     
     264                double doubleValue = *static_cast<double*>(fStandardPointers[0]);// - fRefMjD;
     265                WriteSingleHeaderKey("TSTART", doubleValue, "Time of the first received data");
    292266        }
    293267        fEndMjD = * static_cast<double*>(fStandardPointers[0]);
     
    298272        for (unsigned int i=0;i<fStandardNumBytes.size();i++)
    299273        {
    300                 for (int j=0; j<fStandardNumBytes[i]; j++)
    301                         fCopyBuffer[shift+j] = static_cast<char*>(fStandardPointers[i])[fStandardNumBytes[i]-(j+1)];
     274                const char * charSrc = static_cast<char*>(fStandardPointers[i]);
     275
     276                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)];
    302279                shift+= fStandardNumBytes[i];   
    303280        }
     
    307284                         
    308285        //data copied to buffer, can write to fits
    309         int status = 0;
     286//      int status = 0;
    310287        //TODO check the status after the write operation
    311288        fits_write_tblbytes(fFile->fitsPointer(), fNumRows, 1, fTotalNumBytes, fCopyBuffer, &status);
     
    320297        //This forces the writting of each row to the disk. Otherwise all rows are written when the file is closed.
    321298        ///TODO check whether this consumes too much resources or not. If it does, flush every N write operations instead
    322         try
     299/*      try
    323300        {
    324301                fFile->flush();
     
    330307                fMess->Error(str);     
    331308        }
    332 }
     309*/}
    333310// --------------------------------------------------------------------------
    334311//
     
    341318//                      if (fTable != NULL)
    342319//                              delete fTable;
    343         std::string name = "TEND";
    344         double doubleValue = fEndMjD - fRefMjD;
    345         std::string comment = "Time of the last received data";
    346         fTable->addKey(name, doubleValue, comment);
    347        
     320
     321        WriteSingleHeaderKey("TSTOP", fEndMjD, "Time of the last receied data");
    348322        if (fFile != NULL && fOwner)
    349323                delete fFile;
     
    354328        if (fOwner && fNumOpenFitsFiles != NULL)
    355329                (*fNumOpenFitsFiles)--;
    356         if (fMess)
    357                 delete fMess;
     330//fMess is the MessageImp part of the dataLogger itself. Thus it should NOT be deleted by the Fits files destructor.
     331//      if (fMess)
     332//              delete fMess;
    358333        fMess = NULL;
    359334}
  • trunk/FACT++/src/Fits.h

    r10694 r10725  
    8989
    9090                ///Opens a FITS file
    91                 void Open(const std::string& fileName, const std::string& tableName, CCfits::FITS* file, int* fitsCounter, std::ostream& out);
     91        void Open(const std::string& fileName, const std::string& tableName, CCfits::FITS* file, int* fitsCounter, MessageImp* out);//std::ostream& out);
    9292
    9393                ///Write one line of data. Use the given converter.
     
    9999                ///Get the size currently written on the disk
    100100                int GetWrittenSize();
     101private:
     102                template <typename T>
     103                void WriteSingleHeaderKey(string name, T value, string comment);
    101104
    102105};//Fits
  • trunk/FACT++/src/dataLogger.cc

    r10707 r10725  
    6666#include <sys/stat.h>
    6767
     68//#define HAVE_FITS
    6869//#define ONE_RUN_FITS_ONLY
    6970
     
    977978//! @param I
    978979//!     The current DimInfo
     980//! @param sub
     981//!             The dataLogger's subscription corresponding to this DimInfo
    979982//
    980983void DataLogger::ReportPlease(DimInfo* I, SubscriptionType& sub)
     
    10881091                std::string n = I->getName();
    10891092                std::stringstream msg;
    1090                 msg << n.substr(0, n.find_first_of('/')) << ": " << I->getString();
     1093                msg << n << ": " << I->getString();//n.substr(0, n.find_first_of('/')) << ": " << I->getString();
    10911094
    10921095                if (fNightlyLogFile.is_open())
     
    16991702                        fFileSizesMap[partialName] = 0;
    17001703                }
    1701                 sub.nightlyFile.Open(partialName, serviceName, NULL, &fNumSubAndFitsData.numOpenFits, Out());
     1704                sub.nightlyFile.Open(partialName, serviceName, NULL, &fNumSubAndFitsData.numOpenFits, this);//Out());
    17021705                //notify the opening
    17031706                std::string actualTargetDir;
     
    17711774#ifdef ONE_RUN_FITS_ONLY
    17721775                }
    1773                 sub.runFile.Open(partialName, serviceName, fRunFitsFile, &fNumSubAndFitsData.numOpenFits, Out());
     1776                sub.runFile.Open(partialName, serviceName, fRunFitsFile, &fNumSubAndFitsData.numOpenFits, this);//Out());
    17741777#else
    1775                 sub.runFile.Open(partialName, serviceName, NULL, &fNumSubAndFitsData.numOpenFits, Out());
     1778                sub.runFile.Open(partialName, serviceName, NULL, &fNumSubAndFitsData.numOpenFits, this);//Out());
    17761779#endif //one_run_fits_only
    17771780           if (fNumSubAndFitsIsOn)
Note: See TracChangeset for help on using the changeset viewer.