ATLAS Offline Software
readConfigData.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 #include "FPTracker/ConfigData.h"
7 #include "boost/lexical_cast.hpp"
8 #include "boost/tokenizer.hpp"
9 #include <fstream>
10 #include <string>
11 #include <sstream>
12 
13 
14 namespace FPTracker{
15 
16 
17  class ValueSetter{
18  public:
19  ValueSetter():m_errors(false){}
20 
21  template<class T>
22  bool setValue(T& val, const std::string& s)
23  {
24  bool ok = true;
25  try
26  {
27  val = boost::lexical_cast<T>(s);
28  }
29  catch (boost::bad_lexical_cast& )
30  {
31  m_errors = true;
32  ok = false;
33 
34  m_notConverted.push_back(s);
35  }
36 
37  return ok;
38  }
39 
40  bool errors() const {return m_errors;}
41 
42  std::vector<std::string>::const_iterator begin() const
43  {
44  return m_notConverted.begin();
45  }
46 
47 
48  std::vector<std::string>::const_iterator end() const
49  {
50  return m_notConverted.end();
51  }
52 
53  private:
54  bool m_errors;
55  std::vector< std::string > m_notConverted;
56  };
57 
58 
59  bool readConfigData(std::shared_ptr< std::ifstream> p_mydata, ConfigData& configData){
60  // ConfigData readConfigData(std::string& dir){
61  // Read data cards from Data.txt file
62 
63 
64  std::ifstream& in = *p_mydata;
65  std::string line;
66  ValueSetter vs;
67 
68  boost::char_separator<char> sep(" \f\t\v");
69  typedef boost::tokenizer<boost::char_separator<char> > Tokenizer;
70 
71 
72  std::ostringstream ost;
73  while( std::getline(in, line) )
74  {
75  Tokenizer tok(line, sep);
76  std::vector< std::string > tokens(tok.begin(), tok.end());
77 
78  if ( tokens.size() > 1 )
79  {
80  ost<<tokens[0]<<" "<<tokens[1]<<'\n';
81  std::string& dataname = tokens[0];
82  std::string& svalue = tokens[1];
83  if(dataname == "IP" ) vs.setValue(configData.IP, svalue);
84  if(dataname == "APER") vs.setValue(configData.useaper, svalue);
85  if(dataname == "MBAP") vs.setValue(configData.apermb, svalue);
86  if(dataname == "COL1") vs.setValue(configData.xcol1, svalue);
87  if(dataname == "COL2") vs.setValue(configData.xcol2, svalue);
88  if(dataname == "ZMAX") vs.setValue(configData.absZMagMax, svalue);
89  if(dataname == "ENDM") vs.setValue(configData.endMarker, svalue);
90 
91  if(dataname == "PBEA") {
92  float pbeam;
93  if ( vs.setValue(pbeam, svalue) ){configData.setpbeam(pbeam);}
94  }
95 
96 
97  }
98 
99  }
100 
101  return !vs.errors();
102  }
103 }
checkFileSG.line
line
Definition: checkFileSG.py:75
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
python.trigbs_prescaleL1.ost
ost
Definition: trigbs_prescaleL1.py:104
FPTracker::ConfigData::useaper
bool useaper
Definition: FPTracker/FPTracker/ConfigData.h:14
ConfigData.h
beamspotman.tokens
tokens
Definition: beamspotman.py:1284
FPTracker::ConfigData::xcol1
double xcol1
Definition: FPTracker/FPTracker/ConfigData.h:16
FPTracker::ConfigData::xcol2
double xcol2
Definition: FPTracker/FPTracker/ConfigData.h:17
FPTracker::readConfigData
bool readConfigData(std::shared_ptr< std::ifstream > confDir, ConfigData &)
Definition: readConfigData.cxx:59
FPTracker::ConfigData::absZMagMax
float absZMagMax
Definition: FPTracker/FPTracker/ConfigData.h:23
readConfigData.h
FPTracker::ValueSetter::ValueSetter
ValueSetter()
Definition: readConfigData.cxx:19
CP::DetailSelectionExprParser::Tokenizer
boost::tokenizer< Separator > Tokenizer
Definition: SelectionExprParser.h:34
FPTracker::ValueSetter
Definition: readConfigData.cxx:17
FPTracker::ValueSetter::errors
bool errors() const
Definition: readConfigData.cxx:40
FPTracker::ValueSetter::m_notConverted
std::vector< std::string > m_notConverted
Definition: readConfigData.cxx:55
grepfile.sep
sep
Definition: grepfile.py:38
FPTracker::ValueSetter::begin
std::vector< std::string >::const_iterator begin() const
Definition: readConfigData.cxx:42
FPTracker::ConfigData::endMarker
float endMarker
Definition: FPTracker/FPTracker/ConfigData.h:21
FPTracker::ValueSetter::setValue
bool setValue(T &val, const std::string &s)
Definition: readConfigData.cxx:22
FPTracker::ConfigData::setpbeam
void setpbeam(double)
Definition: FPTracker/src/ConfigData.cxx:37
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
FPTracker::ConfigData
Definition: FPTracker/FPTracker/ConfigData.h:9
FPTracker
Definition: FPTracker/FPTracker/Beamline.h:12
FPTracker::ConfigData::apermb
double apermb
Definition: FPTracker/FPTracker/ConfigData.h:15
FPTracker::ConfigData::IP
int IP
Definition: FPTracker/FPTracker/ConfigData.h:12
FPTracker::ValueSetter::end
std::vector< std::string >::const_iterator end() const
Definition: readConfigData.cxx:48
FPTracker::ValueSetter::m_errors
bool m_errors
Definition: readConfigData.cxx:54