MINT2
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | Private Attributes | List of all members
DiskResidentEventList Class Reference

#include <DiskResidentEventList.h>

Inheritance diagram for DiskResidentEventList:
MINT::IMinimalEventList< DalitzEvent >

Public Member Functions

 DiskResidentEventList ()
 
 DiskResidentEventList (const std::string &fname, const std::string &opt="UPDATE")
 
 DiskResidentEventList (const std::string &fname, int scales, const std::string &treeName, const std::string &opt="UPDATE")
 
 DiskResidentEventList (const DalitzEventPattern &pat)
 
 DiskResidentEventList (const DalitzEventPattern &pat, const std::string &fname, const std::string &opt="RECREATE")
 
 DiskResidentEventList (const MINT::IMinimalEventList< DalitzEvent > &otherList)
 
 DiskResidentEventList (const MINT::IMinimalEventList< DalitzEvent > &otherList, const std::string &newFname, const std::string &opt="RECREATE")
 
virtual ~DiskResidentEventList ()
 
virtual unsigned int size () const
 
virtual bool empty () const
 
DalitzEvent getEvent (unsigned int i) const
 
virtual bool Add (const DalitzEvent &evt)
 
bool Add (const IDalitzEvent &evt)
 
bool Add (const IDalitzEvent *evt)
 
bool Add (const MINT::counted_ptr< IDalitzEvent > &evt)
 
bool Add (const MINT::IMinimalEventList< DalitzEvent > &otherList)
 
bool save ()
 
bool Close ()
 
DalitzHistoSet histoSet () const
 
DalitzHistoSet weightedHistoSet () const
 
DalitzHistoSet reWeightedHistoSet (MINT::IReturnRealForEvent< IDalitzEvent > *w) const
 
DalitzHistoSet weighedReWeightedHistoSet (MINT::IReturnRealForEvent< IDalitzEvent > *w) const
 
bool makePlots (const std::string &filename)
 
DalitzEvent operator() (unsigned int i)
 

Static Public Member Functions

static std::string generateFname ()
 

Protected Member Functions

std::string cName ()
 
std::string ntpName ()
 
bool openFile ()
 
bool makeNtp (const DalitzEvent &evt)
 
bool makeNewFile ()
 
bool fromFile ()
 
bool init ()
 
- Protected Member Functions inherited from MINT::IMinimalEventList< DalitzEvent >
 IMinimalEventList ()
 

Protected Attributes

std::string _fname
 
std::string _opt
 
TFile * _f
 
TNtupleD * _ntp
 
double _scaleData
 
bool _initialised
 

Static Protected Attributes

static int __maxBytes = 10000000
 

Private Attributes

std::string _cName
 
std::string _ntpName
 

Detailed Description

Definition at line 26 of file DiskResidentEventList.h.

Constructor & Destructor Documentation

◆ DiskResidentEventList() [1/7]

DiskResidentEventList::DiskResidentEventList ( )

Definition at line 45 of file DiskResidentEventList.cpp.

47  , _opt("UPDATE")
48  , _f(0)//new TFile(generateFname().c_str(), "UPDATE"))
49  , _ntp(0)
50  , _scaleData(1)
51  , _cName("DalitzEventList")
52  , _ntpName("DalitzEventList")
53 {
54  openFile();
55  init();
56 }
static std::string generateFname()

◆ DiskResidentEventList() [2/7]

DiskResidentEventList::DiskResidentEventList ( const std::string &  fname,
const std::string &  opt = "UPDATE" 
)

Definition at line 79 of file DiskResidentEventList.cpp.

81  : _fname(fname)
82  , _opt(boost::to_upper_copy(opt))
83  , _f(0)//new TFile(fname.c_str(), opt.c_str()))
84  , _ntp(0)
85  , _scaleData(1)
86  , _cName("DalitzEventList")
87  , _ntpName("DalitzEventList")
88 {
89  bool dbThis=false;
90  openFile();
91  cout << "DiskResidentEventList created with file " << fname << endl;
92  fromFile();
93  if(dbThis)cout << " from file done, now init: " << endl;
94  init();
95  if(dbThis)cout << " finished creation" << endl;
96 }

◆ DiskResidentEventList() [3/7]

