Heavy ion Analysis Libriares
Loading...
Searching...
No Matches
Options.cxx
1/*
2 * HalOptions.cxx
3 *
4 * Created on: 21-10-2014
5 * Author: Daniel Wielanek
6 * E-mail: daniel.wielanek@gmail.com
7 * Warsaw University of Technology, Faculty of Physics
8 */
9#include "Options.h"
10
11#include <TObjString.h>
12#include <TRegexp.h>
13namespace Hal {
14 OptionConverter::OptionConverter() {}
15
16 Bool_t OptionConverter::GetOptionInt(Int_t& val, TString option) const {
17 int i = 0;
18 for (auto strval : fNames) {
19 i++;
20 if (strval.EqualTo(option)) {
21 val = fValues[i];
22 return kTRUE;
23 }
24 }
25 if (Hal::Std::FindParam(option, "forced:")) {
26 Cout::PrintInfo("replacing HalFastCut by force !", Hal::EInfo::kLowWarning);
27 TRegexp reg("[9-0]+");
28 option = option(reg);
29 val = option.Atoi();
30 return kTRUE;
31 }
32
33 return kFALSE;
34 }
35
36 void OptionConverter::RegisterOption(TString option) {
37 fNames.push_back(option);
38 fValues.push_back(fValues.size());
39 }
40
41 void OptionConverter::RegisterOption(TString option, Int_t no) {
42 fNames.push_back(option);
43 fValues.push_back(no);
44 }
45
46 Bool_t OptionConverter::GetString(TString& string, Int_t value) const {
47 if (value > 0 && value < (int) fNames.size()) {
48 string = fNames[value];
49 return kTRUE;
50 } else {
51 return kFALSE;
52 }
53 }
54
55 OptionConverter::~OptionConverter() {}
56
57 //==================================================
58
59 OptionArray::OptionArray() {}
60
61 void OptionArray::RegisterLabel(TString label) {
62 for (unsigned int i = 0; i < fLabels.size(); i++) {
63 TString tmp = fLabels[i];
64 if (tmp == label) {
65 Cout::PrintInfo(Form("Label %s already registered", label.Data()), Hal::EInfo::kLowWarning);
66 return;
67 }
68 }
69 if (label.Contains(":") || label.Contains("NULL")) {
70 Cout::PrintInfo("Label can't contain ':' or NULL", Hal::EInfo::kError);
71 return;
72 }
73 // to be sure that all arrays exist
74 fLabels.push_back(label);
75 fParameters.push_back(std::vector<TString>());
76 }
77
78 Bool_t OptionArray::Add(TString option) {
79 TRegexp regexp("[0-9a-zA-Z]+:");
80 TRegexp regexp2(":.[0-9a-zA-Z]+");
81 TString label = option(regexp);
82 label.Remove(label.Length() - 1);
83 TString value = option(regexp2);
84 value.Remove(0, 1);
85 Int_t label_no = -1;
86 for (unsigned int i = 0; i < fLabels.size(); i++) {
87 if (GetLabel(i).EqualTo(label)) {
88 label_no = i;
89 break;
90 }
91 }
92 if (label_no == -1) {
93 Cout::PrintInfo(Form("Can't add string %s because there is no label ", label.Data()), Hal::EInfo::kWarning);
94 return kFALSE;
95 }
96 fParameters[label_no].push_back(value);
97 return kTRUE;
98 }
99
100 TString OptionArray::GetByLabel(TString label, Int_t no) const {
101 for (unsigned int i = 0; i < fLabels.size(); i++) {
102 if (GetLabel(i).EqualTo(label)) {
103 Int_t entries = fParameters[i].size();
104 if (entries == 0 || entries <= no) {
105 if (entries == 0) Cout::PrintInfo(Form("No entries for label %s", label.Data()), Hal::EInfo::kLowWarning);
106 if (entries < no) Cout::PrintInfo(Form("Not enough entries for label %s", label.Data()), Hal::EInfo::kLowWarning);
107 return "NULL";
108 }
109 return fParameters[i][no];
110 }
111 }
112 return "NULL";
113 }
114
115 Int_t OptionArray::GetByLabelNo(TString label) const {
116 for (unsigned int i = 0; i < fLabels.size(); i++) {
117 if (GetLabel(i).EqualTo(label)) { return fParameters[i].size(); }
118 }
119 return 0;
120 }
121
122 TString OptionArray::GetLabel(Int_t i) const { return fLabels[i]; }
123
124 void OptionArray::Print(Option_t* /*opt*/) const {
125 for (unsigned int i = 0; i < fLabels.size(); i++) {
126 Cout::Text(Form("Label %s", fLabels[i].Data()), "L", kYellow);
127 for (unsigned int j = 0; j < fParameters[i].size(); j++) {
128 TString val = fParameters[i][j];
129 Cout::Text(val, "R", kGreen);
130 }
131 }
132 }
133
134 OptionArray::~OptionArray() {}
135} // namespace Hal
static void Text(TString text, TString option="L", Color_t color=-1)
Definition Cout.cxx:92
static void PrintInfo(TString text, Hal::EInfo status)
Definition Cout.cxx:370
Int_t GetByLabelNo(TString label) const
Definition Options.cxx:115
void RegisterLabel(TString label)
Definition Options.cxx:61
TString GetByLabel(TString label, Int_t no=0) const
Definition Options.cxx:100
Bool_t Add(TString option)
Definition Options.cxx:78
void Print(Option_t *="") const
Definition Options.cxx:124
void RegisterOption(TString option)
Definition Options.cxx:36
Bool_t GetOptionInt(Int_t &val, TString option) const
Definition Options.cxx:16
Bool_t GetString(TString &val, Int_t value) const
Definition Options.cxx:46