GWOLLUM 4.2.0
Tools for gravitational-wave analyses
Loading...
Searching...
No Matches
GwollumOptions.h
Go to the documentation of this file.
1
6#ifndef __GwollumOptions__
7#define __GwollumOptions__
8
9#include "IO.h"
10#include "Monitor.h"
11#include <TFile.h>
12#include <TChain.h>
13#include <H5Cpp.h>
14
15using namespace std;
16
28
29public:
43 GwollumOption(const string aTag, const string aKey, const int aDefaultValue, const unsigned int aSize=0);
44
53 GwollumOption(const string aTag, const string aKey, const unsigned int aDefaultValue, const unsigned int aSize=0);
54
63 GwollumOption(const string aTag, const string aKey, const double aDefaultValue, const unsigned int aSize=0);
64
73 GwollumOption(const string aTag, const string aKey, const string aDefaultValue, const unsigned int aSize=0);
74
78 virtual ~GwollumOption(void);
79
89 inline bool IsProvided(void){ return provided; };
90
94 inline string GetTag(void){ return tag; };
95
99 inline string GetKey(void){ return key; };
100
104 inline char GetType(void){ return valtype; };
105
110 inline unsigned int GetSize(void){ return osize; };
111
115 inline unsigned int GetNumberOfValues(void){ return ivec.size()+uvec.size()+dvec.size()+svec.size(); };
116
124 inline bool GetValueI(int &aValue, const unsigned int aValIndex){
125 if(aValIndex<ivec.size()){
126 aValue = ivec[aValIndex];
127 return true;
128 }
129 return false;
130 };
131
138 inline int GetValueI(const unsigned int aValIndex=0){
139 if(aValIndex<ivec.size()) return ivec[aValIndex];
140 return idef;
141 };
142
147 inline vector<int> GetValuesI(void){
148 return ivec;
149 };
150
154 inline int GetDefaultI(void){ return idef; };
155
162 inline void Add(const int aValue){
163 if((valtype=='i')&&(osize==0)){
164 ivec.push_back(aValue);
165 provided = true;
166 }
167 };
168
174 inline void Set(const unsigned int aValIndex, const int aValue){
175 if(valtype!='i') return;
176 if(aValIndex<ivec.size()){
177 ivec[aValIndex] = aValue;
178 provided = true;
179 }
180 };
181
189 inline bool GetValueU(unsigned int &aValue, const unsigned int aValIndex){
190 if(aValIndex<uvec.size()){
191 aValue = uvec[aValIndex];
192 return true;
193 }
194 return false;
195 };
196
203 inline unsigned int GetValueU(const unsigned int aValIndex=0){
204 if(aValIndex<uvec.size()) return uvec[aValIndex];
205 return udef;
206 };
207
212 inline vector<unsigned int> GetValuesU(void){
213 return uvec;
214 };
215
219 inline unsigned int GetDefaultU(void){ return udef; };
220
227 inline void Add(const unsigned int aValue){
228 if((valtype=='u')&&(osize==0)){
229 uvec.push_back(aValue);
230 provided = true;
231 }
232 };
233
239 inline void Set(const unsigned int aValIndex, const unsigned int aValue){
240 if(valtype!='u') return;
241 if(aValIndex<uvec.size()){
242 uvec[aValIndex] = aValue;
243 provided = true;
244 }
245 };
246
254 inline bool GetValueD(double &aValue, const unsigned int aValIndex){
255 if(aValIndex<dvec.size()){
256 aValue = dvec[aValIndex];
257 return true;
258 }
259 return false;
260 };
261
268 inline double GetValueD(const unsigned int aValIndex=0){
269 if(aValIndex<dvec.size()) return dvec[aValIndex];
270 return ddef;
271 };
272
277 inline vector<double> GetValuesD(void){
278 return dvec;
279 };
280
284 inline double GetDefaultD(void){ return ddef; };
285
292 inline void Add(const double aValue){
293 if((valtype=='d')&&(osize==0)){
294 dvec.push_back(aValue);
295 provided = true;
296 }
297 };
298
304 inline void Set(const unsigned int aValIndex, const double aValue){
305 if(valtype!='d') return;
306 if(aValIndex<dvec.size()){
307 dvec[aValIndex] = aValue;
308 provided = true;
309 }
310 };
311
319 inline bool GetValueS(string &aValue, const unsigned int aValIndex){
320 if(aValIndex<svec.size()){
321 aValue = svec[aValIndex];
322 return true;
323 }
324 return false;
325 };
326
333 inline string GetValueS(const unsigned int aValIndex=0){
334 if(aValIndex<svec.size()) return svec[aValIndex];
335 return sdef;
336 };
337
342 inline vector<string> GetValuesS(void){
343 return svec;
344 };
345
349 inline string GetDefaultS(void){ return sdef; };
350
357 inline void Add(const string aValue){
358 if((valtype=='s')&&(osize==0)){
359 svec.push_back(aValue);
360 provided = true;
361 }
362 };
363
369 inline void Set(const unsigned int aValIndex, const string aValue){
370 if(valtype!='s') return;
371 if(aValIndex<svec.size()){
372 svec[aValIndex] = aValue;
373 provided = true;
374 }
375 };
376
387 string GetOptionName(const unsigned int aValIndex);
388
393 void Reset(void);
394
399 void SetDefault(void);
400
401private:
402
403 bool provided;
404 string tag;
405 string key;
406 char valtype;
407 unsigned int osize;
408 int idef;
409 unsigned int udef;
410 double ddef;
411 string sdef;
412 vector<int> ivec;
413 vector<unsigned int> uvec;
414 vector<double> dvec;
415 vector<string> svec;
416};
417
418
435
436 public:
437
446 GwollumOptions(void);
447
451 virtual ~GwollumOptions(void);
452
462 void Copy(GwollumOptions *aG);
463
467 inline void Reset(void){ options.clear(); OptTree->Reset(); };
468
475 inline unsigned int GetOptionIndex(const string aTag, const string aKey){
476 for(unsigned int o=0; o<options.size(); o++)
477 if((!options[o].GetTag().compare(aTag))&&(!options[o].GetKey().compare(aKey))) return o;
478 return options.size();
479 };
480
487 void ResetOption(const string aTag, const string aKey);
488
495 void RemoveOption(const string aTag, const string aKey);
496
508 bool IsTheSame(GwollumOptions *aG);
509
517 void Add(const string aTag, const string aKey, const int aDefaultValue, const unsigned int aSize=0);
518
527 void SetOptionValue(const string aTag, const string aKey, const unsigned int aValIndex, const int aValue);
528
535 void AddOptionValue(const string aTag, const string aKey, const int aValue);
536
544 void Add(const string aTag, const string aKey, const unsigned int aDefaultValue, const unsigned int aSize=0);
545
554 void SetOptionValue(const string aTag, const string aKey, const unsigned int aValIndex, const unsigned int aValue);
555
562 void AddOptionValue(const string aTag, const string aKey, const unsigned int aValue);
563
571 void Add(const string aTag, const string aKey, const double aDefaultValue, const unsigned int aSize=0);
572
581 void SetOptionValue(const string aTag, const string aKey, const unsigned int aValIndex, const double aValue);
582
589 void AddOptionValue(const string aTag, const string aKey, const double aValue);
590
598 void Add(const string aTag, const string aKey, const string aDefaultValue, const unsigned int aSize=0);
599
608 void SetOptionValue(const string aTag, const string aKey, const unsigned int aValIndex, const string aValue);
609
616 void AddOptionValue(const string aTag, const string aKey, const string aValue);
617
625 bool IsProvided(const string aTag, const string aKey);
626
633 inline bool Is(const string aTag, const string aKey){
634 if(GetOptionIndex(aTag, aKey)==options.size()) return false;
635 return true;
636 };
637
644 void SetDefault(const string aTag, const string aKey);
645
651 inline string GetOptionTag(const unsigned int aOptionIndex){
652 if(aOptionIndex>=options.size()) return "";
653 return options[aOptionIndex].GetTag();
654 };
655
661 inline char GetOptionType(const unsigned int aOptionIndex){
662 if(aOptionIndex>=options.size()) return '0';
663 return options[aOptionIndex].GetType();
664 };
665
671 inline int GetOptionDefaultI(const unsigned int aOptionIndex){
672 return options[aOptionIndex].GetDefaultI();
673 };
674
680 inline unsigned int GetOptionDefaultU(const unsigned int aOptionIndex){
681 return options[aOptionIndex].GetDefaultU();
682 };
683
689 inline double GetOptionDefaultD(const unsigned int aOptionIndex){
690 return options[aOptionIndex].GetDefaultD();
691 };
692
698 inline string GetOptionDefaultS(const unsigned int aOptionIndex){
699 return options[aOptionIndex].GetDefaultS();
700 };
701
707 inline string GetOptionKey(const unsigned int aOptionIndex){
708 if(aOptionIndex>=options.size()) return "";
709 return options[aOptionIndex].GetKey();
710 };
711
717 inline unsigned int GetOptionSize(const unsigned int aOptionIndex){
718 return options[aOptionIndex].GetSize();
719 };
720
727 char GetOptionType(const string aTag, const string aKey);
728
735 unsigned int GetOptionSize(const string aTag, const string aKey);
736
743 unsigned int GetOptionNumberOfValues(const string aTag, const string aKey);
744
754 bool GetOptionValueI(int &aValue, const string aTag, const string aKey, const unsigned int aValIndex);
755
764 int GetOptionValueI(const string aTag, const string aKey, const unsigned int aValIndex);
765
773 vector<int> GetOptionValuesI(const string aTag, const string aKey);
774
784 bool GetOptionValueU(unsigned int &aValue, const string aTag, const string aKey, const unsigned int aValIndex);
785
794 unsigned int GetOptionValueU(const string aTag, const string aKey, const unsigned int aValIndex);
795
803 vector<unsigned int> GetOptionValuesU(const string aTag, const string aKey);
804
814 bool GetOptionValueD(double &aValue, const string aTag, const string aKey, const unsigned int aValIndex);
815
824 double GetOptionValueD(const string aTag, const string aKey, const unsigned int aValIndex);
825
833 vector<double> GetOptionValuesD(const string aTag, const string aKey);
834
844 bool GetOptionValueS(string &aValue, const string aTag, const string aKey, const unsigned int aValIndex);
845
854 string GetOptionValueS(const string aTag, const string aKey, const unsigned int aValIndex);
855
863 vector<string> GetOptionValuesS(const string aTag, const string aKey);
864
875 unsigned int ReadTextFile(const string aOptionFile);
876
881 void WriteTextFile(const string aFileName);
882
888 void WriteH5(H5::H5File* aFile, H5::DataSpace &aDataSpace);
889
896 bool ReadTree(const string aRootFileName, const string aTreeName);
897
902 bool ReadTree(TTree *aTree);
903
911 bool ReadChain(bool &aIsUniform, TChain *aChain);
912
919 void FillTree(void);
920
928 void WriteTree(const string aTreeName, const string aRootFileName, const string aSubDirectory="");
929
936 inline void WriteTree(const string aTreeName){ OptTree->Write(aTreeName.c_str()); };
937
941 unsigned int GetOptionsN(void){ return options.size(); };
942
943
944 private:
945
947 vector<GwollumOption> options;
948 TTree *OptTree;
949 string t_tag;
950 string t_key;
951 char t_type;
952 unsigned int t_size;
953 int t_idef;
954 unsigned int t_udef;
955 double t_ddef;
956 string t_sdef;
957 int t_ival;
958 unsigned int t_uval;
959 double t_dval;
960 string t_sval;
961
962
963 ClassDef(GwollumOptions,0)
964};
965
966
967#endif
968
969
Option file parser.
Process monitoring.
Single option.
Definition GwollumOptions.h:27
double ddef
Option double default value.
Definition GwollumOptions.h:410
void Set(const unsigned int aValIndex, const double aValue)
Updates an option value (double).
Definition GwollumOptions.h:304
unsigned int GetDefaultU(void)
Returns the option default value (unsigned int).
Definition GwollumOptions.h:219
void Add(const double aValue)
Adds the option value (double).
Definition GwollumOptions.h:292
void Add(const unsigned int aValue)
Adds the option value (unsigned int).
Definition GwollumOptions.h:227
vector< double > GetValuesD(void)
Returns the list of option values (double).
Definition GwollumOptions.h:277
void Add(const string aValue)
Adds the option value (string).
Definition GwollumOptions.h:357
double GetValueD(const unsigned int aValIndex=0)
Returns the option value (double).
Definition GwollumOptions.h:268
vector< int > GetValuesI(void)
Returns the list of option values (int).
Definition GwollumOptions.h:147
bool GetValueS(string &aValue, const unsigned int aValIndex)
Returns the option value (string).
Definition GwollumOptions.h:319
bool GetValueU(unsigned int &aValue, const unsigned int aValIndex)
Returns the option value (unsigned int).
Definition GwollumOptions.h:189
string GetTag(void)
Returns the option tag.
Definition GwollumOptions.h:94
bool provided
Set to true if the option was explicitly given.
Definition GwollumOptions.h:403
void Set(const unsigned int aValIndex, const unsigned int aValue)
Updates an option value (unsigned int).
Definition GwollumOptions.h:239
string GetDefaultS(void)
Returns the option default value (string).
Definition GwollumOptions.h:349
GwollumOption(const string aTag, const string aKey, const int aDefaultValue, const unsigned int aSize=0)
Constructor of the GwollumOption class (int).
int GetValueI(const unsigned int aValIndex=0)
Returns the option value (int).
Definition GwollumOptions.h:138
string tag
Option tag.
Definition GwollumOptions.h:404
double GetDefaultD(void)
Returns the option default value (double).
Definition GwollumOptions.h:284
string GetKey(void)
Returns the option key.
Definition GwollumOptions.h:99
string GetOptionName(const unsigned int aValIndex)
Returns a codified option name.
Definition GwollumOptions.cc:88
vector< string > svec
Option string vector.
Definition GwollumOptions.h:415
unsigned int GetNumberOfValues(void)
Returns the number of values.
Definition GwollumOptions.h:115
char GetType(void)
Returns the option type.
Definition GwollumOptions.h:104
virtual ~GwollumOption(void)
Destructor of the GwollumOption class.
Definition GwollumOptions.cc:79
unsigned int GetValueU(const unsigned int aValIndex=0)
Returns the option value (unsigned int).
Definition GwollumOptions.h:203
vector< double > dvec
Option double vector.
Definition GwollumOptions.h:414
vector< string > GetValuesS(void)
Returns the list of option values (string).
Definition GwollumOptions.h:342
unsigned int udef
Option unsigned integer default value.
Definition GwollumOptions.h:409
int idef
Option integer default value.
Definition GwollumOptions.h:408
vector< unsigned int > GetValuesU(void)
Returns the list of option values (unsigned int).
Definition GwollumOptions.h:212
char valtype
Option value type.
Definition GwollumOptions.h:406
vector< int > ivec
Option integer vector.
Definition GwollumOptions.h:412
bool GetValueI(int &aValue, const unsigned int aValIndex)
Returns the option value (int).
Definition GwollumOptions.h:124
unsigned int osize
Option size (number of fixed values).
Definition GwollumOptions.h:407
void Set(const unsigned int aValIndex, const string aValue)
Updates an option value (string).
Definition GwollumOptions.h:369
vector< unsigned int > uvec
Option unsigned integer vector.
Definition GwollumOptions.h:413
int GetDefaultI(void)
Returns the option default value (int).
Definition GwollumOptions.h:154
void Add(const int aValue)
Adds an option value (int).
Definition GwollumOptions.h:162
bool GetValueD(double &aValue, const unsigned int aValIndex)
Returns the option value (double).
Definition GwollumOptions.h:254
unsigned int GetSize(void)
Returns the option size.
Definition GwollumOptions.h:110
string key
Option key.
Definition GwollumOptions.h:405
void SetDefault(void)
Set option to default values.
Definition GwollumOptions.cc:113
string sdef
Option string default value.
Definition GwollumOptions.h:411
string GetValueS(const unsigned int aValIndex=0)
Returns the option value (string).
Definition GwollumOptions.h:333
void Set(const unsigned int aValIndex, const int aValue)
Updates an option value (int).
Definition GwollumOptions.h:174
void Reset(void)
Resets the option.
Definition GwollumOptions.cc:98
bool IsProvided(void)
Tests whether an option value was provided.
Definition GwollumOptions.h:89
Interface to manage options.
Definition GwollumOptions.h:434
string t_key
Option TTree: key.
Definition GwollumOptions.h:950
void ResetOption(const string aTag, const string aKey)
Resets the list of option values.
Definition GwollumOptions.cc:185
unsigned int t_size
Option TTree: size.
Definition GwollumOptions.h:952
void FillTree(void)
Saves options in a TTree.
Definition GwollumOptions.cc:821
string GetOptionTag(const unsigned int aOptionIndex)
Returns an option tag.
Definition GwollumOptions.h:651
void Copy(GwollumOptions *aG)
Copies an external GwollumOptions object into this.
Definition GwollumOptions.cc:177
int GetOptionDefaultI(const unsigned int aOptionIndex)
Returns an option default value.
Definition GwollumOptions.h:671
void RemoveOption(const string aTag, const string aKey)
Removes an option.
Definition GwollumOptions.cc:194
double t_dval
Option TTree: value (double).
Definition GwollumOptions.h:959
unsigned int GetOptionNumberOfValues(const string aTag, const string aKey)
Returns the option number of values.
Definition GwollumOptions.cc:360
vector< int > GetOptionValuesI(const string aTag, const string aKey)
Returns the list of option values (int).
Definition GwollumOptions.cc:384
Monitor * mon
Class monitor.
Definition GwollumOptions.h:946
string GetOptionKey(const unsigned int aOptionIndex)
Returns an option key.
Definition GwollumOptions.h:707
int t_ival
Option TTree: value (int).
Definition GwollumOptions.h:957
void WriteH5(H5::H5File *aFile, H5::DataSpace &aDataSpace)
Writes the options as attributes in a hdf5 file.
Definition GwollumOptions.cc:586
bool Is(const string aTag, const string aKey)
Checks whether an option exists.
Definition GwollumOptions.h:633
void WriteTree(const string aTreeName, const string aRootFileName, const string aSubDirectory="")
Writes the option TTree in a TFile.
Definition GwollumOptions.cc:851
TTree * OptTree
Option TTree.
Definition GwollumOptions.h:948
unsigned int t_uval
Option TTree: value (unsigned int).
Definition GwollumOptions.h:958
bool GetOptionValueU(unsigned int &aValue, const string aTag, const string aKey, const unsigned int aValIndex)
Returns an option value (unsigned int).
Definition GwollumOptions.cc:393
string t_sdef
Option TTree: default (string).
Definition GwollumOptions.h:956
bool GetOptionValueS(string &aValue, const string aTag, const string aKey, const unsigned int aValIndex)
Returns an option value (string).
Definition GwollumOptions.cc:443
void Add(const string aTag, const string aKey, const int aDefaultValue, const unsigned int aSize=0)
Adds an option to the list (int).
Definition GwollumOptions.cc:231
void SetOptionValue(const string aTag, const string aKey, const unsigned int aValIndex, const int aValue)
Sets a value of an option (int).
Definition GwollumOptions.cc:237
bool IsTheSame(GwollumOptions *aG)
Checks whether two GwollumOptions objects are identical.
Definition GwollumOptions.cc:203
unsigned int GetOptionSize(const unsigned int aOptionIndex)
Returns an option size.
Definition GwollumOptions.h:717
unsigned int t_udef
Option TTree: default (unsigned int).
Definition GwollumOptions.h:954
void SetDefault(const string aTag, const string aKey)
Sets an option to default value.
Definition GwollumOptions.cc:335
bool GetOptionValueI(int &aValue, const string aTag, const string aKey, const unsigned int aValIndex)
Returns an option value (int).
Definition GwollumOptions.cc:368
vector< GwollumOption > options
List of options.
Definition GwollumOptions.h:947
unsigned int GetOptionsN(void)
Returns the number of options.
Definition GwollumOptions.h:941
double t_ddef
Option TTree: default (double).
Definition GwollumOptions.h:955
char GetOptionType(const unsigned int aOptionIndex)
Returns an option type.
Definition GwollumOptions.h:661
unsigned int ReadTextFile(const string aOptionFile)
Reads an option file and extract the list of options.
Definition GwollumOptions.cc:468
char t_type
Option TTree: type.
Definition GwollumOptions.h:951
bool GetOptionValueD(double &aValue, const string aTag, const string aKey, const unsigned int aValIndex)
Returns an option value (double).
Definition GwollumOptions.cc:418
vector< double > GetOptionValuesD(const string aTag, const string aKey)
Returns the list of option values (double).
Definition GwollumOptions.cc:434
void Reset(void)
Resets the list of options.
Definition GwollumOptions.h:467
unsigned int GetOptionIndex(const string aTag, const string aKey)
Returns the option index.
Definition GwollumOptions.h:475
string t_tag
Option TTree: tag.
Definition GwollumOptions.h:949
vector< string > GetOptionValuesS(const string aTag, const string aKey)
Returns the list of option values (string).
Definition GwollumOptions.cc:459
string GetOptionDefaultS(const unsigned int aOptionIndex)
Returns an option default value.
Definition GwollumOptions.h:698
unsigned int GetOptionDefaultU(const unsigned int aOptionIndex)
Returns an option default value.
Definition GwollumOptions.h:680
GwollumOptions(void)
Constructor of the GwollumOptions class.
Definition GwollumOptions.cc:146
string t_sval
Option TTree: value (string).
Definition GwollumOptions.h:960
bool IsProvided(const string aTag, const string aKey)
Checks whether an option was provided.
Definition GwollumOptions.cc:327
bool ReadTree(const string aRootFileName, const string aTreeName)
Reads options from a TTree in a ROOT file.
Definition GwollumOptions.cc:628
void AddOptionValue(const string aTag, const string aKey, const int aValue)
Appends a value to a variable-size option (int).
Definition GwollumOptions.cc:246
int t_idef
Option TTree: default (int).
Definition GwollumOptions.h:953
double GetOptionDefaultD(const unsigned int aOptionIndex)
Returns an option default value.
Definition GwollumOptions.h:689
void WriteTree(const string aTreeName)
Writes the option TTree in a TFile.
Definition GwollumOptions.h:936
void WriteTextFile(const string aFileName)
Writes all options in a text file.
Definition GwollumOptions.cc:534
virtual ~GwollumOptions(void)
Destructor of the GwollumOptions class.
Definition GwollumOptions.cc:169
bool ReadChain(bool &aIsUniform, TChain *aChain)
Reads options from a TChain.
Definition GwollumOptions.cc:784
vector< unsigned int > GetOptionValuesU(const string aTag, const string aKey)
Returns the list of option values (unsigned int).
Definition GwollumOptions.cc:409
Monitor a GWOLLUM processing.
Definition Monitor.h:39