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 214 of file hcg.cxx.

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

◆ chomptoken()

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

Definition at line 247 of file hcg.cxx.

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

◆ chop()

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

Definition at line 161 of file hcg.cxx.

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

◆ chopends()

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

Definition at line 290 of file hcg.cxx.

291 {
292  chopfirst(s1, s2);
293  choplast(s1, s2);
294  return s1;
295 }

◆ chopfirst()

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

Definition at line 260 of file hcg.cxx.

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

◆ choplast()

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

Definition at line 276 of file hcg.cxx.

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

◆ choptoken()

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

Definition at line 233 of file hcg.cxx.

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

◆ 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 300 of file hcg.cxx.

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

◆ 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
hist_file_dump.d
d
Definition: hist_file_dump.py:142
extractSporadic.c1
c1
Definition: extractSporadic.py:133
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:260
lumiFormat.i
int i
Definition: lumiFormat.py:85
hist_file_dump.f
f
Definition: hist_file_dump.py:140
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:240
choplast
std::string choplast(std::string &s1, const std::string &s2)
Definition: hcg.cxx:276
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:16
python.DataFormatRates.c2
c2
Definition: DataFormatRates.py:123
ReadCellNoiseFromCoolCompare.s2
s2
Definition: ReadCellNoiseFromCoolCompare.py:379
python.SystemOfUnits.s
float s
Definition: SystemOfUnits.py:147