ATLAS Offline Software
ChainString.h
Go to the documentation of this file.
1 /* emacs: this is -*- c++ -*- */
14 #ifndef TrigInDetAnalysisExample_ChainString_H
15 #define TrigInDetAnalysisExample_ChainString_H
16 
17 
18 #include <string>
19 #include <vector>
20 #include <iostream>
21 
22 
23 class ChainString : public std::string {
24 
25 public:
26 
27  ChainString( const std::string& s );
28 
29  ChainString( const ChainString& s );
30 
31  ChainString& operator=(const ChainString&) = default;
32 
33  const std::string& head() const { return m_head; }
34  const std::string& tail() const { return m_tail; }
35  const std::string& roi() const { return m_roi; }
36  const std::string& vtx() const { return m_vtx; }
37  const std::string& element() const { return m_element; }
38  const std::string& extra() const { return m_extra; }
39 
40  bool passed() const { return m_passed; }
41 
42  const std::string& raw() const { return m_raw; }
43 
47  std::string value( const std::string& key ) const {
48  int i=findkey(key);
49  if ( i>=0 ) return m_values[i];
50  return "";
51  }
52 
54  std::string postvalue( const std::string& key ) const {
55  if ( postcount() ) return value( key+"-post" );
56  return "";
57  }
58 
59  const std::vector<std::string>& values() const { return m_values; }
60  const std::vector<std::string>& keys() const { return m_keys; }
61 
62  std::string pre() const { return m_raw.substr( 0, m_raw.find(":post") ); }
63  const std::string& post() const { return m_post; }
64 
65  size_t postcount() const { return m_postcount; }
66 
67  std::string subs( std::string s ) const;
68 
69 public:
70 
71  // chop tokens off the front of a string
72  static std::string chop(std::string& s1, const std::string& s2) {
73  std::string::size_type pos = s1.find_first_of(s2);
74  std::string s3;
75  if ( pos == std::string::npos ) {
76  s3 = s1;
77  s1.erase(0, s1.size());
78  }
79  else {
80  s3 = s1.substr(0, pos);
81  s1.erase(0, pos+1);
82  }
83  return s3;
84  }
85 
86 protected:
87 
88  // chomp tokens off the end of a string
89  static std::string chomp(std::string& s1, const std::string& s2) {
90  // std::string::size_type pos = s1.find(s2);
91  std::string::size_type pos = s1.find_first_of(s2);
92  std::string s3;
93  if ( pos == std::string::npos ) return "";
94 
95  s3 = s1.substr(pos+1, s1.size());
96  s1.erase(pos, s1.size());
97 
98  return s3;
99  }
100 
102  static char toupper( char c ) { return ( c>='a' && c<='z' ? c+'A'-'a' : c ); }
103 
105  static std::string toupper( const std::string& s ) {
106  const char* c = s.c_str();
107  char tmp[512];
108  char* tp = tmp;
109  while (( *tp++ = toupper(*c++) ));
110  return tmp;
111  }
112 
114  static char tolower( char c ) { return ( c>='A' && c<='Z' ? c-'A'+'a' : c ); }
115 
117  static std::string tolower( const std::string& s ) {
118  const char* c = s.c_str();
119  char tmp[512];
120  char* tp = tmp;
121  while (( *tp++ = tolower(*c++) ));
122  return tmp;
123  }
124 
125 protected:
126 
128 
129  void parse( std::string s );
130 
131  int findkey( const std::string& key ) const {
132  for ( int i=m_keys.size() ; i-- ; ) if ( key==m_keys[i] ) return i;
133  return -1;
134  }
135 
136 private:
137 
138  std::string m_head;
139  std::string m_tail;
140  std::string m_roi;
141  std::string m_vtx;
142  std::string m_element;
143  std::string m_extra;
144 
145  bool m_passed;
146 
147  std::string m_raw;
148 
149  std::string m_post;
150  size_t m_postcount;
151 
152  std::vector<std::string> m_keys;
153  std::vector<std::string> m_values;
154 
155 };
156 
157 
158 
159 inline bool operator==( const ChainString& cs, const ChainString& s ) {
160  return cs.raw() == ChainString(s).raw();
161 }
162 
163 inline bool operator==( const ChainString& cs, const std::string& s ) {
164  return cs.raw() == ChainString(s).raw();
165 }
166 
167 inline bool operator==( const std::string& s, const ChainString& cs ) {
168  return cs.raw() == ChainString(s).raw();
169 }
170 
171 
172 
173 #endif // TrigInDetAnalysisExample_ChainString_H
ChainString::m_passed
bool m_passed
Definition: ChainString.h:145
ChainString::postcount
size_t postcount() const
Definition: ChainString.h:65
ChainString::value
std::string value(const std::string &key) const
can't make this return a reference in case there is no such key - could throw an exception then it wo...
Definition: ChainString.h:47
ReadCellNoiseFromCoolCompare.s1
s1
Definition: ReadCellNoiseFromCoolCompare.py:378
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
ChainString::post
const std::string & post() const
Definition: ChainString.h:63
ChainString::m_roi
std::string m_roi
Definition: ChainString.h:140
ChainString::parse
void parse(std::string s)
parse the full specification string
Definition: ChainString.cxx:38
ChainString::postvalue
std::string postvalue(const std::string &key) const
same here regarding returning a reference
Definition: ChainString.h:54
ParticleTest.tp
tp
Definition: ParticleTest.py:25
ChainString::m_vtx
std::string m_vtx
Definition: ChainString.h:141
ChainString
Definition: ChainString.h:23
ChainString::subs
std::string subs(std::string s) const
Definition: ChainString.cxx:127
ChainString::m_element
std::string m_element
Definition: ChainString.h:142
ChainString::tolower
static std::string tolower(const std::string &s)
convert to lower case
Definition: ChainString.h:117
ChainString::pre
std::string pre() const
Definition: ChainString.h:62
ChainString::ChainString
ChainString(const std::string &s)
Definition: ChainString.cxx:16
ChainString::m_extra
std::string m_extra
Definition: ChainString.h:143
lumiFormat.i
int i
Definition: lumiFormat.py:85
ChainString::m_tail
std::string m_tail
Definition: ChainString.h:139
ChainString::chop
static std::string chop(std::string &s1, const std::string &s2)
Definition: ChainString.h:72
ChainString::m_values
std::vector< std::string > m_values
Definition: ChainString.h:153
ChainString::tail
const std::string & tail() const
Definition: ChainString.h:34
operator==
bool operator==(const ChainString &cs, const ChainString &s)
Definition: ChainString.h:159
ChainString::m_raw
std::string m_raw
Definition: ChainString.h:147
ChainString::passed
bool passed() const
Definition: ChainString.h:40
DeMoUpdate.tmp
string tmp
Definition: DeMoUpdate.py:1167
ChainString::m_post
std::string m_post
Definition: ChainString.h:149
ChainString::extra
const std::string & extra() const
Definition: ChainString.h:38
ChainString::m_head
std::string m_head
Definition: ChainString.h:138
ChainString::values
const std::vector< std::string > & values() const
Definition: ChainString.h:59
ChainString::chomp
static std::string chomp(std::string &s1, const std::string &s2)
Definition: ChainString.h:89
ReadCellNoiseFromCoolCompare.s3
s3
Definition: ReadCellNoiseFromCoolCompare.py:380
ChainString::m_keys
std::vector< std::string > m_keys
Definition: ChainString.h:152
ChainString::findkey
int findkey(const std::string &key) const
Definition: ChainString.h:131
ChainString::keys
const std::vector< std::string > & keys() const
Definition: ChainString.h:60
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
ChainString::operator=
ChainString & operator=(const ChainString &)=default
ChainString::head
const std::string & head() const
Definition: ChainString.h:33
ChainString::roi
const std::string & roi() const
Definition: ChainString.h:35
ChainString::tolower
static char tolower(char c)
convert to lower case
Definition: ChainString.h:114
ChainString::toupper
static std::string toupper(const std::string &s)
convert to upper case
Definition: ChainString.h:105
ReadCellNoiseFromCoolCompare.s2
s2
Definition: ReadCellNoiseFromCoolCompare.py:379
ChainString::toupper
static char toupper(char c)
convert to upper case
Definition: ChainString.h:102
ChainString::element
const std::string & element() const
Definition: ChainString.h:37
ChainString::raw
const std::string & raw() const
Definition: ChainString.h:42
python.compressB64.c
def c
Definition: compressB64.py:93
ChainString::vtx
const std::string & vtx() const
Definition: ChainString.h:36
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
ChainString::m_postcount
size_t m_postcount
Definition: ChainString.h:150