GHepRecordHistory.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 - September 23, 2005
9 
10  For the class documentation see the corresponding header file.
11 
12  Important revisions after version 2.0.0 :
13 
14 */
15 //____________________________________________________________________________
16 
17 #include <TSystem.h>
18 
23 
24 using std::endl;
25 
26 using namespace genie;
27 using namespace genie::utils;
28 
29 //____________________________________________________________________________
30 namespace genie {
31  ostream & operator << (ostream & stream, const GHepRecordHistory & history)
32  {
33  history.Print(stream);
34  return stream;
35  }
36 }
37 //___________________________________________________________________________
39 map<int, GHepRecord*>()
40 {
41  this->ReadFlags();
42 }
43 //___________________________________________________________________________
45 map<int, GHepRecord*>()
46 {
47  this->Copy(history);
48  this->ReadFlags();
49 }
50 //___________________________________________________________________________
52 {
53  this->PurgeHistory();
54 }
55 //___________________________________________________________________________
57 {
58 // Adds a GHepRecord 'snapshot' at the history buffer
59 
60  bool go_on = (fEnabledFull || (fEnabledBootstrapStep && step==-1));
61  if(!go_on) return;
62 
63  if(!record) {
64  LOG("GHEP", pWARN)
65  << "Input GHEP record snapshot is null. Is not added at history record";
66  return;
67  }
68 
69  if( this->count(step) == 0 ) {
70 
71  LOG("GHEP", pNOTICE)
72  << "Adding GHEP snapshot for processing step: " << step;
73 
74  GHepRecord * snapshot = new GHepRecord(*record);
75  this->insert( map<int, GHepRecord*>::value_type(step,snapshot));
76 
77  } else {
78  // If you have already stepped back and reprocessing, then you should
79  // have purged the 'recent' history (corresponing to 'after the return
80  // processing step')
81  LOG("GHEP", pWARN)
82  << "GHEP snapshot for processing step: " << step << " already exists!";
83  }
84 }
85 //___________________________________________________________________________
87 {
88  LOG("GHEP", pNOTICE) << "Purging GHEP history buffer";
89 
90  GHepRecordHistory::iterator history_iter;
91  for(history_iter = this->begin();
92  history_iter != this->end(); ++history_iter) {
93 
94  int step = history_iter->first;
95  LOG("GHEP", pINFO)
96  << "Deleting GHEP snapshot for processing step: " << step;
97 
98  GHepRecord * record = history_iter->second;
99  if(record) {
100  delete record;
101  record = 0;
102  }
103  }
104  this->clear();
105 }
106 //___________________________________________________________________________
108 {
109 // Snapshots are added to the history record *after* each processing step
110 // (marked 0,1,2,...). A special snapshot corresponding to the event record
111 // before any processing step is added with key = -1.
112 // Therefore GHepRecordHistory keys should be: -1,0,1,2,3,...
113 
114  LOG("GHEP", pNOTICE)
115  << "Purging recent GHEP history buffer (processing step >= "
116  << start_step << ")";
117 
118  if(start_step < -1) {
119  LOG("GHEP", pWARN)
120  << "Invalid starting step: " << start_step << " - Ignoring";
121  return;
122  }
123 
124  if(start_step == -1) {
125  // delete everything
126  this->PurgeHistory();
127  return;
128  }
129 
130  GHepRecordHistory::iterator history_iter;
131  for(history_iter = this->begin();
132  history_iter != this->end(); ++history_iter) {
133 
134  if(history_iter->first >= start_step) {
135  int step = history_iter->first;
136  LOG("GHEP", pINFO)
137  << "Deleting GHEP snapshot for processing step: " << step;
138  this->erase(history_iter);
139  }
140  }
141 }
142 //___________________________________________________________________________
144 {
145  this->PurgeHistory();
146 
147  GHepRecordHistory::const_iterator history_iter;
148  for(history_iter = history.begin();
149  history_iter != history.end(); ++history_iter) {
150 
151  unsigned int step = history_iter->first;
152  GHepRecord * record = history_iter->second;
153 
154  this->AddSnapshot(step, record);
155  }
156 }
157 //___________________________________________________________________________
158 void GHepRecordHistory::Print(ostream & stream) const
159 {
160  stream << "\n ****** Printing GHEP record history"
161  << " [depth: " << this->size() << "]" << endl;
162 
163  GHepRecordHistory::const_iterator history_iter;
164  for(history_iter = this->begin();
165  history_iter != this->end(); ++history_iter) {
166 
167  unsigned int step = history_iter->first;
168  GHepRecord * record = history_iter->second;
169 
170  stream << "\n[After processing step = " << step << "] :";
171 
172  if(!record) {
173  stream
174  << "** ERR: No history record available for this processing step!";
175  } else {
176  stream << *record;
177  }
178  }
179 }
180 //___________________________________________________________________________
182 {
183  if (gSystem->Getenv("GHEPHISTENABLE")) {
184 
185  string envvar = string(gSystem->Getenv("GHEPHISTENABLE"));
186 
187  fEnabledFull = (envvar=="FULL") ? true:false;
188  fEnabledBootstrapStep = (envvar=="BOOTSTRAP") ? true:false;
189 
190  } else {
191  // set defaults
192  fEnabledFull = false;
193  fEnabledBootstrapStep = true;
194  }
195 
196  LOG("GHEP", pINFO) << "GHEP History Flags: ";
197  LOG("GHEP", pINFO) << " - Keep Full History: "
199  LOG("GHEP", pINFO) << " - Keep Bootstrap Record Only: "
201 }
202 //___________________________________________________________________________
203 
def history()
Definition: g4zmq.py:84
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: GeneratorBase.h:8
string BoolAsYNString(bool b)
Definition: PrintUtils.cxx:115
vector< vector< double > > clear
void Print(ostream &stream) const
ostream & operator<<(ostream &stream, const T2KEvGenMetaData &md)
void PurgeRecentHistory(int start_step)
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:97
void AddSnapshot(int step, GHepRecord *r)
#define pINFO
Definition: Messenger.h:63
#define pWARN
Definition: Messenger.h:61
void Copy(const GHepRecordHistory &history)
def insert(astring, substr, pos, overwrite=True)
bool fEnabledFull
keep the full GHEP record history
#define pNOTICE
Definition: Messenger.h:62
GENIE&#39;s GHEP MC event record.
Definition: GHepRecord.h:46
Root of GENIE utility namespaces.
enum BeamMode string