a Code for the Combination of Indirect and Direct Constraints on High Energy Physics Models Logo
BOL::TwoDimensionalDataPlotter Class Reference

#include <TwoDimensionalDataPlotter.hpp>

Detailed Description

Definition at line 25 of file TwoDimensionalDataPlotter.hpp.

Public Types

typedef std::pair< double, double > DoublePair
 
typedef std::vector< DoublePairDoublePairVector
 
typedef std::pair< DoublePairVector, std::string > DoublePairVectorWithString
 
typedef std::pair< DoublePairVector, StringPairDoublePairVectorWithStringPair
 
typedef std::vector< DoublePairVectorWithStringPairPlotDataVector
 
typedef std::pair< std::string, std::string > StringPair
 

Public Member Functions

void addPoint (double const xValue, double const yValue)
 
void clearEntries (std::string plotFileName)
 
void plotData (PlotDataVector const &dataAndColorsAndLabels, std::string const xAxisLabel="", std::string const yAxisLabel="")
 
void plotData (std::string const legendString="", std::string const xAxisLabel="", std::string const yAxisLabel="")
 
void plotData (std::vector< DoublePairVectorWithString > const &dataAndColors, std::string const xAxisLabel="", std::string const yAxisLabel="")
 
 TwoDimensionalDataPlotter (std::string const &pathToGnuplotExecutable, std::string const &plotFileName)
 
 ~TwoDimensionalDataPlotter ()
 

Protected Attributes

VectorlikeArray< std::pair< double, double > > dataPoints
 
std::string const gnuplotCommandFileName
 
std::string const gnuplotDataFileName
 
WaitingOnSubprocessExecutor gnuplotExecutor
 
std::ofstream outputStream
 
int const patienceTicks
 
std::string plotFileName
 

Member Typedef Documentation

◆ DoublePair

typedef std::pair< double, double > BOL::TwoDimensionalDataPlotter::DoublePair

Definition at line 28 of file TwoDimensionalDataPlotter.hpp.

◆ DoublePairVector

◆ DoublePairVectorWithString

◆ DoublePairVectorWithStringPair

◆ PlotDataVector

◆ StringPair

typedef std::pair< std::string, std::string > BOL::TwoDimensionalDataPlotter::StringPair

Definition at line 29 of file TwoDimensionalDataPlotter.hpp.

Constructor & Destructor Documentation

◆ TwoDimensionalDataPlotter()

BOL::TwoDimensionalDataPlotter::TwoDimensionalDataPlotter ( std::string const &  pathToGnuplotExecutable,
std::string const &  plotFileName 
)

Definition at line 17 of file TwoDimensionalDataPlotter.cpp.

19 :
21 gnuplotDataFileName( "gnuplot_data.txt" ),
22 gnuplotCommandFileName( "gnuplot_input.txt" ),
23 patienceTicks( 10000 ),
24 dataPoints( 0 ),
26 gnuplotExecutor( pathToGnuplotExecutable,
28 {
30 }
WaitingOnSubprocessExecutor gnuplotExecutor
VectorlikeArray< std::pair< double, double > > dataPoints
void setArguments(std::string const &argumentsAsSingleString)

◆ ~TwoDimensionalDataPlotter()

BOL::TwoDimensionalDataPlotter::~TwoDimensionalDataPlotter ( )

Definition at line 32 of file TwoDimensionalDataPlotter.cpp.

33 {
34 if( outputStream.is_open() )
35 {
36 outputStream.close();
37 }
38 }

Member Function Documentation

◆ addPoint()

void BOL::TwoDimensionalDataPlotter::addPoint ( double const  xValue,
double const  yValue 
)
inline

Definition at line 74 of file TwoDimensionalDataPlotter.hpp.

76 {
77 dataPoints.newEnd().first = xValue;
78 dataPoints.getBack().second = yValue;
79 }

◆ clearEntries()

void BOL::TwoDimensionalDataPlotter::clearEntries ( std::string  plotFileName)
inline

Definition at line 82 of file TwoDimensionalDataPlotter.hpp.

83 {
84 this->plotFileName.assign( plotFileName );
85 dataPoints.setSize( 0 );
86 }

◆ plotData() [1/3]

void BOL::TwoDimensionalDataPlotter::plotData ( PlotDataVector const &  dataAndColorsAndLabels,
std::string const  xAxisLabel = "",
std::string const  yAxisLabel = "" 
)

Definition at line 190 of file TwoDimensionalDataPlotter.cpp.

194 {
195 std::string dataFileName;
196 size_t numberOfFileNumberDigits( StringParser::numberOfDigitsInInt(
197 dataAndColorsAndLabels.size() ) );
198 size_t numberOfFiles( dataAndColorsAndLabels.size() );
199
200 std::vector< std::string > dataFileNames;
201 for( size_t whichEntry( 0 );
202 whichEntry < numberOfFiles;
203 ++whichEntry )
204 {
205 dataFileName.assign( gnuplotDataFileName );
206 dataFileName.append( StringParser::intToString( whichEntry,
207 numberOfFileNumberDigits,
208 "" ) );
209 dataFileNames.push_back( dataFileName );
210 outputStream.open( dataFileName.c_str() );
211 if( outputStream.is_open() )
212 // if the file was successfully opened...
213 {
214 for( size_t dataIndex( 0 );
215 dataAndColorsAndLabels[ whichEntry ].first.size() > dataIndex;
216 ++dataIndex )
217 {
219 << dataAndColorsAndLabels[ whichEntry ].first[ dataIndex ].first
220 << " "
221 << dataAndColorsAndLabels[ whichEntry ].first[ dataIndex ].second
222 << std::endl;
223 }
224 outputStream.close();
225 }
226 else
227 {
228 std::cout
229 << std::endl
230 << "BOL::error! TwoDimensionalDataPlotter::plotData() could not open"
231 << dataFileName;
232 std::cout << std::endl;
233 }
234 }
235
236 outputStream.open( gnuplotCommandFileName.c_str() );
237 if( outputStream.is_open() )
238 // if the file was successfully opened...
239 {
241 << "set term postscript eps enhanced color solid" << std::endl
242 << "set ylabel \"" << yAxisLabel << "\"" << std::endl
243 << "set xlabel \"" << xAxisLabel << "\"" << std::endl
244 << "set output \"" << plotFileName << "\"" << std::endl;
245 for( size_t whichEntry( 0 );
246 whichEntry < numberOfFiles;
247 ++whichEntry )
248 {
250 << "set style line " << ( whichEntry + 1 ) << " lt rgb \""
251 << dataAndColorsAndLabels[ whichEntry ].second.first << "\" lw 3"
252 << std::endl;
253 }
255 << "plot ";
256 for( size_t whichEntry( 0 );
257 whichEntry < numberOfFiles;
258 ++whichEntry )
259 {
260 if( 0 < whichEntry )
261 {
262 outputStream << ", ";
263 }
265 << "'" << dataFileNames[ whichEntry ]
266 << "' index 0 title \""
267 << dataAndColorsAndLabels[ whichEntry ].second.second
268 << "\" with lines ls " << ( whichEntry + 1 );
269 }
270 outputStream.close();
271
273 }
274 else
275 {
276 std::cout
277 << std::endl
278 << "BOL::error! TwoDimensionalDataPlotter::plotData() could not open"
280 std::cout << std::endl;
281 }
282 }
static std::string intToString(int inputInt, int const minimumNumberOfDigits, std::string const prefixForPositiveNumbers="+", std::string const prefixForNegativeNumbers="-", char const paddingChar='0')
static int numberOfDigitsInInt(int inputInt)

◆ plotData() [2/3]

void BOL::TwoDimensionalDataPlotter::plotData ( std::string const  legendString = "",
std::string const  xAxisLabel = "",
std::string const  yAxisLabel = "" 
)

Definition at line 42 of file TwoDimensionalDataPlotter.cpp.

45 {
46 outputStream.open( gnuplotDataFileName.c_str() );
47 if( outputStream.is_open() )
48 // if the file was successfully opened...
49 {
50 for( int dataIndex( 0 );
51 dataPoints.getSize() > dataIndex;
52 ++dataIndex )
53 {
55 << dataPoints[ dataIndex ].first << " "
56 << dataPoints[ dataIndex ].second << std::endl;
57 }
58 outputStream.close();
59
61 if( outputStream.is_open() )
62 // if the file was successfully opened...
63 {
65 << "set term postscript eps enhanced color solid" << std::endl
66 << "set output \"" << plotFileName << "\"" << std::endl
67 << "set style line 1 lt rgb \"red\" lw 3" << std::endl
68 << "set ylabel \"" << yAxisLabel << "\"" << std::endl
69 << "set xlabel \"" << xAxisLabel << "\"" << std::endl
70 << "plot '" << gnuplotDataFileName << "' index 0 title \""
71 << legendString << "\" with lines ls 1" << std::endl;
72 outputStream.close();
73
75 }
76 else
77 {
78 std::cout
79 << std::endl
80 << "BOL::error! TwoDimensionalDataPlotter::plotData() could not open"
82 std::cout << std::endl;
83 }
84 }
85 else
86 {
87 std::cout
88 << std::endl
89 << "BOL::error! TwoDimensionalDataPlotter::plotData() could not open"
91 std::cout << std::endl;
92 }
93 }

◆ plotData() [3/3]

void BOL::TwoDimensionalDataPlotter::plotData ( std::vector< DoublePairVectorWithString > const &  dataAndColors,
std::string const  xAxisLabel = "",
std::string const  yAxisLabel = "" 
)

Definition at line 96 of file TwoDimensionalDataPlotter.cpp.

100 {
101 std::string dataFileName;
102 size_t numberOfFileNumberDigits( StringParser::numberOfDigitsInInt(
103 dataAndColors.size() ) );
104
105 std::vector< std::pair< std::string, std::string > > colorsWithFilenames;
106 for( size_t whichEntry( 0 );
107 dataAndColors.size() > whichEntry;
108 ++whichEntry )
109 {
110 dataFileName.assign( gnuplotDataFileName );
111 dataFileName.append( StringParser::intToString( whichEntry,
112 numberOfFileNumberDigits,
113 "" ) );
114 colorsWithFilenames.push_back( std::pair< std::string, std::string >(
115 dataAndColors[ whichEntry ].second,
116 dataFileName ) );
117
118 outputStream.open( dataFileName.c_str() );
119 if( outputStream.is_open() )
120 // if the file was successfully opened...
121 {
122 for( unsigned int dataIndex( 0 );
123 dataAndColors[ whichEntry ].first.size() > dataIndex;
124 ++dataIndex )
125 {
127 << dataAndColors[ whichEntry ].first[ dataIndex ].first << " "
128 << dataAndColors[ whichEntry ].first[ dataIndex ].second
129 << std::endl;
130 }
131 outputStream.close();
132 }
133 else
134 {
135 std::cout
136 << std::endl
137 << "BOL::error! TwoDimensionalDataPlotter::plotData() could not open"
138 << dataFileName;
139 std::cout << std::endl;
140 }
141 }
142
143 outputStream.open( gnuplotCommandFileName.c_str() );
144 if( outputStream.is_open() )
145 // if the file was successfully opened...
146 {
148 << "set term postscript eps enhanced color solid" << std::endl
149 << "set ylabel \"" << yAxisLabel << "\"" << std::endl
150 << "set xlabel \"" << xAxisLabel << "\"" << std::endl
151 << "set output \"" << plotFileName << "\"" << std::endl;
152 for( size_t whichEntry( 0 );
153 colorsWithFilenames.size() > whichEntry;
154 ++whichEntry )
155 {
157 << "set style line " << ( whichEntry + 1 ) << " lt rgb \""
158 << colorsWithFilenames[ whichEntry ].first << "\" lw 3"
159 << std::endl;
160 }
162 << "plot ";
163 for( size_t whichEntry( 0 );
164 colorsWithFilenames.size() > whichEntry;
165 ++whichEntry )
166 {
167 if( 0 < whichEntry )
168 {
169 outputStream << ", ";
170 }
172 << "'" << colorsWithFilenames[ whichEntry ].second
173 << "' index 0 notitle with lines ls " << ( whichEntry + 1 );
174 }
175 outputStream.close();
176
178 }
179 else
180 {
181 std::cout
182 << std::endl
183 << "BOL::error! TwoDimensionalDataPlotter::plotData() could not open"
185 std::cout << std::endl;
186 }
187 }

Member Data Documentation

◆ dataPoints

VectorlikeArray< std::pair< double, double > > BOL::TwoDimensionalDataPlotter::dataPoints
protected

Definition at line 66 of file TwoDimensionalDataPlotter.hpp.

◆ gnuplotCommandFileName

std::string const BOL::TwoDimensionalDataPlotter::gnuplotCommandFileName
protected

Definition at line 64 of file TwoDimensionalDataPlotter.hpp.

◆ gnuplotDataFileName

std::string const BOL::TwoDimensionalDataPlotter::gnuplotDataFileName
protected

Definition at line 63 of file TwoDimensionalDataPlotter.hpp.

◆ gnuplotExecutor

WaitingOnSubprocessExecutor BOL::TwoDimensionalDataPlotter::gnuplotExecutor
protected

Definition at line 68 of file TwoDimensionalDataPlotter.hpp.

◆ outputStream

std::ofstream BOL::TwoDimensionalDataPlotter::outputStream
protected

Definition at line 67 of file TwoDimensionalDataPlotter.hpp.

◆ patienceTicks

int const BOL::TwoDimensionalDataPlotter::patienceTicks
protected

Definition at line 65 of file TwoDimensionalDataPlotter.hpp.

◆ plotFileName

std::string BOL::TwoDimensionalDataPlotter::plotFileName
protected

Definition at line 62 of file TwoDimensionalDataPlotter.hpp.


The documentation for this class was generated from the following files: