CMS 3D CMS Logo

FileInPath.h
Go to the documentation of this file.
1 #ifndef FWCore_Utilities_FileInPath_h
2 #define FWCore_Utilities_FileInPath_h
3 
5 
7 
45 
46 // Notes:
47 //
48 // 1. We do not deal well with paths that contain spaces; this is because
49 // of the way the Utilities system's 'encode' and 'decode' functions
50 // are implemented for FileInPath objects. This could be fixed, if it
51 // is important to handle filenames or paths with embedded spaces.
52 //
53 // 2. All environment variables are read only once, when the FileInPath object is constructed.
54 // Therefore, any changes made to these variables externally during the lifetime of
55 // a FileInPath object will have no effect.
56 
57 #include <iosfwd>
58 #include <string>
59 
60 namespace edm {
61  class FileInPath {
62  public:
63  enum LocationCode { Unknown = 0, Local = 1, Release = 2, Data = 3 };
64 
67  FileInPath();
68 
70  explicit FileInPath(const std::string& r);
71  explicit FileInPath(const char* r);
72 
73  FileInPath(FileInPath const& other);
75  ~FileInPath();
76  void swap(FileInPath& other);
77 
81  std::string relativePath() const;
82 
84  LocationCode location() const;
85 
94  std::string fullPath() const;
95 
98  void write(std::ostream& os) const;
99 
102  void read(std::istream& is);
103 
104  void readFromParameterSetBlob(std::istream& is);
105 
107  static void disableFileLookup();
108 
112  static std::string findFile(std::string const&);
113 
114  private:
122 
123  // Helper function for construction.
124  void getEnvironment();
125  void initialize_();
126  static std::string const& searchPath();
127  };
128 
129  // Free swap function
130  inline void swap(FileInPath& a, FileInPath& b) { a.swap(b); }
131 
132  inline std::ostream& operator<<(std::ostream& os, const edm::FileInPath& fip) {
133  fip.write(os);
134  return os;
135  }
136 
137  inline std::istream& operator>>(std::istream& is, FileInPath& fip) {
138  fip.read(is);
139  return is;
140  }
141 
142  inline bool operator==(edm::FileInPath const& a, edm::FileInPath const& b) {
143  return a.location() == b.location() && a.relativePath() == b.relativePath();
144  }
145 
146 } // namespace edm
147 
148 #endif
std::string canonicalFilename_
Definition: FileInPath.h:116
constexpr bool operator==(ELseverityLevel const &e1, ELseverityLevel const &e2) noexcept
void swap(FileInPath &other)
Definition: FileInPath.cc:147
std::string fullPath() const
Definition: FileInPath.cc:161
static void disableFileLookup()
Should only be called while the edmWriteConfigs executable runs.
Definition: FileInPath.cc:450
std::string dataTop_
Definition: FileInPath.h:120
std::unique_ptr< ParameterDescriptionCases< bool > > operator>>(bool caseValue, ParameterDescriptionNode const &node)
void getEnvironment()
Definition: FileInPath.cc:346
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
void read(std::istream &is)
Definition: FileInPath.cc:206
static std::string const & searchPath()
Definition: FileInPath.cc:340
LocationCode location() const
Where was the file found?
Definition: FileInPath.cc:159
void initialize_()
Definition: FileInPath.cc:376
double b
Definition: hdecay.h:120
std::string relativePath_
Definition: FileInPath.h:115
HLT enums.
double a
Definition: hdecay.h:121
static std::string findFile(std::string const &)
Definition: FileInPath.cc:452
FileInPath & operator=(FileInPath const &other)
Definition: FileInPath.cc:141
void readFromParameterSetBlob(std::istream &is)
Definition: FileInPath.cc:280
std::ostream & operator<<(std::ostream &ost, const HLTGlobalStatus &hlt)
Formatted printout of trigger table.
std::string relativePath() const
Definition: FileInPath.cc:157
void write(std::ostream &os) const
Definition: FileInPath.cc:163
std::string localTop_
Definition: FileInPath.h:118