Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
genie::TuneId Class Reference

GENIE tune ID. More...

#include <TuneId.h>

Public Member Functions

 TuneId (const string &id_str, bool failOnInvalid=true)
 
 TuneId (const TuneId &id)
 
 ~TuneId ()
 
string Name (void) const
 
string Prefix (void) const
 
string Year (void) const
 
string ModelId (void) const
 
string MajorModelId (void) const
 
string MinorModelId (void) const
 
string TunedParamSetId (void) const
 
string FitDataSetId (void) const
 
bool IsConfigured (void) const
 
bool IsValidated (void) const
 
bool IsCustom (void) const
 
bool OnlyConfiguration () const
 
string CMC (void) const
 
string Tail (void) const
 
string CMCDirectory (void) const
 
string TuneDirectory (void) const
 
string BaseDirectory (void) const
 
string CustomSource (void) const
 
void Build (const string &name="")
 
void Decode (string id_str)
 
void Copy (const TuneId &id)
 
bool Compare (const TuneId &id) const
 
void Print (ostream &stream) const
 

Private Member Functions

 TuneId ()
 
bool CheckDirectory ()
 

Private Attributes

string fName
 
string fPrefix
 
string fYear
 
string fModelId
 
string fMajorModelId
 
string fMinorModelId
 
string fTunedParamSetId
 
string fFitDataSetId
 
string fBaseDirectory
 
string fCustomSource
 
bool fIsConfigured
 
bool fIsValidated
 

Friends

ostream & operator<< (ostream &stream, const TuneId &id)
 

Detailed Description

GENIE tune ID.

Author
Marco Roda <Marco.Roda liverpool.ac.uk> University of Liverpool

Costas Andreopoulos <constantinos.andreopoulos cern.ch> University of Liverpool & STFC Rutherford Appleton Laboratory

April 19, 2018

Copyright (c) 2003-2020, The GENIE Collaboration For the full text of the license visit http://copyright.genie-mc.org

Definition at line 37 of file TuneId.h.

Constructor & Destructor Documentation

TuneId::TuneId ( const string id_str,
bool  failOnInvalid = true 
)

Definition at line 52 of file TuneId.cxx.

53  : fName(genie::utils::str::TrimSpaces(id_str)) // remove any lead/trailing
54  , fIsConfigured(false)
55  , fIsValidated(false)
56 {
57  Build(fName);
58  if ( failOnInvalid && ! fIsValidated ) {
59  // status & 0377 is returned to parent on exit() call e.g. [0:255]
60  // SYSEXITS(3) FreeBSD Library Functions Manual
61  // According to style(9), it is not a good practice to call exit(3) with
62  // arbitrary values to indicate a failure condition when ending a program.
63  // Instead, the pre-defined exit codes from sysexits should be used, so the
64  // caller of the process can get a rough estimation about the failure class
65  // without looking up the source code.
66  // EX_USAGE (64) The command was used incorrectly, e.g., with the
67  // wrong number of arguments, a bad flag, a bad syntax
68  // in a parameter, or whatever.
69  // EX_UNAVAILABLE (69) A service is unavailable. This can occur if a supĀ­
70  // port program or file does not exist. This can also
71  // be used as a catchall message when something you
72  // wanted to do doesn't work, but you don't know why.
73 
74  // use 64 when failed Decode name (i.e. ! fIsConfigured )
75  // use 69 when failed to find directory (i.e. ! fIsValidated )
76  if ( fIsConfigured ) exit(69);
77  else exit(64);
78  }
79 }
bool fIsConfigured
Definition: TuneId.h:106
bool fIsValidated
Definition: TuneId.h:107
string TrimSpaces(string input)
Definition: StringUtils.cxx:18
string fName
Definition: TuneId.h:93
void Build(const string &name="")
Definition: TuneId.cxx:124
TuneId::TuneId ( const TuneId id)

Definition at line 81 of file TuneId.cxx.

