CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes
edm::FileInPath Class Reference

#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. More...
 
 FileInPath (const char *r)
 
 FileInPath (FileInPath const &other)
 
std::string fullPath () const
 
LocationCode location () const
 Where was the file found? More...
 
FileInPathoperator= (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 ()
 

Static Public Member Functions

static void disableFileLookup ()
 Should only be called while the edmWriteConfigs executable runs. More...
 
static std::string findFile (std::string const &)
 

Private Member Functions

void getEnvironment ()
 
void initialize_ ()
 

Static Private Member Functions

static std::string const & searchPath ()
 

Private Attributes

std::string canonicalFilename_
 
std::string dataTop_
 
std::string localTop_
 
LocationCode location_
 
std::string relativePath_
 
std::string releaseTop_
 
std::string searchPath_
 

Detailed Description

Definition at line 61 of file FileInPath.h.

Member Enumeration Documentation

◆ LocationCode

Enumerator
Unknown 
Local 
Release 
Data 

Definition at line 63 of file FileInPath.h.

Constructor & Destructor Documentation

◆ FileInPath() [1/4]

edm::FileInPath::FileInPath ( )

Default c'tor does no file-existence check; what file would it check for existence?

Definition at line 104 of file FileInPath.cc.

References getEnvironment().

105  if (s_fileLookupDisabled) {
106  return;
107  }
108  getEnvironment();
109  }
std::string canonicalFilename_
Definition: FileInPath.h:116
void getEnvironment()
Definition: FileInPath.cc:346
LocationCode location_
Definition: FileInPath.h:117
std::string relativePath_
Definition: FileInPath.h:115

◆ FileInPath() [2/4]

edm::FileInPath::FileInPath ( const std::string &  r)
explicit

We throw an exception is the referenced file is not found.

Definition at line 111 of file FileInPath.cc.

References getEnvironment(), and initialize_().

112  if (s_fileLookupDisabled) {
113  return;
114  }
115  getEnvironment();
116  initialize_();
117  }
std::string canonicalFilename_
Definition: FileInPath.h:116
void getEnvironment()
Definition: FileInPath.cc:346
LocationCode location_
Definition: FileInPath.h:117
void initialize_()
Definition: FileInPath.cc:376
std::string relativePath_
Definition: FileInPath.h:115

◆ FileInPath() [3/4]

edm::FileInPath::FileInPath ( const char *  r)
explicit

Definition at line 119 of file FileInPath.cc.

References Exception, edm::errors::FileInPathError, getEnvironment(), and initialize_().

120  if (s_fileLookupDisabled) {
121  return;
122  }
123  if (r == nullptr) {
124  throw edm::Exception(edm::errors::FileInPathError) << "Relative path must not be null\n";
125  }
126  getEnvironment();
127  initialize_();
128  }
std::string canonicalFilename_
Definition: FileInPath.h:116
void getEnvironment()
Definition: FileInPath.cc:346
LocationCode location_
Definition: FileInPath.h:117
void initialize_()
Definition: FileInPath.cc:376
std::string relativePath_
Definition: FileInPath.h:115

◆ FileInPath() [4/4]

edm::FileInPath::FileInPath ( FileInPath const &  other)

Definition at line 130 of file FileInPath.cc.

131  : relativePath_(other.relativePath_),
132  canonicalFilename_(other.canonicalFilename_),
133  location_(other.location_),
134  localTop_(other.localTop_),
135  releaseTop_(other.releaseTop_),
136  dataTop_(other.dataTop_),
137  searchPath_(other.searchPath_) {}
std::string canonicalFilename_
Definition: FileInPath.h:116
std::string dataTop_
Definition: FileInPath.h:120
std::string searchPath_
Definition: FileInPath.h:121
std::string releaseTop_
Definition: FileInPath.h:119
LocationCode location_
Definition: FileInPath.h:117
std::string relativePath_
Definition: FileInPath.h:115
std::string localTop_
Definition: FileInPath.h:118

◆ ~FileInPath()

edm::FileInPath::~FileInPath ( )

Definition at line 139 of file FileInPath.cc.

139 {}

Member Function Documentation

◆ disableFileLookup()

void edm::FileInPath::disableFileLookup ( )
static

Should only be called while the edmWriteConfigs executable runs.

Definition at line 450 of file FileInPath.cc.

450 { s_fileLookupDisabled = true; }

◆ findFile()

std::string edm::FileInPath::findFile ( std::string const &  iFileName)
static

