ATLAS Offline Software
Loading...
Searching...
No Matches
ChainString Class Reference

#include <ChainString.h>

Inheritance diagram for ChainString:
Collaboration diagram for ChainString:

Public Member Functions

 ChainString (const std::string &s)
 ChainString (const ChainString &s)
ChainStringoperator= (const ChainString &)=default
const std::string & head () const
const std::string & tail () const
const std::string & roi () const
const std::string & vtx () const
const std::string & element () const
const std::string & extra () const
bool passed () const
const std::string & raw () const
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 would work, but that is far too excessive
std::string value (size_t i) const
 as above - should really return a const std::string& but we don't want to have to throw an exception for an out of range, or force clients to check the vector size unless they really need to
size_t vsize () const
std::string postvalue (const std::string &key) const
 same here regarding returning a reference
const std::vector< std::string > & values () const
const std::vector< std::string > & keys () const
std::string pre () const
const std::string & post () const
size_t postcount () const
std::string subs (std::string s) const

Static Public Member Functions

static std::string chop (std::string &s1, const std::string &s2)

Protected Member Functions

void parse (std::string s)
 parse the full specification string
int findkey (const std::string &key) const

Static Protected Member Functions

static std::string chomp (std::string &s1, const std::string &s2)
static char toupper (char c)
 convert to upper case
static std::string toupper (const std::string &s)
 convert to upper case
static char tolower (char c)
 convert to lower case
static std::string tolower (const std::string &s)
 convert to lower case

Private Attributes

std::string m_head
std::string m_tail
std::string m_roi
std::string m_vtx
std::string m_element
std::string m_extra
bool m_passed
std::string m_raw
std::string m_post
size_t m_postcount
std::vector< std::string > m_keys
std::vector< std::string > m_values

Detailed Description

Definition at line 23 of file ChainString.h.

Constructor & Destructor Documentation

◆ ChainString() [1/2]

ChainString::ChainString ( const std::string & s)

Definition at line 16 of file ChainString.cxx.

16 :
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}
size_t m_postcount
std::string m_post
void parse(std::string s)
parse the full specification string
std::string m_roi
std::string m_head
std::string m_vtx
std::string m_tail
std::string m_extra
std::string m_raw
std::string m_element

◆ ChainString() [2/2]

ChainString::ChainString ( const ChainString & s)

Definition at line 25 of file ChainString.cxx.

25 :
26 std::string(s),
27 m_head(s.m_head), m_tail(s.m_tail), m_roi(s.m_roi), m_vtx(s.m_vtx),
28 m_element(s.m_element), m_extra(s.m_extra),
29 m_passed(s.m_passed),
30 m_raw(s.m_raw), m_post(s.post()), m_postcount(s.postcount()),
31 m_keys(s.m_keys),
32 m_values(s.m_values) {
33}
std::vector< std::string > m_keys
std::vector< std::string > m_values

Member Function Documentation

◆ chomp()

std::string ChainString::chomp ( std::string & s1,
const std::string & s2 )
inlinestaticprotected

Definition at line 100 of file ChainString.h.

100 {
101 // std::string::size_type pos = s1.find(s2);
102 std::string::size_type pos = s1.find_first_of(s2);
103 std::string s3;
104 if ( pos == std::string::npos ) return "";
105
106 s3 = s1.substr(pos+1, s1.size());
107 s1.erase(pos, s1.size());
108
109 return s3;
110 }

◆ chop()

std::string ChainString::chop ( std::string & s1,
const std::string & s2 )
inlinestatic

Definition at line 83 of file ChainString.h.

83 {
84 std::string::size_type pos = s1.find_first_of(s2);
85 std::string s3;
86 if ( pos == std::string::npos ) {
87 s3 = s1;
88 s1.erase(0, s1.size());
89 }
90 else {
91 s3 = s1.substr(0, pos);
92 s1.erase(0, pos+1);
93 }
94 return s3;
95 }

◆ element()

const std::string & ChainString::element ( ) const
inline

Definition at line 37 of file ChainString.h.

37{ return m_element; }

◆ extra()

const std::string & ChainString::extra ( ) const
inline

Definition at line 38 of file ChainString.h.

38{ return m_extra; }

◆ findkey()

int ChainString::findkey ( const std::string & key) const
inlineprotected

Definition at line 142 of file ChainString.h.

142 {
143 for ( int i=m_keys.size() ; i-- ; ) if ( key==m_keys[i] ) return i;
144 return -1;
145 }

◆ head()

const std::string & ChainString::head ( ) const
inline

Definition at line 33 of file ChainString.h.

33{ return m_head; }

◆ keys()

const std::vector< std::string > & ChainString::keys ( ) const
inline

Definition at line 71 of file ChainString.h.

71{ return m_keys; }

◆ operator=()

ChainString & ChainString::operator= ( const ChainString & )
default

◆ parse()

void ChainString::parse ( std::string s)
protected

parse the full specification string

replace the string by a parsed basic string

overwrite with the parsed string

Definition at line 38 of file ChainString.cxx.

38 {
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}
const std::vector< std::string > & values() const
Definition ChainString.h:70
const std::string & raw() const
Definition ChainString.h:42
size_t postcount() const
Definition ChainString.h:76
static char tolower(char c)
convert to lower case
static std::string chop(std::string &s1, const std::string &s2)
Definition ChainString.h:83
static std::string chomp(std::string &s1, const std::string &s2)
std::vector< std::string > tags
Definition hcg.cxx:107
float j(const xAOD::IParticle &, const xAOD::TrackMeasurementValidation &hit, const Eigen::Matrix3d &jab_inv)

