9 #ifndef LWH_DataPointSet_H
10 #define LWH_DataPointSet_H
20 #include "AIDataPointSet.h"
21 #include "ManagedObject.h"
22 #include "DataPoint.h"
52 throw std::runtime_error(
"LWH cannot handle annotations");
59 throw std::runtime_error(
"LWH cannot handle annotations");
120 return &(dset[index]);
136 bool setCoordinate(
int coord,
137 const std::vector<double> & val,
138 const std::vector<double> & err) {
139 return setCoordinate(coord, val, err, err);
157 bool setCoordinate(
int coord,
158 const std::vector<double> & val,
159 const std::vector<double> & errp,
160 const std::vector<double> & errm) {
161 if ( coord < 0 || coord >= dimension() )
return false;
162 if ( val.size() != dset.size() || errp.size() != dset.size() ||
163 errm.size() != dset.size() )
return false;
164 for (
int i = 0, N = val.size(); i < N; ++i ) {
165 dset[i].coordinate(coord)->setValue(val[i]);
166 dset[i].coordinate(coord)->setErrorPlus(errp[i]);
167 dset[i].coordinate(coord)->setErrorMinus(errm[i]);
176 const IDataPoint *
point(
int index)
const {
177 if ( index < 0 ||
unsigned(index) >= dset.size() )
return 0;
178 return &(dset[index]);
187 return &(dset.back());
197 if ( dimension() && dimension() != point.dimension() )
return false;
208 if ( index < 0 ||
unsigned(index) >= dset.size() )
return false;
209 dset.erase(dset.begin() + index);
221 if ( dset.empty() )
return std::numeric_limits<double>::quiet_NaN();
222 if ( coord < 0 || coord >= dimension() )
223 return std::numeric_limits<double>::quiet_NaN();
224 double low = dset[0].coordinate(coord)->value();
225 for (
int i = 1, N = dset.size(); i < N; ++i )
226 low = std::min(low, dset[i].coordinate(coord)->value());
238 if ( dset.empty() )
return std::numeric_limits<double>::quiet_NaN();
239 if ( coord < 0 || coord >= dimension() )
240 return std::numeric_limits<double>::quiet_NaN();
241 double upp = dset[0].coordinate(coord)->value();
242 for (
int i = 1, N = dset.size(); i < N; ++i )
243 upp = std::max(upp, dset[i].coordinate(coord)->value());
254 for (
int i = 0, N = dset.size(); i < N; ++i )
255 for (
int j = 0, M = dset[i].dimension(); j < M; ++j ) {
256 IMeasurement * m = dset[i].coordinate(j);
257 m->setValue(m->value()*scale);
258 m->setErrorPlus(m->errorPlus()*scale);
259 m->setErrorMinus(m->errorPlus()*scale);
271 for (
int i = 0, N = dset.size(); i < N; ++i )
272 for (
int j = 0, M = dset[i].dimension(); j < M; ++j ) {
273 IMeasurement * m = dset[i].coordinate(j);
274 m->setValue(m->value()*scale);
286 for (
int i = 0, N = dset.size(); i < N; ++i )
287 for (
int j = 0, M = dset[i].dimension(); j < M; ++j ) {
288 IMeasurement * m = dset[i].coordinate(j);
289 m->setErrorPlus(m->errorPlus()*scale);
290 m->setErrorMinus(m->errorPlus()*scale);
299 void *
cast(
const std::string &)
const {
306 bool writeXML(std::ostream & os, std::string path, std::string name) {
307 os <<
" <dataPointSet name=\"" << name
308 <<
"\"\n title=\"" << title()
309 <<
"\" path=\"" << path
310 <<
"\" dimension=\"" << dimension() <<
"\">\n";
311 for (
int d = 0; d < dimension(); ++d )
312 os <<
" <dimension dim=\"" << d <<
"\" title=\"unknown\" />\n";
313 for (
int i = 0, N = size(); i < N; ++i ) {
314 os <<
" <dataPoint>\n";
315 for (
int j = 0, M = dimension(); j < M; ++j )
316 os <<
" <measurement value=\""
317 << point(i)->coordinate(j)->value()
319 << point(i)->coordinate(j)->errorPlus()
320 <<
"\" errorMinus=\""
321 << point(i)->coordinate(j)->errorMinus()
323 os <<
" </dataPoint>\n";
325 os <<
" </dataPointSet>" << std::endl;
334 bool writeFLAT(std::ostream & os, std::string path, std::string name) {
335 os <<
"# " << path <<
"/" << name <<
" " << size()
336 <<
" \"" << title() <<
" \" dimension " << dimension() << std::endl;
337 for (
int i = 0, N = size(); i < N; ++i ) {
338 for (
int j = 0, M = dimension(); j < M; ++j )
339 os << point(i)->coordinate(j)->value() <<
" ";
340 for (
int j = 0, M = dimension(); j < M; ++j )
341 os << point(i)->coordinate(j)->errorPlus() <<
" ";
342 for (
int j = 0, M = dimension(); j < M; ++j )
343 os << point(i)->coordinate(j)->errorMinus() <<
" ";