ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Trigger
TrigT1
L1CaloFEX
L1CaloFEXByteStream
src
channelMappings
src
CSVWrapper.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3
*/
4
#include "
channelMappings/CSVWrapper.h
"
5
#include <iostream>
6
#include <sstream>
7
#include <algorithm>
8
#include <iterator>
15
CSVWrapper::CSVWrapper
(std::ifstream& inputfile):
16
m_valid
(false) ,
m_firstsearch
(true) ,
m_table
(),
m_columnwidth
(0)
17
{
18
std::istream_iterator<std::string> file_start{inputfile};
19
std::istream_iterator<std::string> file_end;
20
21
std::vector<std::string> fileContent;
22
std::copy(file_start,file_end,back_inserter(fileContent));
// copy file content into vector
23
24
fileContent.erase(begin(fileContent));
// first line is comment
25
// WARNING if the line contains spaces, it is
26
// treted as several lines!!!
27
28
for
(
auto
& line: fileContent){
// iterate over lines, unpack
29
std::vector<std::string> table_entry;
30
31
std::string cell;
32
std::stringstream lineStream(line);
33
34
while
(std::getline(lineStream,cell,
','
))
35
table_entry.push_back(cell);
36
m_table
.push_back(std::move(table_entry));
37
}
38
m_columnwidth
=
m_table
.at(10).size();
39
//Intialise prev results vector
40
m_previousresults
.push_back(
m_table
);
41
m_valid
=
true
;
42
}
43
48
std::shared_ptr<CSVWrapper::tableline>
CSVWrapper::FindLine
(
49
const
std::vector<std::pair<int,std::string>>& argumentpairs){
50
std::vector<CSVWrapper::tableline> result =
QueryTable
(argumentpairs);
51
//Check for unique result, if not throw exception
52
if
( result.empty())
53
{
54
CSVWrapper::tableline
returnval;
55
std::shared_ptr<CSVWrapper::tableline> return_ptr (
56
new
CSVWrapper::tableline
(std::move(returnval)));
57
return
return_ptr;
58
}
59
if
(result.size() != 1) {
60
std::cout <<
"Duplicate found!"
<< std::endl;
61
for
(
const
auto
&
res
: result) {
62
for
(
const
auto
&
r
:
res
) {
63
std::cout <<
r
<<
", "
;
64
}
65
std::cout << std::endl;
66
}
67
throw
"Non unique result to FindLine"
;
68
}
69
70
CSVWrapper::tableline
returnval = result.at(0);
71
std::shared_ptr<CSVWrapper::tableline> return_ptr (
72
new
CSVWrapper::tableline
(std::move(returnval)));
73
return
return_ptr;
74
}
75
81
std::vector<std::shared_ptr<CSVWrapper::tableline>>
CSVWrapper::FindLines
(
82
const
std::vector<std::pair<int,std::string>>& argumentpairs){
83
std::vector<CSVWrapper::tableline> result =
QueryTable
(argumentpairs);
84
85
std::vector<std::shared_ptr<CSVWrapper::tableline>> return_vec;
86
if
( result.empty())
87
{
88
CSVWrapper::tableline
returnval;
89
std::shared_ptr<CSVWrapper::tableline> return_ptr (
90
new
CSVWrapper::tableline
(std::move(returnval)));
91
return_vec.push_back(std::move(return_ptr));
92
}
93
else
{
94
for
(
CSVWrapper::tableline
returnval: result) {
95
std::shared_ptr<CSVWrapper::tableline> return_ptr (
96
new
CSVWrapper::tableline
(std::move(returnval)));
97
return_vec.push_back(std::move(return_ptr));
98
}
99
}
100
return
return_vec;
101
}
102
103
CSVWrapper::tableline
CSVWrapper::GetLine
(
const
int
element)
const
{
104
if
(element==-1)
105
return
m_table
.back();
106
return
m_table
.at(element);
107
}
108
113
void
CSVWrapper::PrintTable
(
bool
sample)
const
{
114
if
(
m_valid
){
115
size_t
rowidx(0) ;
116
for
(
const
auto
& row :
m_table
){
117
if
(!sample || (
m_table
.size()-rowidx)<100){
118
for
(
size_t
idx(0);idx<row.size();idx++ ){
119
std::cout << row.at(idx) <<
" , "
;
120
}
121
std::cout << std::endl;
122
}
123
rowidx++;
124
}
125
}
126
}
127
//Check what values compared to the last FindLine search remain the same and are in the same order, halt if no match
128
//i.e match,match,not_match,match will return match,match,not_match,notmatch
129
std::vector<bool>
CSVWrapper::ComparePreviousSearch
(
const
std::vector<std::pair<int,std::string>>& argumentpairs){
130
std::vector<bool> matchvector(argumentpairs.size(),
false
);
131
if
(
m_firstsearch
){
132
m_firstsearch
=
false
;
133
}
134
else
{
135
int
idx = 0;
136
for
(
const
auto
& newsearch : argumentpairs){
137
matchvector.at(idx) = ((newsearch.first ==
m_prevsearch
.at(idx).first) &&
138
(newsearch.second ==
m_prevsearch
.at(idx).second));
139
if
(!matchvector.at(idx))
break
;
//Escape if match fails
140
idx++;
141
}
142
}
143
m_prevsearch
= argumentpairs;
144
return
matchvector;
145
}
146
147
std::vector<CSVWrapper::tableline>
CSVWrapper::QueryTable
(
const
std::vector<std::pair<int,std::string>>&
148
argumentpairs)
149
{
150
//Loop over every column argument in the find statement
151
size_t
searchcolumnidx = 0;
152
auto
matches = this->
ComparePreviousSearch
(argumentpairs);
153
//std::vector<CSVWrapper::tableline> result = m_table;
154
std::vector<CSVWrapper::tableline> result;
155
for
(
bool
matched : matches ){
156
if
(!matched){
//If not the same search as before (in this column)
157
//Complete one column search routine
158
result =
m_previousresults
.at(searchcolumnidx);
159
auto
search
= argumentpairs.at(searchcolumnidx);
160
auto
findmismatch = [&] (
CSVWrapper::tableline
row){
161
return
(row.at(
search
.first) !=
search
.second);
162
};
163
result.erase(
std::remove_if
(result.begin(), result.end(), findmismatch)
164
, result.end() );
165
if
(
m_previousresults
.size() <= searchcolumnidx + 1){
//If unintialised
166
m_previousresults
.push_back(result);
167
}
168
else
{
169
m_previousresults
.at(searchcolumnidx+1) = result;
170
}
171
}
172
searchcolumnidx++;
173
}
174
//Cover Case that exactly the same search as before
175
if
(matches.back() ==
true
){result =
m_previousresults
.at(searchcolumnidx);}
176
return
result;
177
}
CSVWrapper.h
res
std::pair< std::vector< unsigned int >, bool > res
Definition
JetGroupProductTest.cxx:11
CSVWrapper::m_table
std::vector< tableline > m_table
Definition
CSVWrapper.h:29
CSVWrapper::m_valid
bool m_valid
Definition
CSVWrapper.h:27
CSVWrapper::FindLines
std::vector< std::shared_ptr< tableline > > FindLines(const std::vector< std::pair< int, std::string > > &argumentpairs)
Definition
CSVWrapper.cxx:81
CSVWrapper::QueryTable
std::vector< CSVWrapper::tableline > QueryTable(const std::vector< std::pair< int, std::string > > &argumentpairs)
Definition
CSVWrapper.cxx:147
CSVWrapper::PrintTable
void PrintTable(bool sample=false) const
Definition
CSVWrapper.cxx:113
CSVWrapper::GetLine
tableline GetLine(const int element) const
Definition
CSVWrapper.cxx:103
CSVWrapper::m_prevsearch
std::vector< std::pair< int, std::string > > m_prevsearch
Definition
CSVWrapper.h:31
CSVWrapper::m_columnwidth
size_t m_columnwidth
Definition
CSVWrapper.h:30
CSVWrapper::tableline
std::vector< std::string > tableline
Definition
CSVWrapper.h:10
CSVWrapper::ComparePreviousSearch
std::vector< bool > ComparePreviousSearch(const std::vector< std::pair< int, std::string > > &argumentpairs)
Definition
CSVWrapper.cxx:129
CSVWrapper::m_previousresults
std::vector< std::vector< tableline > > m_previousresults
Definition
CSVWrapper.h:32
CSVWrapper::CSVWrapper
CSVWrapper()
CSVWrapper::m_firstsearch
bool m_firstsearch
Definition
CSVWrapper.h:28
CSVWrapper::FindLine
std::shared_ptr< tableline > FindLine(const std::vector< std::pair< int, std::string > > &argumentpairs)
Definition
CSVWrapper.cxx:48
r
int r
Definition
globals.cxx:22
search
void search(TDirectory *td, const std::string &s, std::string cwd, node *n)
recursive directory search for TH1 and TH2 and TProfiles
Definition
hcg.cxx:743
std::remove_if
DataModel_detail::iterator< DVL > remove_if(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end, Predicate pred)
Specialization of remove_if for DataVector/List.
Definition
DVL_algorithms.h:70
Generated on
for ATLAS Offline Software by
1.17.0