GVldContext.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 - November 20, 2004
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 <algorithm>
18 
24 
25 using std::count;
26 
27 using namespace genie;
28 
29 //___________________________________________________________________________
30 namespace genie {
31  ostream & operator<< (ostream& stream, const GVldContext & vldc)
32  {
33  vldc.Print(stream);
34  return stream;
35  }
36 }
37 //___________________________________________________________________________
39 {
40  this->Init();
41 }
42 //___________________________________________________________________________
44 {
45 
46 }
47 //___________________________________________________________________________
48 void GVldContext::Decode(string encoded_vld_context)
49 {
50 //Example:
51 // energy:0-100;
52 
53  string vldc = utils::str::ToUpper(encoded_vld_context);
54 
55  // set defauts for missing entries
57  const Registry * gc = confp->CommonList("Param", "Validation");
58 
59  if(vldc.find("ENERGY") == string::npos) {
60  fEmin = gc->GetDouble("GVLD-Emin");
61  fEmax = gc->GetDouble("GVLD-Emax");
62  }
63 
64  LOG("VldContext", pDEBUG) << "Validity context: " << vldc;
65 
66  vector<string> fields = utils::str::Split(vldc, ";");
67  if(fields.size()==0) return;
68 
69  vector<string>::const_iterator field_iter;
70 
71  for(field_iter = fields.begin(); field_iter != fields.end(); ++field_iter){
72 
73  string curr_field = *field_iter;
74  SLOG("VldContext", pINFO) << " ************ " << curr_field;
75  if(curr_field.size()==0) continue;
76 
77  vector<string> curr_fieldv = utils::str::Split(curr_field, ":");
78  assert(curr_fieldv.size() == 2);
79 
80  string name = curr_fieldv[0];
81  string values = curr_fieldv[1];
82 
83  //-- send the string to an appropriate decoder
84  if (name.find("ENERGY") != string::npos) DecodeENERGY (values);
85  else {
86  SLOG("VldContext", pWARN)
87  << "**** Unknown field named: " << name << " in vld context";
88  }
89  }
90 }
91 //___________________________________________________________________________
92 void GVldContext::DecodeENERGY(string encoded_energy)
93 {
94  SLOG("VldContext", pDEBUG) << "Decoding energy range: " << encoded_energy;
95 
96  vector<string> energy = utils::str::Split(encoded_energy, "-");
97  assert (energy.size() == 2);
98  fEmin = atof( energy[0].c_str() );
99  fEmax = atof( energy[1].c_str() );
100 }
101 //___________________________________________________________________________
103 {
104  fEmin = -1.0;
105  fEmax = -1.0;
106 }
107 //___________________________________________________________________________
108 void GVldContext::Print(ostream & stream) const
109 {
110  stream << "Energy range:..." << "[" << fEmin << ", " << fEmax << "]";
111  stream << "\n";
112 }
113 //___________________________________________________________________________
const XML_Char * name
Definition: expat.h:151
THE MAIN GENIE PROJECT NAMESPACE
Definition: GeneratorBase.h:8
A singleton class holding all configuration registries built while parsing all loaded XML configurati...
Definition: AlgConfigPool.h:41
void Print(ostream &stream) const
RgDbl GetDouble(RgKey key) const
Definition: Registry.cxx:489
Registry * CommonList(const string &file_id, const string &set_name) const
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:97
double energy
Definition: plottest35.C:25
void DecodeENERGY(string encoded_values)
Definition: GVldContext.cxx:92
#define pINFO
Definition: Messenger.h:63
#define pWARN
Definition: Messenger.h:61
vector< string > Split(string input, string delim)
Definition: StringUtils.cxx:42
ostream & operator<<(ostream &stream, const AlgConfigPool &config_pool)
A registry. Provides the container for algorithm configuration parameters.
Definition: Registry.h:66
assert(nhit_max >=nhit_nbins)
string ToUpper(string input)
Definition: StringUtils.cxx:98
#define SLOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a short string (using the FUNCTION and...
Definition: Messenger.h:85
Validity Context for an Event Generator.
Definition: GVldContext.h:38
static AlgConfigPool * Instance()
#define pDEBUG
Definition: Messenger.h:64
void Decode(string encoded_values)
Definition: GVldContext.cxx:48