82 {
83  this->Copy(id);
84 
85  if ( ! CheckDirectory() ) {
86  LOG("TuneId", pWARN) << "No valid subdirectory associated with " << Name() ;
87  }
88 }
string Name(void) const
Definition: TuneId.h:46
void Copy(const TuneId &id)
Definition: TuneId.cxx:165
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
#define pWARN
Definition: Messenger.h:60
bool CheckDirectory()
Definition: TuneId.cxx:205
genie::TuneId::~TuneId ( )
inline

Definition at line 43 of file TuneId.h.

43 {;}
genie::TuneId::TuneId ( )
inlineprivate

Definition at line 89 of file TuneId.h.

89 {;}

Member Function Documentation

string genie::TuneId::BaseDirectory ( void  ) const
inline

Definition at line 76 of file TuneId.h.

76 { return fBaseDirectory; }
string fBaseDirectory
Definition: TuneId.h:103
void TuneId::Build ( const string name = "")

Definition at line 124 of file TuneId.cxx.

124  {
125  LOG("TuneId",pDEBUG)<<"Building tune "<<name;
126  if ( name.size() > 0 ) fName = name ;
127 
128  this -> Decode( fName );
129  if ( ! fIsConfigured ) return; // no point going on
130 
131  if ( this -> CheckDirectory() ) {
132  LOG("TuneId", pINFO) << Name() <<" Tune configured " ;
133  fIsValidated = true;
134  } else {
135  LOG("TuneId", pFATAL) << "No valid tune directory associated with " << Name() ;
136  fIsValidated = false;
137  }
138 }
static QCString name
Definition: declinfo.cpp:673
string Name(void) const
Definition: TuneId.h:46
bool fIsConfigured
Definition: TuneId.h:106
void Decode(string id_str)
Definition: TuneId.cxx:140
#define pFATAL
Definition: Messenger.h:56
uint size() const
Definition: qcstring.h:201
bool fIsValidated
Definition: TuneId.h:107
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
#define pINFO
Definition: Messenger.h:62
string fName
Definition: TuneId.h:93
bool CheckDirectory()
Definition: TuneId.cxx:205
#define pDEBUG
Definition: Messenger.h:63
bool TuneId::CheckDirectory ( )
private

Definition at line 205 of file TuneId.cxx.

205  {
206 
207  std::string pathlist = utils::xml::GetXMLPathList(false) ;
208  std::vector<std::string> paths = utils::str::Split(pathlist,":;,");
209 
210  string top_path = gSystem->ExpandPathName( paths[0].c_str() ) ;
211  string def_path = gSystem->ExpandPathName( utils::xml::GetXMLDefaultPath().c_str() ) ;
212 
213  if ( top_path != def_path ) {
214  fCustomSource = top_path ;
215  }
216 
217  fBaseDirectory = "" ;
218  LOG("TuneId",pDEBUG) << "Base dir validation " ;
219 
220  for ( size_t i=0; i< paths.size(); ++i ) {
221  const char* tmppath = paths[i].c_str();
222  std::string onepath = gSystem->ExpandPathName(tmppath);
223  string test = onepath + "/" + CMC() ;
224  LOG("TuneId", pDEBUG) << " Testing " << test << " directory" ;
225  if ( utils::system::DirectoryExists( test.c_str() ) ) {
226  fBaseDirectory = onepath ;
227  break ;
228  }
229  }
230 
231  if ( fBaseDirectory.size() == 0 ) {
232  LOG("TuneId", pWARN) << " No " << CMC() << " subdirectory found in pathlist";
233  return false ;
234  }
235 
236  if ( ! OnlyConfiguration() ) {
237  if ( ! utils::system::DirectoryExists( TuneDirectory().c_str() ) ) {
238  LOG("TuneId", pWARN) << "No " << Name() << " subdirectory found in " << CMC() ;
239  return false ;
240  }
241  }
242 
243  LOG("TuneId",pDEBUG) << fBaseDirectory ;
244 
245  return true ;
246 }
string GetXMLPathList(bool add_tune=true)
string Name(void) const
Definition: TuneId.h:46
std::string string
Definition: nybbler.cc:12
bool OnlyConfiguration() const
Definition: TuneId.h:69
string fBaseDirectory
Definition: TuneId.h:103
string fCustomSource
Definition: TuneId.h:104
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
string TuneDirectory(void) const
Definition: TuneId.cxx:116
#define pWARN
Definition: Messenger.h:60
vector< string > Split(string input, string delim)
Definition: StringUtils.cxx:36
bool DirectoryExists(const char *path)
Definition: SystemUtils.cxx:92
string CMC(void) const
Definition: TuneId.cxx:90
string GetXMLDefaultPath()
#define pDEBUG
Definition: Messenger.h:63
string TuneId::CMC ( void  ) const

Definition at line 90 of file TuneId.cxx.

90  {
91 
92  string cmc = fPrefix ;
93  cmc += fYear ;
94  cmc += "_" ;
95  cmc += ModelId() ;
96 
97  return cmc ;
98 }
string fYear
Definition: TuneId.h:96
string fPrefix
Definition: TuneId.h:95
string ModelId(void) const
Definition: TuneId.h:49
string TuneId::CMCDirectory ( void  ) const

Definition at line 107 of file TuneId.cxx.

107  {
108 
109  string dir = fBaseDirectory ;
110  dir += "/" + CMC() ;
111 
112  return dir ;
113 
114 }
string dir
string fBaseDirectory
Definition: TuneId.h:103
string CMC(void) const
Definition: TuneId.cxx:90
bool TuneId::Compare ( const TuneId id) const

Definition at line 179 of file TuneId.cxx.

180 {
181  return (this->Name() == id.Name());
182 }
string Name(void) const
Definition: TuneId.h:46
void TuneId::Copy ( const TuneId id)

Definition at line 165 of file TuneId.cxx.

166 {
167  this->fName = id.Name();
168  this->fPrefix = id.Prefix();
169  this->fYear = id.Year();
170  this->fMajorModelId = id.MajorModelId();
171  this->fMinorModelId = id.MinorModelId();
172  this->fTunedParamSetId = id.TunedParamSetId();
173  this->fFitDataSetId = id.FitDataSetId();
174 
175  this->fIsConfigured = id.IsConfigured();
176  this->fIsValidated = id.IsValidated();
177 }
string fMajorModelId
Definition: TuneId.h:98
string fYear
Definition: TuneId.h:96
bool fIsConfigured
Definition: TuneId.h:106
string fTunedParamSetId
Definition: TuneId.h:100
bool fIsValidated
Definition: TuneId.h:107
string fMinorModelId
Definition: TuneId.h:99
string fPrefix
Definition: TuneId.h:95
string fName
Definition: TuneId.h:93
string fFitDataSetId
Definition: TuneId.h:101
string genie::TuneId::CustomSource ( void  ) const
inline

Definition at line 77 of file TuneId.h.

77 { return fCustomSource; }
string fCustomSource
Definition: TuneId.h:104
void TuneId::Decode ( string  id_str)

Definition at line 140 of file TuneId.cxx.

