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"
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 std::ifstream& in = *p_mydata;
64 std::string line;
65 ValueSetter vs;
66
67 std::ostringstream ost;
68 while( std::getline(in, line) )
69 {
70 std::vector< std::string > tokens = CxxUtils::tokenize(line, " \f\t\v");
71
72 if ( tokens.size() > 1 )
73 {
74 ost<<tokens[0]<<" "<<tokens[1]<<'\n';
75 std::string& dataname = tokens[0];
76 std::string& svalue = tokens[1];
77 if(dataname == "IP" ) vs.setValue(configData.IP, svalue);
78 if(dataname == "APER") vs.setValue(configData.useaper, svalue);
79 if(dataname == "MBAP") vs.setValue(configData.apermb, svalue);
80 if(dataname == "COL1") vs.setValue(configData.xcol1, svalue);
81 if(dataname == "COL2") vs.setValue(configData.xcol2, svalue);
82 if(dataname == "ZMAX") vs.setValue(configData.absZMagMax, svalue);
83 if(dataname == "ENDM") vs.setValue(configData.endMarker, svalue);
84
85 if(dataname == "PBEA") {
86 float pbeam;
87 if ( vs.setValue(pbeam, svalue) ){configData.setpbeam(pbeam);}
88 }
89
90 }
91
92 }
93
94 return !vs.errors();
95 }
96}
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)
std::vector< std::string > tokenize(std::string_view the_str, std::string_view delimiters)
Splits the string into smaller substrings.
bool readConfigData(std::shared_ptr< std::ifstream > confDir, ConfigData &)