DiskResidentEventList::DiskResidentEventList ( const std::string &  fname,
int  scales,
const std::string &  treeName,
const std::string &  opt = "UPDATE" 
)

Definition at line 58 of file DiskResidentEventList.cpp.

62  : _fname(fname)
63  , _opt(boost::to_upper_copy(opt))
64  , _f(0)//new TFile(fname.c_str(), opt.c_str()))
65  , _ntp(0)
66  , _scaleData(scale)
67  , _cName(treeName)
68  , _ntpName(treeName+"NTP")
69 {
70  bool dbThis=true;
71  openFile();
72  cout << "DiskResidentEventList created with file " << fname << endl;
73  fromFile();
74  if(dbThis)cout << " from file done, now init: " << endl;
75  init();
76  if(dbThis)cout << " finished creation" << endl;
77 }

◆ DiskResidentEventList() [4/7]

DiskResidentEventList::DiskResidentEventList ( const DalitzEventPattern pat)

Definition at line 177 of file DiskResidentEventList.cpp.

178  : _fname(generateFname())
179  , _opt("UPDATE")
180  , _f(0)//new TFile(generateFname().c_str(), "RECREATE"))
181  , _ntp(0)
182  , _scaleData(1)
183  , _cName("DalitzEventList")
184  , _ntpName("DalitzEventList")
185 {
186  openFile();
187  DalitzEvent evt(pat);
188  makeNtp(evt); // evt won't be saved, just to use "makeNtupleVarname" (clumsy)
189  init();
190 }
bool makeNtp(const DalitzEvent &evt)
static std::string generateFname()

◆ DiskResidentEventList() [5/7]

DiskResidentEventList::DiskResidentEventList ( const DalitzEventPattern pat,
const std::string &  fname,
const std::string &  opt = "RECREATE" 
)

Definition at line 192 of file DiskResidentEventList.cpp.

196  : _fname(fname)
197  , _opt(boost::to_upper_copy(opt))
198  , _f(0)//new TFile(fname.c_str(), opt.c_str()))
199  , _ntp(0)
200  , _scaleData(1)
201  , _cName("DalitzEventList")
202  , _ntpName("DalitzEventList")
203 {
204  openFile();
205  fromFile();
206  DalitzEvent evt(pat);
207  if(0 == _ntp) makeNtp(evt);
208  init();
209 }
bool makeNtp(const DalitzEvent &evt)

◆ DiskResidentEventList() [6/7]

DiskResidentEventList::DiskResidentEventList ( const MINT::IMinimalEventList< DalitzEvent > &  otherList)

Definition at line 99 of file DiskResidentEventList.cpp.

100  : _fname(generateFname())
101  , _opt("UPDATE")
102  , _f(0)//new TFile(generateFname().c_str(), "UPDATE"))
103  , _ntp(0)
104  , _scaleData(1)
105  , _cName("DalitzEventList")
106  , _ntpName("DalitzEventList")
107 {
108  openFile();
109  Add(otherList);
110  init();
111 }
virtual bool Add(const DalitzEvent &evt)
static std::string generateFname()

◆ DiskResidentEventList() [7/7]

DiskResidentEventList::DiskResidentEventList ( const MINT::IMinimalEventList< DalitzEvent > &  otherList,
const std::string &  newFname,
const std::string &  opt = "RECREATE" 
)

Definition at line 125 of file DiskResidentEventList.cpp.

129  : _fname(newFname)
130  , _opt(boost::to_upper_copy(opt))
131  , _f(0)//new TFile(newFname.c_str(), opt.c_str()))
132  // , _counted_ntp(0)
133  , _ntp(0)
134  , _scaleData(1)
135  , _cName("DalitzEventList")
136  , _ntpName("DalitzEventList")
137 {
138  openFile();
139  cout << " copy with new filename : " << newFname << endl;
140  cout << " file pointer: " << _f << endl;
141  fromFile();
142  Add(otherList);
143  init();
144 }
virtual bool Add(const DalitzEvent &evt)

◆ ~DiskResidentEventList()

DiskResidentEventList::~DiskResidentEventList ( )
virtual

Definition at line 211 of file DiskResidentEventList.cpp.

211  {
212  this->Close();
213 }

