Changeset 14217 for trunk/FACT++


Ignore:
Timestamp:
06/22/12 15:30:55 (12 years ago)
Author:
lyard
Message:
farewell run logs
File:
1 edited

Legend:

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

    r14172 r14217  
    8080#include "DimNetwork.h"
    8181
    82 
    8382#ifdef HAVE_FITS
    8483#include "Fits.h"
    8584#endif
     85
    8686
    8787//Dim structures
     
    9999///Run number record. Used to keep track of which run numbers are still active
    100100struct RunNumberType {
    101 #ifdef RUN_LOGS
    102     ///the run number log file
    103     shared_ptr<ofstream> logFile;
    104 #endif
    105     ///the run number report file
    106     shared_ptr<ofstream> reportFile;
    107 #ifdef HAVE_FITS
    108     ///the run number group fits file
    109     shared_ptr<CCfits::FITS> runFitsFile;
    110 #endif
    111 #ifdef RUN_LOGS
    112     ///the log filename
    113     string logName;
    114 #endif
    115     ///the report filename
    116     string reportName;
     101
    117102    ///the actual run number
    118103    int32_t runNumber;
    119104    ///the time at which the run number was received
    120105    Time time;
    121     ///list of opened fits used to create the fits grouping when the run ends
    122     map<string, vector<string> > openedFits;
    123106    ///default constructor
    124107    RunNumberType()
    125108    {
    126 #ifdef RUN_LOGS
    127         logFile = shared_ptr<ofstream>(new ofstream());
    128 #endif
    129         reportFile = shared_ptr<ofstream>(new ofstream());
    130 #ifdef HAVE_FITS
    131         runFitsFile = shared_ptr<CCfits::FITS>();
    132 #endif
    133109        runNumber = 0;
    134110    }
     
    137113    {
    138114
    139     }
    140 
    141     void addServiceToOpenedFits(const string& fileName, const string& serviceName)
    142     {
    143          //most likely I should add this service name.
    144          //the only case for which I should not add it is if a service disapeared, hence the file was closed
    145          //and reopened again. Unlikely to happen, but well it may
    146 
    147          if (find(openedFits[fileName].begin(), openedFits[fileName].end(),
    148                   serviceName)==openedFits[fileName].end())
    149             openedFits[fileName].push_back(serviceName);
    150115    }
    151116};
     
    156121    ///Nightly FITS output file
    157122    Fits    nightlyFile;
    158     ///run-specific FITS output file
    159     Fits    runFile;
    160123#endif
    161124    ///the server
     
    171134    ///whether or not the fits buffer was allocated already
    172135    bool fitsBufferAllocated;
    173 
    174136    ///the actual dimInfo pointer (must be the last in the list to ensure
    175137    /// that it is the first which is deleted -- and consequently none of
    176138    /// the other members can still be in use in an infoHandler)
    177139    shared_ptr<DimStampedInfo> dimInfo;
    178 
    179140    ///Dim info constructor
    180141    SubscriptionType(DimStampedInfo* info=NULL)
     
    189150        dimInfo = shared_ptr<DimStampedInfo>(info);
    190151    }
    191 
    192152    ///default destructor
    193153    ~SubscriptionType()
     
    284244#ifdef HAVE_FITS
    285245    ///Open fits files
    286     void OpenFITSFiles(SubscriptionType& sub, RunNumberType* cRunNumber);
     246    void OpenFITSFiles(SubscriptionType& sub);
    287247    ///Write data to FITS files
    288248    void WriteToFITS(SubscriptionType& sub);
     
    313273    ///configuration flags
    314274    bool fDebugIsOn;
    315 //    float fStatsPeriodDuration;
    316275    bool fOpenedFilesIsOn;
    317276    bool fNumSubAndFitsIsOn;
     
    331290    map<string, vector<string> > fOpenedNightlyFits;
    332291    ///creates a group fits file based on a list of files to be grouped
    333     void CreateFitsGrouping(map<string, vector<string> >& filesToGroup, int runNumber);
     292    void CreateFitsGrouping(map<string, vector<string> >& filesToGroup);
    334293
    335294    bool OpenStreamImp(ofstream &stream, const string &filename, bool mightbeopen);
     
    349308    void AppendYearMonthDaytoPath(string& path);
    350309    ///Form the files path
    351     string CompileFileNameWithPath(const string &path, const string &service, const string & extension, uint32_t run=0/*, const Time &time=Time()*/);
     310    string CompileFileNameWithPath(const string &path, const string &service, const string & extension);
    352311    ///Form the file names only
    353     string CompileFileName(const string& service, const string& extension, uint32_t run=0, const Time& time=Time()) const;
     312    string CompileFileName(const string& service, const string& extension, const Time& time=Time()) const;
    354313    ///Check whether service is in black and/or white list
    355314    bool ShouldSubscribe(const string& server, const string& service);
     
    498457void DataLogger::RemoveService(string server, string service, bool isCmd)
    499458{
    500     Info("Got request for removing service: "+server+"/"+service);
     459    Info("Got request to remove service: "+server+"/"+service);
    501460    if (fDestructing)//this function is called by the super class, after the destructor has deleted its own subscriptions
    502461        return;
     
    666625//! @param extension the extension to add, if any
    667626//
    668 //string DataLogger::CompileFileName(const string &path, const string &service, const string & extension, const Time &time)
    669 string DataLogger::CompileFileName(const string& service, const string& extension, uint32_t run, const Time& time) const
     627string DataLogger::CompileFileName(const string& service, const string& extension, const Time& time) const
    670628{
    671629    ostringstream str;
     
    674632    str << ftime.NightAsInt();
    675633
    676     if (run>0)
    677         str << '_' << setfill('0') << setw(3) << run;
    678 
    679634    if (!service.empty())
    680635        str << '.' << service;
     
    686641}
    687642
    688 string DataLogger::CompileFileNameWithPath(const string& path, const string& service, const string& extension, uint32_t run/*, const Time& time*/)
     643string DataLogger::CompileFileNameWithPath(const string& path, const string& service, const string& extension)
    689644{
    690645    ostringstream str;
     
    702657        CreateDirectory(str.str());
    703658
    704     str << '/' << CompileFileName(service, extension, run, time);
     659    str << '/' << CompileFileName(service, extension, time);
    705660
    706661    return str.str();
     
    733688        Debug(str);
    734689    }
    735     CreateFitsGrouping(fRunNumber.front().openedFits, fRunNumber.front().runNumber);
    736 
    737     //crawl through the subscriptions to see if there are still corresponding fits files opened.
    738     for (SubscriptionsListType::iterator x=fServiceSubscriptions.begin();
    739          x!=fServiceSubscriptions.end(); x++)
    740         for (map<string, SubscriptionType>::iterator y=x->second.begin();
    741              y!=x->second.end(); y++)
    742             if (y->second.runFile.fRunNumber == fRunNumber.front().runNumber && y->second.runFile.IsOpen())
    743             {
    744                 y->second.runFile.Close();
    745             }
    746     //if a grouping file is on, decrease the number of opened fits manually
    747     if (fRunNumber.front().runFitsFile)
    748         (fNumSubAndFitsData.numOpenFits)--;
    749690    //remove the entry
    750691    fRunNumber.pop_front();
     
    787728        (bind(&DataLogger::GoToReady, this))
    788729        ("Stop all data logging, close all files.");
    789 /*
    790     AddEvent(kSM_Logging, "START_RUN", kSM_WaitingRun, kSM_BadRunConfig)
    791         (bind(&DataLogger::StartRun, this))
    792         ("Start the run logging. Run file location must be specified already.");
    793 
    794     AddEvent(kSM_WaitingRun, "STOP_RUN", kSM_Logging)
    795         (bind(&DataLogger::StopRunLogging, this))
    796         ("Wait for a run to be started, open run-files as soon as a run number arrives.");
    797 */
     730
    798731    AddEvent("RESET", kSM_Error, kSM_BadFolder, kSM_DailyWriteError, kSM_RunWriteError)
    799732        (bind(&DataLogger::GoToReady, this))
     
    808741        ("Go from the wait for run to nightly open state.");
    809742
    810     /*
    811     // Add the possible configurations for this machine
    812     AddEvent("SET_FOLDER", "C", kSM_Ready, kSM_BadNightlyConfig)
    813         (bind(&DataLogger::ConfigureNightlyFileName, this, placeholders::_1))
    814         ("Configure the base folder for the nightly files."
    815          "|Path[string]:Absolute or relative path name where the nightly files should be stored.");
    816 
    817     AddEvent("SET_RUN_FOLDER", "C", kSM_Ready, kSM_BadNightlyConfig, kSM_NightlyOpen, kSM_WaitingRun, kSM_BadRunConfig)
    818         (bind(&DataLogger::ConfigureRunFileName, this, placeholders::_1))
    819         ("Configure the base folder for the run files."
    820          "|Path[string]:Absolute or relative path name where the run files should be stored.");
    821      */
    822743     // Provide a print command
    823744     AddEvent("PRINT_INFO")
     
    909830    fDestructing = true;
    910831
    911     //first, let's backup the datalogger/message service subscription
    912 //    shared_ptr<DimStampedInfo> messageBackup;
    913 //    const SubscriptionsListType::iterator x = fServiceSubscriptions.find("DATA_LOGGER");
    914 //    if (x != fServiceSubscriptions.end())
    915 //    {
    916 //        const map<string, SubscriptionType>::iterator y = x->second.find("MESSAGE");
    917 //        if (y != x->second.end())
    918 //            messageBackup = y->second.dimInfo;
    919 //    }
    920 
    921 
    922832    //now clear the services subscriptions
    923833    dim_lock();
     
    933843    GoToReady();
    934844
    935 
    936845    Info("Will soon close the daily log file");
    937846
     
    940849    delete fNumSubAndFits;
    941850
    942     //release message service before closing nightly log file
    943 //    if (messageBackup)
    944  //       messageBackup.reset();
    945 
    946851    if (fNightlyLogFile.is_open())//this file is the only one that has not been closed by GoToReady
    947852    {
    948 //        dim_lock();
    949853        fNightlyLogFile << endl;
    950854        fNightlyLogFile.close();
    951 //        dim_unlock();
    952855    }
    953856
     
    984887        SetCurrentState(Start());
    985888    }
    986     else {if (GetCurrentState() > kSM_Ready)
     889    else
     890    {
     891        if (GetCurrentState() > kSM_Ready)
    987892            fAutoStarted = true;
    988893    }
     
    1022927        return;
    1023928    }
    1024         // Make sure that getTimestampMillisecs is NEVER called before
    1025         // getTimestamp is properly called
    1026         // check that the message has been updated by something, i.e. must be different from its initial value
     929    // Make sure that getTimestampMillisecs is NEVER called before
     930    // getTimestamp is properly called
     931    // check that the message has been updated by something, i.e. must be different from its initial value
    1027932    if (I->getTimestamp() == 0)
    1028933    {
     
    1046951// --------------------------------------------------------------------------
    1047952//
    1048 //! Open the text files associated with the given run number
    1049 //! @param run the run number to be dealt with
    1050 //
    1051 int DataLogger::OpenRunFile(RunNumberType& run)
    1052 {
    1053 #ifdef RUN_LOGS
    1054     // open log file
    1055     run.logName = CompileFileName(fFilePath, "", "log", run.runNumber);
    1056     if (!OpenStream(run.logFile, run.logName))
    1057         return -1;
    1058 #endif
    1059 
    1060     // open report file
    1061     run.reportName = CompileFileNameWithPath(fFilePath, "", "rep", run.runNumber);
    1062     if (!OpenStream(run.reportFile, run.reportName))
    1063         return -1;
    1064 
    1065     //get the size of the newly opened file.
    1066 #ifdef RUN_LOGS
    1067     fFilesStats.FileOpened(run.logName);
    1068 #endif
    1069     fFilesStats.FileOpened(run.reportName);
    1070     //TODO this notification scheme might be messed up now.... fix it !
    1071     const string baseFileName = CompileFileNameWithPath(fFilePath, "", "", run.runNumber);
    1072     NotifyOpenedFile(baseFileName, 3, fOpenedRunFiles);
    1073     run.openedFits.clear();
    1074     return 0;
    1075 }
    1076 // --------------------------------------------------------------------------
    1077 //
    1078953//! Add a new active run number
    1079954//! @param newRun the new run number
     
    1114989    if (GetCurrentState() != kSM_Logging && GetCurrentState() != kSM_WaitingRun )
    1115990        return;
    1116     //open the log and report files
    1117     if (fRunNumber.back().runNumber > 0)
    1118     if (OpenRunFile(fRunNumber.back()) != 0)
    1119     {//an error occured. close current run files and go to error state
    1120         for (list<RunNumberType>::iterator it=fRunNumber.begin(); it != fRunNumber.end(); it++)
    1121         {
    1122             if (it->reportFile->is_open())
    1123             {
    1124                 it->reportFile->close();
    1125                 Info("Closed: "+it->reportName);
    1126             }
    1127 #ifdef RUN_LOGS
    1128             if (it->logFile->is_open())
    1129             {
    1130                 it->logFile->close();
    1131                 Info("Closed: "+it->logName);
    1132             }
    1133 #endif
    1134         }
    1135         StopRunLogging();
    1136         SetCurrentState(kSM_BadFolder);
    1137     }
    1138991
    1139992    if (newRun > 0 && GetCurrentState()  == kSM_WaitingRun)
     
    12071060    }
    12081061
    1209 //    if (Time().h() == 12 && !fDailyFileDayChangedAlready)
    12101062    if (newDayNumber !=  fCurrentDay)
    12111063    {
     
    12491101            return;
    12501102        }
    1251 
    1252  //       fDailyFileDayChangedAlready = true;
    1253     }
    1254 //    if (Time().h() != 12 && fDailyFileDayChangedAlready)
    1255 //        fDailyFileDayChangedAlready = false;
    1256 
     1103    }
    12571104    //create the converter for that service
    12581105    if (!sub.fConv)
     
    12821129    fMjD = cTime.Mjd() ? cTime.Mjd()-40587 : 0;
    12831130
    1284     //figure out which run file should be used
    1285     ofstream* targetRunFile = NULL;
    1286     RunNumberType* cRunNumber = NULL;
    1287     if (GetCurrentState() == kSM_Logging || GetCurrentState() == kSM_WaitingRun)
    1288     {
    1289         list<RunNumberType>::reverse_iterator rit;
    1290         for (rit=fRunNumber.rbegin(); rit!=fRunNumber.rend(); rit++)
    1291         {
    1292             if (rit->time < cTime) //this is the run number that we want to use
    1293             {
    1294                 //Find something better to convert iterator to pointer than the ugly line below....
    1295                 cRunNumber = &(*rit);
    1296                 sub.runNumber = rit->runNumber;
    1297 
    1298                 if (rit->runNumber <= 0)//take only positive numbers.
    1299                     break;
    1300 #ifdef RUN_LOGS
    1301                 targetRunFile = isItaReport ? (rit->reportFile).get() : (rit->logFile).get();
    1302 #else
    1303                 targetRunFile = isItaReport ? (rit->reportFile).get() : NULL;
    1304 #endif
    1305                 break;
    1306             }
    1307         }
    1308         if (rit == fRunNumber.rend() && fRunNumber.size() != 0)
    1309         {
    1310             Error("Could not find an appropriate run number for info coming at time "+cTime.GetAsStr());
    1311             Error("Active run numbers: ");
    1312             for (rit=fRunNumber.rbegin(); rit != fRunNumber.rend(); rit++)
    1313             {
    1314                 ostringstream str;
    1315                 str << " -> " << rit->runNumber;
    1316                 Error(str);
    1317             }
    1318 
    1319         }
    1320     }
    1321 
    13221131    if (isItaReport)
    13231132    {
     
    13421151            //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 !
    13431152            RemoveService(sub.server, sub.service, false);
    1344 //            string server = sub.server;
    1345 //            string service = sub.service;
    1346 //            fServiceSubscriptions.find(server)->second.erase(service);
    13471153            return;
    13481154        }
     
    13661172                return;
    13671173        }
    1368         //write entry to run-report
    1369         if (targetRunFile && targetRunFile->is_open())
    1370         {
    1371             *targetRunFile << header.str() << text << endl;
    1372             if (!CheckForOfstreamError(*targetRunFile, false))
    1373                 return;
    1374         }
    13751174#ifdef HAVE_FITS
    13761175        //check if the last received event was before noon and if current one is after noon.
    13771176        //if so, close the file so that it gets reopened.
    1378 //        if (sub.nightlyFile.IsOpen())
    1379 //            if ((sub.lastReceivedEvent != Time::None) && (sub.lastReceivedEvent.h() < 12) && (cTime.h() >= 12))
    1380 //            {
    1381 //                sub.nightlyFile.Close();
    1382 //            }
    1383         sub.lastReceivedEvent = cTime;//ici
    1384         if (!sub.nightlyFile.IsOpen() || !sub.runFile.IsOpen() || sub.runNumber != sub.runFile.fRunNumber)
     1177        sub.lastReceivedEvent = cTime;
     1178        if (!sub.nightlyFile.IsOpen())
    13851179            if (GetCurrentState() != kSM_Ready)
    1386                 OpenFITSFiles(sub, cRunNumber);
     1180                OpenFITSFiles(sub);
    13871181        WriteToFITS(sub);
    13881182#endif
     
    14041198            //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 !
    14051199            RemoveService(sub.server, sub.service, false);
    1406 //            string server = sub.server;
    1407 //            string service = sub.service;
    1408 //            fServiceSubscriptions.find(server)->second.erase(service);
    14091200            return;
    14101201        }
     
    14241215                return;
    14251216        }
    1426         if (targetRunFile && targetRunFile->is_open())
    1427         {
    1428             MessageImp(*targetRunFile).Write(cTime, msg.str().c_str(),  fQuality);
    1429             if (!CheckForOfstreamError(*targetRunFile, false))
    1430                 return;
    1431         }
    1432 
    1433         sub.lastReceivedEvent = cTime;//ici
    1434         if (!sub.nightlyFile.IsOpen() || !sub.runFile.IsOpen() || sub.runNumber != sub.runFile.fRunNumber)
     1217
     1218        sub.lastReceivedEvent = cTime;
     1219        if (!sub.nightlyFile.IsOpen())
    14351220            if (GetCurrentState() != kSM_Ready)
    1436                 OpenFITSFiles(sub, cRunNumber);
     1221                OpenFITSFiles(sub);
    14371222        WriteToFITS(sub);
    14381223    }
     
    14821267        Message("Nightly report-file: "+fFullNightlyReportFileName);
    14831268
    1484     for (list<RunNumberType>::const_iterator it=fRunNumber.begin(); it!=fRunNumber.end(); it++)
    1485     {
    1486 #ifdef RUN_LOGS
    1487         if (it->logFile->is_open())
    1488             Message("Run log-file:    " + it->logName);
    1489 #endif
    1490         if (it->reportFile->is_open())
    1491             Message("Run report-file: " + it->reportName);
    1492     }
    1493 
    14941269    const DimWriteStatistics::Stats statVar = fFilesStats.GetTotalSizeWritten();
    14951270 //   /*const bool statWarning =*/ calculateTotalSizeWritten(statVar, true);
     
    16701445// --------------------------------------------------------------------------
    16711446//
    1672 //!    Sets the path to use for the Nightly log file.
    1673 //! @param evt
    1674 //!     the event transporting the path
    1675 //! @returns
    1676 //!        currently only the current state.
    1677 /*
    1678 int DataLogger::ConfigureFilePath(const Event& evt)
    1679 {
    1680     if (!evt.GetText())
    1681     {
    1682         Error("Empty folder given. Please specify a valid path.");
    1683         return GetCurrentState();
    1684     }
    1685 
    1686     const string givenPath = evt.GetText();
    1687     if (!DoesPathExist(givenPath))
    1688     {
    1689         Error("Provided path '"+givenPath+"' is not a valid folder... ignored.");
    1690         return GetCurrentState();
    1691     }
    1692 
    1693     Message("New folder: "+givenPath);
    1694 
    1695     fFilePath = givenPath;
    1696 
    1697     fFilesStats.SetCurrentFolder(givenPath);
    1698 
    1699     return GetCurrentState();
    1700 }
    1701 */
    1702 
    1703 // --------------------------------------------------------------------------
    1704 //
    17051447//! Notifies the DIM service that a particular file was opened
    17061448//! @ param name the base name of the opened file, i.e. without path nor extension.
     
    17831525//! @param sub
    17841526//!     the current DimInfo subscription being examined
    1785 void DataLogger::OpenFITSFiles(SubscriptionType& sub, RunNumberType* cRunNumber)
     1527void DataLogger::OpenFITSFiles(SubscriptionType& sub)
    17861528{
    17871529    string serviceName(sub.dimInfo->getName());
    17881530
    1789     //if run number has changed, reopen a new fits file with the correct run number.
    1790      if (sub.runFile.IsOpen() && sub.runFile.fRunNumber != sub.runNumber)
    1791      {
    1792          sub.runFile.Close();
    1793          Info("Closed: "+sub.runFile.GetName()+" (new run number)");
    1794      }
    1795 
    1796      //we must check if we should group this service subscription to a single fits file before we replace the / by _
    1797     bool hasGrouping = false;
    1798     if (!sub.runFile.IsOpen() && ((GetCurrentState() == kSM_Logging) || (GetCurrentState() == kSM_WaitingRun)))
    1799     {//will we find this service in the grouping list ?
    1800         for (set<string>::const_iterator it=fGrouping.begin(); it!=fGrouping.end(); it++)
    1801         {
    1802             if (serviceName.find(*it) != string::npos)
    1803             {
    1804                 hasGrouping = true;
    1805                 break;
    1806             }
    1807         }
    1808     }
    18091531    for (unsigned int i=0;i<serviceName.size(); i++)
    18101532    {
     
    18431565            fNumSubAndFits->Update();
    18441566    }
    1845     //do the actual file open
    1846     if (!sub.runFile.IsOpen() && (GetCurrentState() == kSM_WaitingRun || GetCurrentState() == kSM_Logging) && sub.runNumber > 0)
    1847     {//buffer for the run file have already been allocated when doing the Nightly file
    1848 
    1849         const string partialName =
    1850             CompileFileNameWithPath(fFilePath, hasGrouping ? "" : serviceName, "fits", sub.runNumber);
    1851 
    1852         const string fileNameOnly =
    1853             partialName.substr(partialName.find_last_of('/')+1, partialName.size());
    1854 
    1855         //get the size of the file we're about to open
    1856         if (fFilesStats.FileOpened(partialName))
    1857             cRunNumber->openedFits[fileNameOnly].push_back(serviceName);
    1858         else
    1859             if (hasGrouping)
    1860             {
    1861              cRunNumber->addServiceToOpenedFits(fileNameOnly, serviceName);
    1862             }
    1863 
    1864         if (hasGrouping && (!cRunNumber->runFitsFile.get()))
    1865             try
    1866             {
    1867                 cRunNumber->runFitsFile = shared_ptr<CCfits::FITS>(new CCfits::FITS(partialName, CCfits::RWmode::Write));
    1868                 (fNumSubAndFitsData.numOpenFits)++;
    1869             }   
    1870             catch (CCfits::FitsException e)
    1871             {
    1872                 ostringstream str;
    1873                 str << "Open FITS file " << partialName << ": " << e.message();
    1874                 Error(str);
    1875                 cRunNumber->runFitsFile = shared_ptr<CCfits::FITS>();
    1876                 GoToRunWriteErrorState();
    1877                 return;
    1878             }
    1879 
    1880         const string baseFileName = CompileFileNameWithPath(fFilePath, "", "", sub.runNumber);
    1881         NotifyOpenedFile(baseFileName, 7, fOpenedRunFiles);
    1882 
    1883         if (hasGrouping)
    1884         {
    1885             if (!sub.runFile.Open(partialName, serviceName, &fNumSubAndFitsData.numOpenFits, this, sub.runNumber, cRunNumber->runFitsFile.get()))
    1886             {
    1887                 GoToRunWriteErrorState();
    1888                 return;
    1889             }
    1890         }
    1891         else
    1892         {
    1893             if (!sub.runFile.Open(partialName, serviceName, &fNumSubAndFitsData.numOpenFits, this, sub.runNumber))
    1894             {
    1895                 GoToRunWriteErrorState();
    1896                 return;
    1897             }
    1898         }
    1899 
    1900         ostringstream str;
    1901         str << "Opened: " << partialName << " (Nfits=" << fNumSubAndFitsData.numOpenFits << ")";
    1902         Info(str);
    1903 
    1904         if (fNumSubAndFitsIsOn)
    1905             fNumSubAndFits->Update();
    1906     }
     1567
    19071568}   
    19081569// --------------------------------------------------------------------------
     
    19161577    Description dateDesc(string("Time"), string("Modified Julian Date"), string("MJD"));
    19171578    sub.nightlyFile.AddStandardColumn(dateDesc, "1D", &fMjD, sizeof(double));
    1918     sub.runFile.AddStandardColumn(dateDesc, "1D", &fMjD, sizeof(double));
    19191579
    19201580    Description QoSDesc("QoS", "Quality of service", "");
    19211581    sub.nightlyFile.AddStandardColumn(QoSDesc, "1J", &fQuality, sizeof(int));
    1922     sub.runFile.AddStandardColumn(QoSDesc, "1J", &fQuality, sizeof(int));
    19231582
    19241583    // Compilation failed
     
    19371596    Info(str);
    19381597    sub.nightlyFile.InitDataColumns(GetDescription(sub.server, sub.service), dataFormatsLocal, sub.dimInfo->getData(), this);
    1939     sub.runFile.InitDataColumns(GetDescription(sub.server, sub.service), dataFormatsLocal, sub.dimInfo->getData(), this);
    19401598
    19411599    sub.fitsBufferAllocated = true;
     
    19521610            if (!sub.nightlyFile.Write(*sub.fConv.get()))
    19531611            {
    1954                 //sub.nightlyFile.Close();
    19551612                RemoveService(sub.server, sub.service, false);
    19561613                GoToNightlyWriteErrorState();
    19571614                return;
    19581615            }
    1959  //           sub.nightlyFile.Flush();
    19601616         }
    1961 
    1962         if (sub.runFile.IsOpen())
    1963         {
    1964             if (!sub.runFile.Write(*sub.fConv.get()))
    1965             {
    1966                 sub.runFile.Close();
    1967                 RemoveService(sub.server, sub.service, false);
    1968                 GoToRunWriteErrorState();
    1969                 return;
    1970             }
    1971         }
    19721617}
    19731618#endif //if has_fits
     
    19921637}
    19931638
    1994 /*
    1995 // --------------------------------------------------------------------------
    1996 //
    1997 //! Implements the StartRun transition.
    1998 //! Concatenates the given path for the run file and the filename itself (based on the run number),
    1999 //! and tries to open it.
    2000 //! @returns
    2001 //!        kSM_Logging if success, kSM_BadRunConfig if failure.
    2002 int DataLogger::StartRun()
    2003 {
    2004     if (fDebugIsOn)
    2005     {
    2006         Debug("Starting Run Logging...");   
    2007     }
    2008     //open all the relevant run-files. i.e. all the files associated with run numbers.
    2009     for (list<RunNumberType>::iterator it=fRunNumber.begin(); it != fRunNumber.end(); it++)
    2010         if (OpenRunFile(*it) != 0)
    2011         {
    2012             StopRun();
    2013             return kSM_BadRunConfig;
    2014         }
    2015 
    2016     return kSM_Logging;
    2017 }
    2018 */
     1639
    20191640#ifdef HAVE_FITS
    20201641// --------------------------------------------------------------------------
     
    20251646//! @param runNumber the run number that should be used for grouping. 0 means nightly group
    20261647//
    2027 void DataLogger::CreateFitsGrouping(map<string, vector<string> > & filesToGroup, int runNumber)
     1648void DataLogger::CreateFitsGrouping(map<string, vector<string> > & filesToGroup)
    20281649{
    20291650    if (fDebugIsOn)
    20301651    {
    20311652        ostringstream str;
    2032         str << "Creating fits group for ";
    2033         if (runNumber != 0)
    2034             str << "run files";
    2035         else
    2036             str << "nightly files";
     1653        str << "Creating fits group for nightly files";
    20371654        Debug(str);
    20381655    }
     
    20641681        return;
    20651682    }
    2066     const string groupName = CompileFileNameWithPath(fFilePath, "", "fits", runNumber);
     1683    const string groupName = CompileFileNameWithPath(fFilePath, "", "fits");
    20671684
    20681685    Info("Creating FITS group in: "+groupName);
    20691686
    20701687    CCfits::Table* groupTable;
    2071 //    const int maxCharLength = FILENAME_MAX;
     1688
    20721689    try
    20731690    {
     
    21221739    char *startOfLocation  = realBuffer.data()+8+3;
    21231740    char *startOfName      = realBuffer.data()+8+3+maxCharLength;
    2124  //   char* startOfMemVer    = reinterpret_cast<char*>(&fitsBuffer[8+3+2*maxCharLength]);
    2125  //   char* startOfMemPos    = reinterpret_cast<char*>(&fitsBuffer[8+3+2*maxCharLength+1]);
    21261741
    21271742    strcpy(startOfExtension, "BINTABLE");
     
    21811796        Debug("Stopping Run Logging...");   
    21821797    }
    2183     //it may be that dim tries to write a dimInfo at the same time as we're closing files. Prevent this
    2184 
    2185 //    dim_lock();
    2186     for (list<RunNumberType>::const_iterator it=fRunNumber.begin(); it != fRunNumber.end(); it++)
    2187     {
    2188 #ifdef RUN_LOGS
    2189         if (!it->logFile->is_open() || !it->reportFile->is_open())
    2190 #else
    2191         if (!it->reportFile->is_open())
    2192 #endif
    2193             return kSM_FatalError;
    2194 #ifdef RUN_LOGS
    2195         it->logFile->close();
    2196         Info("Closed: "+it->logName);
    2197 
    2198 #endif
    2199         it->reportFile->close();
    2200         Info("Closed: "+it->reportName);
    2201     }
    2202 
    2203 #ifdef HAVE_FITS
    2204     for (SubscriptionsListType::iterator i = fServiceSubscriptions.begin(); i != fServiceSubscriptions.end(); i++)
    2205         for (map<string, SubscriptionType>::iterator j = i->second.begin(); j != i->second.end(); j++)
    2206         {
    2207             if (j->second.runFile.IsOpen())
    2208                 j->second.runFile.Close();
    2209         }
    2210 #endif
    2211     NotifyOpenedFile("", 0, fOpenedRunFiles);
     1798
    22121799    if (fNumSubAndFitsIsOn)
    22131800        fNumSubAndFits->Update();
     
    22171804        RemoveOldestRunNumber();
    22181805    }
    2219 //    dim_unlock();
    22201806    return kSM_WaitingRun;
    22211807}
     
    22601846    }
    22611847#ifdef HAVE_FITS
    2262     CreateFitsGrouping(fOpenedNightlyFits, 0);
     1848    CreateFitsGrouping(fOpenedNightlyFits);
    22631849#endif
    22641850    return kSM_Ready;
     
    22741860{
    22751861    int cState = GetCurrentState();
    2276 
    2277 //    if (cState == kSM_Logging)
    2278 //        cState = kSM_NightlyOpen;
    22791862
    22801863    if (cState == kSM_Ready)
     
    24732056        return 127;
    24742057
    2475 //    try
    24762058    {
    24772059        // No console access at all
     
    24852067            return RunShell<LocalConsole>(conf);
    24862068    }
    2487 /*    catch (exception& e)
    2488     {
    2489         cerr << "Exception: " << e.what() << endl;
    2490         return -1;
    2491     }*/
     2069
    24922070
    24932071    return 0;
Note: See TracChangeset for help on using the changeset viewer.