Changeset 11405


Ignore:
Timestamp:
07/14/11 11:42:42 (13 years ago)
Author:
lyard
Message:
various improvements of the datalogger
Location:
trunk/FACT++/src
Files:
3 edited

Legend:

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

    r11373 r11405  
    7373        fDataPointer = dataPointer;
    7474        fDataNumBytes = numDataBytes;   
     75}
     76// --------------------------------------------------------------------------
     77//
     78//! This looks for a suitable table in the fits file, i.e. that corresponds to the name and column names. (no format check yet)
     79//! @param tableName. the base table name to be obtained. If not suitable, numbers are appened to the name
     80//! @param allNames. the name of all columns
     81//! @param allDataTypes. the data types of all columns
     82//! @param allUnits. the units of the columns
     83//! @return a pointer to the newly retrieved/created table
     84//
     85CCfits::Table* Fits::findSuitableTableInFitsFile(const string& tableName,const vector<string>& allNames, const vector<string>& allDataTypes, const vector<string>& allUnits)
     86{
     87    const multimap< string, CCfits::ExtHDU * >& extMap = fFile->extension();
     88    for (int i=0;i<100;i++)
     89    {
     90        if (i==10)
     91            fMess->Error("Already 10 different tables with different formats exist in this file. Please consider re-creating the file entirely (i.e. delete it please)");
     92        ostringstream cTableName;
     93        cTableName << tableName;
     94        if (i != 0)
     95            cTableName << "-" << i;
     96        //current table name does not exist yet. return its associated fits table newly created
     97        if (extMap.find(cTableName.str()) == extMap.end())
     98        {
     99            for (multimap<string, CCfits::ExtHDU*>::const_iterator it=extMap.begin(); it!= extMap.end(); it++)
     100                fMess->Debug(it->first);
     101            return fFile->addTable(cTableName.str(), 0, allNames, allDataTypes, allUnits);
     102        }
     103        CCfits::Table* cTable;
     104        cTable = dynamic_cast<CCfits::Table*>(extMap.find(cTableName.str())->second);
     105
     106        if (!cTable)
     107            return NULL;//something wrong happened while getting the table pointer
     108
     109        //now check that the table columns are the same as the service columns
     110        cTable->makeThisCurrent();
     111        const map<string, Column*> cMap = cTable->column();
     112        for (unsigned int j=0;j<allNames.size();j++)
     113            if (cMap.find(allNames[j]) == cMap.end())
     114                continue;
     115
     116        return cTable;
     117    }
     118    fMess->Error("One hundred trials for new table format failed. aborting");
     119    return NULL;
    75120}
    76121// --------------------------------------------------------------------------
     
    152197                fFile->read(tryToLoadName);
    153198
    154             const multimap< string, CCfits::ExtHDU * >& extMap = fFile->extension();
    155             if (extMap.find(tableName) == extMap.end())
    156             {
    157                 for (multimap<string, CCfits::ExtHDU*>::const_iterator it=extMap.begin(); it!= extMap.end(); it++)
    158                     fMess->Debug(it->first);
    159                 fTable = fFile->addTable(tableName, 0, allNames, allDataTypes, allUnits);
    160             }
    161             else
    162             {
    163                 fTable = dynamic_cast<CCfits::Table*>(extMap.find(tableName)->second);
    164             }
     199//          const multimap< string, CCfits::ExtHDU * >& extMap = fFile->extension();
     200//          if (extMap.find(tableName) == extMap.end())
     201//          {
     202//              for (multimap<string, CCfits::ExtHDU*>::const_iterator it=extMap.begin(); it!= extMap.end(); it++)
     203//                  fMess->Debug(it->first);
     204//              fTable = fFile->addTable(tableName, 0, allNames, allDataTypes, allUnits);
     205//          }
     206//          else
     207//          {
     208//              fTable = dynamic_cast<CCfits::Table*>(extMap.find(tableName)->second);
     209//          }
     210        fTable = findSuitableTableInFitsFile(tableName, allNames, allDataTypes, allUnits);
     211
    165212            if (!fTable)
    166213            {
     
    188235                        const map<string, Column*> cMap = fTable->column();
    189236
    190                         for (map<string, Column*>::const_iterator cMapIt = cMap.begin(); cMapIt != cMap.end(); cMapIt++)
     237            for (map<string, Column*>::const_iterator cMapIt = cMap.begin(); cMapIt != cMap.end(); cMapIt++)
    191238                        {
    192239                                if (!cMapIt->second->isRead())
     
    349396            delete fFile;
    350397
    351             fMess->Info("Closed: "+fFileName);
     398        fMess->Info("Closed: "+fFileName);
     399        if (fNumOpenFitsFiles != NULL)
     400            (*fNumOpenFitsFiles)--;
    352401        }
    353402        fFile = NULL;
     
    355404                delete [] fCopyBuffer;
    356405        fCopyBuffer = NULL;
    357         if (fOwner && fNumOpenFitsFiles != NULL)
    358                 (*fNumOpenFitsFiles)--;
     406
    359407//fMess is the MessageImp part of the dataLogger itself. Thus it should NOT be deleted by the Fits files destructor.
    360408//      if (fMess)
  • trunk/FACT++/src/Fits.h

    r11015 r11405  
    107107                template <typename T>
    108108                bool WriteSingleHeaderKey(const string &name, const T &value, const string &comment);
     109                CCfits::Table* findSuitableTableInFitsFile(const string& tableName,const vector<string>& allNames, const vector<string>& allDataTypes, const vector<string>& allUnits);
    109110
    110111};//Fits
  • trunk/FACT++/src/datalogger.cc

    r11347 r11405  
    506506void DataLogger::RemoveService(const string& server, const string& service, bool isCmd)
    507507{
     508    if (fDestructing)//this function is called by the super class, after the destructor has deleted its own subscriptions
     509        return;
     510
    508511    if (isCmd)
    509512        return;
     
    10521055{
    10531056    if (fDebugIsOn)
    1054     {
    10551057        Debug("DataLogger destruction starts");   
    1056     }
     1058
     1059    //this boolean should not be required anymore, because it
    10571060    fDestructing = true;
    1058     //first let's go to the ready state
    1059     GoToReadyPlease();
     1061
     1062    //first, let's backup the datalogger/message service subscription
     1063    shared_ptr<DimStampedInfo> messageBackup;
     1064    bool dataloggerMessageFound = false;
     1065    SubscriptionsListType::iterator x;
     1066    map<string, SubscriptionType>::iterator y;
     1067    x = fServiceSubscriptions.find("DATA_LOGGER");
     1068    if (x != fServiceSubscriptions.end())
     1069    {
     1070        y = x->second.find("MESSAGE");
     1071        if (y != x->second.end())
     1072        {
     1073            dataloggerMessageFound = true;
     1074            messageBackup = y->second.dimInfo;
     1075        }
     1076    }
     1077
    10601078    dim_lock();
    1061     //release the services subscriptions
     1079
     1080     //now clear the services subscriptions
    10621081    fServiceSubscriptions.clear();
    10631082
    10641083    //clear any remaining run number (should remain only one)
    10651084    while (fRunNumber.size() > 0)
    1066      {
     1085    {
    10671086         RemoveOldestRunNumber();
    1068      }
    1069 //    dim_unlock();
     1087    }
     1088    //go to the ready state. i.e. close all files, run-wise first
     1089    GoToReadyPlease();
     1090
     1091    dim_unlock();
     1092
     1093    Info("Will soon close the daily log file");
     1094
    10701095    delete fOpenedNightlyFiles;
    10711096    delete fOpenedRunFiles;
    10721097    delete fNumSubAndFits;
    1073 //    delete fStatsMonitoring;
     1098
     1099    //release message service before closing nightly log file
     1100    if (dataloggerMessageFound)
     1101        messageBackup.reset();
     1102
     1103    if (fNightlyLogFile.is_open())//this file is the only one that has not been closed by GoToReadyPlease
     1104    {
     1105        dim_lock();
     1106        fNightlyLogFile.close();
     1107        dim_unlock();
     1108    }
    10741109
    10751110    if (fDebugIsOn)
    1076     {
    10771111        Debug("DataLogger desctruction ends");   
    1078     }
    10791112}
    10801113// --------------------------------------------------------------------------
     
    11331166void DataLogger::infoHandler()
    11341167{
    1135     // Make sure getTimestamp is called _before_ getTimestampMillisecs
    1136     if (fDestructing)
    1137         return;
    1138 
    11391168    DimInfo* I = getInfo();
    11401169
     
    13601389    const bool isItaReport = fmt!="C";
    13611390
    1362     if (!fNightlyReportFile.is_open())
     1391    if (!fNightlyLogFile.is_open())
    13631392        return;
    13641393
     
    14811510            ostringstream str;
    14821511            str << "Parsing service " << sub.dimInfo->getName();
    1483             str << " failed: " << e.what();
     1512            str << " failed: " << e.what() << " removing the subscription for now.";
    14841513            Error(str);
    1485 //            if (fDebugIsOn)
    1486 //           {
    1487 //              ostringstream str2;
    1488 //             str2 << sub.dimInfo->getString() << "\n";
    1489 //                Debug(str2);
    1490 //            }
     1514            //remove this subscription from the list.
     1515            //because these operators use references to elements, and because they're supposed here to erase these objects on the way, I'm not too sure... so duplicate the names !
     1516            string server = sub.server;
     1517            string service = sub.service;
     1518            fServiceSubscriptions.find(server)->second.erase(service);
    14911519            return;
    14921520        }
     
    15331561    else
    15341562    {//write entry to both Nightly and run logs
    1535         vector<string> strings = sub.fConv->ToStrings(I->getData());
     1563        vector<string> strings;
     1564        try
     1565        {
     1566           strings = sub.fConv->ToStrings(I->getData());
     1567        }
     1568        catch (const runtime_error &e)
     1569        {
     1570            ostringstream str;
     1571            str << "Parsing service " << sub.dimInfo->getName();
     1572            str << " failed: " << e.what() << " removing the subscription for now.";
     1573            Error(str);
     1574            //remove this subscription from the list.
     1575            //because these operators use references to elements, and because they're supposed here to erase these objects on the way, I'm not too sure... so duplicate the names !
     1576            string server = sub.server;
     1577            string service = sub.service;
     1578            fServiceSubscriptions.find(server)->second.erase(service);
     1579            return;
     1580        }
    15361581        if (strings.size() > 1)
    15371582        {
     
    24432488//   dim_lock();
    24442489   const string baseFileName = CompileFileNameWithPath(fNightlyFilePath, "", "");
    2445     if (fNightlyLogFile.is_open())
     2490    if (fNightlyLogFile.is_open() && !fDestructing)//in case we're destructing the datalogger, wait before closing the log file.
    24462491    {
    24472492        fNightlyLogFile.close();
Note: See TracChangeset for help on using the changeset viewer.