Ignore:
Timestamp:
07/14/11 11:42:42 (13 years ago)
Author:
lyard
Message:
various improvements of the datalogger
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.