#include <FWCore/ParameterSet/interface/FileInPath.h>
Public Types | |
enum | LocationCode { Unknown = 0, Local = 1, Release = 2, Data = 3 } |
Public Member Functions | |
FileInPath (FileInPath const &other) | |
FileInPath (const char *r) | |
FileInPath (const std::string &r) | |
We throw an exception is the referenced file is not found. | |
FileInPath () | |
Default c'tor does no file-existence check; what file would it check for existence? | |
std::string | fullPath () const |
Return a string that can be used to open the referenced file. | |
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) |
Read from the given istream, and set contents accordingly. | |
std::string | relativePath () const |
Return a string containing the canonical form of the relative* path. | |
void | swap (FileInPath &other) |
void | write (std::ostream &os) const |
Write contents to the given ostream. | |
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 69 of file FileInPath.h.
FileInPath::FileInPath | ( | ) |
Default c'tor does no file-existence check; what file would it check for existence?
Definition at line 91 of file FileInPath.cc.
References getEnvironment().
00091 : 00092 relativePath_(), 00093 canonicalFilename_(), 00094 location_(Unknown) 00095 { 00096 getEnvironment(); 00097 }
FileInPath::FileInPath | ( | const std::string & | r | ) | [explicit] |
We throw an exception is the referenced file is not found.
Definition at line 99 of file FileInPath.cc.
References getEnvironment(), and initialize_().
00099 : 00100 relativePath_(r), 00101 canonicalFilename_(), 00102 location_(Unknown) 00103 { 00104 getEnvironment(); 00105 initialize_(); 00106 }
FileInPath::FileInPath | ( | const char * | r | ) | [explicit] |
Definition at line 108 of file FileInPath.cc.
References getEnvironment(), and initialize_().
00108 : 00109 relativePath_(r ? 00110 r : 00111 ((throw edm::Exception(edm::errors::FileInPathError) 00112 << "Relative path must not be null\n"), r)), 00113 canonicalFilename_(), 00114 location_(Unknown) 00115 { 00116 getEnvironment(); 00117 initialize_(); 00118 }
FileInPath::FileInPath | ( | FileInPath const & | other | ) |
Definition at line 120 of file FileInPath.cc.
00120 : 00121 relativePath_(other.relativePath_), 00122 canonicalFilename_(other.canonicalFilename_), 00123 location_(other.location_), 00124 localTop_(other.localTop_), 00125 releaseTop_(other.releaseTop_), 00126 dataTop_(other.dataTop_), 00127 searchPath_(other.searchPath_) 00128 {}
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.
Referenced by SiStripBadChannelBuilder::algoAnalyze(), SiStripBadFiberBuilder::algoAnalyze(), SiStripThresholdBuilder::analyze(), SiStripApvGainBuilder::analyze(), SiStripNoisesBuilder::analyze(), SiStripPedestalsBuilder::analyze(), cms::HcalConstantsASCIIWriter::analyze(), SiStripPerformanceSummaryBuilder::analyze(), cms::HcalConstantsASCIIWriter::beginJob(), ProtonTaggerFilter::beginJob(), PileUpProducer::beginJob(), GoodSeedProducer::beginJob(), BOOST_PYTHON_MODULE(), edm::PythiaSource::call_slhagive(), edm::PythiaProducer::call_slhagive(), CaloMiscalibTools::CaloMiscalibTools(), ClusterShapeTrajectoryFilter::ClusterShapeTrajectoryFilter(), CustomPhysicsList::CustomPhysicsList(), TrackProbabilityXMLtoDB::endJob(), EvtGenProducer::EvtGenProducer(), FastL1GlobalAlgo::FastL1GlobalAlgo(), MultipleScatteringX0Data::fileName(), CSCReadoutMappingFromFile::fill(), ImpactParameterCalibration::fromXml(), GeometryConfiguration::GeometryConfiguration(), SiStripBadStripFromASCIIFile::getNewObject(), SiStripGainFromAsciiFile::getNewObject(), cond::FipProtocolParser::getRealConnect(), HcalTPGCoderULUT::HcalTPGCoderULUT(), HcalRecHitsMaker::init(), CombinedJetCorrector::initCorrectors(), JetPlusTrackCorrector::JetPlusTrackCorrector(), L1GtTriggerMenuXmlProducer::L1GtTriggerMenuXmlProducer(), popcon::L1RPCConfigSourceHandler::L1RPCConfigSourceHandler(), L1MuDTPtaLut::load(), L1MuDTEtaPatternLut::load(), L1MuDTExtLut::load(), L1MuDTPhiLut::load(), L1MuDTQualPatternLut::load(), ClusterShapeTrackFilter::loadClusterLimits(), TripletFilter::loadClusterLimits(), SiStripHashedDetIdFakeESSource::make(), SiStripFedCablingFakeESSource::make(), edm::pset::makeDefaultPSet(), SiStripNoiseFakeESSource::makeNoise(), SiStripPedestalsFakeESSource::makePedestals(), MCJetCorrector::MCJetCorrector(), MCJetCorrector3D::MCJetCorrector3D(), MuonErrorMatrix::MuonErrorMatrix(), PhysicsTools::MVAComputerESSourceBase::MVAComputerESSourceBase(), NuclearInteractionSimulator::NuclearInteractionSimulator(), DDLParser::parseOneFile(), EcalTrigPrimESProducer::parseTextFile(), EcalElectronicsMappingBuilder::parseTextMap(), EcalTrigTowerConstituentsMapBuilder::parseTextMap(), CaloTowerConstituentsMapBuilder::parseTextMap(), PixelErrorParametrization::PixelErrorParametrization(), SiPixelFakeLorentzAngleESSource::produce(), SiPixelFakeGainForHLTESSource::produce(), SiStripGainFakeESSource::produce(), HepPDTESSource::produce(), SiPixelFakeGainESSource::produce(), SiStripThresholdFakeESSource::produce(), CaloTPGTranscoderULUTs::produce(), SiStripLAFakeESSource::produce(), SiPixelFakeGainOfflineESSource::produce(), MaskedRctInputDigiProducer::produce(), SiStripQualityConfigurableFakeESSource::produce(), edm::PtYDistributor::PtYDistributor(), PUJetCorrector::PUJetCorrector(), FIPConfiguration::readConfig(), CSCTFPtLUT::readLUT(), CSCSectorReceiverLUT::readLUTsFromFile(), GsfBetheHeitlerUpdator::readParameters(), edm::pset::IncludeNode::resolve(), RPCCalibSetUp::RPCCalibSetUp(), RPCDBSimSetUp::RPCDBSimSetUp(), SiStripBadModuleByHandBuilder::SiStripBadModuleByHandBuilder(), SiStripQuality::SiStripQuality(), SiStripQualityHotStripIdentifier::SiStripQualityHotStripIdentifier(), SiStripQualityHotStripIdentifierRoot::SiStripQualityHotStripIdentifierRoot(), SiStripQualityStatistics::SiStripQualityStatistics(), and PhysicsTools::MVATrainerLooper::Trainer::Trainer().
00171 { 00172 return canonicalFilename_; 00173 }
Definition at line 319 of file FileInPath.cc.
References DATATOP(), envstring(), edm::errors::FileInPathError, LOCALTOP(), PathVariableName(), and RELEASETOP().
Referenced by FileInPath().
00320 { 00321 if (!envstring(RELEASETOP, releaseTop_)) { 00322 releaseTop_.clear(); 00323 } 00324 if (releaseTop_.empty()) { 00325 // RELEASETOP was not set. This means that the environment is set 00326 // for the base release itself. So LOCALTOP actually contains the 00327 // location of the base release. 00328 if (!envstring(LOCALTOP, releaseTop_)) { 00329 releaseTop_.clear(); 00330 } 00331 } else { 00332 if (!envstring(LOCALTOP, localTop_)) { 00333 localTop_.clear(); 00334 } 00335 } 00336 if (!envstring(DATATOP, dataTop_)) { 00337 dataTop_.clear(); 00338 } 00339 if (!envstring(PathVariableName, searchPath_)) { 00340 throw edm::Exception(edm::errors::FileInPathError) 00341 << PathVariableName 00342 << " must be defined\n"; 00343 }
void FileInPath::initialize_ | ( | ) | [private] |
Definition at line 346 of file FileInPath.cc.
References end, edm::errors::FileInPathError, it, locateFile(), path(), PathVariableName(), and tokenize.
Referenced by FileInPath().
00348 { 00349 if (relativePath_.empty()) 00350 throw edm::Exception(edm::errors::FileInPathError) 00351 << "Relative path must not be empty\n"; 00352 00353 // Find the file, based on the value of path variable. 00354 typedef std::vector<std::string> stringvec_t; 00355 stringvec_t pathElements = tokenize(searchPath_, ":"); 00356 stringvec_t::const_iterator it = pathElements.begin(); 00357 stringvec_t::const_iterator end = pathElements.end(); 00358 while (it != end) { 00359 // Set the boost::fs path to the current element of 00360 // CMSSW_SEARCH_PATH: 00361 bf::path pathPrefix(*it, bf::no_check); 00362 00363 // Does the a file exist? locateFile throws is it finds 00364 // something goofy. 00365 if (locateFile(pathPrefix, relativePath_)) { 00366 // Convert relative path to canonical form, and save it. 00367 relativePath_ = bf::path(relativePath_, bf::no_check).normalize().string(); 00368 00369 // Save the absolute path. 00370 canonicalFilename_ = bf::complete(relativePath_, 00371 pathPrefix).string(); 00372 if (canonicalFilename_.empty()) 00373 throw edm::Exception(edm::errors::FileInPathError) 00374 << "fullPath is empty" 00375 << "\nrelativePath() is: " << relativePath_ 00376 << "\npath prefix is: " << pathPrefix.string() 00377 << '\n'; 00378 00379 // From the current path element, find the branch path (basically the path minus the 00380 // last directory, e.g. /src or /share): 00381 for (bf::path br = pathPrefix.branch_path(); !br.normalize().string().empty(); br = br.branch_path()) { 00382 00383 if (!localTop_.empty()) { 00384 // Create a path object for our local path LOCALTOP: 00385 bf::path local_(localTop_, bf::no_check); 00386 // If the branch path matches the local path, the file was found locally: 00387 if (br == local_) { 00388 location_ = Local; 00389 return; 00390 } 00391 } 00392 00393 if (!releaseTop_.empty()) { 00394 // Create a path object for our release path RELEASETOP: 00395 bf::path release_(releaseTop_, bf::no_check); 00396 // If the branch path matches the release path, the file was found in the release: 00397 if (br == release_) { 00398 location_ = Release; 00399 return; 00400 } 00401 } 00402 00403 if (!dataTop_.empty()) { 00404 // Create a path object for our data path DATATOP: 00405 bf::path data_(dataTop_, bf::no_check); 00406 // If the branch path matches the data path, the file was found in the data area: 00407 if (br == data_) { 00408 location_ = Data; 00409 return; 00410 } 00411 } 00412 } 00413 00414 // This is really gross --- this organization of if/else 00415 // inside the while-loop should be changed so that 00416 // this break isn't needed. 00417 } 00418 // Keep trying 00419 ++it; 00420 } 00421 00422 // If we got here, we ran out of path elements without finding 00423 // what we're looking found. 00424 throw edm::Exception(edm::errors::FileInPathError) 00425 << "Unable to find file " 00426 << relativePath_ 00427 << " anywhere in the search path." 00428 << "\nThe search path is defined by: " 00429 << PathVariableName 00430 << "\n${" 00431 << PathVariableName 00432 << "} is: " 00433 << getenv(PathVariableName.c_str()) 00434 << "\nCurrent directory is: " 00435 << bf::initial_path().string() 00436 << "\n";
bool FileInPath::isLocal | ( | ) | const |
Was the file found under the "local" area?
Definition at line 164 of file FileInPath.cc.
Referenced by BOOST_PYTHON_MODULE().
FileInPath::LocationCode FileInPath::location | ( | ) | const |
Where was the file found?
Definition at line 158 of file FileInPath.cc.
Referenced by edm::operator==().
00159 { 00160 return location_; 00161 }
FileInPath & FileInPath::operator= | ( | FileInPath const & | other | ) |
Definition at line 131 of file FileInPath.cc.
References swap(), and pyDBSRunClass::temp.
00132 { 00133 FileInPath temp(other); 00134 this->swap(temp); 00135 return *this; 00136 }
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 BASE(), DATATOP(), edm::errors::FileInPathError, muonGeometry::loc, LOCALTOP(), RELEASETOP(), Unknown, and version().
Referenced by edm::operator>>().
00240 { 00241 std::string vsn; 00242 std::string relname; 00243 std::string canFilename; 00244 #if 1 00245 // This #if needed for backward compatibility 00246 // for files written before CMSSW_1_5_0_pre3. 00247 is >> vsn; 00248 if (!is) return; 00249 bool oldFormat = (version != vsn); 00250 if (oldFormat) { 00251 relname = vsn; 00252 bool local; 00253 is >> local; 00254 location_ = (local ? Local : Release); 00255 is >> canFilename; 00256 } else { 00257 // Current format 00258 int loc; 00259 is >> relname >> loc; 00260 location_ = static_cast<FileInPath::LocationCode>(loc); 00261 if (location_ != Unknown) is >> canFilename; 00262 } 00263 #else 00264 is >> vsn >> relname >> loc >> canFilename; 00265 #endif 00266 if (!is) return; 00267 relativePath_ = relname; 00268 if (location_ == Local) { 00269 if (localTop_.empty()) { 00270 throw edm::Exception(edm::errors::FileInPathError) 00271 << "Environment Variable " 00272 << LOCALTOP 00273 << " is not set.\n"; 00274 } 00275 #if 1 00276 // This #if needed for backward compatibility 00277 // for files written before CMSSW_1_5_0_pre3. 00278 if (oldFormat) { 00279 canonicalFilename_ = canFilename; 00280 } else 00281 #endif 00282 canonicalFilename_ = localTop_ + canFilename; 00283 } else if (location_ == Release) { 00284 if (releaseTop_.empty()) { 00285 throw edm::Exception(edm::errors::FileInPathError) 00286 << "Environment Variable " 00287 << RELEASETOP 00288 << " is not set.\n"; 00289 } 00290 #if 1 00291 // This #if needed for backward compatibility 00292 // for files written before CMSSW_1_5_0_pre3. 00293 if (oldFormat) { 00294 std::string::size_type pos = canFilename.find(BASE); 00295 if (pos == 0) { 00296 // Replace the placehoder with the path to the base release (site dependent). 00297 canonicalFilename_ = releaseTop_ + canFilename.substr(BASE.size()); 00298 } else { 00299 // Needed for files written before CMSSW_1_2_0_pre2. 00300 canonicalFilename_ = canFilename; 00301 } 00302 } else 00303 #endif 00304 canonicalFilename_ = releaseTop_ + canFilename; 00305 } else if (location_ == Data) { 00306 if (dataTop_.empty()) { 00307 throw edm::Exception(edm::errors::FileInPathError) 00308 << "Environment Variable " 00309 << DATATOP 00310 << " is not set.\n"; 00311 } 00312 canonicalFilename_ = dataTop_ + canFilename; 00313 }
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.
Referenced by BOOST_PYTHON_MODULE(), edm::operator==(), and edm::pset::ImplicitIncludeNode::resolve().
00152 { 00153 return relativePath_; 00154 }
void FileInPath::swap | ( | FileInPath & | other | ) |
Definition at line 139 of file FileInPath.cc.
References canonicalFilename_, dataTop_, localTop_, location_, relativePath_, releaseTop_, searchPath_, and std::swap().
Referenced by edm::swap().
00140 { 00141 relativePath_.swap(other.relativePath_); 00142 canonicalFilename_.swap(other.canonicalFilename_); 00143 std::swap(location_, other.location_); 00144 localTop_.swap(other.localTop_); 00145 releaseTop_.swap(other.releaseTop_); 00146 dataTop_.swap(other.dataTop_); 00147 searchPath_.swap(other.searchPath_); 00148 }
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 DATATOP(), edm::errors::FileInPathError, LOCALTOP(), RELEASETOP(), Unknown, and version().
Referenced by edm::operator<<().
00177 { 00178 if (location_ == Unknown) { 00179 os << version << ' ' << relativePath_ << ' ' << location_; 00180 } else if (location_ == Local) { 00181 // Guarantee a site independent value by stripping $LOCALTOP. 00182 if (localTop_.empty()) { 00183 throw edm::Exception(edm::errors::FileInPathError) 00184 << "Environment Variable " 00185 << LOCALTOP 00186 << " is not set.\n"; 00187 } 00188 std::string::size_type pos = canonicalFilename_.find(localTop_); 00189 if (pos != 0) { 00190 throw edm::Exception(edm::errors::FileInPathError) 00191 << "Path " 00192 << canonicalFilename_ 00193 << " is not in the local release area " 00194 << localTop_ 00195 << "\n"; 00196 } 00197 os << version << ' ' << relativePath_ << ' ' << location_ << ' ' << canonicalFilename_.substr(localTop_.size()); 00198 } else if (location_ == Release) { 00199 // Guarantee a site independent value by stripping $RELEASETOP. 00200 if (releaseTop_.empty()) { 00201 throw edm::Exception(edm::errors::FileInPathError) 00202 << "Environment Variable " 00203 << RELEASETOP 00204 << " is not set.\n"; 00205 } 00206 std::string::size_type pos = canonicalFilename_.find(releaseTop_); 00207 if (pos != 0) { 00208 throw edm::Exception(edm::errors::FileInPathError) 00209 << "Path " 00210 << canonicalFilename_ 00211 << " is not in the base release area " 00212 << releaseTop_ 00213 << "\n"; 00214 } 00215 os << version << ' ' << relativePath_ << ' ' << location_ << ' ' << canonicalFilename_.substr(releaseTop_.size()); 00216 } else if (location_ == Data) { 00217 // Guarantee a site independent value by stripping $DATATOP. 00218 if (dataTop_.empty()) { 00219 throw edm::Exception(edm::errors::FileInPathError) 00220 << "Environment Variable " 00221 << DATATOP 00222 << " is not set.\n"; 00223 } 00224 std::string::size_type pos = canonicalFilename_.find(dataTop_); 00225 if (pos != 0) { 00226 throw edm::Exception(edm::errors::FileInPathError) 00227 << "Path " 00228 << canonicalFilename_ 00229 << " is not in the data area " 00230 << dataTop_ 00231 << "\n"; 00232 } 00233 os << version << ' ' << relativePath_ << ' ' << location_ << ' ' << canonicalFilename_.substr(dataTop_.size()); 00234 } 00235 }
std::string edm::FileInPath::canonicalFilename_ [private] |
std::string edm::FileInPath::dataTop_ [private] |
std::string edm::FileInPath::localTop_ [private] |
LocationCode edm::FileInPath::location_ [private] |
std::string edm::FileInPath::relativePath_ [private] |
std::string edm::FileInPath::releaseTop_ [private] |
std::string edm::FileInPath::searchPath_ [private] |