Member Function Documentation

◆ Add() [1/5]

bool DiskResidentEventList::Add ( const DalitzEvent evt)
virtual

Implements MINT::IMinimalEventList< DalitzEvent >.

Definition at line 322 of file DiskResidentEventList.cpp.

322  {
323  if(0 == _f) makeNewFile();
324  _f->cd();
325  if(0 == _ntp) makeNtp(evt);
326  unsigned int arraySize = evt.ntupleVarArraySize();
327  vector<Double_t> array(arraySize);
328 
329  bool success = evt.fillNtupleVarArray(array);
330  if(! success){
331  cout << "ERROR in DiskResidentEventList::Add(const DalitzEvent& evt)"
332  << ", call to DalitzEvent::fillNtupleVarArray"
333  << " returned failure for event:\n" << evt
334  << endl;
335  }else{
336  //_f = _ntp->GetCurrentFile();
337  //_f->cd();
338  _ntp->Fill(&(array[0]));
339  _f = _ntp->GetCurrentFile();
340  // above lines: to pick up when TNtuple (TTree) changes
341  // files in case the current one is too big. All this
342  // rubbish is necessary because of root's crazy way of
343  // handling this.
344  }
345 
346  return true;
347 }
bool makeNtp(const DalitzEvent &evt)
bool fillNtupleVarArray(std::vector< Double_t > &array) const
unsigned int ntupleVarArraySize() const

◆ Add() [2/5]

bool DiskResidentEventList::Add ( const IDalitzEvent evt)

Definition at line 349 of file DiskResidentEventList.cpp.

349  {
350  DalitzEvent nevt(&evt);
351  return Add(nevt);
352 }
virtual bool Add(const DalitzEvent &evt)

◆ Add() [3/5]

bool DiskResidentEventList::Add ( const IDalitzEvent evt)

Definition at line 353 of file DiskResidentEventList.cpp.

353  {
354  DalitzEvent nevt(evt);
355  return Add(nevt);
356 }
virtual bool Add(const DalitzEvent &evt)

◆ Add() [4/5]

bool DiskResidentEventList::Add ( const MINT::counted_ptr< IDalitzEvent > &  evt)

Definition at line 357 of file DiskResidentEventList.cpp.

357  {
358  DalitzEvent nevt(evt.get());
359  return Add(nevt);
360 }
virtual bool Add(const DalitzEvent &evt)
X * get() const
Definition: counted_ptr.h:123

◆ Add() [5/5]

bool DiskResidentEventList::Add ( const MINT::IMinimalEventList< DalitzEvent > &  otherList)

Definition at line 361 of file DiskResidentEventList.cpp.

361  {
362  if(0 == otherList.size()) return false;
363  for(unsigned int i=0; i < otherList.size(); i++){
364  Add(otherList.getEvent(i));
365  }
366  return true;
367 }
virtual bool Add(const DalitzEvent &evt)
virtual EVENT_TYPE getEvent(unsigned int i) const =0
virtual unsigned int size() const =0

◆ Close()

bool DiskResidentEventList::Close ( )

Definition at line 397 of file DiskResidentEventList.cpp.

397  {
398  bool dbThis=false;
399  bool success = true;
400 
401  if(dbThis){
402  cout << "DiskResidentEventList::Close() called"
403  << " for filename = " << _fname << endl;
404  }
405  if(0 == _f) return false;
406  if(0 == _ntp) return false;
407  // Don't understand why sometimes the TFile is already closed by the time the destructor is called,
408  // but this avoids crases since _ntp is invalidated.
409  if(!_f->IsOpen()) return false ;
410 
411  if(_opt.size() != 0 && _opt != "OPEN" && _opt != "READ"){
412  success &= save();
413  if(dbThis && ! success){
414  cout << "DiskResidentEventList::Close() failure in saving when closing"
415  << endl;
416  }
417  if(dbThis) cout << "saved file with success = " << success << endl;
418  }
419  //_f->cd();
420  //_ntp->Write();
421  //_f->Write();
422  if(dbThis) {
423  cout << "_f " << _f << " _ntp " << _ntp << endl ;
424  cout << "_f->IsOpen() " << _f->IsOpen() << endl ;
425  cout << "mustcleanup " << _f->TestBit(kMustCleanup) << endl ;
426  cout << "_ntp->GetName() " << _ntp->GetName() << endl ;
427  cout << "getting current file" << endl;
428  }
429  _f = _ntp->GetCurrentFile();
430  if(dbThis) cout << "_f = " << _f << endl;
431  _f->cd();
432  if(dbThis) cout << "cd'ed to _f and now about to Write" << endl;
433  // _f->Write();
434  if(dbThis) cout << "written,now closing" <<endl;
435  _f->Close();
436  if(dbThis) cout << "closed." << endl;
437  //delete _ntp;
438  //delete _f;
439  _f = 0;
440  _ntp = 0;
441 
442  (void)dbThis;
443  return success;
444 }