Uses the same algorithm to find the file but does not determine the location. Returns an empty string if unfound.

Definition at line 452 of file FileInPath.cc.

References castor_dqm_sourceclient_file_cfg::path, searchPath(), and edm::tokenize().

Referenced by magneticfield::InterpolatorBuilder::build(), and magneticfield::InterpolatorBuilder::InterpolatorBuilder().

452  {
453  // Find the file, based on the value of path variable.
454  auto pathElements = tokenize(searchPath(), ":");
455  for (auto const& element : pathElements) {
456  // Set the boost::fs path to the current element of
457  // CMSSW_SEARCH_PATH:
458  std::filesystem::path pathPrefix(element);
459 
460  // Does the a file exist? locateFile throws is it finds
461  // something goofy.
462  if (locateFile(pathPrefix, iFileName)) {
463  // Convert relative path to canonical form, and save it.
464  return std::filesystem::absolute(pathPrefix / iFileName).string();
465  }
466  }
467  return {};
468  }
static std::string const & searchPath()
Definition: FileInPath.cc:340
std::vector< std::string > tokenize(std::string const &input, std::string const &separator)
breaks the input string into tokens, delimited by the separator
Definition: Parse.cc:52

◆ fullPath()

std::string edm::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 161 of file FileInPath.cc.

References canonicalFilename_.

