ATLAS Offline Software
ChainString.cxx
Go to the documentation of this file.
1 /* emacs: this is -*- c++ -*- */
13 
14 
15 
16 ChainString::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 
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 }
34 
35 
36 
38 void 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( 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 }
123 
124 
125 
126 
127 std::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 }
ChainString::m_passed
bool m_passed
Definition: ChainString.h:156
ChainString::postcount
size_t postcount() const
Definition: ChainString.h:76
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
ChainString::m_vtx
std::string m_vtx
Definition: ChainString.h:152
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:153
ChainString::ChainString
ChainString(const std::string &s)
Definition: ChainString.cxx:16
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
m_raw
std::string_view m_raw
the raw input string
Definition: TProperty.cxx:47
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
ChainString::m_keys
std::vector< std::string > m_keys
Definition: ChainString.h:163
ChainString.h
ChainString::tolower
static char tolower(char c)
convert to lower case
Definition: ChainString.h:125
CaloCondBlobAlgs_fillNoiseFromASCII.fields
fields
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:106
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
ChainString::m_postcount
size_t m_postcount
Definition: ChainString.h:161