◆ cName()

std::string DiskResidentEventList::cName ( )
protected

Definition at line 23 of file DiskResidentEventList.cpp.

23  {
24  return _cName;}

◆ empty()

bool DiskResidentEventList::empty ( ) const
virtual

Definition at line 291 of file DiskResidentEventList.cpp.

291  {
292  return (0 == this->size());
293 }
virtual unsigned int size() const

◆ fromFile()

bool DiskResidentEventList::fromFile ( )
protected

Definition at line 246 of file DiskResidentEventList.cpp.

246  {
247  bool dbThis=false;
248  if(dbThis) cout << "DiskResidentEventList::fromFile() called" << endl;
249  if(0 == _f) makeNewFile();
250  if(_f->IsZombie()){
251  cout << "WARNING in DiskResidentEventList::fromFile():"
252  << " current file is zombie - making new one" << endl;
253  makeNewFile();
254  }
255  if(dbThis) cout << " opened file" << endl;
256  if(dbThis) _f->ls(); cout << " that's in it" << endl;
257  _f->cd();
258  if(dbThis){
259  cout << " cd'ed to file " << endl;
260  cout << " now calling " << "_f->Get(" << cName() << ")" << endl;
261  }
262  _ntp = (TNtupleD*) _f->Get(cName().c_str());
263  if(dbThis) cout << " got ntuple : " << _ntp << endl;
264  if(0 == _ntp){
265  return false;
266  }else{
267  if(dbThis){
268  cout << "Success in DiskResidentEventList::fromFile(): "
269  << " found ntuple: " << _ntp->ClassName() << ", " << cName()
270  << " in file: ";
271  _f->Print();
272  cout << endl;
273  }
274  }
275  if(dbThis) cout << " now calling init" << endl;
276  init();
277  if(dbThis) cout << "DiskResidentEventList::fromFile() returning 'true'"
278  << endl;
279  return true;
280 }

◆ generateFname()

std::string DiskResidentEventList::generateFname ( )
static

Definition at line 29 of file DiskResidentEventList.cpp.

29  {
30  string baseName = "DiskResidentEventList";
31  string name = baseName;
32  bool exists = true;
33  ofstream checkFile;
34  int i=0;
35  do{
36  name = baseName + "_" + anythingToString(i++) + ".root";
37  checkFile.open( name.c_str(), ios::in );
38  exists = ! checkFile.fail();
39  checkFile.close();
40  }while(exists);
41 
42  return name;
43 }
bool exists(const string &fname)
std::string anythingToString(const T &anything)
Definition: Utils.h:62

◆ getEvent()

DalitzEvent DiskResidentEventList::getEvent ( unsigned int  i) const
virtual

Implements MINT::IMinimalEventList< DalitzEvent >.

Definition at line 447 of file DiskResidentEventList.cpp.

447  {
448  if(i > size()){
449  cout << "FATAL ERROR in DiskResidentEventList::operator()"
450  << " index i=" << i << " out of range " << size()
451  << endl;
452  throw "index out of range";
453  }
454  if(0 == _ntp){
455  cout << "FATAL ERROR in DiskResidentEventList::operator()"
456  << "there is no ntuple "
457  << endl;
458  }
459  _ntp->GetEvent(i);
460  return DalitzEvent(_ntp);
461 }
virtual unsigned int size() const

◆ histoSet()

DalitzHistoSet DiskResidentEventList::histoSet ( ) const

Definition at line 463 of file DiskResidentEventList.cpp.

