ATLAS Offline Software
Public Member Functions | Private Types | Private Member Functions | Private Attributes | Friends | List of all members
DBline Class Reference

#include <dbline.h>

Inheritance diagram for DBline:
Collaboration diagram for DBline:

Public Member Functions

 DBline ()
 
 DBline (std::ifstream &file)
 
 DBline (std::istream &stream)
 
void connect (std::ifstream &file)
 
void connect (std::istream &stream)
 
DBlinetoken (std::string_view)
 
template<class type >
DBlinetoken (std::string_view, type t)
 
template<class type >
DBlinetoken (std::string_view, type t, int size)
 
void go_until (std::string_view token)
 
bool empty (void) const
 
DBlinereset_fmt (void)
 
const DBfmtdbhex () const
 
const DBfmtdboct () const
 
const DBfmtdbdec () const
 
DBlineoperator>> (std::string &str)
 
DBlineoperator>> (int &i)
 
DBlineoperator>> (uint8_t &i8)
 
DBlineoperator>> (uint16_t &i16)
 
DBlineoperator>> (uint32_t &i32)
 
DBlineoperator>> (uint64_t &i64)
 
DBlineoperator>> (const DBfmt &f)
 
DBlineoperator>> (std::string_view token)
 
DBlineoperator++ ()
 
DBlineoperator++ (int i)
 
DBlineoperator+ (int i)
 
 operator bool ()
 
bool operator! ()
 
 operator DBstatus ()
 
DBlineoperator() (std::string_view)
 
DBlineoperator() (std::string_view, int)
 
DBlineoperator() (std::string_view, int, int)
 
DBlineoperator<< (std::istream &input)
 
DBlineoperator<< (std::ifstream &file)
 

Private Types

enum  exist_quote { no_quote, begin_quote, end_quote, error }
 
typedef enum DBline::exist_quote quote
 

Private Member Functions

void reset_data (void)
 
void reset_status (void)
 
void reset (void)
 
void GoodExtraction (void)
 
void BadExtraction (void)
 
void erase_comment (void)
 
void GetToken (size_t pos, std::string_view token)
 
void GetLine (std::istream &input)
 
template<class type >
void GetValue (type &value)
 
void GetValue (std::string &value)
 
quote check_quote (std::string &) const
 
void GetStr (std::string &)
 
bool check_data (void)
 

Private Attributes

std::ios::fmtflags m_default
 
std::ifstream * m_file {nullptr}
 
std::istream * m_stream {nullptr}
 
std::string m_data
 
std::string m_backup
 
unsigned long int m_pos {0}
 
int m_line {0}
 
bool m_fail {false}
 
bool m_empty {false}
 
DBstatus m_extraction {extracted}
 
int m_base {10}
 
DBfmt m_dbfmt_hex
 
DBfmt m_dbfmt_oct
 
DBfmt m_dbfmt_dec
 

Friends

std::ifstream & operator>> (std::ifstream &file, DBline &db)
 
std::istream & operator>> (std::istream &stream, DBline &db)
 
std::ostream & operator<< (std::ostream &stream, DBline &db)
 

Detailed Description

Definition at line 255 of file dbline.h.

Member Typedef Documentation

◆ quote

typedef enum DBline::exist_quote DBline::quote
private

Member Enumeration Documentation

◆ exist_quote

enum DBline::exist_quote
private
Enumerator
no_quote 
begin_quote 
end_quote 
error 

Definition at line 257 of file dbline.h.

Constructor & Destructor Documentation

◆ DBline() [1/3]

DBline::DBline ( )

Definition at line 360 of file dbline.cxx.

360  {
361  this->unsetf(std::ios::skipws | std::ios::left | std::ios::right | std::ios::internal | std::ios::oct | std::ios::hex |
362  std::ios::showbase | std::ios::showpoint | std::ios::uppercase | std::ios::scientific | std::ios::fixed |
363  std::ios::showpos | std::ios::boolalpha);
364  m_default = flags();
365  m_dbfmt_hex.setf(std::ios::hex, std::ios::basefield);
366  m_dbfmt_oct.setf(std::ios::oct, std::ios::basefield);
367  m_dbfmt_dec.setf(std::ios::dec, std::ios::basefield);
368 }

