Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
RooAbsDataStore.cxx
Go to the documentation of this file.
1 /*****************************************************************************
2  * Project: RooFit *
3  * Package: RooFitCore *
4  * @(#)root/roofitcore:$Id$
5  * Authors: *
6  * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu *
7  * DK, David Kirkby, UC Irvine, dkirkby@uci.edu *
8  * *
9  * Copyright (c) 2000-2005, Regents of the University of California *
10  * and Stanford University. All rights reserved. *
11  * *
12  * Redistribution and use in source and binary forms, *
13  * with or without modification, are permitted according to the terms *
14  * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
15  *****************************************************************************/
16 
17 /**
18 \file RooAbsDataStore.cxx
19 \class RooAbsDataStore
20 \ingroup Roofitcore
21 
22 RooAbsDataStore is the abstract base class for data collection that
23 use a TTree as internal storage mechanism
24 **/
25 
26 #include "RooFit.h"
27 #include "RooMsgService.h"
28 #include "RooAbsDataStore.h"
29 
30 #include "Riostream.h"
31 #include <iomanip>
32 #include "TClass.h"
33 
34 using namespace std ;
35 
36 ClassImp(RooAbsDataStore);
37 ;
38 
39 
40 ////////////////////////////////////////////////////////////////////////////////
41 /// Default constructor
42 
43 RooAbsDataStore::RooAbsDataStore()
44 {
45  _doDirtyProp = kTRUE ;
46 }
47 
48 
49 
50 
51 ////////////////////////////////////////////////////////////////////////////////
52 /// Default constructor
53 
54 RooAbsDataStore::RooAbsDataStore(const char* name, const char* title, const RooArgSet& vars) :
55  TNamed(name,title)
56 {
57  // clone the fundamentals of the given data set into internal buffer
58  _vars.add(vars) ;
59 
60  _doDirtyProp = kTRUE ;
61 }
62 
63 
64 
65 
66 ////////////////////////////////////////////////////////////////////////////////
67 
68 RooAbsDataStore::RooAbsDataStore(const RooAbsDataStore& other, const char* newname) : TNamed(other), RooPrintable(other)
69 {
70  if (newname) {
71  SetName(newname) ;
72  }
73  _vars.add(other._vars) ;
74  _doDirtyProp = other._doDirtyProp ;
75 }
76 
77 
78 
79 ////////////////////////////////////////////////////////////////////////////////
80 
81 RooAbsDataStore::RooAbsDataStore(const RooAbsDataStore& other, const RooArgSet& vars, const char* newname) : TNamed(other), RooPrintable(other)
82 {
83  if (newname) {
84  SetName(newname) ;
85  }
86  _vars.add(vars) ;
87  _doDirtyProp = other._doDirtyProp ;
88 }
89 
90 
91 
92 ////////////////////////////////////////////////////////////////////////////////
93 /// Destructor
94 
95 RooAbsDataStore::~RooAbsDataStore()
96 {
97 
98 }
99 
100 
101 
102 ////////////////////////////////////////////////////////////////////////////////
103 /// Return true if currently loaded coordinate is considered valid within
104 /// the current range definitions of all observables
105 
106 Bool_t RooAbsDataStore::valid() const
107 {
108  return kTRUE ;
109 }
110 
111 
112 ////////////////////////////////////////////////////////////////////////////////
113 /// Print name of dataset
114 
115 void RooAbsDataStore::printName(ostream& os) const
116 {
117  os << GetName() ;
118 }
119 
120 
121 
122 ////////////////////////////////////////////////////////////////////////////////
123 /// Print title of dataset
124 
125 void RooAbsDataStore::printTitle(ostream& os) const
126 {
127  os << GetTitle() ;
128 }
129 
130 
131 
132 ////////////////////////////////////////////////////////////////////////////////
133 /// Print class name of dataset
134 
135 void RooAbsDataStore::printClassName(ostream& os) const
136 {
137  os << IsA()->GetName() ;
138 }
139 
140 
141 
142 ////////////////////////////////////////////////////////////////////////////////
143 /// Print value of the dataset, i.e. the sum of weights contained in the dataset
144 
145 void RooAbsDataStore::printValue(ostream& os) const
146 {
147  os << numEntries() << " entries" ;
148 }
149 
150 
151 
152 ////////////////////////////////////////////////////////////////////////////////
153 /// Print argument of dataset, i.e. the observable names
154 
155 void RooAbsDataStore::printArgs(ostream& os) const
156 {
157  os << "[" ;
158  Bool_t first(kTRUE) ;
159  for (const auto arg : _vars) {
160  if (first) {
161  first=kFALSE ;
162  } else {
163  os << "," ;
164  }
165  os << arg->GetName() ;
166  }
167  os << "]" ;
168 }
169 
170 
171 
172 
173 
174 
175 ////////////////////////////////////////////////////////////////////////////////
176 /// Define default print options, for a given print style
177 
178 Int_t RooAbsDataStore::defaultPrintContents(Option_t* /*opt*/) const
179 {
180  return kName|kClassName|kArgs|kValue ;
181 }
182 
183 
184 
185 
186 
187 ////////////////////////////////////////////////////////////////////////////////
188 /// Detailed printing interface
189 
190 void RooAbsDataStore::printMultiline(ostream& os, Int_t /*content*/, Bool_t verbose, TString indent) const
191 {
192  os << indent << "DataStore " << GetName() << " (" << GetTitle() << ")" << endl ;
193  os << indent << " Contains " << numEntries() << " entries" << endl;
194 
195  if (!verbose) {
196  os << indent << " Observables " << _vars << endl ;
197  } else {
198  os << indent << " Observables: " << endl ;
199  _vars.printStream(os,kName|kValue|kExtras|kTitle,kVerbose,indent+" ") ;
200  }
201 
202  if(verbose) {
203  if (_cachedVars.getSize()>0) {
204  os << indent << " Caches " << _cachedVars << endl ;
205  }
206 // if(_truth.getSize() > 0) {
207 // os << indent << " Generated with ";
208 // TString deeper(indent) ;
209 // deeper += " " ;
210 // _truth.printStream(os,kName|kValue,kStandard,deeper) ;
211 // }
212  }
213 }
214 
215 
216 
217 ////////////////////////////////////////////////////////////////////////////////
218 /// Get the weights of the events in the range [first, last[.
219 /// This is a slow default implementation that will fill a vector with every
220 /// event retrieved one by one.
221 /// Derived classes may just return the range of the original data.
222 
223 RooSpan<const double> RooAbsDataStore::getWeightBatch(std::size_t first, std::size_t last) const {
224 
225  std::vector<double> ret;//TODO try to align storage
226  ret.reserve(last-first);
227 
228  for (auto i = first; i < last; ++i) {
229  ret.push_back(weight(i));
230  }
231 
232  return RooSpan<const double>(std::move(ret));
233 }
234