Referenced by Phase1PixelSummaryMap::addNamedBins(), MillePedeAlignmentAlgorithm::addPxbSurvey(), SiStripPedestalsBuilder::analyze(), SiStripThresholdBuilder::analyze(), SiStripApvGainBuilder::analyze(), SiStripNoisesBuilder::analyze(), SiStripNoisesAndBadCompsChecker::analyze(), JetCorrectorDemo::analyze(), MuonGeometrySVGTemplate::analyze(), HcalLutAnalyzer::analyze(), HGCalWaferValidation::analyze(), PixelRegions::attachedDets(), BeamSpotFakeConditions::BeamSpotFakeConditions(), JetCorrectorDBWriter::beginJob(), ProtonTaggerFilter::beginJob(), OMTFReconstruction::beginRun(), omtf::OmtfPacker::beginRun(), omtf::OmtfUnpacker::beginRun(), GoodSeedProducer::beginRun(), ExternalLHEProducer::beginRunProduce(), HGCalValidator::bookHistograms(), SiStripQualityHotStripIdentifier::bookHistos(), BTagSFProducer::BTagSFProducer(), HcalTPGCoderULUT::buildCoder(), MagGeoBuilderFromDDD::buildInterpolator(), CacheData::CacheData(), CaloMiscalibTools::CaloMiscalibTools(), CaloMiscalibToolsMC::CaloMiscalibToolsMC(), GBRForestWriter::categoryEntryType::categoryEntryType(), CTPPSPixelDAQMappingESSourceXML::CompleteFileName(), TotemDAQMappingESSourceXML::CompleteFileName(), createGBRForest(), CSCTFPtLUT::CSCTFPtLUT(), SiStripPopConNoisesHandlerFromDQM::dqmEndJob(), SiStripPopConPedestalsHandlerFromDQM::dqmEndJob(), SiStripPopConBadComponentsHandlerFromDQM::dqmEndJob(), DTOccupancyTestML::dqmEndLuminosityBlock(), dtCalibration::DTTTrigResidualCorrection::DTTTrigResidualCorrection(), EcalEBPhase2TPParamProducer::EcalEBPhase2TPParamProducer(), ElectronPATIdMVAProducer::ElectronPATIdMVAProducer(), OccupancyPlots::endRun(), ESDataFormatterV4::ESDataFormatterV4(), ESDigiToRaw::ESDigiToRaw(), ESElectronicsMapper::ESElectronicsMapper(), ESIntegrityClient::ESIntegrityClient(), ESPedestalClient::ESPedestalClient(), ESUnpacker::ESUnpacker(), LateralityCoarsedProvider::fill_lat_combinations(), MuonPathSLFitter::fillLuts(), MuonPathCorFitter::fillLuts(), HGCalTriggerGeometryV9Imp2::fillMaps(), HGCalTriggerGeometryV9Imp3::fillMaps(), edm::service::FixMissingStreamerInfos::FixMissingStreamerInfos(), ESTrivialConditionRetriever::getChannelStatusFromConfiguration(), EcalTrivialConditionRetriever::getChannelStatusFromConfiguration(), EcalTrivialConditionRetriever::getMappingFromConfiguration(), SiStripGainFromAsciiFile::getNewObject(), SiStripBadModuleByHandBuilder::getNewObject(), SiStripBadChannelBuilder::getNewObject(), SiStripBadStripFromASCIIFile::getNewObject(), SiStripNoisesFromDBMiscalibrator::getNewObject_withDefaults(), EcalMappingElectronicsHandler::getNewObjects(), EcalTrivialConditionRetriever::getPFRecHitThresholdsFromConfiguration(), EcalTrivialConditionRetriever::getTrgChannelStatusFromConfiguration(), ESTrivialConditionRetriever::getWeightsFromConfiguration(), EcalTrivialConditionRetriever::getWeightsFromConfiguration(), HcalHardcodeCalibrations::HcalHardcodeCalibrations(), HcalLaserEventFilter2012::HcalLaserEventFilter2012(), l1t::HGC3DClusterTMVASelector::HGC3DClusterTMVASelector(), HGCalMappingESProducer::HGCalMappingESProducer(), HGCalNumberingScheme::HGCalNumberingScheme(), HGCalTriggerTowerGeometryHelper::HGCalTriggerTowerGeometryHelper(), HGCalValidator::HGCalValidator(), HGCScintSD::HGCScintSD(), PDFWeightsHelper::Init(), gen::EvtGenInterface::init(), l1tpf::corrector::init_(), CandidateBoostedDoubleSecondaryVertexComputer::initialize(), MuonTagger::initialize(), CandidateChargeBTagComputer::initialize(), CombinedMVAV2JetTagComputer::initialize(), ElectronTagger::initialize(), CharmTagger::initialize(), HeavyIonCSVTagger::initialize(), ApeSettingAlgorithm::initialize(), TritonEDFilterT< G, Capabilities >::initializeGlobalCache(), TritonEDProducerT< G, Capabilities >::initializeGlobalCache(), DeepMETProducer::initializeGlobalCache(), L1NNTauProducer::initializeGlobalCache(), TracksterLinksProducer::initializeGlobalCache(), L1NNCaloTauProducer::initializeGlobalCache(), L1NNCaloTauEmulator::initializeGlobalCache(), DeepTauId::initializeGlobalCache(), L2TauNNProducerAlpaka::initializeGlobalCache(), L2TauNNProducer::initializeGlobalCache(), PileupJetIdProducer::initJetEnergyCorrector(), egammaTools::EgammaDNNHelper::initScalerFiles(), reco::DeepSCGraphEvaluation::initTensorFlowGraphAndSession(), L1FPGATrackProducer::L1FPGATrackProducer(), L1TGlobalPrescalesVetosESProducer::L1TGlobalPrescalesVetosESProducer(), L1TGlobalPrescalesVetosFractESProducer::L1TGlobalPrescalesVetosFractESProducer(), L1TMuonOverlapParamsESProducer::L1TMuonOverlapParamsESProducer(), L1TrackVertexAssociationProducer::L1TrackVertexAssociationProducer(), CovarianceParameterization::load(), L1MuDTPtaLut::load(), L1MuDTPhiLut::load(), L1MuDTEtaPatternLut::load(), L1MuBMTEtaPatternLut::load(), L1MuDTQualPatternLut::load(), L1MuBMTQualPatternLut::load(), L1MuDTExtLut::load(), L1TMuonBarrelParamsHelper::load_ext(), L1TMuonBarrelParamsHelper::load_phi(), L1TMuonBarrelParamsHelper::load_pt(), DTCCablingMapProducer::LoadModulesToDTCCablingMapFromCSV(), ClusterShapeHitFilter::loadStripLimits(), SiStripFedCablingFakeESSource::make(), jpt::Map::Map(), MaterialBudgetCategorizer::MaterialBudgetCategorizer(), MPFilter::MPFilter(), MuonHLTSeedMVAClassifier::MuonHLTSeedMVAClassifier(), pat::MuonMvaIDEstimator::MuonMvaIDEstimator(), MuonPathAnalyticAnalyzer::MuonPathAnalyticAnalyzer(), MuonPathAnalyzerInChamber::MuonPathAnalyzerInChamber(), MuonPathAssociator::MuonPathAssociator(), MuonPathConfirmator::MuonPathConfirmator(), MuonPathFitter::MuonPathFitter(), MuonPathSLFitter::MuonPathSLFitter(), MVAJetPuId::MVAJetPuId(), MVAVariableManager< reco::GsfElectron >::MVAVariableManager(), fastsim::NuclearInteraction::NuclearInteraction(), NuclearInteractionSimulator::NuclearInteractionSimulator(), OnlineDQMDigiAD::OnlineDQMDigiAD(), OverlapValidation::OverlapValidation(), HcalTBObjectUnpacker::parseCalib(), cond::persistency::parseFipConnectionString(), EcalEBTrigPrimPhase2ESProducer::parseTextFile(), EcalTrigPrimESProducer::parseTextFile(), EcalTrigTowerConstituentsMapBuilder::parseTextMap(), CaloTowerConstituentsMapBuilder::parseTextMap(), EcalEBTrigPrimPhase2ESProducer::parseWeightsFile(), cms::PileupJPTJetIdAlgo::PileupJPTJetIdAlgo(), PixelTemplateSmearerBase::PixelTemplateSmearerBase(), l1tpf::HGC3DClusterEgID::prepareTMVA(), LwtnnESProducer::produce(), SiPixelFakeLorentzAngleESSource::produce(), HepPDTESSource::produce(), SiPixelFakeGainOfflineESSource::produce(), SiPixelFakeGainESSource::produce(), SiPixelFakeGainForHLTESSource::produce(), ALPAKA_ACCELERATOR_NAMESPACE::hgcal::HGCalMappingModuleESProducer::produce(), HcalTPGCoderULUT::produce(), ALPAKA_ACCELERATOR_NAMESPACE::hgcal::HGCalMappingCellESProducer::produce(), CaloTPGTranscoderULUTs::produce(), MaskedRctInputDigiProducer::produce(), ecaldqm::MLClient::producePlots(), gen::PtYDistributor::PtYDistributor(), gen::Py8HMC3InterfaceBase::Py8HMC3InterfaceBase(), gen::Py8InterfaceBase::Py8InterfaceBase(), PYBIND11_MODULE(), QualityTester::QualityTester(), SiStripApvGainFromFileBuilder::read_tickmark(), reco::DeepSCGraphEvaluation::readInputFeaturesConfig(), CSCTFPtLUT::readLUT(), CSCSectorReceiverLUT::readLUTsFromFile(), GsfBetheHeitlerUpdator::readParameters(), gen::ReggeGribovPartonMCHadronizer::ReggeGribovPartonMCHadronizer(), RPCCalibSetUp::RPCCalibSetUp(), RPCDBSimSetUp::RPCDBSimSetUp(), L1TrackQuality::runEmulatedTQ(), SelectedElectronFEDListProducer< TEle, TCand >::SelectedElectronFEDListProducer(), L1TrackQuality::setL1TrackQuality(), ecaldqm::LedClient::setParams(), ShiftedJetProducerT< T, Textractor >::ShiftedJetProducerT(), ShiftedPFCandidateProducerForNoPileUpPFMEt::ShiftedPFCandidateProducerForNoPileUpPFMEt(), ShiftedPFCandidateProducerForPFNoPUMEt::ShiftedPFCandidateProducerForPFNoPUMEt(), SiLinearChargeDivider::SiLinearChargeDivider(), SiStripApvGainFakeESSource::SiStripApvGainFakeESSource(), SiStripBadModuleConfigurableFakeESSource::SiStripBadModuleConfigurableFakeESSource(), SiStripBaseDelayFakeESSource::SiStripBaseDelayFakeESSource(), SiStripClusters2ApproxClusters::SiStripClusters2ApproxClusters(), SiStripDigitizerAlgorithm::SiStripDigitizerAlgorithm(), SiStripFedCablingFakeESSource::SiStripFedCablingFakeESSource(), SiStripHitEffFromCalibTree::SiStripHitEffFromCalibTree(), SiStripHitResolFromCalibTree::SiStripHitResolFromCalibTree(), SiStripLatencyFakeESSource::SiStripLatencyFakeESSource(), SiStripNoisesFakeESSource::SiStripNoisesFakeESSource(), SiStripPedestalsFakeESSource::SiStripPedestalsFakeESSource(), SiStripThresholdFakeESSource::SiStripThresholdFakeESSource(), trends(), TritonClient::TritonClient(), TtSemiLepHitFitProducer< LeptonCollection >::TtSemiLepHitFitProducer(), emtf::phase2::EMTFContext::update(), l1tVertexFinder::AlgoSettings::vx_pattrec_graph(), l1tVertexFinder::AlgoSettings::vx_trkw_graph(), and FWRecoGeometryESProducer::writeTrackerParametersXML().