◆ passed()

bool ChainString::passed ( ) const
inline

Definition at line 40 of file ChainString.h.

40{ return m_passed; }

◆ post()

const std::string & ChainString::post ( ) const
inline

Definition at line 74 of file ChainString.h.

74{ return m_post; }

◆ postcount()

size_t ChainString::postcount ( ) const
inline

Definition at line 76 of file ChainString.h.

76{ return m_postcount; }

◆ postvalue()

std::string ChainString::postvalue ( const std::string & key) const
inline

same here regarding returning a reference

Definition at line 65 of file ChainString.h.

65 {
66 if ( postcount() ) return value( key+"-post" );
67 return "";
68 }
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

◆ pre()

std::string ChainString::pre ( ) const
inline

Definition at line 73 of file ChainString.h.

73{ return m_raw.substr( 0, m_raw.find(":post") ); }

◆ raw()

const std::string & ChainString::raw ( ) const
inline

Definition at line 42 of file ChainString.h.

42{ return m_raw; }

◆ roi()

const std::string & ChainString::roi ( ) const
inline

Definition at line 35 of file ChainString.h.

35{ return m_roi; }

◆ subs()

std::string ChainString::subs ( std::string s) const

Definition at line 127 of file ChainString.cxx.

127 {
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}

◆ tail()

const std::string & ChainString::tail ( ) const
inline

Definition at line 34 of file ChainString.h.

34{ return m_tail; }

◆ tolower() [1/2]

char ChainString::tolower ( char c)
inlinestaticprotected

convert to lower case

Definition at line 125 of file ChainString.h.

125{ return ( c>='A' && c<='Z' ? c-'A'+'a' : c ); }

◆ tolower() [2/2]

std::string ChainString::tolower ( const std::string & s)
inlinestaticprotected

convert to lower case

Definition at line 128 of file ChainString.h.

128 {
129 const char* c = s.c_str();
130 char tmp[512];
131 char* tp = tmp;
132 while (( *tp++ = tolower(*c++) ));
133 return tmp;
134 }

◆ toupper() [1/2]

char ChainString::toupper ( char c)
inlinestaticprotected

convert to upper case

Definition at line 113 of file ChainString.h.

113{ return ( c>='a' && c<='z' ? c+'A'-'a' : c ); }

◆ toupper() [2/2]

std::string ChainString::toupper ( const std::string & s)
inlinestaticprotected

convert to upper case

Definition at line 116 of file ChainString.h.

116 {
117 const char* c = s.c_str();
118 char tmp[512];
119 char* tp = tmp;
120 while (( *tp++ = toupper(*c++) ));
121 return tmp;
122 }
static char toupper(char c)
convert to upper case

◆ value() [1/2]

std::string ChainString::value ( const std::string & key) const
inline

can't make this return a reference in case there is no such key - could throw an exception then it would work, but that is far too excessive

Definition at line 47 of file ChainString.h.

47 {
48 int i=findkey(key);
49 if ( i>=0 ) return m_values[i];
50 return "";
51 }
int findkey(const std::string &key) const

◆ value() [2/2]

std::string ChainString::value ( size_t i) const
inline

as above - should really return a const std::string& but we don't want to have to throw an exception for an out of range, or force clients to check the vector size unless they really need to

Definition at line 57 of file ChainString.h.

57 {
58 if ( i<m_values.size() ) return m_values[i];
59 return "";
60 }

◆ values()

const std::vector< std::string > & ChainString::values ( ) const
inline

Definition at line 70 of file ChainString.h.

70{ return m_values; }

◆ vsize()

size_t ChainString::vsize ( ) const
inline

Definition at line 62 of file ChainString.h.

62{ return m_values.size(); }

◆ vtx()

const std::string & ChainString::vtx ( ) const
inline

Definition at line 36 of file ChainString.h.

36{ return m_vtx; }

Member Data Documentation

◆ m_element

std::string ChainString::m_element
private

Definition at line 153 of file ChainString.h.

◆ m_extra

std::string ChainString::m_extra
private

Definition at line 154 of file ChainString.h.

◆ m_head

std::string ChainString::m_head
private

Definition at line 149 of file ChainString.h.

◆ m_keys

std::vector<std::string> ChainString::m_keys
private

Definition at line 163 of file ChainString.h.

◆ m_passed

bool ChainString::m_passed
private

Definition at line 156 of file ChainString.h.

◆ m_post

std::string ChainString::m_post
private

Definition at line 160 of file ChainString.h.

◆ m_postcount

size_t ChainString::m_postcount
private

Definition at line 161 of file ChainString.h.

◆ m_raw

std::string ChainString::m_raw
private

Definition at line 158 of file ChainString.h.

◆ m_roi

std::string ChainString::m_roi
private

Definition at line 151 of file ChainString.h.

◆ m_tail

std::string ChainString::m_tail
private

Definition at line 150 of file ChainString.h.

◆ m_values

std::vector<std::string> ChainString::m_values
private

Definition at line 164 of file ChainString.h.

◆ m_vtx

std::string ChainString::m_vtx
private

Definition at line 152 of file ChainString.h.


The documentation for this class was generated from the following files: