Heavy ion Analysis Libriares
Loading...
Searching...
No Matches
UniqueOptions.cxx
1/*
2 * UniqueOptions.cxx
3 *
4 * Created on: 17 lut 2024
5 * Author: Daniel Wielanek
6 * E-mail: daniel.wielanek@gmail.com
7 * Warsaw University of Technology, Faculty of Physics
8 */
9#include "UniqueOptions.h"
10
11#include "Std.h"
12
13#include <iostream>
14
15namespace Hal {
16 void UniqueOptions::OverwriteTag(TString newStr, TString oldStr) {
17 for (auto& i : fOpts) {
18 if (i == oldStr) {
19 i = newStr;
20 return;
21 }
22 }
23 }
24
25 void UniqueOptions::AddConflicts(std::initializer_list<TString> list) {
26 auto vec = Hal::Std::GetVector(list);
27 for (auto& p : vec)
28 p.ToLower();
29 fConflicts.push_back(vec);
30 }
31
32 Bool_t UniqueOptions::AddTag(TString tag, Bool_t overwrite) {
33 tag.ToLower();
34 for (auto conf : fConflicts) {
35 for (auto potConf : conf) {
36 if (potConf == tag) { // potential conflict found
37 for (auto potConf2 : conf) {
38 if (CheckTag(potConf2)) {
39 if (overwrite) {
40 OverwriteTag(tag, potConf2);
41 return kTRUE;
42 }
43 return kFALSE;
44 }
45 }
46 }
47 }
48 }
49 fOpts.push_back(tag);
50 return kTRUE;
51 }
52
53 Bool_t UniqueOptions::RemoveTag(TString tag) {
54 tag.ToLower();
55 for (unsigned int i = 0; i < fOpts.size(); i++) {
56 TString opt = fOpts[i];
57 if (tag == opt) {
58 fOpts.erase(fOpts.begin() + i);
59 return kTRUE;
60 }
61 }
62 return kFALSE;
63 }
64
65 Bool_t UniqueOptions::CheckTag(TString tag) const {
66 tag.ToLower();
67 for (auto i : fOpts) {
68 if (i == tag) return kTRUE;
69 }
70 return kFALSE;
71 }
72
73 void UniqueOptions::Print(Option_t* /*option*/) const {
74 std::cout << "Conflicts" << std::endl;
75 for (auto i : fConflicts) {
76 std::cout << "\t";
77 for (auto j : i) {
78 std::cout << j << " ";
79 }
80 std::cout << std::endl;
81 }
82 std::cout << "Tags" << std::endl;
83 for (auto i : fOpts) {
84 std::cout << "\t" << i << std::endl;
85 }
86 }
87
88} /* namespace Hal */
Bool_t CheckTag(TString tag) const
Bool_t RemoveTag(TString tag)
void AddConflicts(std::initializer_list< TString > list)
Bool_t AddTag(TString tag, Bool_t overwrite=kTRUE)