161 { return canonicalFilename_; }
std::string canonicalFilename_
Definition: FileInPath.h:116

◆ getEnvironment()

void edm::FileInPath::getEnvironment ( void  )
private

Definition at line 346 of file FileInPath.cc.

References dataTop_, Exception, edm::errors::FileInPathError, localTop_, releaseTop_, searchPath(), searchPath_, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by FileInPath().

346  {
348  if (searchPath_.empty()) {
349  throw edm::Exception(edm::errors::FileInPathError) << PathVariableName << " must be defined\n";
350  }
351 
352  static std::string const releaseTop = removeSymLinksSrc(RELEASETOP);
353  releaseTop_ = releaseTop;
354 
355  static std::string const localTop = removeSymLinksSrc(LOCALTOP);
356  localTop_ = localTop;
357 
358  static std::string const dataTop = removeSymLinks(DATATOP);
359  dataTop_ = dataTop;
360 
361  if (releaseTop_.empty()) {
362  // RELEASETOP was not set. This means that the environment is set
363  // for the base release itself. So LOCALTOP actually contains the
364  // location of the base release.
366  localTop_.clear();
367  }
368  if (releaseTop_ == localTop_) {
369  // RELEASETOP is the same as LOCALTOP. This means that the environment is set
370  // for the base release itself. So LOCALTOP actually contains the
371  // location of the base release.
372  localTop_.clear();
373  }
374  }
std::string dataTop_
Definition: FileInPath.h:120
std::string searchPath_
Definition: FileInPath.h:121
std::string releaseTop_
Definition: FileInPath.h:119
static std::string const & searchPath()
Definition: FileInPath.cc:340
std::string localTop_
Definition: FileInPath.h:118

