ATLAS Offline Software
Functions
utils.h File Reference
#include <string>
#include <vector>
#include <iostream>
Include dependency graph for utils.h:

Go to the source code of this file.

Functions

std::string chop (std::string &, const std::string &)
 
std::string chomp (std::string &, const std::string &)
 
std::string choptoken (std::string &, const std::string &)
 
std::string chomptoken (std::string &, const std::string &)
 
void removespace (std::string &s, const std::string &s2=" \t")
 
void replace (std::string &s, const std::string &s2=" \t", const std::string &s3="-")
 
void replace (std::string &s, char c1, char c2) noexcept
 
std::string chopfirst (std::string &s1, const std::string &s2="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.:/")
 
std::string choplast (std::string &s1, const std::string &s2="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_")
 
std::string chopends (std::string &s1, const std::string &s2=" \t")
 
std::string basename (std::string name)
 
std::string dirname (std::string name)
 
void depunctuate (std::string &)
 
double deltaPhi (double, double)
 
bool canopen (const std::string &)
 
std::string number (const int &i, const std::string &s="%d")
 
std::string number (const double &d, const std::string &s="%lf")
 

Detailed Description


Author
M.Sutton
Date
Thu Jun 23 01:53:36 BST 2005

Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration

Definition in file utils.h.

Function Documentation

◆ basename()

std::string basename ( std::string  name)

Definition at line 207 of file utils.cxx.

207  {
208  std::string::size_type pos = name.find( '/' );
209  while ( pos!=std::string::npos ) {
210  name = name.substr( pos+1, name.size()-pos-1 );
211  pos = name.find( '/' );
212  }
213  return name;
214 }

◆ canopen()

bool canopen ( const std::string &  )

Definition at line 178 of file utils.cxx.

178  {
179  FILE* f = fopen(s.c_str(), "r");
180  if ( f ) { fclose(f); return true; }
181  return false;
182 }

◆ chomp()

std::string chomp ( std::string &  ,
const std::string &   
)

Definition at line 211 of file hcg.cxx.

212 {
213  std::string::size_type pos = s1.find(s2);
214  std::string s3;
215  if ( pos == std::string::npos ) {
216  s3 = s1;
217  s1.clear();
218  }
219  else {
220  s3 = s1.substr(pos+s2.size(),s1.size());
221  s1.erase(pos,s1.size());
222  }
223  return s3;
224 }

◆ chomptoken()

std::string chomptoken ( std::string &  ,
const std::string &   
)

Definition at line 244 of file hcg.cxx.

245 {
246  std::string s3 = "";
247  std::string::size_type pos = s1.find(s2);
248  if ( pos != std::string::npos ) {
249  s3 = s1.substr(pos, s1.size());
250  s1.erase(pos, s1.size());
251  }
252  return s3;
253 }

◆ chop()

std::string chop ( std::string &  ,
const std::string &   
)

Definition at line 158 of file hcg.cxx.

159 {
160  std::string::size_type pos = s1.find(s2);
161  std::string s3;
162  if ( pos == std::string::npos ) {
163  s3 = s1;
164  s1.erase(0, s1.size());
165  }
166  else {
167  s3 = s1.substr(0, pos);
168  s1.erase(0, pos+s2.size());
169  }
170  return s3;
171 }

◆ chopends()

std::string chopends ( std::string &  s1,
const std::string &  s2 = " \t" 
)

Definition at line 287 of file hcg.cxx.

288 {
289  chopfirst(s1, s2);
290  choplast(s1, s2);
291  return s1;
292 }

◆ chopfirst()

std::string chopfirst ( std::string &  s1,
const std::string &  s2 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.:/" 
)

Definition at line 257 of file hcg.cxx.

258 {
259  std::string s3;
260  std::string::size_type pos = s1.find_first_not_of(s2);
261  if ( pos != std::string::npos ) {
262  s3 = s1.substr(0, pos);
263  s1.erase(0, pos);
264  }
265  else {
266  s3 = s1;
267  s1.clear();
268  }
269  return s3;
270 }

◆ choplast()

std::string choplast ( std::string &  s1,
const std::string &  s2 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_" 
)

Definition at line 273 of file hcg.cxx.

