Ignore:
Timestamp:
06/10/11 20:12:47 (13 years ago)
Author:
tbretz
Message:
More improvements to logging; log when files are opened and/or closed (to be completed); Simplified some messages
File:
1 edited

Legend:

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

    r10991 r10992  
    370370    DimStampedInfo* SubscribeToPlease(const string& server, const string& service);
    371371    ///Open a text file and checks for ofstream status
    372     void OpenTextFilePlease(ofstream& stream, const string& name);
     372    bool OpenTextFilePlease(ofstream& stream, const string& name);
    373373    ///Check if a dir is . and returns the actual string corresponding to .
    374374//    string CheckIfDirIsDot(const string& dir);
     
    582582//! @name the file name
    583583//
    584 void DataLogger::OpenTextFilePlease(ofstream& stream, const string& name)
    585 {
     584bool DataLogger::OpenTextFilePlease(ofstream& stream, const string& name)
     585{
     586    Info("Opening: "+name);
     587
    586588    errno = 0;
    587589    stream.open(name.c_str(), ios_base::out | ios_base::app);
     
    589591    {
    590592        ostringstream str;
    591         str << "Open file " << name << ": " << strerror(errno) << " (errno=" << errno << ")";
     593        str << "Trying to open file " << name << ": " << strerror(errno) << " (errno=" << errno << ")";
    592594        Error(str);
    593     }
    594 }
     595        return false;
     596    }
     597
     598    return true;
     599}
     600
    595601// --------------------------------------------------------------------------
    596602//
     
    740746            if (y->second.runFile.fRunNumber == fRunNumber.front().runNumber && y->second.runFile.IsOpen())
    741747            {
    742                 if (fDebugIsOn)
    743                 {
    744                     ostringstream str;
    745                     str << "Closing Fits run file " << y->second.runFile.fFileName;
    746                     Debug(str);
    747                 }
    748748                y->second.runFile.Close();
     749
     750                Info("Closed: "+y->second.runFile.fFileName);
    749751            }
    750752    //if a grouping file is on, decrease the number of opened fits manually
     
    11781180bool DataLogger::OpenStream(shared_ptr<ofstream> stream, const string &filename)
    11791181{
     1182    Info("Opening: "+filename);
     1183
    11801184    if (stream->is_open())
    11811185    {
     
    13231327        fNightlyReportFile.close();
    13241328
     1329        Info("Closed: "+fFullNightlyLogFileName);
     1330        Info("Closed: "+fFullNightlyReportFileName);
     1331
    13251332        fFullNightlyLogFileName = CompileFileName(fNightlyFilePath, "", "log");
    13261333        OpenTextFilePlease(fNightlyLogFile, fFullNightlyLogFileName);
     1334        //FIXME: Handle return code properly!
    13271335
    13281336        fFullNightlyReportFileName = CompileFileName(fNightlyFilePath, "", "rep");
    13291337        OpenTextFilePlease(fNightlyReportFile, fFullNightlyReportFileName);
     1338        //FIXME: Handle return code properly!
    13301339
    13311340        fDailyFileDayChangedAlready = true;
     
    17351744    }
    17361745
    1737     Message("New "+type+" folder specified: "+givenPath);
     1746    Message("New "+type+" folder: "+givenPath);
    17381747
    17391748    target = givenPath;
     
    18301839    }
    18311840    fFullNightlyLogFileName = CompileFileName(fNightlyFilePath, "", "log");
    1832     OpenTextFilePlease(fNightlyLogFile, fFullNightlyLogFileName);
     1841    if (!OpenTextFilePlease(fNightlyLogFile, fFullNightlyLogFileName))
     1842        return kSM_BadNightlyConfig;
     1843
    18331844
    18341845    fFullNightlyReportFileName = CompileFileName(fNightlyFilePath, "", "rep");
    1835     OpenTextFilePlease(fNightlyReportFile, fFullNightlyReportFileName);
    1836 
    1837     if (!fNightlyLogFile.is_open() || !fNightlyReportFile.is_open())
    1838     {   
    1839         ostringstream str;
    1840         str << "Something went wrong while openning nightly files " << fFullNightlyLogFileName << " and " << fFullNightlyReportFileName;
    1841         Error(str);
     1846    if (!OpenTextFilePlease(fNightlyReportFile, fFullNightlyReportFileName))
    18421847        return kSM_BadNightlyConfig;
    1843     }
     1848
    18441849    //get the size of the newly opened file.
    18451850    fBaseSizeNightly = GetFileSize(fFullNightlyLogFileName);
     
    18711876     if (sub.runFile.IsOpen() && sub.runFile.fRunNumber != sub.runNumber)
    18721877     {
    1873          if (fDebugIsOn)
    1874              Debug("Run number changed. Closing " + sub.runFile.fFileName);
    18751878         sub.runFile.Close();
     1879         Info("Closed: "+sub.runFile.fFileName+" (new run number)");
    18761880     }
    18771881
     
    19101914            fOpenedNightlyFits[fileNameOnly].push_back(serviceName);
    19111915
     1916        ostringstream str;
     1917        str << "Opening: " << partialName << " (Nfits=" << fNumSubAndFitsData.numOpenFits << ")";
     1918        Info(str);
     1919
    19121920        if (!sub.nightlyFile.Open(partialName, serviceName, NULL, &fNumSubAndFitsData.numOpenFits, this, 0))
    19131921        {
     
    19201928        if (fNumSubAndFitsIsOn)
    19211929            fNumSubAndFits->updateService();
    1922         if (fDebugIsOn)
    1923         {
    1924             ostringstream str;
    1925             str << "Opened Nightly FITS: " << partialName << " and table: " << serviceName << ".current number of opened FITS: " << fNumSubAndFitsData.numOpenFits;
    1926             Debug(str);
    1927         }
    19281930    }
    19291931    //do the actual file open
     
    19341936        if (hasGrouping)
    19351937        {
    1936             partialName = CompileFileName(fRunFilePath, sub.runNumber, "group", "fits");
     1938            partialName = CompileFileName(fRunFilePath, sub.runNumber, "", "fits");
    19371939            fileNameOnly = partialName.substr(partialName.find_last_of('/')+1, partialName.size());
    19381940        }
     
    19601962            {
    19611963                ostringstream str;
    1962                 str << "Could not open FITS Run file " << partialName << " reason: " << e.message();
     1964                str << "Open FITS file " << partialName << ": " << e.message();
    19631965                Error(str);
    19641966                cRunNumber->runFitsFile = shared_ptr<CCfits::FITS>();//NULL;
     
    19671969        const string baseFileName = CompileFileName(fRunFilePath, sub.runNumber, "", "");
    19681970        NotifyOpenedFile(baseFileName, 7, fOpenedRunFiles);// + '_' + serviceName, 4);
     1971
     1972        ostringstream str;
     1973        str << "Opening: " << partialName << " (Nfits=" << fNumSubAndFitsData.numOpenFits << ")";
     1974        Info(str);
     1975
    19691976        if (hasGrouping)
    19701977        {
     
    19831990            }
    19841991        }
    1985        if (fNumSubAndFitsIsOn)
    1986            fNumSubAndFits->updateService();
    1987            if (fDebugIsOn)
    1988         {
    1989             ostringstream str;
    1990             str << "Opened Run FITS: " << partialName << " and table: " << serviceName << ".current number of opened FITS: " << fNumSubAndFitsData.numOpenFits;
    1991             Debug(str);
    1992         }
     1992        if (fNumSubAndFitsIsOn)
     1993            fNumSubAndFits->updateService();
    19931994    }
    19941995}   
     
    21652166        groupName = CompileFileName(fNightlyFilePath, "", "fits");
    21662167
     2168    Info("Creating FITS group in: "+groupName);
     2169
    21672170    CCfits::Table* groupTable;
    21682171    int maxCharLength = 50;//FILENAME_MAX;
     
    21902193     {
    21912194         ostringstream str;
    2192          str << "Could not open or create FITS table GROUPING in  file " << groupName << " reason: " << e.message();
     2195         str << "Creating FITS table GROUPING in " << groupName << ": " << e.message();
    21932196         Error(str);
    21942197         return;
     
    22322235            if (status)
    22332236            {
     2237                char text[30];//max length of cfitsio error strings (from doc)
     2238                fits_get_errstatus(status, text);
    22342239                ostringstream str;
    2235                 str << "Could not write row #" << i << "In the fits grouping file " << groupName << ". Cfitsio error code: " << status;
     2240                str << "Writing FITS row " << i << " in " << groupName << ": " << text << " (file_write_tblbytes, rc=" << status << ")";
    22362241                Error(str);
     2242                // FIXME: What to do in case of error?
    22372243            }
    22382244        }
Note: See TracChangeset for help on using the changeset viewer.