Changeset 15153


Ignore:
Timestamp:
03/26/13 17:01:18 (12 years ago)
Author:
lyard
Message:
changed close time of files from noon to 30 minutes after sunrise for faster transfer to archive. Also disabled writing of report file.
File:
1 edited

Legend:

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

    r15107 r15153  
    8585
    8686#include "DimState.h"
     87
     88#include <libnova/solar.h>
     89#include <libnova/rise_set.h>
    8790
    8891//Dim structures
     
    239242    //overloading of DIM's infoHandler function
    240243    int infoCallback(const EventImp& evt, unsigned int infoIndex);
     244
     245    Time GetSunRise(const Time &time=Time());
    241246
    242247    /***************************************************
     
    386391
    387392    //Current day variable. Used to close nightly files when night changes
    388     int fCurrentDay;
     393    Time fCurrentDay;
    389394    Time lastFlush;
    390395
     
    849854
    850855    //calculate time suitable for naming files.
    851     const Time ftime = time-boost::posix_time::hours(12);
     856    //fCurrentDay is 30 minutes after upcoming sunrise. So just use 12 hours before then
     857    const Time ftime = fCurrentDay-boost::posix_time::hours(12);
    852858
    853859    //output it
     
    858864        CreateDirectory(str.str());
    859865
    860     str << '/' << CompileFileName(service, extension, time);
     866    str << '/' << CompileFileName(service, extension, fCurrentDay);
    861867
    862868    return str.str();
     
    916922    //calculate time "centered" around noon instead of midnight
    917923    const Time timeNow;
    918     const Time nowMinusTwelve = timeNow-boost::posix_time::hours(12);
    919     fCurrentDay = (int)(nowMinusTwelve.Mjd());//nowMinusTwelve.M()*31 + nowMinusTwelve.D();//assume 31 days per month. we do not really care, only want unique number per day of the year
     924//    const Time nowMinusTwelve = timeNow-boost::posix_time::hours(12);
     925    //the "current day" is actually the next closing time of nightly files
     926    //the next closing time is 30 minutes after upcoming sunrise.
     927    //If we are within 30 minutes after sunrise, closing time is soon
     928    fCurrentDay = GetSunRise(Time()-boost::posix_time::minutes(30)) + boost::posix_time::minutes(30);//(int)(nowMinusTwelve.Mjd());//nowMinusTwelve.M()*31 + nowMinusTwelve.D();//assume 31 days per month. we do not really care, only want unique number per day of the year
    920929    lastFlush = Time();
    921930
     
    12551264    AddNewRunNumber(evt.GetXtra(), evt.GetTime());
    12561265}
     1266// --------------------------------------------------------------------------
     1267//
     1268//! Get SunRise. Copied from drivectrl.cc
     1269//! Used to know when to close and reopen files
     1270//!
     1271Time DataLogger::GetSunRise(const Time &time)
     1272{
     1273    const double lon = -(17.+53./60+26.525/3600);
     1274    const double lat =   28.+45./60+42.462/3600;
     1275
     1276    ln_lnlat_posn observer;
     1277    observer.lng = lon;
     1278    observer.lat = lat;
     1279
     1280    // This caluclates the sun-rise of the next day after 12:00 noon
     1281    ln_rst_time sun_day;
     1282    if (ln_get_solar_rst(time.JD(), &observer, &sun_day)==1)
     1283    {
     1284        Fatal("GetSunRise reported the sun to be circumpolar!");
     1285        return Time(Time::none);
     1286    }
     1287
     1288    if (Time(sun_day.rise)>=time)
     1289        return Time(sun_day.rise);
     1290
     1291    if (ln_get_solar_rst(time.JD()+0.5, &observer, &sun_day)==1)
     1292    {
     1293        Fatal("GetSunRise reported the sun to be circumpolar!");
     1294        return Time(Time::none);
     1295    }
     1296
     1297    return Time(sun_day.rise);
     1298}
    12571299
    12581300// --------------------------------------------------------------------------
     
    12851327    // if number of days has changed, then files should be closed and reopenned.
    12861328    const Time timeNow;
    1287     const Time nowMinusTwelve = timeNow-boost::posix_time::hours(12);
    1288     int newDayNumber = (int)(nowMinusTwelve.Mjd());//nowMinusTwelve.M()*31 + nowMinusTwelve.D();//assume 31 days per month. we do not really care, only want unique number per day of the year
     1329//    const Time nowMinusTwelve = timeNow-boost::posix_time::hours(12);
     1330//    int newDayNumber = (int)(nowMinusTwelve.Mjd());
    12891331
    12901332    //also check if we should flush the nightly files
     
    13051347            Debug("Just flushed nightly fits files to the disk");
    13061348    }
    1307 
    1308     if (newDayNumber !=  fCurrentDay)
    1309     {
    1310         fCurrentDay = newDayNumber;
     1349    //check if we should close and reopen the nightly files
     1350    if (timeNow > fCurrentDay)//GetSunRise(fCurrentDay)+boost::posix_time::minutes(30)) //if we went past 30 minutes after sunrise
     1351    {
     1352        //set the next closing time. If we are here, we have passed 30 minutes after sunrise.
     1353        fCurrentDay = GetSunRise(timeNow-boost::posix_time::minutes(30))+boost::posix_time::minutes(30);
    13111354        //crawl through the subcriptions and close any open nightly file
    13121355        SubscriptionsListType::iterator x;
     
    13741417    if (isItaReport)
    13751418    {
     1419//DISABLED REPORT WRITING BY THOMAS REQUEST
    13761420        //write text header
    1377         string serviceName = (sub.service == "MESSAGE") ? "" : "_"+sub.service;
     1421/*        string serviceName = (sub.service == "MESSAGE") ? "" : "_"+sub.service;
    13781422        header << sub.server << serviceName << " " << fQuality << " ";
    13791423        header << evt.GetTime() << " ";
     
    14141458                return;
    14151459        }
     1460*/
    14161461#ifdef HAVE_FITS
    14171462        //check if the last received event was before noon and if current one is after noon.
Note: See TracChangeset for help on using the changeset viewer.