Changeset 10968 for trunk


Ignore:
Timestamp:
06/09/11 23:31:28 (13 years ago)
Author:
tbretz
Message:
Added some const-qualifiers and did a few minor changes to the layout of the code.
File:
1 edited

Legend:

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

    r10955 r10968  
    416416    if (path[path.size()-1] == '/')
    417417        path = path.substr(0, path.size()-1);
     418
    418419    //create boost path
    419     boost::filesystem::path fullPath =  boost::filesystem::system_complete(boost::filesystem::path(path));
     420    const boost::filesystem::path fullPath =  boost::filesystem::system_complete(boost::filesystem::path(path));
    420421
    421422    //if path does not exist, check if upper levels exist already
    422     if (!boost::filesystem::exists(fullPath))
    423     {
    424         if (path.size() <= 1)
    425         {//we're hitting "/", which SHOULD have existed...
    426             Error("Something unexpected happened while creating a path");
    427         }
    428         CreateDirectory(path.substr(0, path.find_last_of('/')));
    429     }
    430     else
    431     {//if path already exist, make sure it does not designate a file (filenames cannot be checked if they do not exist)
    432         if (!boost::filesystem::is_directory(fullPath))
    433         {
    434             Error("Path to be created contains a file name: '" + path + "'");
    435             return false;
    436         }
    437 
    438         return true;
    439     }
     423    if (boost::filesystem::exists(fullPath))
     424    {
     425        //if path already exist, make sure it does not designate a file (filenames cannot be checked if they do not exist)
     426        if (boost::filesystem::is_directory(fullPath))
     427            return true;
     428
     429        Error("Path to be created contains a file name: '" + path + "'");
     430        return false;
     431    }
     432
     433    if (path.size() <= 1)
     434    {//we're hitting "/", which SHOULD have existed...
     435        Error("Something unexpected happened while creating a path");
     436    }
     437    CreateDirectory(path.substr(0, path.find_last_of('/')));
     438
    440439    //path does not exist, and upper level have been created already by recusrion.
    441     mode_t rightsMask = S_IRWXU | S_IXGRP | S_IRGRP | S_IXOTH | S_IROTH; //everybody read, owner writes
    442 
    443     int returnValue = mkdir(path.c_str(), rightsMask);
     440    const mode_t rightsMask = S_IRWXU | S_IXGRP | S_IRGRP | S_IXOTH | S_IROTH; //everybody read, owner writes
     441
     442    const int returnValue = mkdir(path.c_str(), rightsMask);
    444443
    445444    if (returnValue != 0)
     
    461460bool DataLogger::DoesPathExist(string path)
    462461{
    463     boost::filesystem::path fullPath = boost::filesystem::system_complete(boost::filesystem::path(path));
    464 
     462    const boost::filesystem::path fullPath = boost::filesystem::system_complete(boost::filesystem::path(path));
    465463
    466464    if (!boost::filesystem::exists(fullPath))
     
    596594    errno = 0;
    597595    stream.open(name.c_str(), ios_base::out | ios_base::app);
    598     if (errno != 0)
     596    if (!stream)
    599597    {
    600598        ostringstream str;
    601         str << "Unable to open file: " << name << ". Reason: " << strerror(errno) << " [" << errno << "]";
     599        str << "Open file " << name << ": " << strerror(errno) << " (errno=" << errno << ")";
    602600        Error(str);
    603601    }
     
    793791            if (y->second.runFile.IsOpen())
    794792            {
    795                     fFileSizesMap[y->second.runFile.fFileName] = y->second.runFile.GetWrittenSize();
    796                     if (isPrinting)
    797                         Message("-> "+y->second.runFile.fFileName);
     793                fFileSizesMap[y->second.runFile.fFileName] = y->second.runFile.GetWrittenSize();
     794                if (isPrinting)
     795                    Message("-> "+y->second.runFile.fFileName);
    798796            }
    799797            if (y->second.nightlyFile.IsOpen())
     
    848846    return shouldWarn;
    849847}
     848
    850849//static members initialization
    851850//since I do not check the transition/config names any longer, indeed maybe these could be hard-coded... but who knows what will happen in the future ?
     
    11301129
    11311130    //update the fits files sizes
    1132     Time cTime = Time();
     1131    const Time cTime = Time();
    11331132    if ((fStatsPeriodDuration != 0) && ((cTime.Mjd() - fPreviousStatsUpdateTime)*24*60*60 > fStatsPeriodDuration))
    11341133    {
     
    11631162    }
    11641163    run.logName = CompileFileName(fRunFilePath, run.runNumber, "", "log");
     1164
    11651165    errno = 0;
    11661166    run.logFile->open(run.logName.c_str(), ios_base::out | ios_base::app);
     
    11681168    {
    11691169        ostringstream str;
    1170         str << "Unable to open run Log " << run.logName << ". Reason: " << strerror(errno) << " [" << errno << "]";
     1170        str << "Unable to open log-file " << run.logName << ": " << strerror(errno) << " (errno=" << errno << ")";
    11711171        Error(str);
    11721172    }
     
    11811181        return -1;
    11821182    }
     1183
    11831184    errno = 0;
    11841185    run.reportFile->open(run.reportName.c_str(), ios_base::out | ios_base::app);
     
    11861187    {
    11871188        ostringstream str;
    1188         str << "Unable to open run report " << run.reportName << ". Reason: " << strerror(errno) << " [" << errno << "]";
     1189        str << "Unable to open rep-file " << run.reportName << ": " << strerror(errno) << " (errno=" << errno << ")";
    11891190        Error(str);
    11901191    }
     
    12121213
    12131214    //TODO this notification scheme might be messed up now.... fix it !
    1214     string baseFileName = CompileFileName(fRunFilePath, run.runNumber, "", "");
     1215    const string baseFileName = CompileFileName(fRunFilePath, run.runNumber, "", "");
    12151216    NotifyOpenedFile(baseFileName, 3, fOpenedRunFiles);
    12161217    run.openedFits.clear();
     
    16531654int DataLogger::SetNumSubsAndFitsOnOff(const Event& evt)
    16541655{
    1655     bool backupSubs = fNumSubAndFitsIsOn;
     1656    const bool backupSubs = fNumSubAndFitsIsOn;
    16561657    fNumSubAndFitsIsOn = evt.GetBool();
     1658
    16571659    if (fNumSubAndFitsIsOn == backupSubs)
    16581660        Warn("Warning: Number of subscriptions service mode was already in the requested state");
     
    17001702int DataLogger::ConfigureRunFileName(const Event& evt)
    17011703{
    1702     if (evt.GetText() != NULL)
    1703     {
    1704         string givenPath = string(evt.GetText());
    1705         if (!DoesPathExist(givenPath))
    1706         {
    1707             Error("Provided path is not a valid folder. Ignored");
    1708             return GetCurrentState();
    1709         }
    1710         fRunFilePath = givenPath;
    1711         Message("New Run folder specified: " + fRunFilePath);
    1712     }
    1713     else
     1704    if (evt.GetText() == NULL)
     1705    {
    17141706        Error("Empty Nightly folder given. Please specify a valid path");
     1707        return GetCurrentState();
     1708    }
     1709
     1710    const string givenPath = string(evt.GetText());
     1711    if (!DoesPathExist(givenPath))
     1712    {
     1713        Error("Provided path is not a valid folder. Ignored");
     1714        return GetCurrentState();
     1715    }
     1716
     1717    fRunFilePath = givenPath;
     1718    Message("New Run folder specified: " + fRunFilePath);
    17151719
    17161720    return GetCurrentState();
     
    17981802
    17991803    //notify that a new file has been opened.
    1800     string baseFileName = CompileFileName(fNightlyFilePath, "", "");
     1804    const string baseFileName = CompileFileName(fNightlyFilePath, "", "");
    18011805    NotifyOpenedFile(baseFileName, 3, fOpenedNightlyFiles);
    18021806
     
    18151819{
    18161820    string serviceName(sub.dimInfo->getName());
     1821
    18171822    //if run number has changed, reopen a new fits file with the correct run number.
    18181823     if (sub.runFile.IsOpen() && sub.runFile.fRunNumber != sub.runNumber)
     
    18221827         sub.runFile.Close();
    18231828     }
    1824       //we must check if we should group this service subscription to a single fits file before we replace the / by _
     1829
     1830     //we must check if we should group this service subscription to a single fits file before we replace the / by _
    18251831    bool hasGrouping = false;
    18261832    if (!sub.runFile.IsOpen() && (GetCurrentState() == kSM_Logging))
     
    18471853    if (!sub.nightlyFile.IsOpen())
    18481854    {
    1849         string fileNameOnly, partialName;
    1850         partialName = CompileFileName(fNightlyFilePath, serviceName, "fits");
    1851         fileNameOnly = partialName.substr(partialName.find_last_of('/')+1, partialName.size());
     1855        string partialName = CompileFileName(fNightlyFilePath, serviceName, "fits");
     1856
     1857        const string fileNameOnly = partialName.substr(partialName.find_last_of('/')+1, partialName.size());
    18521858        if (!sub.fitsBufferAllocated)
    18531859            AllocateFITSBuffers(sub);
     
    18621868        }
    18631869        //notify the opening
    1864         string baseFileName = CompileFileName(fNightlyFilePath, "", "");
     1870        const string baseFileName = CompileFileName(fNightlyFilePath, "", "");
    18651871        NotifyOpenedFile(baseFileName, 7, fOpenedNightlyFiles);
    18661872        if (fNumSubAndFitsIsOn)
     
    19111917            }
    19121918
    1913         string baseFileName = CompileFileName(fRunFilePath, sub.runNumber, "", "");
     1919        const string baseFileName = CompileFileName(fRunFilePath, sub.runNumber, "", "");
    19141920        NotifyOpenedFile(baseFileName, 7, fOpenedRunFiles);// + '_' + serviceName, 4);
    19151921        if (hasGrouping)
     
    19461952void DataLogger::AllocateFITSBuffers(SubscriptionType& sub)
    19471953{
    1948     int size = sub.dimInfo->getSize();
    1949      
    19501954    //Init the time columns of the file
    19511955    Description dateDesc(string("Time"), string("Modified Julian Date"), string("MjD"));
     
    19671971    //we've got a nice structure describing the format of this service's messages.
    19681972    //Let's create the appropriate FITS columns
     1973    int size = sub.dimInfo->getSize();
     1974
    19691975    vector<string> dataFormatsLocal;
    19701976    for (unsigned int i=0;i<flist.size()-1;i++)
     
    20032009             break;
    20042010             case 'S':
     2011                 size--;
    20052012                 //for strings, the number of elements I get is wrong. Correct it
    20062013                 dataQualifier.str(""); //clear
    2007                  dataQualifier << size-1 <<  "A";
    2008                  size = size-1;
     2014                 dataQualifier << size <<  "A";
    20092015             break;
    20102016             
     
    20322038                SetCurrentState(kSM_WriteError);
    20332039         }
     2040
    20342041        if (sub.runFile.IsOpen())
    20352042        {
Note: See TracChangeset for help on using the changeset viewer.