◆ initialize_()

void edm::FileInPath::initialize_ ( )
private

Definition at line 376 of file FileInPath.cc.

References beamvalidation::br, canonicalFilename_, Data, dataTop_, Exception, edm::errors::FileInPathError, Local, localTop_, location_, castor_dqm_sourceclient_file_cfg::path, relativePath_, Release, releaseTop_, searchPath_, and edm::tokenize().

Referenced by FileInPath().

376  {
377  if (relativePath_.empty()) {
378  throw edm::Exception(edm::errors::FileInPathError) << "Relative path must not be empty\n";
379  }
380 
381  // Find the file, based on the value of searchPath.
382  typedef std::vector<std::string> stringvec_t;
383  stringvec_t pathElements = tokenize(searchPath_, ":");
384  for (auto const& element : pathElements) {
385  // Set the path to the current element of CMSSW_SEARCH_PATH:
386  std::filesystem::path pathPrefix(element);
387 
388  // Does the a file exist? locateFile throws is it finds
389  // something goofy.
390  if (locateFile(pathPrefix, relativePath_)) {
391  // Convert relative path to canonical form, and save it.
392  relativePath_ = std::filesystem::path(relativePath_).lexically_normal().string();
393  //std::filesystem::path(relativePath_).normalize().string();
394 
395  // Save the absolute path.
396  canonicalFilename_ = std::filesystem::absolute(pathPrefix / relativePath_).string();
397  if (canonicalFilename_.empty()) {
399  << "fullPath is empty"
400  << "\nrelativePath() is: " << relativePath_ << "\npath prefix is: " << pathPrefix.string() << '\n';
401  }
402 
403  // From the current path element, find the branch path (basically the path minus the
404  // last directory, e.g. /src or /share):
405  for (std::filesystem::path br = pathPrefix.parent_path();
406  !std::filesystem::weakly_canonical(br).string().empty();
407  br = br.parent_path()) {
408  if (!localTop_.empty()) {
409  // Create a path object for our local path LOCALTOP:
411  // If the branch path matches the local path, the file was found locally:
412  if (br == local_) {
413  location_ = Local;
414  return;
415  }
416  }
417 
418  if (!releaseTop_.empty()) {
419  // Create a path object for our release path RELEASETOP:
421  // If the branch path matches the release path, the file was found in the release:
422  if (br == release_) {
423  location_ = Release;
424  return;
425  }
426  }
427 
428  if (!dataTop_.empty()) {
429  // Create a path object for our data path DATATOP:
431  // If the branch path matches the data path, the file was found in the data area:
432  if (br == data_) {
433  location_ = Data;
434  return;
435  }
436  }
437  }
438  }
439  }
440 
441  // If we got here, we ran out of path elements without finding
442  // what we're looking found.
444  << "edm::FileInPath unable to find file " << relativePath_ << " anywhere in the search path."
445  << "\nThe search path is defined by: " << PathVariableName << "\n${" << PathVariableName
446  << "} is: " << std::getenv(PathVariableName.c_str())
447  << "\nCurrent directory is: " << std::filesystem::current_path().string() << "\n";
448  }
std::string canonicalFilename_
Definition: FileInPath.h:116
std::string dataTop_
Definition: FileInPath.h:120
std::string searchPath_
Definition: FileInPath.h:121
std::string releaseTop_
Definition: FileInPath.h:119
LocationCode location_
Definition: FileInPath.h:117
std::vector< std::string > tokenize(std::string const &input, std::string const &separator)
breaks the input string into tokens, delimited by the separator
Definition: Parse.cc:52
std::string relativePath_
Definition: FileInPath.h:115
std::string localTop_
Definition: FileInPath.h:118

