#include <FileInPath.h>
Public Types | |
enum | LocationCode { Unknown = 0, Local = 1, Release = 2, Data = 3 } |
Public Member Functions | |
FileInPath () | |
FileInPath (const std::string &r) | |
We throw an exception is the referenced file is not found. | |
FileInPath (FileInPath const &other) | |
FileInPath (const char *r) | |
std::string | fullPath () const |
bool | isLocal () const |
Was the file found under the "local" area? | |
LocationCode | location () const |
Where was the file found? | |
FileInPath & | operator= (FileInPath const &other) |
void | read (std::istream &is) |
void | readFromParameterSetBlob (std::istream &is) |
std::string | relativePath () const |
void | swap (FileInPath &other) |
void | write (std::ostream &os) const |
~FileInPath () | |
Private Member Functions | |
void | getEnvironment () |
void | initialize_ () |
Private Attributes | |
std::string | canonicalFilename_ |
std::string | dataTop_ |
std::string | localTop_ |
LocationCode | location_ |
std::string | relativePath_ |
std::string | releaseTop_ |
std::string | searchPath_ |
Definition at line 68 of file FileInPath.h.
FileInPath::FileInPath | ( | ) |
Default c'tor does no file-existence check; what file would it check for existence?
Definition at line 89 of file FileInPath.cc.
References getEnvironment().
: relativePath_(), canonicalFilename_(), location_(Unknown) { getEnvironment(); }
FileInPath::FileInPath | ( | const std::string & | r | ) | [explicit] |
We throw an exception is the referenced file is not found.
Definition at line 97 of file FileInPath.cc.
References getEnvironment(), and initialize_().
: relativePath_(r), canonicalFilename_(), location_(Unknown) { getEnvironment(); initialize_(); }
FileInPath::FileInPath | ( | const char * | r | ) | [explicit] |
Definition at line 106 of file FileInPath.cc.
References getEnvironment(), and initialize_().
: relativePath_(r ? r : ((throw edm::Exception(edm::errors::FileInPathError) << "Relative path must not be null\n"), r)), canonicalFilename_(), location_(Unknown) { getEnvironment(); initialize_(); }
FileInPath::FileInPath | ( | FileInPath const & | other | ) |
Definition at line 118 of file FileInPath.cc.
: relativePath_(other.relativePath_), canonicalFilename_(other.canonicalFilename_), location_(other.location_), localTop_(other.localTop_), releaseTop_(other.releaseTop_), dataTop_(other.dataTop_), searchPath_(other.searchPath_) {}
FileInPath::~FileInPath | ( | ) |
Definition at line 128 of file FileInPath.cc.
{}
std::string FileInPath::fullPath | ( | ) | const |
Return a string that can be used to open the referenced file.
Note that operations on this file may fail, including testing for existence. This is because the state of a filesystem is global; other threads, processes, etc., may have removed the file since we checked on its existence at the time of construction of the FileInPath object.
Definition at line 170 of file FileInPath.cc.
References canonicalFilename_.
Referenced by MillePedeAlignmentAlgorithm::addPxbSurvey(), SiStripBadChannelBuilder::algoAnalyze(), SiStripBadFiberBuilder::algoAnalyze(), JetCorrectorDemo::analyze(), SiStripApvGainBuilder::analyze(), SiStripThresholdBuilder::analyze(), MuonGeometrySVGTemplate::analyze(), SiStripNoiseNormalizedWithApvGainBuilder::analyze(), SiStripNoisesBuilder::analyze(), SiStripApvGainBuilderFromTag::analyze(), SiStripPedestalsBuilder::analyze(), cms::HcalConstantsASCIIWriter::analyze(), BeamSpotFakeConditions::BeamSpotFakeConditions(), cms::HcalConstantsASCIIWriter::beginJob(), ProtonTaggerFilter::beginJob(), JetCorrectorDBWriter::beginJob(), PileUpProducer::beginRun(), GoodSeedProducer::beginRun(), BOOST_PYTHON_MODULE(), SiStripDetVOffBuilder::BuildDetVOffObj(), MagGeoBuilderFromDDD::buildInterpolator(), MaterialBudgetCategorizer::buildMaps(), CaloMeanResponse::CaloMeanResponse(), CaloMiscalibTools::CaloMiscalibTools(), CaloMiscalibToolsMC::CaloMiscalibToolsMC(), CastorTextCalibrations::CastorTextCalibrations(), SiStripBadModuleGenerator::createObject(), SiStripThresholdGenerator::createObject(), SiStripBaseDelayGenerator::createObject(), SiStripLatencyGenerator::createObject(), SiStripLorentzAngleGenerator::createObject(), SiStripNoisesGenerator::createObject(), CSCMonitorModule::CSCMonitorModule(), CSCTFPtLUT::CSCTFPtLUT(), CustomPhysicsList::CustomPhysicsList(), HcalTPGCoderULUT::dbRecordCallback(), DTTTrigResidualCorrection::DTTTrigResidualCorrection(), TrackProbabilityXMLtoDB::endJob(), ESDataFormatterV4::ESDataFormatterV4(), ESElectronicsMapper::ESElectronicsMapper(), gen::EvtGenInterface::EvtGenInterface(), FastL1GlobalAlgo::FastL1GlobalAlgo(), MultipleScatteringX0Data::fileName(), CSCReadoutMappingFromFile::fill(), SiStripGain::fillNewGain(), popcon::SiStripPopConHandlerUnitTestGain< T >::fillObject(), popcon::SiStripPopConHandlerUnitTestNoise< T >::fillObject(), popcon::SiStripPopConHandlerUnitTest< T >::fillObject(), muonisolation::IsolatorByNominalEfficiency::findPath(), SumHistoCalibration::fromXml(), ImpactParameterCalibration::fromXml(), GeometryConfiguration::GeometryConfiguration(), ESTrivialConditionRetriever::getChannelStatusFromConfiguration(), EcalTrivialConditionRetriever::getChannelStatusFromConfiguration(), EcalTrivialConditionRetriever::getMappingFromConfiguration(), SiStripBadStripFromASCIIFile::getNewObject(), SiStripGainFromAsciiFile::getNewObject(), EcalMappingElectronicsHandler::getNewObjects(), cond::FipProtocolParser::getRealConnect(), EcalTrivialConditionRetriever::getTrgChannelStatusFromConfiguration(), ESTrivialConditionRetriever::getWeightsFromConfiguration(), EcalTrivialConditionRetriever::getWeightsFromConfiguration(), HcalForwardLibWriter::HcalForwardLibWriter(), HcalTextCalibrations::HcalTextCalibrations(), HcalTPGCoderULUT::HcalTPGCoderULUT(), HFShowerLibrary::HFShowerLibrary(), HcalRecHitsMaker::init(), CastorShowerLibrary::initFile(), ApeSettingAlgorithm::initialize(), JetCalibrationParameterSetTauJet::JetCalibrationParameterSetTauJet(), JetPartonNamespace::JetPartonCalibrationParameterSet::JetPartonCalibrationParameterSet(), L1GtTriggerMenuXmlProducer::L1GtTriggerMenuXmlProducer(), L1MuDTPtaLut::load(), L1MuDTEtaPatternLut::load(), L1MuDTExtLut::load(), L1MuDTPhiLut::load(), L1MuDTQualPatternLut::load(), EnergyLossPlain::loadOptimalWeights(), ClusterShapeHitFilter::loadPixelLimits(), ClusterShapeHitFilter::loadStripLimits(), SiStripHashedDetIdFakeESSource::make(), SiStripFedCablingFakeESSource::make(), jpt::Map::Map(), MuonErrorMatrix::MuonErrorMatrix(), PhysicsTools::MVATrainer::MVATrainer(), NuclearInteractionSimulator::NuclearInteractionSimulator(), DDLParser::parseOneFile(), EcalTrigPrimESProducer::parseTextFile(), EcalTrigTowerConstituentsMapBuilder::parseTextMap(), CaloTowerConstituentsMapBuilder::parseTextMap(), SiPixelFakeLorentzAngleESSource::produce(), SiPixelFakeGainForHLTESSource::produce(), HepPDTESSource::produce(), SiPixelFakeGainESSource::produce(), JetCorrectionService< Corrector >::produce(), CaloTPGTranscoderULUTs::produce(), SiPixelFakeGainOfflineESSource::produce(), SiPixelFakeCPEGenericErrorParmESSource::produce(), MaskedRctInputDigiProducer::produce(), SiPixelFakeTemplateDBObjectESSource::produce(), gen::PtYDistributor::PtYDistributor(), SiStripFEDErrorsDQM::readBadAPVs(), SiStripBadComponentsDQMService::readBadComponents(), FIPConfiguration::readConfig(), CSCTFPtLUT::readLUT(), CSCSectorReceiverLUT::readLUTsFromFile(), SiStripNoisesDQMService::readNoises(), GsfBetheHeitlerUpdator::readParameters(), SiStripPedestalsDQMService::readPedestals(), RPCCalibSetUp::RPCCalibSetUp(), RPCDBSimSetUp::RPCDBSimSetUp(), RPCRecHitProducer::RPCRecHitProducer(), gen::Pythia6Service::setPYUPDAParams(), gen::Pythia6Service::setSLHAParams(), PhiSymmetryCalibration::setUp(), SiPixelActionExecutor::setupQTests(), SiStripBadModuleByHandBuilder::SiStripBadModuleByHandBuilder(), SiStripDetInfoFileReader::SiStripDetInfoFileReader(), SiStripDQMProfileToTkMapConverter::SiStripDQMProfileToTkMapConverter(), SiStripHitEffFromCalibTree::SiStripHitEffFromCalibTree(), SiStripQuality::SiStripQuality(), SiStripQualityHotStripIdentifier::SiStripQualityHotStripIdentifier(), SiStripQualityHotStripIdentifierRoot::SiStripQualityHotStripIdentifierRoot(), SiStripQualityStatistics::SiStripQualityStatistics(), and ZSPJPTJetCorrector::ZSPJPTJetCorrector().
{ return canonicalFilename_; }
void FileInPath::getEnvironment | ( | void | ) | [private] |
Definition at line 382 of file FileInPath.cc.
References dataTop_, Exception, edm::errors::FileInPathError, localTop_, releaseTop_, and searchPath_.
Referenced by FileInPath().
{ if (!envstring(RELEASETOP, releaseTop_)) { releaseTop_.clear(); } if (releaseTop_.empty()) { // RELEASETOP was not set. This means that the environment is set // for the base release itself. So LOCALTOP actually contains the // location of the base release. if (!envstring(LOCALTOP, releaseTop_)) { releaseTop_.clear(); } } else { if (!envstring(LOCALTOP, localTop_)) { localTop_.clear(); } } if (!envstring(DATATOP, dataTop_)) { dataTop_.clear(); } if (!envstring(PathVariableName, searchPath_)) { throw edm::Exception(edm::errors::FileInPathError) << PathVariableName << " must be defined\n"; } }
void FileInPath::initialize_ | ( | ) | [private] |
Definition at line 409 of file FileInPath.cc.
References beamvalidation::br, canonicalFilename_, Data, dataTop_, end, Exception, edm::errors::FileInPathError, Local, localTop_, location_, path(), relativePath_, Release, releaseTop_, searchPath_, and edm::tokenize().
Referenced by FileInPath().
{ if (relativePath_.empty()) throw edm::Exception(edm::errors::FileInPathError) << "Relative path must not be empty\n"; // Find the file, based on the value of path variable. typedef std::vector<std::string> stringvec_t; stringvec_t pathElements = tokenize(searchPath_, ":"); stringvec_t::const_iterator it = pathElements.begin(); stringvec_t::const_iterator end = pathElements.end(); while (it != end) { // Set the boost::fs path to the current element of // CMSSW_SEARCH_PATH: bf::path pathPrefix(*it, bf::no_check); // Does the a file exist? locateFile throws is it finds // something goofy. if (locateFile(pathPrefix, relativePath_)) { // Convert relative path to canonical form, and save it. relativePath_ = bf::path(relativePath_, bf::no_check).normalize().string(); // Save the absolute path. canonicalFilename_ = bf::complete(relativePath_, pathPrefix).string(); if (canonicalFilename_.empty()) throw edm::Exception(edm::errors::FileInPathError) << "fullPath is empty" << "\nrelativePath() is: " << relativePath_ << "\npath prefix is: " << pathPrefix.string() << '\n'; // From the current path element, find the branch path (basically the path minus the // last directory, e.g. /src or /share): for (bf::path br = pathPrefix.branch_path(); !br.normalize().string().empty(); br = br.branch_path()) { if (!localTop_.empty()) { // Create a path object for our local path LOCALTOP: bf::path local_(localTop_, bf::no_check); // If the branch path matches the local path, the file was found locally: if (br == local_) { location_ = Local; return; } } if (!releaseTop_.empty()) { // Create a path object for our release path RELEASETOP: bf::path release_(releaseTop_, bf::no_check); // If the branch path matches the release path, the file was found in the release: if (br == release_) { location_ = Release; return; } } if (!dataTop_.empty()) { // Create a path object for our data path DATATOP: bf::path data_(dataTop_, bf::no_check); // If the branch path matches the data path, the file was found in the data area: if (br == data_) { location_ = Data; return; } } } // This is really gross --- this organization of if/else // inside the while-loop should be changed so that // this break isn't needed. } // Keep trying ++it; } // If we got here, we ran out of path elements without finding // what we're looking found. throw edm::Exception(edm::errors::FileInPathError) << "edm::FileInPath unable to find file " << relativePath_ << " anywhere in the search path." << "\nThe search path is defined by: " << PathVariableName << "\n${" << PathVariableName << "} is: " << getenv(PathVariableName.c_str()) << "\nCurrent directory is: " << bf::initial_path().string() << "\n"; }
bool FileInPath::isLocal | ( | ) | const |
Was the file found under the "local" area?
Definition at line 164 of file FileInPath.cc.
References Local, and location_.
Referenced by BOOST_PYTHON_MODULE().
FileInPath::LocationCode FileInPath::location | ( | ) | const |
Where was the file found?
Definition at line 158 of file FileInPath.cc.
References location_.
Referenced by edm::operator==().
{ return location_; }
FileInPath & FileInPath::operator= | ( | FileInPath const & | other | ) |
Definition at line 131 of file FileInPath.cc.
References swap(), and cond::rpcobtemp::temp.
{ FileInPath temp(other); this->swap(temp); return *this; }
void FileInPath::read | ( | std::istream & | is | ) |
Read from the given istream, and set contents accordingly. Reading errors are reflected in the state of the stream.
Definition at line 239 of file FileInPath.cc.
References linker::BASE, canonicalFilename_, dataTop_, Exception, edm::errors::FileInPathError, Local, localTop_, location_, pos, relativePath_, Release, releaseTop_, Unknown, and BeamSplash_cfg::version.
Referenced by edm::operator>>().
{ std::string vsn; std::string relname; std::string canFilename; #if 1 // This #if needed for backward compatibility // for files written before CMSSW_1_5_0_pre3. is >> vsn; if (!is) return; bool oldFormat = (version != vsn); if (oldFormat) { relname = vsn; bool local; is >> local; location_ = (local ? Local : Release); is >> canFilename; } else { // Current format int loc; is >> relname >> loc; location_ = static_cast<FileInPath::LocationCode>(loc); if (location_ != Unknown) is >> canFilename; } #else is >> vsn >> relname >> loc >> canFilename; #endif if (!is) return; relativePath_ = relname; if (location_ == Local) { if (localTop_.empty()) { throw edm::Exception(edm::errors::FileInPathError) << "Environment Variable " << LOCALTOP << " is not set.\n"; } #if 1 // This #if needed for backward compatibility // for files written before CMSSW_1_5_0_pre3. if (oldFormat) { canonicalFilename_ = canFilename; } else #endif canonicalFilename_ = localTop_ + canFilename; } else if (location_ == Release) { if (releaseTop_.empty()) { throw edm::Exception(edm::errors::FileInPathError) << "Environment Variable " << RELEASETOP << " is not set.\n"; } #if 1 // This #if needed for backward compatibility // for files written before CMSSW_1_5_0_pre3. if (oldFormat) { std::string::size_type pos = canFilename.find(BASE); if (pos == 0) { // Replace the placehoder with the path to the base release (site dependent). canonicalFilename_ = releaseTop_ + canFilename.substr(BASE.size()); } else { // Needed for files written before CMSSW_1_2_0_pre2. canonicalFilename_ = canFilename; } } else #endif canonicalFilename_ = releaseTop_ + canFilename; } else if (location_ == Data) { if (dataTop_.empty()) { throw edm::Exception(edm::errors::FileInPathError) << "Environment Variable " << DATATOP << " is not set.\n"; } canonicalFilename_ = dataTop_ + canFilename; } }
void FileInPath::readFromParameterSetBlob | ( | std::istream & | is | ) |
Definition at line 319 of file FileInPath.cc.
References linker::BASE, canonicalFilename_, dataTop_, Exception, edm::errors::FileInPathError, Local, localTop_, location_, pos, relativePath_, Release, releaseTop_, Unknown, and BeamSplash_cfg::version.
Referenced by edm::decode().
{ std::string vsn; std::string relname; std::string canFilename; is >> vsn; if (!is) return; bool oldFormat = (version != vsn); if (oldFormat) { relname = vsn; bool local; is >> local; location_ = (local ? Local : Release); is >> canFilename; } else { // Current format int loc; is >> relname >> loc; location_ = static_cast<FileInPath::LocationCode>(loc); if (location_ != Unknown) is >> canFilename; } if (!is) return; relativePath_ = relname; if (location_ == Local) { if (localTop_.empty()) { localTop_ = "@LOCAL"; } if (oldFormat) { canonicalFilename_ = canFilename; } else canonicalFilename_ = localTop_ + canFilename; } else if (location_ == Release) { if (releaseTop_.empty()) { releaseTop_="@RELEASE"; } if (oldFormat) { std::string::size_type pos = canFilename.find(BASE); if (pos == 0) { // Replace the placehoder with the path to the base release (site dependent). canonicalFilename_ = releaseTop_ + canFilename.substr(BASE.size()); } else { // Needed for files written before CMSSW_1_2_0_pre2. canonicalFilename_ = canFilename; } } else canonicalFilename_ = releaseTop_ + canFilename; } else if (location_ == Data) { if (dataTop_.empty()) { throw edm::Exception(edm::errors::FileInPathError) << "Environment Variable " << DATATOP << " is not set.\n"; } canonicalFilename_ = dataTop_ + canFilename; } }
std::string FileInPath::relativePath | ( | ) | const |
Return a string containing the canonical form of the relative* path. DO NOT USE THIS AS THE FILENAME for any file operations; use fullPath() for that purpose.
Definition at line 151 of file FileInPath.cc.
References relativePath_.
Referenced by BOOST_PYTHON_MODULE(), and edm::operator==().
{ return relativePath_; }
void FileInPath::swap | ( | FileInPath & | other | ) |
Definition at line 139 of file FileInPath.cc.
References canonicalFilename_, dataTop_, localTop_, location_, relativePath_, releaseTop_, and searchPath_.
Referenced by operator=(), and edm::swap().
{ relativePath_.swap(other.relativePath_); canonicalFilename_.swap(other.canonicalFilename_); std::swap(location_, other.location_); localTop_.swap(other.localTop_); releaseTop_.swap(other.releaseTop_); dataTop_.swap(other.dataTop_); searchPath_.swap(other.searchPath_); }
void FileInPath::write | ( | std::ostream & | os | ) | const |
Write contents to the given ostream. Writing errors are reflected in the state of the stream.
Definition at line 176 of file FileInPath.cc.
References canonicalFilename_, dataTop_, Exception, edm::errors::FileInPathError, Local, localTop_, location_, pos, relativePath_, Release, releaseTop_, Unknown, and BeamSplash_cfg::version.
Referenced by edm::operator<<().
{ if (location_ == Unknown) { os << version << ' ' << relativePath_ << ' ' << location_; } else if (location_ == Local) { // Guarantee a site independent value by stripping $LOCALTOP. if (localTop_.empty()) { throw edm::Exception(edm::errors::FileInPathError) << "Environment Variable " << LOCALTOP << " is not set.\n"; } std::string::size_type pos = canonicalFilename_.find(localTop_); if (pos != 0) { throw edm::Exception(edm::errors::FileInPathError) << "Path " << canonicalFilename_ << " is not in the local release area " << localTop_ << "\n"; } os << version << ' ' << relativePath_ << ' ' << location_ << ' ' << canonicalFilename_.substr(localTop_.size()); } else if (location_ == Release) { // Guarantee a site independent value by stripping $RELEASETOP. if (releaseTop_.empty()) { throw edm::Exception(edm::errors::FileInPathError) << "Environment Variable " << RELEASETOP << " is not set.\n"; } std::string::size_type pos = canonicalFilename_.find(releaseTop_); if (pos != 0) { throw edm::Exception(edm::errors::FileInPathError) << "Path " << canonicalFilename_ << " is not in the base release area " << releaseTop_ << "\n"; } os << version << ' ' << relativePath_ << ' ' << location_ << ' ' << canonicalFilename_.substr(releaseTop_.size()); } else if (location_ == Data) { // Guarantee a site independent value by stripping $DATATOP. if (dataTop_.empty()) { throw edm::Exception(edm::errors::FileInPathError) << "Environment Variable " << DATATOP << " is not set.\n"; } std::string::size_type pos = canonicalFilename_.find(dataTop_); if (pos != 0) { throw edm::Exception(edm::errors::FileInPathError) << "Path " << canonicalFilename_ << " is not in the data area " << dataTop_ << "\n"; } os << version << ' ' << relativePath_ << ' ' << location_ << ' ' << canonicalFilename_.substr(dataTop_.size()); } }
std::string edm::FileInPath::canonicalFilename_ [private] |
Definition at line 124 of file FileInPath.h.
Referenced by fullPath(), initialize_(), read(), readFromParameterSetBlob(), swap(), and write().
std::string edm::FileInPath::dataTop_ [private] |
Definition at line 128 of file FileInPath.h.
Referenced by getEnvironment(), initialize_(), read(), readFromParameterSetBlob(), swap(), and write().
std::string edm::FileInPath::localTop_ [private] |
Definition at line 126 of file FileInPath.h.
Referenced by getEnvironment(), initialize_(), read(), readFromParameterSetBlob(), swap(), and write().
LocationCode edm::FileInPath::location_ [private] |
Definition at line 125 of file FileInPath.h.
Referenced by initialize_(), isLocal(), location(), read(), readFromParameterSetBlob(), swap(), and write().
std::string edm::FileInPath::relativePath_ [private] |
Definition at line 123 of file FileInPath.h.
Referenced by initialize_(), read(), readFromParameterSetBlob(), relativePath(), swap(), and write().
std::string edm::FileInPath::releaseTop_ [private] |
Definition at line 127 of file FileInPath.h.
Referenced by getEnvironment(), initialize_(), read(), readFromParameterSetBlob(), swap(), and write().
std::string edm::FileInPath::searchPath_ [private] |
Definition at line 129 of file FileInPath.h.
Referenced by getEnvironment(), initialize_(), and swap().