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

Go to the source code of this file.

Functions

std::string choptoken (std::string &s1, const std::string &s2)
 
std::string chomptoken (std::string &s1, const std::string &s2)
 
std::string chopfirst (std::string &s1, const std::string &s2)
 
std::string chopends (std::string &s1, const std::string &s2)
 
std::string choplast (std::string &s1, const std::string &s2)
 
std::string chop (std::string &s1, const std::string &s2)
 
std::string chomp (std::string &s1, const std::string &s2)
 
void removespace (std::string &s, const std::string &s2)
 
void replace (std::string &s, const std::string &s2, const std::string &s3)
 
void replace (std::string &s, char c1, char c2) noexcept
 
void depunctuate (std::string &s)
 
double deltaPhi (double phi1, double phi2)
 
bool canopen (const std::string &s)
 
std::string number (const double &d, const std::string &s)
 
std::string number (const int &i, const std::string &s)
 
std::string dirname (std::string name)
 
std::string basename (std::string name)
 

Detailed Description


Author
M.Sutton
Date
Thu Jun 23 01:11:43 BST 2005

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

Definition in file utils.cxx.

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 &  s)

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 &  s1,
const std::string &  s2 
)

Definition at line 115 of file utils.cxx.

116 {
117  std::string::size_type pos = s1.find(s2);
118  std::string s3;
119  if ( pos == std::string::npos ) {
120  s3 = std::move(s1);
121  s1.clear();
122  }
123  else {
124  s3 = s1.substr(pos+s2.size(),s1.size());
125  s1.erase(pos,s1.size());
126  }
127  return s3;
128 }

◆ chomptoken()

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

Definition at line 47 of file utils.cxx.

48 {
49  std::string s3 = "";
50  std::string::size_type pos = s1.find_last_of(s2);
51  if ( pos != std::string::npos ) {
52  s3 = s1.substr(pos, s1.size());
53  s1.erase(pos, s1.size());
54  }
55  return s3;
56 }

◆ chop()

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

Definition at line 98 of file utils.cxx.

99 {
100  std::string::size_type pos = s1.find(s2);
101  std::string s3;
102  if ( pos == std::string::npos ) {
103  s3 = std::move(s1);
104  s1.clear();
105  }
106  else {
107  s3 = s1.substr(0, pos);
108  s1.erase(0, pos+s2.size());
109  }
110  return s3;
111 }

◆ chopends()

std::string chopends ( std::string &  s1,
const std::string &  s2 
)

Definition at line 76 of file utils.cxx.

77 {
78  chopfirst(s1, s2);
79  choplast(s1, s2);
80  return s1;
81 }

◆ chopfirst()

std::string chopfirst ( std::string &  s1,
const std::string &  s2 
)

Definition at line 60 of file utils.cxx.

61 {
62  std::string s3;
63  std::string::size_type pos = s1.find_first_not_of(s2);
64  if ( pos != std::string::npos ) {
65  s3 = s1.substr(0, pos);
66  s1.erase(0, pos);
67  }
68  else {
69  s3 = s1;
70  s1.clear();
71  }
72  return s3;
73 }

◆ choplast()

std::string choplast ( std::string &  s1,
const std::string &  s2 
)

Definition at line 85 of file utils.cxx.

86 {
87  std::string s3 = "";
88  std::string::size_type pos = s1.find_last_not_of(s2);
89  if ( pos != std::string::npos ) {
90  s3 = s1.substr(pos+1, s1.size());
91  s1.erase(pos+1, s1.size());
92  }
93  return s3;
94 }

◆ choptoken()

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

Definition at line 34 of file utils.cxx.

35 {
36  std::string s3 = "";
37  std::string::size_type pos = s1.find(s2);
38  if ( pos != std::string::npos ) {
39  s3 = s1.substr(0, pos+1);
40  s1.erase(0, pos+1);
41  }
42  return s3;
43 }

◆ deltaPhi()

double deltaPhi ( double  phi1,
double  phi2 
)

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 &  s)

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 
)

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 
)

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 
)

Definition at line 132 of file utils.cxx.

133 {
134  std::string::size_type pos;
135  while ( (pos = s.find(s2))!=std::string::npos ) {
136  s.erase(pos, 1);
137  }
138 }

◆ 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,
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
chopfirst
std::string chopfirst(std::string &s1, const std::string &s2)
Definition: utils.cxx:60
replace
void replace(std::string &s, const std::string &s2, const std::string &s3)
Definition: utils.cxx:142
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
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
python.DataFormatRates.c2
c2
Definition: DataFormatRates.py:123
ReadCellNoiseFromCoolCompare.s2
s2
Definition: ReadCellNoiseFromCoolCompare.py:379
choplast
std::string choplast(std::string &s1, const std::string &s2)
Definition: utils.cxx:85