◆ location()

FileInPath::LocationCode edm::FileInPath::location ( ) const

◆ operator=()

FileInPath & edm::FileInPath::operator= ( FileInPath const &  other)

Definition at line 141 of file FileInPath.cc.

References trackingPlots::other, swap(), and groupFilesInBlocks::temp.

141  {
143  this->swap(temp);
144  return *this;
145  }
void swap(FileInPath &other)
Definition: FileInPath.cc:147

◆ read()

void edm::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 206 of file FileInPath.cc.

References canonicalFilename_, Data, dataTop_, Exception, edm::errors::FileInPathError, DTRecHitClients_cfi::local, Local, localTop_, location_, relativePath_, Release, releaseTop_, AlCaHLTBitMon_QueryRunRegistry::string, Unknown, and BeamSplash_cfg::version.

Referenced by edmIntegrityCheck.PublishToFileSystem::get(), and edm::operator>>().

206  {
207  std::string vsn;
208  std::string relname;
209  std::string canFilename;
210 #if 1
211  // This #if needed for backward compatibility
212  // for files written before CMSSW_1_5_0_pre3.
213  is >> vsn;
214  if (!is)
215  return;
216  bool oldFormat = (version != vsn);
217  if (oldFormat) {
218  relname = vsn;
219  bool local;
220  is >> local;
221  location_ = (local ? Local : Release);
222  is >> canFilename;
223  } else {
224  // Current format
225  int loc;
226  is >> relname >> loc;
227  location_ = static_cast<FileInPath::LocationCode>(loc);
228  if (location_ != Unknown) {
229  is >> canFilename;
230  } else if (relname == "@") {
231  relname = "";
232  }
233  }
234 #else
235  is >> vsn >> relname >> loc >> canFilename;
236 #endif
237  if (!is)
238  return;
239  relativePath_ = relname;
240  if (location_ == Local) {
241  if (localTop_.empty()) {
242  throw edm::Exception(edm::errors::FileInPathError) << "Environment Variable " << LOCALTOP << " is not set.\n"
243  << "Trying to read Local file: " << canFilename << ".\n";
244  }
245 #if 1
246  // This #if needed for backward compatibility
247  // for files written before CMSSW_1_5_0_pre3.
248  if (oldFormat) {
249  canonicalFilename_ = canFilename;
250  } else
251 #endif
252  canonicalFilename_ = localTop_ + canFilename;
253  } else if (location_ == Release) {
254  if (releaseTop_.empty()) {
255  throw edm::Exception(edm::errors::FileInPathError) << "Environment Variable " << RELEASETOP << " is not set.\n";
256  }
257 #if 1
258  // This #if needed for backward compatibility
259  // for files written before CMSSW_1_5_0_pre3.
260  if (oldFormat) {
261  std::string::size_type pos = canFilename.find(BASE);
262  if (pos == 0) {
263  // Replace the placehoder with the path to the base release (site dependent).
264  canonicalFilename_ = releaseTop_ + canFilename.substr(BASE.size());
265  } else {
266  // Needed for files written before CMSSW_1_2_0_pre2.
267  canonicalFilename_ = canFilename;
268  }
269  } else
270 #endif
271  canonicalFilename_ = releaseTop_ + canFilename;
272  } else if (location_ == Data) {
273  if (dataTop_.empty()) {
274  throw edm::Exception(edm::errors::FileInPathError) << "Environment Variable " << DATATOP << " is not set.\n";
275  }
276  canonicalFilename_ = dataTop_ + canFilename;
277  }
278  }
std::string canonicalFilename_
Definition: FileInPath.h:116
std::string dataTop_
Definition: FileInPath.h:120
uint16_t size_type
std::string releaseTop_
Definition: FileInPath.h:119
LocationCode location_
Definition: FileInPath.h:117
std::string relativePath_
Definition: FileInPath.h:115
std::string localTop_
Definition: FileInPath.h:118

