GHepRecordHistory.cxx
Go to the documentation of this file.
1 //____________________________________________________________________________
2 /*
3  Copyright (c) 2003-2020, The GENIE Collaboration
4  For the full text of the license visit http://copyright.genie-mc.org
5 
6  Costas Andreopoulos <constantinos.andreopoulos \at cern.ch>
7  University of Liverpool & STFC Rutherford Appleton Laboratory
8 */
9 //____________________________________________________________________________
10 
11 #include <TSystem.h>
12 
17 
18 using std::endl;
19 
20 using namespace genie;
21 using namespace genie::utils;
22 
23 //____________________________________________________________________________
24 namespace genie {
25  ostream & operator << (ostream & stream, const GHepRecordHistory & history)
26  {
27  history.Print(stream);
28  return stream;
29  }
30 }
31 //___________________________________________________________________________
33 map<int, GHepRecord*>()
34 {
35  this->ReadFlags();
36 }
37 //___________________________________________________________________________
39 map<int, GHepRecord*>()
40 {
41  this->Copy(history);
42  this->ReadFlags();
43 }
44 //___________________________________________________________________________
46 {
47  this->PurgeHistory();
48 }
49 //___________________________________________________________________________
51 {
52 // Adds a GHepRecord 'snapshot' at the history buffer
53 
54  bool go_on = (fEnabledFull || (fEnabledBootstrapStep && step==-1));
55  if(!go_on) return;
56 
57  if(!record) {
58  LOG("GHEP", pWARN)
59  << "Input GHEP record snapshot is null. Is not added at history record";
60  return;
61  }
62 
63  if( this->count(step) == 0 ) {
64 
65  LOG("GHEP", pNOTICE)
66  << "Adding GHEP snapshot for processing step: " << step;
67 
68  GHepRecord * snapshot = new GHepRecord(*record);
69  this->insert( map<int, GHepRecord*>::value_type(step,snapshot));
70 
71  } else {
72  // If you have already stepped back and reprocessing, then you should
73  // have purged the 'recent' history (corresponing to 'after the return
74  // processing step')
75  LOG("GHEP", pWARN)
76  << "GHEP snapshot for processing step: " << step << " already exists!";
77  }
78 }
79 //___________________________________________________________________________
81 {
82  LOG("GHEP", pNOTICE) << "Purging GHEP history buffer";
83 
84  GHepRecordHistory::iterator history_iter;
85  for(history_iter = this->begin();
86  history_iter != this->end(); ++history_iter) {
87 
88  int step = history_iter->first;
89  LOG("GHEP", pINFO)
90  << "Deleting GHEP snapshot for processing step: " << step;
91 
92  GHepRecord * record = history_iter->second;
93  if(record) {
94  delete record;
95  record = 0;
96  }
97  }
98  this->clear();
99 }
100 //___________________________________________________________________________
102 {
103 // Snapshots are added to the history record *after* each processing step
104 // (marked 0,1,2,...). A special snapshot corresponding to the event record
105 // before any processing step is added with key = -1.
106 // Therefore GHepRecordHistory keys should be: -1,0,1,2,3,...
107 
108  LOG("GHEP", pNOTICE)
109  << "Purging recent GHEP history buffer (processing step >= "
110  << start_step << ")";
111 
112  if(start_step < -1) {
113  LOG("GHEP", pWARN)
114  << "Invalid starting step: " << start_step << " - Ignoring";
115  return;
116  }
117 
118  if(start_step == -1) {
119  // delete everything
120  this->PurgeHistory();
121  return;
122  }
123 
124  GHepRecordHistory::iterator history_iter;
125  for(history_iter = this->begin();
126  history_iter != this->end(); ++history_iter) {
127 
128  if(history_iter->first >= start_step) {
129  int step = history_iter->first;
130  LOG("GHEP", pINFO)
131  << "Deleting GHEP snapshot for processing step: " << step;
132  this->erase(history_iter);
133  }
134  }
135 }
136 //___________________________________________________________________________
138 {
139  this->PurgeHistory();
140 
142  for(history_iter = history.begin();
143  history_iter != history.end(); ++history_iter) {
144 
145  unsigned int step = history_iter->first;
146  GHepRecord * record = history_iter->second;
147 
148  this->AddSnapshot(step, record);
149  }
150 }
151 //___________________________________________________________________________
152 void GHepRecordHistory::Print(ostream & stream) const
153 {
154  stream << "\n ****** Printing GHEP record history"
155  << " [depth: " << this->size() << "]" << endl;
156 
158  for(history_iter = this->begin();
159  history_iter != this->end(); ++history_iter) {
160 
161  unsigned int step = history_iter->first;
162  GHepRecord * record = history_iter->second;
163 
164  stream << "\n[After processing step = " << step << "] :";
165 
166  if(!record) {
167  stream
168  << "** ERR: No history record available for this processing step!";
169  } else {
170  stream << *record;
171  }
172  }
173 }
174 //___________________________________________________________________________
176 {
177  if (gSystem->Getenv("GHEPHISTENABLE")) {
178 
179  string envvar = string(gSystem->Getenv("GHEPHISTENABLE"));
180 
181  fEnabledFull = (envvar=="FULL") ? true:false;
182  fEnabledBootstrapStep = (envvar=="BOOTSTRAP") ? true:false;
183 
184  } else {
185  // set defaults
186  fEnabledFull = false;
187  fEnabledBootstrapStep = true;
188  }
189 
190  LOG("GHEP", pINFO) << "GHEP History Flags: ";
191  LOG("GHEP", pINFO) << " - Keep Full History: "
193  LOG("GHEP", pINFO) << " - Keep Bootstrap Record Only: "
195 }
196 //___________________________________________________________________________
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
intermediate_table::iterator iterator
bool fEnabledBootstrapStep
keep only the record that bootsrapped the generation cycle
Holds the history of the GHEP event record as it being modified by the processing steps of an event g...
THE MAIN GENIE PROJECT NAMESPACE
Definition: AlgCmp.h:25
std::string string
Definition: nybbler.cc:12
string BoolAsYNString(bool b)
Definition: PrintUtils.cxx:108
void Print(ostream &stream) const
intermediate_table::const_iterator const_iterator
ostream & operator<<(ostream &stream, const T2KEvGenMetaData &md)
void PurgeRecentHistory(int start_step)
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
void AddSnapshot(int step, GHepRecord *r)
#define pINFO
Definition: Messenger.h:62
#define pWARN
Definition: Messenger.h:60
void Copy(const GHepRecordHistory &history)
bool fEnabledFull
keep the full GHEP record history
vector< vector< double > > clear
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:72
#define pNOTICE
Definition: Messenger.h:61
GENIE&#39;s GHEP MC event record.
Definition: GHepRecord.h:45
Root of GENIE utility namespaces.
QTextStream & endl(QTextStream &s)