463  {
464  DalitzHistoSet hs;
465  for(unsigned int i=0; i< this->size(); i++){
466  hs.addEvent(this->getEvent(i));
467  }
468  return hs;
469 }
virtual unsigned int size() const
void addEvent(const IDalitzEvent &evt, double weight=1)
DalitzEvent getEvent(unsigned int i) const

◆ init()

bool DiskResidentEventList::init ( )
protected

Definition at line 282 of file DiskResidentEventList.cpp.

282  {
283  if(0 != _ntp) _ntp->SetAutoSave(__maxBytes);
284  return (0 != _ntp);
285 }

◆ makeNewFile()

bool DiskResidentEventList::makeNewFile ( )
protected

Definition at line 295 of file DiskResidentEventList.cpp.

295  {
296  _f = TFile::Open(generateFname().c_str(), "RECREATE");
297  // owned by gDirectory, I don't delete this myself.
298  return (0 != _f);
299 }
static std::string generateFname()

◆ makeNtp()

bool DiskResidentEventList::makeNtp ( const DalitzEvent evt)
protected

Definition at line 301 of file DiskResidentEventList.cpp.

301  {
302  if(0 == _f){
303  cout << "WARNING DiskResidentEventList::makeNtp - no file. "
304  << "That shouldn't happen. I'll have one made." << endl;
305  makeNewFile();
306  }
307  _f->cd();
308  _ntp = (TNtupleD*) _f->FindObject(ntpName().c_str());
309  if(0 == _ntp){
310  _ntp = new TNtupleD(cName().c_str(), ntpName().c_str()
311  , evt.makeNtupleVarnames().c_str()
312  );
313  cout << "made new ntuple" << endl;
314  }else{
315  cout << "found old ntuple" << endl;
316  }
317  if(0 != _ntp){
318  _ntp->SetAutoSave(__maxBytes);
319  }
320  return 0 != _ntp;
321 }
std::string makeNtupleVarnames() const

◆ makePlots()

bool DiskResidentEventList::makePlots ( const std::string &  filename)

Definition at line 502 of file DiskResidentEventList.cpp.

502  {
503  histoSet().save(filename);
504  return true;
505 }
DalitzHistoSet histoSet() const
bool save(const std::string &filename="DalitzHistos.root") const

◆ ntpName()

std::string DiskResidentEventList::ntpName ( )
protected

Definition at line 26 of file DiskResidentEventList.cpp.

26  {
27  return _ntpName;}

◆ openFile()

bool DiskResidentEventList::openFile ( )
protected

Definition at line 215 of file DiskResidentEventList.cpp.

215  {
216  bool dbThis=true;
217  if(dbThis){
218  cout << "Hello from DiskResidentEventList::openFile()" << endl;
219  cout << " calling: TFile("
220  << _fname << ", " << _opt << ", " << _fname << ")"
221  << endl;
222  }
223  if(0 == _f)_f = TFile::Open(_fname.c_str(), _opt.c_str()
224  , _fname.c_str()
225  );
226 
227  if(0 == _f) return makeNewFile();
228  if(_f->IsZombie()) return makeNewFile();
229  if(! _f->IsOpen()) return makeNewFile();
230  if(! _f->IsWritable()) {
231  //return makeNewFile();
232  cout << "Warning in DiskResidentEventList: file "
233  << _fname << " not writable!"
234  << endl;
235  }
236  if(dbThis){
237  cout << " got _f = " << _f << endl;
238  cout << " _f->ls() " << endl;
239  _f->ls();
240  cout << "?" << endl;
241  }
242 
243 // if (1 ==1) return makeNewFile();
244  return true;
245 }

◆ operator()()

DalitzEvent DiskResidentEventList::operator() ( unsigned int  i)

◆ reWeightedHistoSet()

DalitzHistoSet DiskResidentEventList::reWeightedHistoSet ( MINT::IReturnRealForEvent< IDalitzEvent > *  w) const

Definition at line 480 of file DiskResidentEventList.cpp.