◆ DBline() [2/3]

DBline::DBline ( std::ifstream &  file)

Definition at line 370 of file dbline.cxx.

370  :
371  DBline() {
372  m_file = &file;
373 }

◆ DBline() [3/3]

DBline::DBline ( std::istream &  stream)

Definition at line 375 of file dbline.cxx.

375  :
376  DBline() {
377  m_stream = &stream;
378 }

Member Function Documentation

◆ BadExtraction()

void DBline::BadExtraction ( void  )
private

Definition at line 39 of file dbline.cxx.

39  {
41  if (!m_backup.empty()) {
42  m_data = std::move(m_backup);
43  m_backup.clear();
44  }
45 }

◆ check_data()

bool DBline::check_data ( void  )
inlineprivate

Definition at line 364 of file dbline.h.

364  {
365  m_empty = std::all_of(m_data.begin(), m_data.end(), isspace);
366  return m_empty;
367 }

◆ check_quote()

DBline::quote DBline::check_quote ( std::string &  str) const
private

Definition at line 139 of file dbline.cxx.

139  {
140  const size_t pos = str.find('"');
141  if (pos == std::string::npos)
142  return no_quote;
143  else if (pos == 0) {
144  str.erase(0, 1);
145  return begin_quote;
146  } else if (pos == str.length() - 1) {
147  str.erase(pos, 1);
148  return end_quote;
149  }
150  return error;
151 }

◆ connect() [1/2]

void DBline::connect ( std::ifstream &  file)

Definition at line 157 of file dbline.cxx.

157  {
158  if ((&file) != m_file) {
159  m_line = 0;
160  m_fail = 0;
161  m_stream = nullptr;
162  m_file = &file;
163  }
164 }

◆ connect() [2/2]

void DBline::connect ( std::istream &  stream)

Definition at line 166 of file dbline.cxx.

166  {
167  if ((&stream) != m_stream) {
168  m_line = 0;
169  m_fail = 0;
170  m_file = nullptr;
171  m_stream = &stream;
172  }
173 }

◆ dbdec()

const DBfmt & DBline::dbdec ( ) const
inline

Definition at line 373 of file dbline.h.

373 { return m_dbfmt_dec; }

◆ dbhex()

const DBfmt & DBline::dbhex ( ) const
inline

Definition at line 369 of file dbline.h.

369 { return m_dbfmt_hex; }

◆ dboct()

const DBfmt & DBline::dboct ( ) const
inline

Definition at line 371 of file dbline.h.

371 { return m_dbfmt_oct; }

◆ empty()

bool DBline::empty ( void  ) const
inline

Definition at line 375 of file dbline.h.

375 { return m_empty; }

◆ erase_comment()

void DBline::erase_comment ( void  )
private

Definition at line 51 of file dbline.cxx.

51  {
52  const size_t pos = m_data.find('#');
53  if (pos != std::string::npos) m_data.erase(pos);
54 }

◆ GetLine()

void DBline::GetLine ( std::istream &  input)
private

Definition at line 62 of file dbline.cxx.

62  {
63  if (!check_data()) {
64  MsgStream log(Athena::getMessageSvc(true), "DBline");
65  log << MSG::WARNING << "line " << std::setw(4) << m_line << " -|" << m_data.c_str() << " .. not understood!" << endmsg;
66  }
67  reset();
68  if (input.eof()) {
69  m_fail = true;
70  return;
71  }
72  m_line++;
73  std::getline(input, m_data);
74  erase_comment();
75  check_data();
76  if (input.eof()) m_fail = true;
77 }

◆ GetStr()

void DBline::GetStr ( std::string &  str)
private

Definition at line 120 of file dbline.cxx.

