ATLAS Offline Software
Loading...
Searching...
No Matches
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
7#include "boost/lexical_cast.hpp"
8#include "boost/tokenizer.hpp"
9#include <fstream>
10#include <string>
11#include <sstream>
12
13
14namespace FPTracker{
15
16
18 public:
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:
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}
std::vector< std::string >::const_iterator end() const
std::vector< std::string >::const_iterator begin() const
std::vector< std::string > m_notConverted
bool setValue(T &val, const std::string &s)
bool readConfigData(std::shared_ptr< std::ifstream > confDir, ConfigData &)