274 {
275  std::string s3 = "";
276  std::string::size_type pos = s1.find_last_not_of(s2);
277  if ( pos != std::string::npos ) {
278  s3 = s1.substr(pos+1, s1.size());
279  s1.erase(pos+1, s1.size());
280  }
281  return s3;
282 }

◆ choptoken()

std::string choptoken ( std::string &  ,
const std::string &   
)

Definition at line 230 of file hcg.cxx.

231 {
232  std::string s3 = "";
233  std::string::size_type pos = s1.find(s2);
234  if ( pos != std::string::npos ) {
235  s3 = s1.substr(0, pos+s2.size());
236  s1.erase(0, pos+s2.size());
237  }
238  return s3;
239 }

◆ deltaPhi()

double deltaPhi ( double  ,
double   
)

Definition at line 169 of file utils.cxx.

169  {
170  double delta = fabs(phi1-phi2);
171  delta = (delta > M_PI) ? (2.0*M_PI - delta) : delta;
172  return delta;
173 }

◆ depunctuate()

void depunctuate ( std::string &  )

Definition at line 157 of file utils.cxx.

158 {
159  std::string::size_type pos;
160  while ( (pos = s.find(':'))!=std::string::npos ) {
161  s.erase(pos, 1);
162  }
163 }

◆ dirname()

std::string dirname ( std::string  name)

Definition at line 200 of file utils.cxx.

200  {
201  std::string::size_type pos = name.find_last_of( '/' );
202  if ( pos!=std::string::npos ) name.resize( pos );
203  return name;
204 }

◆ number() [1/2]

std::string number ( const double &  d,
const std::string &  s = "%lf" 
)

Definition at line 186 of file utils.cxx.

186  {
187  char tmp[512];
188  sprintf(tmp, s.c_str(), d);
189  return tmp;
190 }

◆ number() [2/2]

std::string number ( const int &  i,
const std::string &  s = "%d" 
)

Definition at line 192 of file utils.cxx.

192  {
193  char tmp[512];
194  sprintf(tmp, s.c_str(), i);
195  return tmp;
196 }

◆ removespace()

void removespace ( std::string &  s,
const std::string &  s2 = " \t" 
)

Definition at line 297 of file hcg.cxx.

298 {
299  std::string::size_type pos;
300  while ( (pos = s.find(s2))!=std::string::npos ) {
301  s.erase(pos, s2.size());
302  }
303 }

◆ replace() [1/2]

void replace ( std::string &  s,
char  c1,
char  c2 
)
noexcept

Definition at line 152 of file utils.cxx.

152  {
153  std::replace(s.begin(), s.end(), c1, c2);
154 }

◆ replace() [2/2]

void replace ( std::string &  s,
const std::string &  s2 = " \t",
const std::string &  s3 = "-" 
)

Definition at line 142 of file utils.cxx.

143 {
144  std::string::size_type pos;
145  // while ( (pos = s.find(" "))!=std::string::npos ) {
146  // s.replace(pos, 1, "-");
147  while ( (pos = s.find(s2))!=std::string::npos ) {
148  s.replace(pos, 1, s3);
149  }
150 }
ReadCellNoiseFromCoolCompare.s1
s1
Definition: ReadCellNoiseFromCoolCompare.py:378
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
hist_file_dump.d
d
Definition: hist_file_dump.py:137
extractSporadic.c1
c1
Definition: extractSporadic.py:134
M_PI
#define M_PI
Definition: ActiveFraction.h:11
replace
void replace(std::string &s, const std::string &s2, const std::string &s3)
Definition: utils.cxx:142
chopfirst
std::string chopfirst(std::string &s1, const std::string &s2)
Definition: hcg.cxx:257
lumiFormat.i
int i
Definition: lumiFormat.py:85
hist_file_dump.f
f
Definition: hist_file_dump.py:135
DeMoUpdate.tmp
string tmp
Definition: DeMoUpdate.py:1167
ReadCellNoiseFromCoolCompare.s3
s3
Definition: ReadCellNoiseFromCoolCompare.py:380
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
choplast
std::string choplast(std::string &s1, const std::string &s2)
Definition: hcg.cxx:273
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
python.DataFormatRates.c2
c2
Definition: DataFormatRates.py:123
ReadCellNoiseFromCoolCompare.s2
s2
Definition: ReadCellNoiseFromCoolCompare.py:379