Ignore:
Timestamp:
08/11/11 23:09:13 (13 years ago)
Author:
tbretz
Message:
Implemented a new determination fo run-number after noon in the fadctrl; created the possibility to add the date to the raw-data path; allow to set the path as program option; for all this moved some code from the datalogger to DimWriteStatistics
File:
1 edited

Legend:

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

    r11837 r11893  
    414414bool DataLogger::CreateDirectory(string path)
    415415{
    416     //remove last '/', if present
    417     if (path[path.size()-1] == '/')
    418         path = path.substr(0, path.size()-1);
    419 
    420     //create boost path
    421     const boost::filesystem::path fullPath =  boost::filesystem::system_complete(boost::filesystem::path(path));
    422 
    423     //if path does not exist, check if upper levels exist already
    424     if (boost::filesystem::exists(fullPath))
    425     {
    426         //if path already exist, make sure it does not designate a file (filenames cannot be checked if they do not exist)
    427         if (boost::filesystem::is_directory(fullPath))
    428             return true;
    429 
    430         Error("Path to be created contains a file name: '" + path + "'");
     416    try
     417    {
     418        DimWriteStatistics::CreateDirectory(path);
     419        return true;
     420    }
     421    catch (const runtime_error &e)
     422    {
     423        Error(e.what());
    431424        return false;
    432425    }
    433 
    434     if (path.size() <= 1)
    435     {//we're hitting "/", which SHOULD have existed...
    436         Error("Something unexpected happened while creating a path");
    437     }
    438     CreateDirectory(path.substr(0, path.find_last_of('/')));
    439 
    440     //path does not exist, and upper level have been created already by recusrion.
    441     const mode_t rightsMask = S_IRWXU | S_IXGRP | S_IRGRP | S_IXOTH | S_IROTH; //everybody read, owner writes
    442 
    443     const int returnValue = mkdir(path.c_str(), rightsMask);
    444 
    445     if (returnValue != 0)
    446     {
    447         ostringstream str;
    448         str << "mkdir() failed for '" << path << "': " << strerror(errno) << " [errno=" << errno << "]";
    449         Error(str.str());
    450         return false;
    451     }
    452 
    453     return true;
    454426}
    455427// --------------------------------------------------------------------------
     
    461433bool DataLogger::DoesPathExist(string path)
    462434{
    463     const boost::filesystem::path fullPath = boost::filesystem::system_complete(boost::filesystem::path(path));
    464 
    465     if (!boost::filesystem::exists(fullPath))
    466        return false;
    467 
    468     if (!boost::filesystem::is_directory(fullPath))
    469     {
    470         Error("Path given for checking '" + path + "' designate a file name. Please provide a path name only");
    471         return false;
    472     }
    473 
    474     if (access(path.c_str(), R_OK|W_OK|X_OK) != 0)
    475     {
    476         Error("Missing read, write or execute permissions on directory '" + path + "'");
    477         return false;
    478     }
    479 
    480     return true;
    481 }
     435    return DimWriteStatistics::DoesPathExist(path, *this);
     436}
     437
    482438// --------------------------------------------------------------------------
    483439//
Note: See TracChangeset for help on using the changeset viewer.