Jpp  17.3.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JRootObjectID.hh
Go to the documentation of this file.
1 #ifndef __JGIZMO__JROOTOBJECTID__
2 #define __JGIZMO__JROOTOBJECTID__
3 
4 #include <string>
5 #include <istream>
6 #include <ostream>
7 #include <cctype>
8 
9 #include "TString.h"
10 
11 #include "JLang/JException.hh"
12 
13 
14 /**
15  * \author mdejong
16  */
17 
18 namespace JGIZMO {}
19 namespace JPP { using namespace JGIZMO; }
20 
21 namespace JGIZMO {
22 
23  using JLANG::JParseError;
24 
25  /**
26  * Auxiliary class to handle file name, ROOT directory and object name.
27  *
28  * The general syntax is as follows:\n
29  * <pre>
30  * <file name>:[<directory/>]<object name>
31  * </pre>
32  * where
33  * <tt><directory></tt> is optional and
34  * <tt><object name></tt> may be a regular expression (TRegexp).
35  */
37  {
38  public:
39 
40  static const char LABEL_L_BRACKET = '['; //!< left bracket for label
41  static const char LABEL_R_BRACKET = ']'; //!< right bracket for label
42  static const char FILENAME_SEPARATOR = ':'; //!< file name separator
43  static const char PATHNAME_SEPARATOR = '/'; //!< path name separator
44 
45 
46  /**
47  * Default constructor.
48  */
50  {}
51 
52 
53  /**
54  * Constructor.
55  *
56  * \param file_name file name
57  * \param name object name
58  */
60  const std::string& name) :
61  file_name(file_name),
62  directory(""),
63  name (name)
64  {}
65 
66 
67  /**
68  * Constructor.
69  *
70  * \param file_name file name
71  * \param dir directory name
72  * \param name object name
73  */
75  const std::string& dir,
76  const std::string& name) :
77  file_name(file_name),
78  directory(dir),
79  name (name)
80  {}
81 
82 
83  /**
84  * Constructor.
85  *
86  * \param full_name full object name
87  */
88  JRootObjectID(const std::string& full_name)
89  {
90  std::istringstream(full_name) >> *this;
91  }
92 
93 
94  /**
95  * Get file name.
96  *
97  * \return file name
98  */
99  const std::string& getFilename() const
100  {
101  return file_name;
102  }
103 
104 
105  /**
106  * Get directory.
107  *
108  * \return directory
109  */
110  TString getDirectory() const
111  {
112  return TString(directory.c_str());
113  }
114 
115 
116  /**
117  * Get object name.
118  *
119  * \return object name
120  */
121  TString getObjectName() const
122  {
123  return TString(name.c_str());
124  }
125 
126 
127  /**
128  * Get full file name, including path.
129  *
130  * \return file name
131  */
132  TString getFullFilename() const
133  {
134  if (getDirectory() == "")
135  return getFilename();
136  else
138  }
139 
140 
141  /**
142  * Get full object name, including path.
143  *
144  * \return object name
145  */
146  TString getFullObjectName() const
147  {
148  if (getDirectory() == "")
149  return getObjectName();
150  else
152  }
153 
154 
155  /**
156  * Check validity.
157  *
158  * \return true if valid ROOT object identifier; else false
159  */
160  bool is_valid() const
161  {
162  return (file_name != "" &&
163  name != "");
164  }
165 
166  /**
167  * Clear.
168  */
169  void clear()
170  {
171  file_name.clear();
172  directory.clear();
173  name .clear();
174  }
175 
176 
177  /**
178  * Equal operator for object identifiers.
179  *
180  * \param first first object identifier
181  * \param second second object identifier
182  * \return true if first and second object identifier are equal; else false
183  */
184  friend inline bool operator==(const JRootObjectID& first, const JRootObjectID& second)
185  {
186  return (first.getFilename() == second.getFilename() &&
187  first.getDirectory() == second.getDirectory() &&
188  first.getObjectName() == second.getObjectName());
189  }
190 
191 
192  /**
193  * Read object identifier from input.
194  *
195  * \param in input stream
196  * \param object object identifier
197  * \return input stream
198  */
199  friend inline std::istream& operator>>(std::istream& in, JRootObjectID& object)
200  {
201  using namespace std;
202 
203  object.clear();
204 
205  string buffer;
206 
207  for (int bracket = 0; in.peek() != EOF; ) {
208 
209  const char c = (char) in.get();
210 
211  if (c == LABEL_L_BRACKET) {
212 
213  ++bracket;
214 
215  } else if (c == LABEL_R_BRACKET) {
216 
217  --bracket;
218 
219  } else if (isspace(c)) {
220 
221  if (bracket <= 0) {
222  break;
223  }
224  }
225 
226  buffer.push_back(c);
227  }
228 
229  size_t pos = buffer.find(FILENAME_SEPARATOR);
230 
231  if (pos != string::npos) {
232 
233  object.file_name = buffer.substr(0, pos);
234  object.name = buffer.substr(pos + 1);
235 
236  pos = object.name.rfind(PATHNAME_SEPARATOR);
237 
238  if (pos != string::npos) {
239 
240  object.directory = object.name.substr(0, pos);
241  object.name = object.name.substr(pos + 1);
242  }
243 
244  } else if (!buffer.empty()) {
245 
246  throw JParseError("JRootObjectID error parsing " + buffer);
247  }
248 
249  return in;
250  }
251 
252 
253  /**
254  * Write object identifier to output.
255  *
256  * \param out output stream
257  * \param object object identifier
258  * \return output stream
259  */
260  friend inline std::ostream& operator<<(std::ostream& out, const JRootObjectID& object)
261  {
262  return out << object.getFilename() << FILENAME_SEPARATOR << object.getFullObjectName();
263  }
264 
265  protected:
269  };
270 }
271 
272 #endif
JRootObjectID(const std::string &file_name, const std::string &name)
Constructor.
Exceptions.
TString getFullFilename() const
Get full file name, including path.
TString getFullObjectName() const
Get full object name, including path.
const std::string & getFilename() const
Get file name.
Auxiliary class to handle file name, ROOT directory and object name.
static const char LABEL_L_BRACKET
left bracket for label
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
static const char LABEL_R_BRACKET
right bracket for label
TString getDirectory() const
Get directory.
JRootObjectID(const std::string &file_name, const std::string &dir, const std::string &name)
Constructor.
static const char FILENAME_SEPARATOR
file name separator
static const char PATHNAME_SEPARATOR
path name separator
JRootObjectID(const std::string &full_name)
Constructor.
then awk string
friend std::istream & operator>>(std::istream &in, JRootObjectID &object)
Read object identifier from input.
TString getObjectName() const
Get object name.
$WORKDIR ev_configure_dqsimulator txt echo process $DQ_SIMULATOR $i $SOURCE_HOST[$index] csh c(setenv ROOTSYS $ROOTSYS &&source $JPP_DIR/setenv.csh $JPP_DIR &&($DQ_SIMULATOR\-u\$NAME\$\-H\$SERVER\$\-M\$LOGGER\$\-d $DEBUG</dev/null > &/dev/null &))'
friend bool operator==(const JRootObjectID &first, const JRootObjectID &second)
Equal operator for object identifiers.
Exception for parsing value.
Definition: JException.hh:180
bool is_valid() const
Check validity.
friend std::ostream & operator<<(std::ostream &out, const JRootObjectID &object)
Write object identifier to output.
JRootObjectID()
Default constructor.
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY JAcoustics sh $DETECTOR_ID source JAcousticsToolkit sh CHECK_EXIT_CODE typeset A EMITTERS get_tripods $WORKDIR tripod txt EMITTERS get_transmitters $WORKDIR transmitter txt EMITTERS for EMITTER in
Definition: JCanberra.sh:46