141 {
142  static TPRegexp pattern("^([A-Za-z]+)(\\d{2})_(\\d{2})([a-z])_([a-z0-9]{2})_([a-z0-9]{3})$");
143  // TPRegexp pattern("([A-Za-z]+)(\\d{2})_(\\d{2})([a-z])_(\\d{2})_(\\d{3})");
144 
145  TString tstr(id_str.c_str());
146  TObjArray * matches = pattern.MatchS(tstr);
147  if ( matches -> GetEntries() != 7) {
148  LOG("TuneId", pFATAL) << "Bad tune pattern "<<id_str<<" - form is eg G18_01a_00_000";
149  fIsConfigured = false;
150  return;
151  } else {
152  fIsConfigured = true;
153  }
154 
155  this -> fPrefix = ((TObjString*)matches->At(1))->String().Data();
156  this -> fYear = ((TObjString*)matches->At(2))->String().Data();
157  this -> fMajorModelId = ((TObjString*)matches->At(3))->String().Data();
158  this -> fMinorModelId = ((TObjString*)matches->At(4))->String().Data();
159  this -> fTunedParamSetId = ((TObjString*)matches->At(5))->String().Data();
160  this -> fFitDataSetId = ((TObjString*)matches->At(6))->String().Data();
161 
162  delete matches;
163 }
string fMajorModelId
Definition: TuneId.h:98
string fYear
Definition: TuneId.h:96
bool fIsConfigured
Definition: TuneId.h:106
#define pFATAL
Definition: Messenger.h:56
string fTunedParamSetId
Definition: TuneId.h:100
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
string fMinorModelId
Definition: TuneId.h:99
JAVACC_STRING_TYPE String
Definition: JavaCC.h:22
string fPrefix
Definition: TuneId.h:95
std::string pattern
Definition: regex_t.cc:35
string fFitDataSetId
Definition: TuneId.h:101
string genie::TuneId::FitDataSetId ( void  ) const
inline

Definition at line 53 of file TuneId.h.

53 { return fFitDataSetId; } // xxx
string fFitDataSetId
Definition: TuneId.h:101
bool genie::TuneId::IsConfigured ( void  ) const
inline

Definition at line 55 of file TuneId.h.

55 { return fIsConfigured; }
bool fIsConfigured
Definition: TuneId.h:106
bool genie::TuneId::IsCustom ( void  ) const
inline

Definition at line 62 of file TuneId.h.

62 { return fCustomSource.size() > 0 ; }
string fCustomSource
Definition: TuneId.h:104
bool genie::TuneId::IsValidated ( void  ) const
inline

Definition at line 59 of file TuneId.h.

59 { return fIsValidated; }
bool fIsValidated
Definition: TuneId.h:107
string genie::TuneId::MajorModelId ( void  ) const
inline

Definition at line 50 of file TuneId.h.

50 { return fMajorModelId; } // MM
string fMajorModelId
Definition: TuneId.h:98
string genie::TuneId::MinorModelId ( void  ) const
inline

Definition at line 51 of file TuneId.h.

51 { return fMinorModelId; } // v
string fMinorModelId
Definition: TuneId.h:99
string genie::TuneId::ModelId ( void  ) const
inline

Definition at line 49 of file TuneId.h.

49 { return fMajorModelId + fMinorModelId; } // MMv
string fMajorModelId
Definition: TuneId.h:98
string fMinorModelId
Definition: TuneId.h:99
string genie::TuneId::Name ( void  ) const
inline

Definition at line 46 of file TuneId.h.

46 { return fName; } // Gdd_MMv_PP_xxx
string fName
Definition: TuneId.h:93
bool genie::TuneId::OnlyConfiguration ( ) const
inline

Definition at line 69 of file TuneId.h.

69 { return (TunedParamSetId() == "00") ; }
string TunedParamSetId(void) const
Definition: TuneId.h:52
string genie::TuneId::Prefix ( void  ) const
inline

Definition at line 47 of file TuneId.h.

47 { return fPrefix; } // G
string fPrefix
Definition: TuneId.h:95
void TuneId::Print ( ostream &  stream) const

Definition at line 184 of file TuneId.cxx.