120  {
121  GetValue(str);
123  if (pos == no_quote) { return; }
124  if (pos == begin_quote) {
125  const size_t pos = m_data.find('"', m_pos);
126  if (pos == std::string::npos) {
127  str.clear();
128  BadExtraction();
129  return;
130  }
131  str.append(m_data, m_pos, pos);
132  m_data.erase(m_pos, (pos - m_pos) + 1);
133  } else {
134  str.clear();
135  BadExtraction();
136  }
137 }

◆ GetToken()

void DBline::GetToken ( size_t  pos,
std::string_view  token 
)
private

Definition at line 56 of file dbline.cxx.

56  {
58  m_data.erase(pos, token.length());
59  m_pos = pos;
60 }

◆ GetValue() [1/2]

void DBline::GetValue ( std::string &  value)
private

Definition at line 104 of file dbline.cxx.

104  {
105  if (!m_extraction || m_fail) return;
106  const size_t start = m_data.find_first_not_of(' ', m_pos);
107  if (start == std::string::npos) {
108  BadExtraction();
109  return;
110  }
111  size_t stop = m_data.find_first_of(' ', start + 1);
112  if (stop == std::string::npos) stop = m_data.size();
113 
114  value = m_data.substr(start, stop - start);
115 
116  m_data.erase(m_pos, stop - m_pos);
117  check_data();
118 }

◆ GetValue() [2/2]

template<class type >
void DBline::GetValue ( type &  value)
private

Definition at line 83 of file dbline.cxx.

83  {
84  if (!m_extraction || m_fail) return;
85  const size_t start = m_data.find_first_not_of(' ', m_pos);
86  if (start == std::string::npos) {
87  BadExtraction();
88  return;
89  }
90  size_t stop = m_data.find_first_of(' ', start + 1);
91  if (stop == std::string::npos) stop = m_data.size();
92 
93  if constexpr(std::is_unsigned_v<type>) {
94  unsigned long temp = std::stoul(m_data.substr(start, stop - start), nullptr, m_base);
95  value = temp;
96  } else {
97  int temp = std::stoi(m_data.substr(start, stop - start), nullptr, m_base);
98  value = temp;
99  }
100  m_data.erase(m_pos, stop - m_pos);
101  check_data();
102 }

◆ go_until()

void DBline::go_until ( std::string_view  token)

Definition at line 229 of file dbline.cxx.

229  {
230  if (m_file) do
231  GetLine(*m_file);
232  while (m_data.find(token) == std::string::npos);
233  if (m_stream) do
234  GetLine(*m_stream);
235  while (m_data.find(token) == std::string::npos);
236 }

◆ GoodExtraction()

void DBline::GoodExtraction ( void  )
private

Definition at line 38 of file dbline.cxx.

◆ operator bool()

DBline::operator bool ( )

Definition at line 335 of file dbline.cxx.

335 { return !(m_fail | !static_cast<bool>(m_extraction)); }

◆ operator DBstatus()

DBline::operator DBstatus ( )

Definition at line 337 of file dbline.cxx.

337 { return m_extraction; }

◆ operator!()

bool DBline::operator! ( )

Definition at line 336 of file dbline.cxx.

336 { return m_fail | !static_cast<bool>(m_extraction); }

◆ operator()() [1/3]

DBline & DBline::operator() ( std::string_view  str)

Definition at line 343 of file dbline.cxx.

343  {
344  token(str);
345  return *this;
346 }

◆ operator()() [2/3]

DBline & DBline::operator() ( std::string_view  str,
int  n 
)

Definition at line 348 of file dbline.cxx.

348  {
349  token(str, n);
350  return *this;
351 }

◆ operator()() [3/3]

DBline & DBline::operator() ( std::string_view  str,
int  n,
int  s 
)

Definition at line 353 of file dbline.cxx.

353  {
354  token(str, n, s);
355  return *this;
356 }

◆ operator+()

DBline & DBline::operator+ ( int  i)

Definition at line 323 of file dbline.cxx.

323  {
324  for (int j = 0; j < i; j++) {
325  if (m_file) GetLine(*m_file);
326  if (m_stream) GetLine(*m_stream);
327  }
328  return *this;
329 }

