Changeset 12535


Ignore:
Timestamp:
11/16/11 10:24:51 (13 years ago)
Author:
lyard
Message:
fixed a poorly dealt with closing of files once a day. Should be better now
File:
1 edited

Legend:

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

    r12480 r12535  
    386386    bool fShouldAutoStart;
    387387    bool fAutoStarted;
     388
     389    //Current day variable. Used to close nightly files when night changes
     390    int fCurrentDay;
    388391public:
    389392    int Write(const Time &time, const std::string &txt, int qos=kMessage);
     
    751754    //initialize member data
    752755    fFilePath = ".";
     756
     757    //calculate time "centered" around noon instead of midnight
     758    const Time timeNow;
     759    const Time nowMinusTwelve = timeNow-boost::posix_time::hours(12);
     760    fCurrentDay = nowMinusTwelve.M()*31 + nowMinusTwelve.D();//assume 31 days per month. we do not really care, only want unique number per day of the year
    753761
    754762    //Give a name to this machine's specific states
     
    11791187    // of only one.
    11801188    //
    1181     if (Time().h() == 12 && !fDailyFileDayChangedAlready)
    1182     {
     1189    // Last but not least, the datalogger MUST receive at least one service update during
     1190    // noon otherwise this is skipped (which is not good). Thus I would suggest that the datalogger
     1191    // should always subscribe to at least its statistics services.
     1192    //
     1193    //calculate time "centered" around noon instead of midnight
     1194    const Time timeNow;
     1195    const Time nowMinusTwelve = timeNow-boost::posix_time::hours(12);
     1196    int newDayNumber = nowMinusTwelve.M()*31 + nowMinusTwelve.D();//assume 31 days per month. we do not really care, only want unique number per day of the year
     1197
     1198//    if (Time().h() == 12 && !fDailyFileDayChangedAlready)
     1199    if (newDayNumber !=  fCurrentDay)
     1200    {
     1201        fCurrentDay = newDayNumber;
     1202        //crawl through the subcriptions and close any open nightly file
     1203        SubscriptionsListType::iterator x;
     1204        map<string, SubscriptionType>::iterator y;
     1205        for (x=fServiceSubscriptions.begin(); x != fServiceSubscriptions.end(); x++)
     1206        {//find current service is subscriptions
     1207            for (y=x->second.begin(); y!=x->second.end();y++)
     1208                if (y->second.nightlyFile.IsOpen())
     1209                {
     1210                    y->second.nightlyFile.Close();
     1211                }
     1212        }
     1213
    11831214        if (fDebugIsOn)
    1184             Debug("Its Noon! Closing and reopening nightly text files");
     1215            Debug("Day have changed! Closing and reopening nightly files");
    11851216
    11861217        fNightlyLogFile << endl;
     
    12081239        }
    12091240
    1210         fDailyFileDayChangedAlready = true;
    1211     }
    1212     if (Time().h() != 12 && fDailyFileDayChangedAlready)
    1213         fDailyFileDayChangedAlready = false;
     1241 //       fDailyFileDayChangedAlready = true;
     1242    }
     1243//    if (Time().h() != 12 && fDailyFileDayChangedAlready)
     1244//        fDailyFileDayChangedAlready = false;
    12141245
    12151246    //create the converter for that service
     
    13251356        //check if the last received event was before noon and if current one is after noon.
    13261357        //if so, close the file so that it gets reopened.
    1327         if (sub.nightlyFile.IsOpen())
    1328             if ((sub.lastReceivedEvent != Time::None) && (sub.lastReceivedEvent.h() < 12) && (cTime.h() >= 12))
    1329             {
    1330                 sub.nightlyFile.Close();
    1331             }
     1358//        if (sub.nightlyFile.IsOpen())
     1359//            if ((sub.lastReceivedEvent != Time::None) && (sub.lastReceivedEvent.h() < 12) && (cTime.h() >= 12))
     1360//            {
     1361//                sub.nightlyFile.Close();
     1362//            }
    13321363        sub.lastReceivedEvent = cTime;//ici
    13331364        if (!sub.nightlyFile.IsOpen() || !sub.runFile.IsOpen() || sub.runNumber != sub.runFile.fRunNumber)
Note: See TracChangeset for help on using the changeset viewer.