CacheBranchFx.cxx
Go to the documentation of this file.
1 //____________________________________________________________________________
2 /*
3  Copyright (c) 2003-2019, The GENIE Collaboration
4  For the full text of the license visit http://copyright.genie-mc.org
5  or see $GENIE/LICENSE
6 
7  Author: Costas Andreopoulos <costas.andreopoulos \at stfc.ac.uk>
8  University of Liverpool & STFC Rutherford Appleton Lab - November 26, 2004
9 
10  For the class documentation see the corresponding header file.
11 
12  Important revisions after version 2.0.0 :
13  @ Jun 25, 2008 - CA
14  Partial re-write to fix a serious memory leak. Holding x,y values in a map
15  rather than a circular ntuple.
16 
17 */
18 //____________________________________________________________________________
19 
21 
22 using namespace genie;
23 
25 
26 //____________________________________________________________________________
27 namespace genie
28 {
29  ostream & operator << (ostream & stream, const CacheBranchFx & cbntp)
30  {
31  cbntp.Print(stream);
32  return stream;
33  }
34 }
35 //____________________________________________________________________________
38 {
39  this->Init();
40 }
41 //____________________________________________________________________________
44 {
45  this->Init();
46  fName = name;
47 }
48 //____________________________________________________________________________
50 {
51  this->CleanUp();
52 }
53 //____________________________________________________________________________
55 {
56  fName = "";
57  fSpline = 0;
58 }
59 //____________________________________________________________________________
61 {
62  if(fSpline) delete fSpline;
63  fFx.clear();
64 }
65 //____________________________________________________________________________
67 {
68  this->CleanUp();
69  this->Init();
70 }
71 //____________________________________________________________________________
72 void CacheBranchFx::AddValues(double x, double y)
73 {
74  fFx.insert(map<double,double>::value_type(x,y));
75 }
76 //____________________________________________________________________________
78 {
79  int n = fFx.size();
80  double * x = new double[n];
81  double * y = new double[n];
82 
83  int i=0;
84  map<double,double>::const_iterator iter = fFx.begin();
85  for( ; iter !=fFx.end(); ++iter) {
86  x[i] = iter->first;
87  y[i] = iter->second;
88  i++;
89  }
90 
91  if(fSpline) delete fSpline;
92  fSpline = new Spline(n,x,y);
93 
94  delete [] x;
95  delete [] y;
96 }
97 //____________________________________________________________________________
98 void CacheBranchFx::Print(ostream & stream) const
99 {
100  stream << "type: [CacheBranchFx] - nentries: " << fFx.size()
101  << " / spline: " << ((fSpline) ? "built" : "null");
102 }
103 //____________________________________________________________________________
104 double CacheBranchFx::operator () (double x) const
105 {
106  if(!fSpline) return 0;
107  else return fSpline->Evaluate(x);
108 }
109 //____________________________________________________________________________
const XML_Char * name
Definition: expat.h:151
THE MAIN GENIE PROJECT NAMESPACE
Definition: GeneratorBase.h:8
void Print(ostream &stream) const
map< double, double > fFx
x->y map
Definition: CacheBranchFx.h:64
A numeric analysis tool class for interpolating 1-D functions.
Definition: Spline.h:47
string fName
cache branch name
Definition: CacheBranchFx.h:63
double Evaluate(double x) const
Definition: Spline.cxx:362
void AddValues(double x, double y)
Spline * fSpline
spline y = f(x)
Definition: CacheBranchFx.h:65
ostream & operator<<(ostream &stream, const AlgConfigPool &config_pool)
ClassImp(CacheBranchFx)
double operator()(double x) const
A simple cache branch storing the cached data in a TNtuple.
Definition: CacheBranchFx.h:38
The TObject at the root of concrete cache branches.
Definition: CacheBranchI.h:26