185 {
186  std::string status = "Standard";
187  if ( IsCustom() ) status = "Custom";
188  if ( ! IsValidated() ) status = "BadDirectory";
189  if ( ! IsConfigured() ) status = "BadConfig";
190  stream << status << " GENIE tune: " << this -> Name() << std::endl;
191  stream << " - Prefix ............... : " << this->Prefix() << std::endl;
192  stream << " - Year ................. : " << this->Year() << std::endl;
193  stream << " - Major model ID ....... : " << this->MajorModelId() << std::endl;
194  stream << " - Minor model ID ....... : " << this->MinorModelId() << std::endl;
195  stream << " - Tuned param set ID ... : " << this->TunedParamSetId() << std::endl;
196  stream << " - Fit dataset ID ....... : " << this->FitDataSetId() << std::endl;
197  stream << " - Tune directory ....... : " << this->TuneDirectory() << std::endl;
198  stream << " - Base directory ....... : " << this->fBaseDirectory << std::endl;
199  if ( IsCustom() )
200  stream << " - Custom directory ..... : " << this -> fCustomSource << std::endl;
201 
202  stream << std::flush;
203 }
string Name(void) const
Definition: TuneId.h:46
string MajorModelId(void) const
Definition: TuneId.h:50
std::string string
Definition: nybbler.cc:12
string Year(void) const
Definition: TuneId.h:48
string FitDataSetId(void) const
Definition: TuneId.h:53
bool IsCustom(void) const
Definition: TuneId.h:62
bool IsValidated(void) const
Definition: TuneId.h:59
string fBaseDirectory
Definition: TuneId.h:103
string fCustomSource
Definition: TuneId.h:104
string TuneDirectory(void) const
Definition: TuneId.cxx:116
QTextStream & flush(QTextStream &s)
string MinorModelId(void) const
Definition: TuneId.h:51
bool IsConfigured(void) const
Definition: TuneId.h:55
string Prefix(void) const
Definition: TuneId.h:47
string TunedParamSetId(void) const
Definition: TuneId.h:52
QTextStream & endl(QTextStream &s)
string TuneId::Tail ( void  ) const

Definition at line 100 of file TuneId.cxx.

100  {
101 
102  string tail = fTunedParamSetId ;
103  tail += "_" + fFitDataSetId ;
104  return tail ;
105 }
string fTunedParamSetId
Definition: TuneId.h:100
string fFitDataSetId
Definition: TuneId.h:101
string TuneId::TuneDirectory ( void  ) const

Definition at line 116 of file TuneId.cxx.

116  {
117 
118  string dir = CMCDirectory() ;
119  if ( ! OnlyConfiguration() ) dir += "/" + Name() ;
120 
121  return dir ;
122 }
string Name(void) const
Definition: TuneId.h:46
string CMCDirectory(void) const
Definition: TuneId.cxx:107
string dir
bool OnlyConfiguration() const
Definition: TuneId.h:69
string genie::TuneId::TunedParamSetId ( void  ) const
inline

Definition at line 52 of file TuneId.h.

52 { return fTunedParamSetId; } // PP
string fTunedParamSetId
Definition: TuneId.h:100
string genie::TuneId::Year ( void  ) const
inline

Definition at line 48 of file TuneId.h.

48 { return fYear; } // dd
string fYear
Definition: TuneId.h:96

Friends And Related Function Documentation

ostream& operator<< ( ostream &  stream,
const TuneId id 
)
friend

Definition at line 35 of file TuneId.cxx.

36  {
37  id.Print(stream);
38  return stream;
39  }

Member Data Documentation

string genie::TuneId::fBaseDirectory
private

Definition at line 103 of file TuneId.h.

string genie::TuneId::fCustomSource
private

Definition at line 104 of file TuneId.h.

string genie::TuneId::fFitDataSetId
private

Definition at line 101 of file TuneId.h.

bool genie::TuneId::fIsConfigured
private

Definition at line 106 of file TuneId.h.

bool genie::TuneId::fIsValidated
private

Definition at line 107 of file TuneId.h.

string genie::TuneId::fMajorModelId
private

Definition at line 98 of file TuneId.h.

string genie::TuneId::fMinorModelId
private

Definition at line 99 of file TuneId.h.

string genie::TuneId::fModelId
private

Definition at line 97 of file TuneId.h.

string genie::TuneId::fName
private

Definition at line 93 of file TuneId.h.

string genie::TuneId::fPrefix
private

Definition at line 95 of file TuneId.h.

string genie::TuneId::fTunedParamSetId
private

Definition at line 100 of file TuneId.h.

string genie::TuneId::fYear
private

Definition at line 96 of file TuneId.h.


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