◆ operator++() [1/2]

DBline & DBline::operator++ ( )

Definition at line 309 of file dbline.cxx.

309  {
310  if (m_file) GetLine(*m_file);
311  if (m_stream) GetLine(*m_stream);
312  return *this;
313 }

◆ operator++() [2/2]

DBline & DBline::operator++ ( int  i)

Definition at line 315 of file dbline.cxx.

315  {
316  for (int j = -1; j < i; j++) {
317  if (m_file) GetLine(*m_file);
318  if (m_stream) GetLine(*m_stream);
319  }
320  return *this;
321 }

◆ operator<<() [1/2]

DBline & DBline::operator<< ( std::ifstream &  file)

Definition at line 380 of file dbline.cxx.

380  {
381  connect(file);
382  GetLine(file);
383  return *this;
384 }

◆ operator<<() [2/2]

DBline & DBline::operator<< ( std::istream &  input)

Definition at line 386 of file dbline.cxx.

386  {
387  connect(input);
388  GetLine(input);
389  return *this;
390 }

◆ operator>>() [1/8]

DBline & DBline::operator>> ( const DBfmt f)

Definition at line 280 of file dbline.cxx.

280  {
281  flags(f.flags());
282  const std::ios_base::fmtflags fmt = f.flags() & std::ios_base::basefield;
283  switch (fmt) {
284  case std::ios::hex: m_base = 16; break;
285  case std::ios::oct: m_base = 8; break;
286  default: m_base = 10;
287  }
288  return *this;
289 }

◆ operator>>() [2/8]

DBline & DBline::operator>> ( int &  i)

Definition at line 255 of file dbline.cxx.

255  {
256  GetValue(i);
257  return *this;
258 }

◆ operator>>() [3/8]

DBline & DBline::operator>> ( std::string &  str)

Definition at line 251 of file dbline.cxx.

251  {
252  GetStr(str);
253  return *this;
254 }

◆ operator>>() [4/8]

DBline & DBline::operator>> ( std::string_view  token)

Definition at line 295 of file dbline.cxx.

295  {
296  if (!m_extraction || check_data() || m_fail) return *this;
297  const size_t pos = m_data.find(token, m_pos);
298  if (pos != std::string::npos)
299  GetToken(pos, token);
300  else
301  BadExtraction();
302  return *this;
303 }

◆ operator>>() [5/8]

DBline & DBline::operator>> ( uint16_t &  i16)

Definition at line 263 of file dbline.cxx.

263  {
264  GetValue(i16);
265  return *this;
266 }

◆ operator>>() [6/8]

DBline & DBline::operator>> ( uint32_t &  i32)

Definition at line 267 of file dbline.cxx.

267  {
268  GetValue(i32);
269  return *this;
270 }

◆ operator>>() [7/8]

DBline & DBline::operator>> ( uint64_t &  i64)

Definition at line 271 of file dbline.cxx.

271  {
272  GetValue(i64);
273  return *this;
274 }

◆ operator>>() [8/8]

DBline & DBline::operator>> ( uint8_t &  i8)

Definition at line 259 of file dbline.cxx.

259  {
260  GetValue(i8);
261  return *this;
262 }

◆ reset()

void DBline::reset ( void  )
private

Definition at line 29 of file dbline.cxx.

29  {
30  reset_data();
31  reset_status();
32 }

◆ reset_data()

void DBline::reset_data ( void  )
private

Definition at line 20 of file dbline.cxx.

20  {
21  m_data.clear();
22  m_pos = 0;
23  m_backup.clear();
24 }

◆ reset_fmt()

DBline & DBline::reset_fmt ( void  )

Definition at line 241 of file dbline.cxx.

241  {
242  m_base = 10;
243  flags(m_default);
244  return *this;
245 }

◆ reset_status()

void DBline::reset_status ( void  )
private

Definition at line 25 of file dbline.cxx.

25  {
27  m_empty = false;
28 }

◆ token() [1/3]

DBline & DBline::token ( std::string_view  token)

