11 #include "BCDataSet.h"
13 #include "BCDataPoint.h"
34 int ndatapoints = int(fBCDataVector->size());
35 for (
int i = 0; i < ndatapoints; ++i)
36 delete fBCDataVector->at(i);
37 fBCDataVector->clear();
45 if (bcdataset.fBCDataVector) {
46 fBCDataVector =
new BCDataVector();
47 for (
int i = 0; i < int(bcdataset.fBCDataVector->size()); ++i) {
48 if (bcdataset.fBCDataVector->at(i))
49 fBCDataVector->push_back(
new BCDataPoint(*(bcdataset.fBCDataVector->at(i))));
51 fBCDataVector->push_back(0);
61 if (bcdataset.fBCDataVector) {
62 fBCDataVector =
new BCDataVector();
63 for (
int i = 0; i < int(bcdataset.fBCDataVector->size()); ++i) {
64 if (bcdataset.fBCDataVector->at(i))
65 fBCDataVector->push_back(
new BCDataPoint(*(bcdataset.fBCDataVector->at(i))));
67 fBCDataVector->push_back(0);
81 return fBCDataVector ? fBCDataVector->size() : 0;
89 if (fBCDataVector && fBCDataVector->size() > 0)
92 BCLog::OutError(
"BCDataSet::GetNValuesPerPoint : Data set doesn't exist yet");
102 BCLog::OutError(
"BCDataSet::GetDataPoint : Dataset is empty.");
108 return fBCDataVector->at(index);
111 BCLog::OutError(
"BCDataSet::GetDataPoint : Index out of range. Return 0.");
119 std::vector<double> components( N , 0.0 );
122 for (
unsigned int i = 0; i < N; ++i) {
125 components[i] = point->
GetValue(index);
138 TFile * file = TFile::Open(filename,
"READ");
143 BCLog::OutError(Form(
"BCDataSet::ReadDataFromFileTree : Could not open file %s.", filename));
148 TTree * tree = (TTree*) file->Get(treename);
153 BCLog::OutError(Form(
"BCDataSet::ReadDataFromFileTree : Could not find TTree %s.", treename));
162 if (fBCDataVector != 0)
164 fBCDataVector->clear();
166 BCLog::OutDetail(
"BCDataSet::ReadDataFromFileTree : Overwrite existing data.");
171 fBCDataVector =
new BCDataVector();
176 std::string branches(branchnames);
179 std::vector<std::string> * branchnamevector =
new std::vector<std::string>;
183 int temp_index = branches.find_first_of(
",");
189 while(branches.size() > 0)
192 std::string branchname;
197 if (temp_index == -1)
198 branchname = branches;
202 branchname.assign(branches, 0, temp_index);
205 branchnamevector->push_back(branchname);
213 if (temp_index == -1)
218 branches.erase(0, temp_index + 1);
221 temp_index = branches.find_first_of(
",");
225 std::vector<double> data;
226 data.assign(nbranches, 0.0);
229 for (
int i = 0; i < nbranches; i++)
230 tree->SetBranchAddress(branchnamevector->at(i).data(), &data.at(i));
233 int nentries = tree->GetEntries();
238 BCLog::OutError(Form(
"BCDataSet::ReadDataFromFileTree : No events in TTree %s.", treename));
247 for (
int ientry = 0; ientry < nentries; ientry++)
250 tree->GetEntry(ientry);
257 for (
int i = 0; i < nbranches; i++)
281 file.open(filename, std::fstream::in);
286 BCLog::OutError(Form(
"BCDataSet::ReadDataFromFileText : Could not open file %s.", filename));
291 if (fBCDataVector != 0)
293 fBCDataVector->clear();
295 BCLog::OutDetail(
"BCDataSet::ReadDataFromFileTxt : Overwrite existing data.");
300 fBCDataVector =
new BCDataVector();
303 std::vector<double> data;
304 data.assign(nbranches, 0.0);
314 while(file >> data[i])
327 for (
int i = 0; i < nbranches; i++)
341 BCLog::OutError(Form(
"BCDataSet::ReadDataFromFileText : No events in the file %s.", filename));
363 if (fBCDataVector == 0)
364 fBCDataVector =
new BCDataVector();
367 fBCDataVector->push_back(datapoint);
378 if (fBCDataVector != 0)
379 fBCDataVector->clear();
387 if (!fBCDataVector) {
388 BCLog::OutError(
"BCDataSet::Dump : Data set is empty. Nothing to dump.");
392 BCLog::OutSummary(
"Data set summary:");
393 BCLog::OutSummary(Form(
"Number of points : %d",
int(fBCDataVector->size())));
394 BCLog::OutSummary(Form(
"Number of values per point : %d",
GetDataPoint(0)->GetNValues()));
396 for (
unsigned int i=0; i< fBCDataVector->size(); i++) {
397 BCLog::OutSummary(Form(
"Data point %5d : ", i));
398 for (
unsigned int j=0; j<n; j++)
399 BCLog::OutSummary(Form(
"%d : %12.5g", j,
GetDataPoint(i)->GetValue(j)));
A class representing a data point.
unsigned int GetNValues() const
unsigned int GetNValuesPerPoint()
A class representing a set of data points.
BCDataSet & operator=(const BCDataSet &bcdataset)
int ReadDataFromFileTree(const char *filename, const char *treename, const char *branchnames)
std::vector< double > GetDataComponents(int index)
double GetValue(unsigned index) const
int ReadDataFromFileTxt(const char *filename, int nvariables)
BCDataPoint * GetDataPoint(unsigned int index)
unsigned int GetNDataPoints()
void AddDataPoint(BCDataPoint *datapoint)
void SetValue(unsigned index, double value)