◆ readFromParameterSetBlob()

void edm::FileInPath::readFromParameterSetBlob ( std::istream &  is)

Definition at line 280 of file FileInPath.cc.

References canonicalFilename_, Data, dataTop_, Exception, edm::errors::FileInPathError, DTRecHitClients_cfi::local, Local, localTop_, location_, relativePath_, Release, releaseTop_, AlCaHLTBitMon_QueryRunRegistry::string, Unknown, and BeamSplash_cfg::version.

280  {
281  std::string vsn;
282  std::string relname;
283  std::string canFilename;
284  is >> vsn;
285  if (!is)
286  return;
287  bool oldFormat = (version != vsn);
288  if (oldFormat) {
289  relname = vsn;
290  bool local;
291  is >> local;
292  location_ = (local ? Local : Release);
293  is >> canFilename;
294  } else {
295  // Current format
296  int loc;
297  is >> relname >> loc;
298  location_ = static_cast<FileInPath::LocationCode>(loc);
299  if (location_ != Unknown) {
300  is >> canFilename;
301  } else if (relname == "@") {
302  relname = "";
303  }
304  }
305  if (!is)
306  return;
307  relativePath_ = relname;
308  if (location_ == Local) {
309  if (localTop_.empty()) {
310  localTop_ = "@LOCAL";
311  }
312  if (oldFormat) {
313  canonicalFilename_ = canFilename;
314  } else
315  canonicalFilename_ = localTop_ + canFilename;
316  } else if (location_ == Release) {
317  if (releaseTop_.empty()) {
318  releaseTop_ = "@RELEASE";
319  }
320  if (oldFormat) {
321  std::string::size_type pos = canFilename.find(BASE);
322  if (pos == 0) {
323  // Replace the placehoder with the path to the base release (site dependent).
324  canonicalFilename_ = releaseTop_ + canFilename.substr(BASE.size());
325  } else {
326  // Needed for files written before CMSSW_1_2_0_pre2.
327  canonicalFilename_ = canFilename;
328  }
329  } else
330  canonicalFilename_ = releaseTop_ + canFilename;
331  } else if (location_ == Data) {
332  if (dataTop_.empty()) {
333  throw edm::Exception(edm::errors::FileInPathError) << "Environment Variable " << DATATOP << " is not set.\n";
334  }
335  canonicalFilename_ = dataTop_ + canFilename;
336  }
337  }
std::string canonicalFilename_
Definition: FileInPath.h:116
std::string dataTop_
Definition: FileInPath.h:120
uint16_t size_type
std::string releaseTop_
Definition: FileInPath.h:119
LocationCode location_
Definition: FileInPath.h:117
std::string relativePath_
Definition: FileInPath.h:115
std::string localTop_
Definition: FileInPath.h:118

◆ relativePath()

std::string edm::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 157 of file FileInPath.cc.

References relativePath_.

Referenced by PDFWeightsHelper::Init(), and PYBIND11_MODULE().

157 { return relativePath_; }
std::string relativePath_
Definition: FileInPath.h:115

◆ searchPath()

std::string const & edm::FileInPath::searchPath ( )
staticprivate

Definition at line 340 of file FileInPath.cc.

References AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by findFile(), and getEnvironment().

340  {
341  static std::string const s_searchPath = removeSymLinksTokens(PathVariableName);
342  return s_searchPath;
343  }

◆ swap()

void edm::FileInPath::swap ( FileInPath other)

Definition at line 147 of file FileInPath.cc.

References canonicalFilename_, dataTop_, localTop_, location_, trackingPlots::other, relativePath_, releaseTop_, searchPath_, and edm::swap().

Referenced by operator=().

147  {
148  relativePath_.swap(other.relativePath_);
149  canonicalFilename_.swap(other.canonicalFilename_);
150  std::swap(location_, other.location_);
151  localTop_.swap(other.localTop_);
152  releaseTop_.swap(other.releaseTop_);
153  dataTop_.swap(other.dataTop_);
154  searchPath_.swap(other.searchPath_);
155  }
std::string canonicalFilename_
Definition: FileInPath.h:116
std::string dataTop_
Definition: FileInPath.h:120
std::string searchPath_
Definition: FileInPath.h:121
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:112
std::string releaseTop_
Definition: FileInPath.h:119
LocationCode location_
Definition: FileInPath.h:117
std::string relativePath_
Definition: FileInPath.h:115
std::string localTop_
Definition: FileInPath.h:118

