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

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

◆ chop()

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

Definition at line 72 of file ChainString.h.

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

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

131  {
132  for ( int i=m_keys.size() ; i-- ; ) if ( key==m_keys[i] ) return i;
133  return -1;
134  }

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

60 { 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 63 of file ChainString.h.

63 { return m_post; }

◆ postcount()

size_t ChainString::postcount ( ) const
inline

Definition at line 65 of file ChainString.h.

65 { return m_postcount; }

◆ postvalue()

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

same here regarding returning a reference

Definition at line 54 of file ChainString.h.

54  {
55  if ( postcount() ) return value( key+"-post" );
56  return "";
57  }

◆ pre()

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

Definition at line 62 of file ChainString.h.

62 { 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]

static char ChainString::tolower ( char  c)
inlinestaticprotected

convert to lower case

Definition at line 114 of file ChainString.h.

114 { 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 117 of file ChainString.h.

117  {
118  const char* c = s.c_str();
119  char tmp[512];
120  char* tp = tmp;
121  while (( *tp++ = tolower(*c++) ));
122  return tmp;
123  }

◆ toupper() [1/2]

static char ChainString::toupper ( char  c)
inlinestaticprotected

convert to upper case

Definition at line 102 of file ChainString.h.

102 { 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 105 of file ChainString.h.

105  {
106  const char* c = s.c_str();
107  char tmp[512];
108  char* tp = tmp;
109  while (( *tp++ = toupper(*c++) ));
110  return tmp;
111  }

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

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

◆ values()

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

Definition at line 59 of file ChainString.h.

59 { return m_values; }

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

◆ m_extra

std::string ChainString::m_extra
private

Definition at line 143 of file ChainString.h.

◆ m_head

std::string ChainString::m_head
private

Definition at line 138 of file ChainString.h.

◆ m_keys

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

Definition at line 152 of file ChainString.h.

◆ m_passed

bool ChainString::m_passed
private

Definition at line 145 of file ChainString.h.

◆ m_post

std::string ChainString::m_post
private

Definition at line 149 of file ChainString.h.

◆ m_postcount

size_t ChainString::m_postcount
private

Definition at line 150 of file ChainString.h.

◆ m_raw

std::string ChainString::m_raw
private

Definition at line 147 of file ChainString.h.

◆ m_roi

std::string ChainString::m_roi
private

Definition at line 140 of file ChainString.h.

◆ m_tail

std::string ChainString::m_tail
private

Definition at line 139 of file ChainString.h.

◆ m_values

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

Definition at line 153 of file ChainString.h.

◆ m_vtx

std::string ChainString::m_vtx
private

Definition at line 141 of file ChainString.h.


The documentation for this class was generated from the following files:
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::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
ParticleTest.tp
tp
Definition: ParticleTest.py:25
ChainString::m_vtx
std::string m_vtx
Definition: ChainString.h:141
ChainString::m_element
std::string m_element
Definition: ChainString.h:142
tags
std::vector< std::string > tags
Definition: hcg.cxx:102
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::m_raw
std::string m_raw
Definition: ChainString.h:147
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:149
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
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
ChainString::tolower
static char tolower(char c)
convert to lower case
Definition: ChainString.h:114
ReadCellNoiseFromCoolCompare.s2
s2
Definition: ReadCellNoiseFromCoolCompare.py:379
ChainString::toupper
static char toupper(char c)
convert to upper case
Definition: ChainString.h:102
CaloCondBlobAlgs_fillNoiseFromASCII.fields
fields
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:106
ChainString::raw
const std::string & raw() const
Definition: ChainString.h:42
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:150