480  {
481  // mainly for diagnostics
482  DalitzHistoSet hs;
483  if(0 == w) return hs;
484  for(unsigned int i=0; i< this->size(); i++){
485  DalitzEvent evt( this->getEvent(i));
486  hs.addEvent(evt, w->RealVal(evt));
487  }
488  return hs;
489 }
virtual double RealVal(EVENT_TYPE &evt)=0
virtual unsigned int size() const
void addEvent(const IDalitzEvent &evt, double weight=1)
DalitzEvent getEvent(unsigned int i) const

◆ save()

bool DiskResidentEventList::save ( )

Definition at line 375 of file DiskResidentEventList.cpp.

375  {
376  bool dbThis=false;
377  if(0 == _ntp) return false;
378  if(0 == _f) return false;
379  bool success=true;
380  if(dbThis){
381  cout << "DiskResidentEventList::save() called"
382  << " for filename = " << _fname << endl;
383  }
384  //_f->cd();
385  // success &=
386  //_f = _ntp->GetCurrentFile();
387  //_f->cd();
388  if(0 == _f || (! _f->IsWritable()) || (! _f->IsOpen())){
389  cout << "big problem with f in DiskResidentEventList::save()" << endl;
390  throw "Scheibenkartoffel";
391  }
392  _ntp->AutoSave();
393  if(dbThis)cout << " done the saving" << endl;
394  return success;
395 }

◆ size()

unsigned int DiskResidentEventList::size ( ) const
virtual

Implements MINT::IMinimalEventList< DalitzEvent >.

Definition at line 287 of file DiskResidentEventList.cpp.

287  {
288  if(0 == _ntp) return 0;
289  return _ntp->GetEntries()/_scaleData;
290 }

◆ weighedReWeightedHistoSet()

DalitzHistoSet DiskResidentEventList::weighedReWeightedHistoSet ( MINT::IReturnRealForEvent< IDalitzEvent > *  w) const

Definition at line 491 of file DiskResidentEventList.cpp.

491  {
492  // mainly for diagnostics
493  DalitzHistoSet hs;
494  if(0 == w) return hs;
495  for(unsigned int i=0; i< this->size(); i++){
496  DalitzEvent evt(this->getEvent(i));
497  hs.addEvent(evt, w->RealVal(evt) * (evt.getWeight()));
498  }
499  return hs;
500 }
virtual double RealVal(EVENT_TYPE &evt)=0
virtual unsigned int size() const
void addEvent(const IDalitzEvent &evt, double weight=1)
DalitzEvent getEvent(unsigned int i) const

◆ weightedHistoSet()

DalitzHistoSet DiskResidentEventList::weightedHistoSet ( ) const

Definition at line 471 of file DiskResidentEventList.cpp.

471  {
472  // mainly for diagnostics
473  DalitzHistoSet hs;
474  for(unsigned int i=0; i< this->size(); i++){
475  DalitzEvent evt(this->getEvent(i));
476  hs.addEvent(evt, evt.getWeight());
477  }
478  return hs;
479 }
virtual unsigned int size() const
void addEvent(const IDalitzEvent &evt, double weight=1)
DalitzEvent getEvent(unsigned int i) const

Member Data Documentation

◆ __maxBytes

int DiskResidentEventList::__maxBytes = 10000000
staticprotected

Definition at line 38 of file DiskResidentEventList.h.

◆ _cName

std::string DiskResidentEventList::_cName
private

Definition at line 111 of file DiskResidentEventList.h.

◆ _f

TFile* DiskResidentEventList::_f
protected

Definition at line 31 of file DiskResidentEventList.h.

◆ _fname

std::string DiskResidentEventList::_fname
protected

Definition at line 28 of file DiskResidentEventList.h.

◆ _initialised

bool DiskResidentEventList::_initialised
protected

Definition at line 36 of file DiskResidentEventList.h.

◆ _ntp

TNtupleD* DiskResidentEventList::_ntp
protected

Definition at line 32 of file DiskResidentEventList.h.

◆ _ntpName

std::string DiskResidentEventList::_ntpName
private

Definition at line 112 of file DiskResidentEventList.h.

◆ _opt

std::string DiskResidentEventList::_opt
protected

Definition at line 29 of file DiskResidentEventList.h.

◆ _scaleData

double DiskResidentEventList::_scaleData
protected

Definition at line 33 of file DiskResidentEventList.h.


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