◆ write()

void edm::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 163 of file FileInPath.cc.

References canonicalFilename_, Data, dataTop_, Exception, edm::errors::FileInPathError, Local, localTop_, location_, l1tGTMenu_BTagSeeds_cff::os, relativePath_, Release, releaseTop_, Unknown, and BeamSplash_cfg::version.

Referenced by edm::operator<<().

163  {
164  if (location_ == Unknown) {
165  if (relativePath_.empty()) {
166  os << version << " @ " << location_;
167  } else {
168  os << version << ' ' << relativePath_ << ' ' << location_;
169  }
170  } else if (location_ == Local) {
171  // Guarantee a site independent value by stripping $LOCALTOP.
172  if (localTop_.empty()) {
173  throw edm::Exception(edm::errors::FileInPathError) << "Environment Variable " << LOCALTOP << " is not set.\n";
174  }
176  if (pos != 0) {
178  << "Path " << canonicalFilename_ << " is not in the local release area " << localTop_ << "\n";
179  }
180  os << version << ' ' << relativePath_ << ' ' << location_ << ' ' << canonicalFilename_.substr(localTop_.size());
181  } else if (location_ == Release) {
182  // Guarantee a site independent value by stripping $RELEASETOP.
183  if (releaseTop_.empty()) {
184  throw edm::Exception(edm::errors::FileInPathError) << "Environment Variable " << RELEASETOP << " is not set.\n";
185  }
187  if (pos != 0) {
189  << "Path " << canonicalFilename_ << " is not in the base release area " << releaseTop_ << "\n";
190  }
191  os << version << ' ' << relativePath_ << ' ' << location_ << ' ' << canonicalFilename_.substr(releaseTop_.size());
192  } else if (location_ == Data) {
193  // Guarantee a site independent value by stripping $DATATOP.
194  if (dataTop_.empty()) {
195  throw edm::Exception(edm::errors::FileInPathError) << "Environment Variable " << DATATOP << " is not set.\n";
196  }
198  if (pos != 0) {
200  << "Path " << canonicalFilename_ << " is not in the data area " << dataTop_ << "\n";
201  }
202  os << version << ' ' << relativePath_ << ' ' << location_ << ' ' << canonicalFilename_.substr(dataTop_.size());
203  }
204  }
std::string canonicalFilename_
Definition: FileInPath.h:116
std::string dataTop_
Definition: FileInPath.h:120
uint16_t size_type
std::string releaseTop_
Definition: FileInPath.h:119
LocationCode location_
Definition: FileInPath.h:117
std::string relativePath_
Definition: FileInPath.h:115
std::string localTop_
Definition: FileInPath.h:118

Member Data Documentation

◆ canonicalFilename_

std::string edm::FileInPath::canonicalFilename_
private

Definition at line 116 of file FileInPath.h.

Referenced by fullPath(), initialize_(), read(), readFromParameterSetBlob(), swap(), and write().

◆ dataTop_

std::string edm::FileInPath::dataTop_
private

Definition at line 120 of file FileInPath.h.

Referenced by getEnvironment(), initialize_(), read(), readFromParameterSetBlob(), swap(), and write().

◆ localTop_

std::string edm::FileInPath::localTop_
private

Definition at line 118 of file FileInPath.h.

Referenced by getEnvironment(), initialize_(), read(), readFromParameterSetBlob(), swap(), and write().

◆ location_

LocationCode edm::FileInPath::location_
private

Definition at line 117 of file FileInPath.h.

Referenced by initialize_(), location(), read(), readFromParameterSetBlob(), swap(), and write().

◆ relativePath_

std::string edm::FileInPath::relativePath_
private

Definition at line 115 of file FileInPath.h.

Referenced by initialize_(), read(), readFromParameterSetBlob(), relativePath(), swap(), and write().

◆ releaseTop_

std::string edm::FileInPath::releaseTop_
private

Definition at line 119 of file FileInPath.h.

Referenced by getEnvironment(), initialize_(), read(), readFromParameterSetBlob(), swap(), and write().

◆ searchPath_

std::string edm::FileInPath::searchPath_
private

Definition at line 121 of file FileInPath.h.

Referenced by getEnvironment(), initialize_(), and swap().