ATLAS Offline Software
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Private Attributes | List of all members
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
 
std::string head () const
 
std::string tail () const
 
std::string roi () const
 
std::string vtx () const
 
std::string element () const
 
std::string extra () const
 
bool passed () 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
More...
 
std::string postvalue (const std::string &key) const
 same here regarding returning a reference More...
 
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 More...
 
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 More...
 
static std::string toupper (const std::string &s)
 convert to upper case More...
 
static char tolower (char c)
 convert to lower case More...
 
static std::string tolower (const std::string &s)
 convert to lower case More...
 

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 }

◆ 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 }

Member Function Documentation

◆ chomp()

static 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()

static 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()

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

Definition at line 37 of file ChainString.h.

37 { return m_element; }

◆ extra()

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()

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( 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  *(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 = raw;
121 
122 }

◆ 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  }

◆ 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()

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

Definition at line 53 of file ChainString.h.

53 { return m_raw; }

◆ roi()

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()

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

Definition at line 34 of file ChainString.h.

34 { return m_tail; }

◆ tolower() [1/2]

static 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]

static 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]

static 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]

static 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  }

◆ value()

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 58 of file ChainString.h.

58  {
59  int i=findkey(key);
60  if ( i>=0 ) return m_values[i];
61  return "";
62  }

◆ values()

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

Definition at line 70 of file ChainString.h.

70 { return m_values; }

◆ vtx()

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:
ChainString::m_passed
bool m_passed
Definition: ChainString.h:156
ChainString::postcount
size_t postcount() const
Definition: ChainString.h:76
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:58
ReadCellNoiseFromCoolCompare.s1
s1
Definition: ReadCellNoiseFromCoolCompare.py:378
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
ChainString::m_roi
std::string m_roi
Definition: ChainString.h:151
ChainString::parse
void parse(std::string s)
parse the full specification string
Definition: ChainString.cxx:38
ParticleTest.tp
tp
Definition: ParticleTest.py:25
ChainString::m_vtx
std::string m_vtx
Definition: ChainString.h:152
ChainString::m_element
std::string m_element
Definition: ChainString.h:153
tags
std::vector< std::string > tags
Definition: hcg.cxx:102
ChainString::m_extra
std::string m_extra
Definition: ChainString.h:154
lumiFormat.i
int i
Definition: lumiFormat.py:85
ChainString::m_tail
std::string m_tail
Definition: ChainString.h:150
ChainString::chop
static std::string chop(std::string &s1, const std::string &s2)
Definition: ChainString.h:83
ChainString::m_values
std::vector< std::string > m_values
Definition: ChainString.h:164
ChainString::m_raw
std::string m_raw
Definition: ChainString.h:158
hist_file_dump.f
f
Definition: hist_file_dump.py:135
DeMoUpdate.tmp
string tmp
Definition: DeMoUpdate.py:1167
ChainString::m_post
std::string m_post
Definition: ChainString.h:160
ChainString::m_head
std::string m_head
Definition: ChainString.h:149
ChainString::values
const std::vector< std::string > & values() const
Definition: ChainString.h:70
ChainString::raw
std::string raw() const
Definition: ChainString.h:53
ChainString::chomp
static std::string chomp(std::string &s1, const std::string &s2)
Definition: ChainString.h:100
ReadCellNoiseFromCoolCompare.s3
s3
Definition: ReadCellNoiseFromCoolCompare.py:380
ChainString::m_keys
std::vector< std::string > m_keys
Definition: ChainString.h:163
ChainString::findkey
int findkey(const std::string &key) const
Definition: ChainString.h:142
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
ChainString::tolower
static char tolower(char c)
convert to lower case
Definition: ChainString.h:125
ReadCellNoiseFromCoolCompare.s2
s2
Definition: ReadCellNoiseFromCoolCompare.py:379
ChainString::toupper
static char toupper(char c)
convert to upper case
Definition: ChainString.h:113
CaloCondBlobAlgs_fillNoiseFromASCII.fields
fields
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:106
python.compressB64.c
def c
Definition: compressB64.py:93
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
ChainString::m_postcount
size_t m_postcount
Definition: ChainString.h:161