Definition at line 179 of file dbline.cxx.

179  {
181  if (check_data()) {
182  BadExtraction();
183  return *this;
184  }
185  const size_t pos = m_data.find(token);
186 
187  if (pos != std::string::npos) {
188  const size_t finalpos = pos + token.length();
189  char prev = (pos) ? m_data[pos - 1] : ' ';
190  char foll = (finalpos < m_data.length()) ? m_data[finalpos] : ' ';
191  if (prev == ' ' && foll == ' ')
192  GetToken(pos, token);
193  else
194  BadExtraction();
195  } else
196  BadExtraction();
197  return *this;
198 }

◆ token() [2/3]

template<class type >
DBline & DBline::token ( std::string_view  str,
type  t 
)

Definition at line 200 of file dbline.cxx.

200  {
201  const size_t pos = str.find('#');
202  if (pos != std::string::npos) {
203  const std::string rep = std::to_string(t);
204 
205  std::string new_token{str};
206  new_token.replace(pos, rep.length(), rep);
207  token(new_token);
208  } else
209  token(str);
210 
211  return *this;
212 }

◆ token() [3/3]

template<class type >
DBline & DBline::token ( std::string_view  str,
type  t,
int  size 
)

Definition at line 214 of file dbline.cxx.

214  {
215  const size_t pos = str.find('#');
216  if (pos != std::string::npos) {
217  std::ostringstream rep;
218  rep << std::setw(2) << std::setfill('0') << t;
219 
220  std::string new_token{str};
221  new_token.replace(pos, rep.str().length(), rep.str());
222  token(new_token);
223  } else
224  token(str);
225 
226  return *this;
227 }

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  stream,
DBline db 
)
friend

Definition at line 408 of file dbline.cxx.

408  {
409  stream << db.m_data;
410  return stream;
411 }

◆ operator>> [1/2]

std::ifstream& operator>> ( std::ifstream &  file,
DBline db 
)
friend

Definition at line 396 of file dbline.cxx.

396  {
397  db.connect(file);
398  db.GetLine(file);
399  return file;
400 }

◆ operator>> [2/2]

std::istream& operator>> ( std::istream &  stream,
DBline db 
)
friend

Definition at line 402 of file dbline.cxx.

402  {
403  db.connect(stream);
404  db.GetLine(stream);
405  return stream;
406 }

Member Data Documentation

◆ m_backup

std::string DBline::m_backup
private

Definition at line 262 of file dbline.h.

◆ m_base

int DBline::m_base {10}
private

Definition at line 268 of file dbline.h.

◆ m_data

std::string DBline::m_data
private

Definition at line 262 of file dbline.h.

◆ m_dbfmt_dec

DBfmt DBline::m_dbfmt_dec
private

Definition at line 296 of file dbline.h.

◆ m_dbfmt_hex

DBfmt DBline::m_dbfmt_hex
private

Definition at line 294 of file dbline.h.

◆ m_dbfmt_oct

DBfmt DBline::m_dbfmt_oct
private

Definition at line 295 of file dbline.h.

◆ m_default

std::ios::fmtflags DBline::m_default
private

Definition at line 259 of file dbline.h.

◆ m_empty

bool DBline::m_empty {false}
private

Definition at line 266 of file dbline.h.

◆ m_extraction

DBstatus DBline::m_extraction {extracted}
private

Definition at line 267 of file dbline.h.

◆ m_fail

bool DBline::m_fail {false}
private

Definition at line 265 of file dbline.h.

◆ m_file

std::ifstream* DBline::m_file {nullptr}
private

Definition at line 260 of file dbline.h.

◆ m_line

int DBline::m_line {0}
private

Definition at line 264 of file dbline.h.

◆ m_pos

unsigned long int DBline::m_pos {0}
private

Definition at line 263 of file dbline.h.

◆ m_stream

std::istream* DBline::m_stream {nullptr}
private

Definition at line 261 of file dbline.h.


