MINT2
FromFileGenerator.cpp
Go to the documentation of this file.
1 // author: Jonas Rademacker (Jonas.Rademacker@bristol.ac.uk)
2 // status: Mon 9 Feb 2009 19:17:59 GMT
4 #include <iostream>
5 using namespace std;
6 using namespace MINT;
7 
8 FromFileGenerator::FromFileGenerator(const std::string& fname
9  , const std::string& ntpName)
10  : BaseGenerator()
11  , _opt("READ")
12  , _dL(fname,1,ntpName)
13  , _listExhausted(false)
14  , _listIndex(0)
15  , _gen(0)
16  , _doBootstrap("FromFileGenerator::doBootstrap",0)
17 {
18  cout << "FromFileGenerator::FromFileGenerator(" << fname << ")" << endl;
19  std::cout << "Got Intergrator events " << _dL.size() << std::endl;
20 
21  if(_doBootstrap){
22  while( _bootstrap_indices.size() < _dL.size() )_bootstrap_indices.push_back(TMath::Nint(gRandom->Uniform(0,_dL.size()-1)));
23  sort(_bootstrap_indices.begin(), _bootstrap_indices.end());
24  rotate(_bootstrap_indices.begin(),_bootstrap_indices.begin() + TMath::Nint(gRandom->Uniform(0,_dL.size()-1)), _bootstrap_indices.end());
25  }
26 
27 }
28 FromFileGenerator::FromFileGenerator(const std::string& fname
30  addThisWhenFileEmpty
31  , const std::string& opt
32  , const std::string& ntpName
33  )
34  : BaseGenerator()
35  , _opt( ("" != opt ? opt : ( 0 == addThisWhenFileEmpty ? "READ" : "UPDATE") ) )
36  , _dL(fname, 1, ntpName, _opt)
37  , _listExhausted(false)
38  , _listIndex(0)
39  , _gen(addThisWhenFileEmpty)
40  , _doBootstrap("FromFileGenerator::doBootstrap",0)
41 {
42  cout << " FromFileGenerator::FromFileGenerator(" << fname
43  << ", " << addThisWhenFileEmpty
44  << ", " << opt << ")" << endl;
45 
46  std::cout << "Got Intergrator events " << _dL.size() << std::endl;
47 
48  if(_doBootstrap){
49  while( _bootstrap_indices.size() < _dL.size() )_bootstrap_indices.push_back(TMath::Nint(gRandom->Uniform(0,_dL.size()-1)));
50  sort(_bootstrap_indices.begin(), _bootstrap_indices.end());
51  rotate(_bootstrap_indices.begin(),_bootstrap_indices.begin() + TMath::Nint(gRandom->Uniform(0,_dL.size()-1)), _bootstrap_indices.end());
52  }
53 }
54 
56  bool dbThis=false;
57 
58  if(0 == _gen) return counted_ptr<IDalitzEvent>(0);
60 
61  if(0 == evtPtr) return evtPtr;
62 
64  evtPtr->setMothers3Momentum(mothers3Momentum());
65  }
66 
67  if(_opt != "READ"){
68  if(dbThis){
69  cout << "FromFileGenerator::newEventFromGenerator():"
70  << " saving event to list"
71  << " opt = " << _opt << endl;
72  }
73  _dL.Add(*evtPtr);
74  _listIndex++;
75  }
76  return evtPtr;
77 }
80  if(_listIndex < _dL.size()){
81 
82  int index = _listIndex;
84 
86  if(mothers3MomentumIsSet() && 0 != evtPtr){
88  }
89  _listIndex++;
90  return evtPtr;
91  }else{
92  _listExhausted=true;
93  }
94  return newEventFromGenerator();
95 }
96 
98  if(! _listExhausted) return false;
99  if(0 == _gen) return true;
100  return _gen->exhausted();
101 }
102 
104  _listExhausted=true;
105  if(0 != _gen) _gen->ensureFreshEvents();
106  return true;
107 }
110 }
111 
113  return _dL.save();
114 }
116  return _dL.Close();
117 }
118 
120  return _dL;
121 }
123  return _dL;
124 }
125 
126 
127 //======
128 //
virtual void setMothers3Momentum(const TVector3 &mp3)
MINT::IEventGenerator< IDalitzEvent > * _gen
virtual bool saveFile()
virtual bool exhausted() const =0
std::vector< int > _bootstrap_indices
virtual bool exhausted() const
FromFileGenerator(const std::string &fname="integrationEvents.root", const std::string &ntpName="DalitzEventList")
virtual bool Add(const DalitzEvent &evt)
bool mothers3MomentumIsSet() const
unsigned int _listIndex
virtual MINT::counted_ptr< IDalitzEvent > newEventFromGenerator()
virtual unsigned int size() const
MINT::NamedParameter< int > _doBootstrap
virtual counted_ptr< RETURN_TYPE > newEvent()=0
DiskResidentEventList & getEventList()
virtual bool closeFile()
virtual bool ensureFreshEvents()=0
virtual bool ensureFreshEvents()
virtual MINT::counted_ptr< IDalitzEvent > newDalitzEvent()
TVector3 mothers3Momentum() const
DalitzEvent getEvent(unsigned int i) const
virtual MINT::counted_ptr< IDalitzEvent > newEvent()
DiskResidentEventList _dL