Changeset 15060 for trunk/FACT++/src


Ignore:
Timestamp:
03/13/13 15:36:40 (12 years ago)
Author:
lyard
Message:
added extra service and changed behaviour in case of format change for services
File:
1 edited

Legend:

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

    r14992 r15060  
    145145    //shared_ptr<DimStampedInfo> dimInfo;
    146146    unsigned int index;
     147    ///counter to know if format has changed during operations
     148    unsigned int increment;
    147149
    148150    ///Dim info constructor
     
    160162        //dimInfo = shared_ptr<DimStampedInfo>(info);
    161163        index = 0;
     164        increment = 0;
    162165    }
    163166    ///default destructor
     
    282285    NumSubAndFitsType fNumSubAndFitsData;
    283286
     287    ///Service for broadcasting subscription status
     288    DimDescribedService* fCurrentSubscription;
     289    ///Number of seconds since the last update of the subscribed list
     290    int fCurrentSubscriptionUpdateRate;
     291    ///The last time in seconds of the day when the service was update
     292    Time fLastSubscriptionUpdate;
     293    ///update the service
     294    void updateSubscriptionList();
     295    ///set the duration between two updates. a zero or negative value disables the service updates
     296    int setSubscriptionListUpdateTimeLapse(const Event& evt);
    284297    /***************************************************
    285298     * DATA LOGGER's CONFIGURATION STUFF
     
    405418    return GetCurrentState();
    406419}
     420/**
     421 *  UPDATE SUBSCRIPTION LIST. Updates the subscription list service if enough time has passed.
     422 *                            Otherwise does nothing
     423 */
     424void DataLogger::updateSubscriptionList()
     425{
     426    if (fCurrentSubscriptionUpdateRate <= 0) return;
     427    Time timeNow;
     428    //if less than the update rate time has passed, just return
     429    if (timeNow - fLastSubscriptionUpdate < boost::posix_time::seconds(fCurrentSubscriptionUpdateRate))
     430        return;
     431    //TODO remove me !
     432//    cout << "Updating subscription list with: " << endl;
     433
     434    fLastSubscriptionUpdate = timeNow;
     435
     436    //update service !
     437    ostringstream output;
     438    for (auto serverIt=fServiceSubscriptions.begin();serverIt!=fServiceSubscriptions.end(); serverIt++)
     439    {
     440        if (serverIt->first == "DATA_LOGGER")
     441            continue;
     442        for (auto serviceIt=serverIt->second.begin(); serviceIt!=serverIt->second.end(); serviceIt++)
     443        {
     444            output << serverIt->first << "/" << serviceIt->first << ",";
     445            if (serviceIt->second.lastReceivedEvent != Time::None)
     446                output << (timeNow - serviceIt->second.lastReceivedEvent).total_seconds();
     447            else
     448                output << "-1";
     449            output << "\n";
     450        }
     451    }
     452//TODO remove me !
     453//cout << output.str();
     454    fCurrentSubscription->setData(output.str().c_str(), output.str().size()+1);
     455    fCurrentSubscription->setQuality(0);
     456    fCurrentSubscription->Update();
     457}
     458int DataLogger::setSubscriptionListUpdateTimeLapse(const Event& evt)
     459{
     460    fCurrentSubscriptionUpdateRate = evt.GetInt();
     461
     462    return GetCurrentState();
     463}
    407464vector<Description> DataLogger::GetDescription(const string& server, const string& service)
    408465{
     
    540597                }
    541598                list[service].nightlyFile.Close();
    542                 string fileNameWithoutFits = fileName.substr(0, fileName.size()-4);
     599                list[service].increment++;
     600                Warn("Format of "+server+"/"+service+" has changed. Closing "+fileName);
     601/*                string fileNameWithoutFits = fileName.substr(0, fileName.size()-4);
    543602                int counter=0;
    544603                while (counter < 100)
     
    549608                    if (!testStream) //fileName available
    550609                    {
    551                         Warn("Format of "+server+"/"+service+" has changed. Closing "+fileName+" and renaming it to "+newFileName.str());
    552610                        rename(fileName.c_str(), newFileName.str().c_str());
    553611                        break;
     
    557615                if (counter==100)
    558616                    Error("Could not rename "+fileName+" after 100 trials (because of format change). Aborting");
     617*/
    559618                //reallocate the fits buffer...
    560619                list[service].fitsBufferAllocated = false;
     
    895954            ("Print information about the internal status of the data logger.");
    896955
     956
    897957     OpenFileToDim fToDim;
    898958     fToDim.code = 0;
     
    920980     fNumSubAndFitsIsOn = true;
    921981
     982     string emptyString="";
     983     //Subscription list service
     984     fCurrentSubscription = new DimDescribedService(GetName() + "/SUBSCRIPTIONS", "C", emptyString.c_str(),
     985                                     "List of all the services subscribed by datalogger, except the ones provided by itself."
     986                                     "|Liste[string]:list of logged services and the delay in seconds since last update");
     987     fCurrentSubscriptionUpdateRate = 60; //by default, 1 minute between each update
     988     fLastSubscriptionUpdate = timeNow;
     989
    922990     // provide services control commands
    923991     AddEvent("SET_DEBUG_MODE", "B:1", kSM_NightlyOpen, kSM_Logging, kSM_WaitingRun, kSM_Ready)
     
    9451013         ("Set the timeout delay for old run numbers."
    9461014          "|timeout[min]:Time out in minutes after which files for expired runs are closed.");
     1015     //Provide access to the duration between two updates of the service list
     1016     AddEvent("SET_SERVICE_LIST_UPDATE_INTERVAL", "I:1", kSM_Ready, kSM_NightlyOpen, kSM_Logging, kSM_WaitingRun)
     1017         (bind(&DataLogger::setSubscriptionListUpdateTimeLapse, this, placeholders::_1))
     1018         ("Set the min interval between two services-list updates."
     1019          "|duration[sec]:The interval between two updates, in seconds.");
    9471020
    9481021     fDestructing = false;
     
    10001073    delete fOpenedRunFiles;
    10011074    delete fNumSubAndFits;
     1075    delete fCurrentSubscription;
    10021076
    10031077    if (fNightlyLogFile.is_open())//this file is the only one that has not been closed by GoToReady
     
    12911365    fQuality = evt.GetQoS();
    12921366
     1367    //update subscription last received time
     1368    sub.lastReceivedEvent = cTime;
     1369    //update subscription list service if required
     1370    updateSubscriptionList();
     1371
    12931372    fMjD = cTime.Mjd() ? cTime.Mjd()-40587 : 0;
    12941373
     
    13091388            ostringstream str;
    13101389            str << "Parsing service " << evt.GetName();
    1311             str << " failed: " << e.what() << " removing the subscription for now.";
    1312             Error(str);
     1390            str << " failed: " << e.what() << " removing the subscription to " << sub.server << "/" << sub.service;
     1391            Warn(str);
    13131392            //remove this subscription from the list.
    13141393            //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 !
     
    13381417        //check if the last received event was before noon and if current one is after noon.
    13391418        //if so, close the file so that it gets reopened.
    1340         sub.lastReceivedEvent = cTime;
     1419//        sub.lastReceivedEvent = cTime;
    13411420        if (!sub.nightlyFile.IsOpen())
    13421421            if (GetCurrentState() != kSM_Ready)
     
    13801459        }
    13811460
    1382         sub.lastReceivedEvent = cTime;
     1461//        sub.lastReceivedEvent = cTime;
    13831462        if (!sub.nightlyFile.IsOpen())
    13841463            if (GetCurrentState() != kSM_Ready)
     
    13861465        WriteToFITS(sub, evt.GetData());
    13871466    }
    1388 
    13891467}
    13901468
     
    17041782    if (!sub.nightlyFile.IsOpen())
    17051783    {
    1706         const string partialName = CompileFileNameWithPath(fFilePath, serviceName, "fits");
     1784        string incrementedServiceName = serviceName;
     1785        if (sub.increment != 0)
     1786        {
     1787            ostringstream str;
     1788            str << "." << sub.increment;
     1789            incrementedServiceName += str.str();
     1790        }
     1791        const string partialName = CompileFileNameWithPath(fFilePath, incrementedServiceName, "fits");
    17071792
    17081793        const string fileNameOnly = partialName.substr(partialName.find_last_of('/')+1, partialName.size());
Note: See TracChangeset for help on using the changeset viewer.