Ignore:
Timestamp:
05/31/11 10:19:09 (13 years ago)
Author:
lyard
Message:
minor changes
File:
1 edited

Legend:

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

    r10867 r10887  
    194194    }
    195195
     196    void addServiceToOpenedFits(const string& fileName, const string& serviceName)
     197    {//most likely I should add this service name.
     198     //the only case for which I should not add it is if a service disapeared, hence the file was closed
     199     //and reopened again. Unlikely to happen, but well it may
     200        bool found = false;
     201        for (vector<string>::iterator it=openedFits[fileName].begin(); it!=openedFits[fileName].end(); it++)
     202            if (*it == serviceName)
     203            {
     204                found = true;
     205                break;
     206            }
     207        if (!found)
     208            openedFits[fileName].push_back(serviceName);
     209    }
     210
    196211};
    197212///Dim subscription type. Stores all the relevant info to handle a Dim subscription
     
    456471    ///retrieves the size of a file
    457472    off_t GetFileSize(string&);
     473    ///Form the base (without extension) name of the nightly text files (logs and reports)
     474    void FormBaseNightlyTextFileName(string& name);
    458475    ///Form the name of the nightly text files (logs and reports)
    459476    void FormNightlyTextFileName(string& name, bool isReport);
     477    ///Form the base (without extension) name of the run text files (logs and reports)
     478    void FormBaseRunTextFileName(string& name, const int runNumber);
    460479    ///Form the name of the run text files (logs and reports)
    461480    void FormRunTextFileName(string& name, bool isReport, const int runNumber);
     
    478497    ///Remembers the size of newly opened files. for statistic purposes
    479498    bool RememberFileOrigSizePlease(string& fileName, bool nightly);
     499    ///Checks if the input osftream is in error state, and if so close it.
     500    void CheckForOfstreamError(ofstream& out);
    480501}; //DataLogger
    481502
    482503// --------------------------------------------------------------------------
    483504//
    484 //!
     505//! Checks if the given ofstream is in error state and if so, close it
     506//! @param out the ofstream that should be checked
     507//
     508void DataLogger::CheckForOfstreamError(ofstream& out)
     509{
     510    if (!out.good())
     511    {
     512        Error("An error occured while writing to a text file. Closing it");
     513        if (out.is_open())
     514            out.close();
     515    }
     516}
     517// --------------------------------------------------------------------------
     518//
     519//! Checks the size on disk of a given size, and remembers it in the relevant member variable
     520//! @param fileName the file for which the size on disk should be retrieved
     521//! @param nightly whether this is a run or nightly file, so that its size is added to the correct member variable
    485522//
    486523bool DataLogger::RememberFileOrigSizePlease(string& fileName, bool nightly)
     
    500537// --------------------------------------------------------------------------
    501538//
    502 //!
     539//! Checks if a given directory is simply '.' and retrieves the coresponding full path
     540//! @param dir the input directory that should be checked against
     541//! @return the full path corresponding to the input directory
    503542//
    504543string DataLogger::CheckIfDirIsDot(const string& dir)
     
    525564// --------------------------------------------------------------------------
    526565//
    527 //!
     566//! Open a text file and checks for error code
     567//! @param stream the ofstream for which the file should be opened
     568//! @name the file name
    528569//
    529570void DataLogger::OpenTextFilePlease(ofstream& stream, const string& name)
     
    644685// --------------------------------------------------------------------------
    645686//
     687//! Form the base (without extension) name of the run text files (logs and reports)
     688//! @param name the full file name
     689//! @param runNumber the current run number for which this file should be opened
     690//
     691void DataLogger::FormBaseRunTextFileName(string& name, const int runNumber)
     692{
     693    ostringstream sRun;
     694    sRun << runNumber;
     695
     696    name = CheckIfDirIsDot(fRunFilePath) + '/' + sRun.str();
     697}
     698// --------------------------------------------------------------------------
     699//
    646700//! Form the name of the run text files (logs and reports)
    647701//! @param name the full file name
     
    651705void DataLogger::FormRunTextFileName(string& name, bool isReport, const int runNumber)
    652706{
    653     ostringstream sRun;
    654     sRun << runNumber;
    655 
    656     name = fRunFilePath + '/' + sRun.str();
     707    FormBaseRunTextFileName(name, runNumber);
    657708
    658709    if (isReport)
     
    663714// --------------------------------------------------------------------------
    664715//
     716//! Form the base (without extension) name of the nightly text files (logs and reports)
     717//! @param name the full file name
     718//
     719void DataLogger::FormBaseNightlyTextFileName(string& name)
     720{
     721    Time time;
     722    ostringstream sTime;
     723    sTime << time.Y() << "_" << time.M() << "_" << time.D();
     724
     725    name = CheckIfDirIsDot(fNightlyFilePath) + '/' + sTime.str();
     726}
     727// --------------------------------------------------------------------------
     728//
    665729//! Form the name of the nightly text files (logs and reports)
    666730//! @param name the full file name
     
    669733void DataLogger::FormNightlyTextFileName(string& name, bool isReport)
    670734{
    671     Time time;
    672     ostringstream sTime;
    673     sTime << time.Y() << "_" << time.M() << "_" << time.D();
    674 
    675     name = fNightlyFilePath + '/' + sTime.str();
     735    FormBaseNightlyTextFileName(name);
     736
    676737    if (isReport)
    677738        name += ".rep";
     
    12671328
    12681329    //TODO this notification scheme might be messed up now.... fix it !
    1269     ostringstream sRun;
    1270     sRun << run.runNumber;
    1271     NotifyOpenedFile(CheckIfDirIsDot(fRunFilePath) + '/' + sRun.str(), 3, fOpenedRunFiles);
     1330    string baseFileName;
     1331    FormBaseRunTextFileName(baseFileName, run.runNumber);
     1332    NotifyOpenedFile(baseFileName, 3, fOpenedRunFiles);
    12721333    run.openedFits.clear();
    12731334    return 0;
     
    14261487        {
    14271488            fNightlyReportFile << header.str() << text << endl;
    1428             //check if either eof, bailbit or batbit are set
    1429             if (!fNightlyReportFile.good())
    1430             {
    1431                 Error("An error occured while writing to the nightly report file. Closing it");
    1432                 if (fNightlyReportFile.is_open())
    1433                     fNightlyReportFile.close();
    1434             }
     1489            CheckForOfstreamError(fNightlyReportFile);
    14351490        }
    14361491        //write entry to run-report
     
    14381493        {
    14391494            *targetRunFile << header.str() << text << endl;
    1440             if (!targetRunFile->good())
    1441             {
    1442                 Error("An error occured while writing to the run report file. Closing it.");
    1443                 if (targetRunFile->is_open())
    1444                     targetRunFile->close();
    1445             }
     1495            CheckForOfstreamError(*targetRunFile);
    14461496        }
    14471497    }
     
    14561506            MessageImp nightlyMess(fNightlyLogFile);
    14571507            nightlyMess.Write(cTime, msg.str().c_str(), fQuality);
    1458             if (!fNightlyLogFile.good())
    1459             {
    1460                 Error("An error occured while writing to the nightly log file. Closing it.");
    1461                 if (fNightlyLogFile.is_open())
    1462                     fNightlyLogFile.close();   
    1463             }
     1508            CheckForOfstreamError(fNightlyLogFile);
    14641509        }
    14651510        if (targetRunFile && targetRunFile->is_open())
     
    14671512            MessageImp runMess(*targetRunFile);
    14681513            runMess.Write(cTime, msg.str().c_str(), fQuality);
    1469             if (!targetRunFile->good())
    1470             {
    1471                 Error("An error occured while writing to the run log file. Closing it.");
    1472                 if (targetRunFile->is_open())
    1473                     targetRunFile->close();
    1474             }
     1514            CheckForOfstreamError(*targetRunFile);
    14751515        }
    14761516    }
     
    18641904            Debug(str);
    18651905        }
     1906        if (name.size()+1 > FILENAME_MAX)
     1907        {
     1908            Error("Provided file name \"" + name + "\" is longer than allowed file name length");
     1909        }
    18661910        OpenFileToDim fToDim;
    18671911        fToDim.code = type;
     
    19071951
    19081952    //notify that a new file has been opened.
    1909     Time time;
    1910     ostringstream sTime;
    1911     sTime << time.Y() << "_" << time.M() << "_" << time.D();
    1912     NotifyOpenedFile(CheckIfDirIsDot(fNightlyFilePath) + '/' + sTime.str(), 3, fOpenedNightlyFiles);
     1953    string baseFileName;
     1954    FormBaseNightlyTextFileName(baseFileName);
     1955    NotifyOpenedFile(baseFileName, 3, fOpenedNightlyFiles);
    19131956
    19141957    fOpenedNightlyFits.clear();
     
    19682011
    19692012        //notify the opening
    1970         Time time;
    1971         ostringstream sTime;
    1972         sTime << time.Y() << "_" << time.M() << "_" << time.D();
    1973         NotifyOpenedFile(CheckIfDirIsDot(fNightlyFilePath) + '/' + sTime.str(), 7, fOpenedNightlyFiles);
     2013        string baseFileName;
     2014        FormBaseNightlyTextFileName(baseFileName);
     2015        NotifyOpenedFile(baseFileName, 7, fOpenedNightlyFiles);
    19742016        if (fNumSubAndFitsIsOn)
    19752017            fNumSubAndFits->updateService();
     
    20002042        else
    20012043            if (hasGrouping)
    2002             {//most likely I should add this service name.
    2003              //the only case for which I should not add it is if a service disapeared, hence the file was closed
    2004              //and reopened again. Unlikely to happen, but well it may
    2005                 bool found = false;
    2006                 for (vector<string>::iterator it=cRunNumber->openedFits[fileNameOnly].begin(); it!=cRunNumber->openedFits[fileNameOnly].end(); it++)
    2007                     if (*it == serviceName)
    2008                     {
    2009                         found = true;
    2010                         break;
    2011                     }
    2012                 if (!found)
    2013                     cRunNumber->openedFits[fileNameOnly].push_back(serviceName);
     2044            {
     2045             cRunNumber->addServiceToOpenedFits(fileNameOnly, serviceName);
    20142046            }
    20152047
     
    20282060            }
    20292061
    2030         ostringstream sRun;
    2031         sRun << sub.runNumber;
    2032         NotifyOpenedFile(CheckIfDirIsDot(fRunFilePath) + '/' + sRun.str(), 7, fOpenedRunFiles);// + '_' + serviceName, 4);
     2062        string baseFileName;
     2063        FormBaseRunTextFileName(baseFileName, sub.runNumber);
     2064        NotifyOpenedFile(baseFileName, 7, fOpenedRunFiles);// + '_' + serviceName, 4);
    20332065        if (hasGrouping)
    20342066            sub.runFile.Open(partialName, serviceName, cRunNumber->runFitsFile, &fNumSubAndFitsData.numOpenFits, this, sub.runNumber);//Out());
     
    25882620int main(int argc, const char* argv[])
    25892621{
    2590 
    2591     float salut1 = 1.0f/0.0f;
    2592     if (salut1 != salut1)
    2593         cout << "NaN !";
    2594         else
    2595             cout << "regular number";
    2596 
    25972622    Configuration conf(argv[0]);
    25982623    conf.SetPrintUsage(PrintUsage);
Note: See TracChangeset for help on using the changeset viewer.