The documentation for this class was generated from the following files:
python.CaloRecoConfig.f
f
Definition: CaloRecoConfig.py:127
DBline::m_stream
std::istream * m_stream
Definition: dbline.h:261
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
DBline::end_quote
@ end_quote
Definition: dbline.h:257
DBline::m_base
int m_base
Definition: dbline.h:268
DBline::m_line
int m_line
Definition: dbline.h:264
DBline::check_quote
quote check_quote(std::string &) const
Definition: dbline.cxx:139
DBline::m_backup
std::string m_backup
Definition: dbline.h:262
AthenaPoolTestRead.flags
flags
Definition: AthenaPoolTestRead.py:8
make_hlt_rep.rep
rep
Definition: make_hlt_rep.py:32
CaloCondBlobAlgs_fillNoiseFromASCII.db
db
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:43
mergePhysValFiles.start
start
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:14
DBline::GetValue
void GetValue(type &value)
Definition: dbline.cxx:83
athena.value
value
Definition: athena.py:122
PixelModuleFeMask_create_db.stop
int stop
Definition: PixelModuleFeMask_create_db.py:76
DBline::m_data
std::string m_data
Definition: dbline.h:262
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
DBline::check_data
bool check_data(void)
Definition: dbline.h:364
DBline::m_fail
bool m_fail
Definition: dbline.h:265
DBline::m_dbfmt_dec
DBfmt m_dbfmt_dec
Definition: dbline.h:296
DBline::reset_status
void reset_status(void)
Definition: dbline.cxx:25
AthenaPoolTestWrite.stream
string stream
Definition: AthenaPoolTestWrite.py:12
DBline::m_default
std::ios::fmtflags m_default
Definition: dbline.h:259
DBline::token
DBline & token(std::string_view)
Definition: dbline.cxx:179
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
not_extracted
@ not_extracted
Definition: dbline.h:248
DBline::reset_data
void reset_data(void)
Definition: dbline.cxx:20
DBline::DBline
DBline()
Definition: dbline.cxx:360
DBline::quote
enum DBline::exist_quote quote
extracted
@ extracted
Definition: dbline.h:248
DBline::reset
void reset(void)
Definition: dbline.cxx:29
DBline::m_empty
bool m_empty
Definition: dbline.h:266
lumiFormat.i
int i
Definition: lumiFormat.py:92
beamspotman.n
n
Definition: beamspotman.py:731
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
DBline::BadExtraction
void BadExtraction(void)
Definition: dbline.cxx:39
DBline::no_quote
@ no_quote
Definition: dbline.h:257
PlotPulseshapeFromCool.input
input
Definition: PlotPulseshapeFromCool.py:106
file
TFile * file
Definition: tile_monitor.h:29
DBline::GetToken
void GetToken(size_t pos, std::string_view token)
Definition: dbline.cxx:56
DBline::m_pos
unsigned long int m_pos
Definition: dbline.h:263
DBline::GetLine
void GetLine(std::istream &input)
Definition: dbline.cxx:62
DBline::m_dbfmt_hex
DBfmt m_dbfmt_hex
Definition: dbline.h:294
DBline::m_dbfmt_oct
DBfmt m_dbfmt_oct
Definition: dbline.h:295
DBline::GoodExtraction
void GoodExtraction(void)
Definition: dbline.cxx:38
DBline::m_file
std::ifstream * m_file
Definition: dbline.h:260
DBline::begin_quote
@ begin_quote
Definition: dbline.h:257
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
DBline::m_extraction
DBstatus m_extraction
Definition: dbline.h:267
fmt
DBline::erase_comment
void erase_comment(void)
Definition: dbline.cxx:51
DBline::connect
void connect(std::ifstream &file)
Definition: dbline.cxx:157
DBline::error
@ error
Definition: dbline.h:257
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
str
Definition: BTagTrackIpAccessor.cxx:11
DBline::GetStr
void GetStr(std::string &)
Definition: dbline.cxx:120
error
Definition: IImpactPoint3dEstimator.h:70
python.CaloEstimatedGainTool_test.i32
def i32(x)
Definition: CaloEstimatedGainTool_test.py:16