ATLAS Offline Software
Loading...
Searching...
No Matches
ChainString.cxx
Go to the documentation of this file.
1/* emacs: this is -*- c++ -*- */
10
11
13
14
15
16ChainString::ChainString( const std::string& s ) :
17 std::string(s),
18 m_head(""), m_tail(""), m_roi(""), m_vtx(""), m_element(""), m_extra(""),
19 m_passed(true), m_raw(""), m_post(""), m_postcount(0) {
20 if ( s.find(":post")!=std::string::npos ) m_post = s.substr( s.find(":post")+6, s.size() );
21 parse(s);
22}
23
24
34
35
36
38void ChainString::parse( std::string s ) {
39
40 std::vector<std::string> fields;
41
42 while ( !s.empty() ) fields.push_back( chop( s, ":" ) );
43
44 bool postkeys = false;
45
46 size_t keycount = 0;
47
48 if ( fields.size() ) m_head = fields[0];
49
50 for ( size_t i=1 ; i<fields.size() ; i++ ) {
51 std::string dte = chomp( fields[i], ";" );
52 if ( !postkeys && dte=="DTE" ) m_passed = false;
53 if ( fields[i]=="DTE" ) m_passed = false;
54 else if ( fields[i]=="post" ) postkeys = true;
55 else { // if ( fields[i].find("=")!=std::string::npos ) {
56 std::string f = fields[i];
57 std::string key = chop( f, "=" );
58 if ( f=="" ) {
59 f=key;
60 key="";
61 }
62 if ( postkeys ) { key += "-post"; m_postcount++; }
63 else keycount++;
64 m_keys.push_back( tolower(key) );
65 m_values.push_back( std::move(f) );
66 }
67 }
68
69 std::string tags[5] = { "key", "roi", "vtx", "te", "extra" };
70 bool tagged[5] = { false, false, false, false, false };
71
72 std::string* values[5] = { &m_tail, &m_roi, &m_vtx, &m_element, &m_extra };
73
74 for ( size_t i=0 ; i<keycount && i<5 ; i++ ) {
75 if ( m_keys[i] == "" ) {
76 if ( tagged[i] ) std::cerr << "tag already allocated : " << tags[i] << " with value " << *values[i] << std::endl;
77 else *values[i] = m_values[i];
78 }
79 else {
80 bool unset = true;
81 for ( int j=0 ; j<5 ; j++ ) {
82 if ( tags[j]==m_keys[i] ) {
83 if ( tagged[j] ) std::cerr << "tag already allocated : " << tags[j] << " with value " << *values[j] << std::endl;
84 else {
85 *values[j] = m_values[i];
86 unset = false;
87 tagged[j] = true;
88 }
89 }
90 }
91 if ( unset ) std::cerr << "no such tag: " << m_keys[i] << std::endl;
92 }
93 }
94
95#if 0
96 std::cout << "head: " << m_head << std::endl;
97 std::cout << "key: " << m_tail << std::endl;
98 std::cout << "roi: " << m_roi << std::endl;
99 std::cout << "vtx: " << m_vtx << std::endl;
100 std::cout << "te: " << m_element << std::endl;
101 std::cout << "ind: " << m_extra << std::endl;
102 std::cout << "pass: " << m_passed << std::endl;
103#endif
104
106
107 std::string raw = m_head;
108 for ( int i=0 ; i<5 ; i++ ) if ( *values[i]!="" ) raw += ":" + *values[i];
109 if ( !m_passed ) raw += ";DTE";
110
112 *static_cast<std::string*>(this) = raw;
113
114 raw = m_head;
115 for ( int i=0 ; i<5 ; i++ ) if ( *values[i]!="" ) raw += ":" + tags[i] + "=" + *values[i];
116 if ( !m_passed ) raw += ";DTE";
117
118 if ( postcount() ) raw += ":post:" + m_post;
119
120 m_raw = std::move(raw);
121
122}
123
124
125
126
127std::string ChainString::subs( std::string s ) const {
128
129 std::string tags[5] = { "key=", "roi=", "vtx=", "te=", "extra=" };
130
131 const std::string* values[5] = { &m_tail, &m_roi, &m_vtx, &m_element, &m_extra };
132
133 for ( int i=0 ; i<5 ; i++ ) if ( *values[i]!="" ) s += ":" + tags[i] + *values[i];
134 if ( !m_passed ) s += ";DTE";
135
136 if ( postcount() ) s += ":post:" + m_post;
137
138 return s;
139}
size_t m_postcount
std::string m_post
std::string subs(std::string s) const
ChainString(const std::string &s)
const std::string & post() const
Definition ChainString.h:63
const std::vector< std::string > & values() const
Definition ChainString.h:59
void parse(std::string s)
parse the full specification string
std::string m_roi
const std::string & raw() const
Definition ChainString.h:42
std::vector< std::string > m_keys
size_t postcount() const
Definition ChainString.h:65
std::string m_head
static char tolower(char c)
convert to lower case
static std::string chop(std::string &s1, const std::string &s2)
Definition ChainString.h:72
static std::string chomp(std::string &s1, const std::string &s2)
Definition ChainString.h:89
std::vector< std::string > m_values
std::string m_vtx
std::string m_tail
std::string m_extra
std::string m_raw
std::string m_element
STL class.
std::vector< std::string > tags
Definition hcg.cxx:105
STL namespace.