Project
Loading...
Searching...
No Matches
IdPath.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
12// Path string identifying the object: //
13// (example: "ZDC/Calib/Pedestals") //
14#include "CCDB/IdPath.h"
15#include <fairlogger/Logger.h> // for LOG
16#include <TObjArray.h> // for TObjArray
17#include <TObjString.h> // for TObjString
18#include <TRegexp.h> // for TRegexp
19
20using namespace o2::ccdb;
21
23
24IdPath::IdPath() : TObject(), mPath(""), mLevel0(""), mLevel1(""), mLevel2(""), mValid(kTRUE), mWildcard(kFALSE)
25{
26 // default constructor
27}
28
30 : TObject(other),
31 mPath(other.mPath),
32 mLevel0(""),
33 mLevel1(""),
34 mLevel2(""),
35 mValid(other.mValid),
36 mWildcard(other.mWildcard)
37{
38 // constructor
39 init();
40 InitPath();
41}
42
43IdPath::IdPath(const char* level0, const char* level1, const char* level2)
44 : TObject(), mPath(""), mLevel0(level0), mLevel1(level1), mLevel2(level2), mValid(kTRUE), mWildcard(kFALSE)
45{
46 // constructor
47
48 mPath += level0;
49 mPath += '/';
50 mPath += level1;
51 mPath += '/';
52 mPath += level2;
53
54 if ((isWord(mLevel0) || mLevel0 == "*") && (isWord(mLevel1) || mLevel1 == "*") &&
55 (isWord(mLevel2) || mLevel2 == "*")) {
56
57 mValid = kTRUE;
58 } else {
59 mValid = kFALSE;
60 LOG(error) << R"(Invalid Path ")" << level0 << "/" << level1 << "/" << level2 << R"("!)";
61 }
62
63 init();
64}
65
66IdPath::IdPath(const char* path)
67 : TObject(), mPath(path), mLevel0(""), mLevel1(""), mLevel2(""), mValid(kTRUE), mWildcard(kFALSE)
68{
69 // constructor
70
71 init();
72 InitPath();
73}
74
75IdPath::IdPath(const TString& path)
76 : TObject(), mPath(path), mLevel0(""), mLevel1(""), mLevel2(""), mValid(kTRUE), mWildcard(kFALSE)
77{
78 init();
79 InitPath();
80}
81
82void IdPath::InitPath()
83{
84 // sets mLevel0, mLevel1, mLevel2, validity flagss from mPath
85
86 TSubString strippedString = mPath.Strip(TString::kBoth);
87 TString aString(strippedString);
88 strippedString = aString.Strip(TString::kBoth, '/');
89
90 TObjArray* anArray = TString(strippedString).Tokenize("/");
91 Int_t paramCount = anArray->GetEntriesFast();
92
93 if (paramCount == 1) {
94 if (mPath == "*") {
95 mLevel0 = "*";
96 mLevel1 = "*";
97 mLevel2 = "*";
98
99 mValid = kTRUE;
100 } else {
101 mValid = kFALSE;
102 }
103
104 } else if (paramCount == 2) {
105 mLevel0 = ((TObjString*)anArray->At(0))->GetString();
106 TString bString = ((TObjString*)anArray->At(1))->GetString();
107
108 if (isWord(mLevel0) && bString == "*") {
109 mLevel1 = "*";
110 mLevel2 = "*";
111
112 mValid = kTRUE;
113
114 } else {
115 mValid = kFALSE;
116 }
117
118 } else if (paramCount == 3) {
119 mLevel0 = ((TObjString*)anArray->At(0))->GetString();
120 mLevel1 = ((TObjString*)anArray->At(1))->GetString();
121 mLevel2 = ((TObjString*)anArray->At(2))->GetString();
122
123 if ((isWord(mLevel0) || mLevel0 == "*") && (isWord(mLevel1) || mLevel1 == "*") &&
124 (isWord(mLevel2) || mLevel2 == "*")) {
125
126 mValid = kTRUE;
127 } else {
128 mValid = kFALSE;
129 }
130
131 } else {
132 mValid = kFALSE;
133 }
134
135 if (!mValid) {
136 LOG(info) << R"(Invalid Path ")" << mPath.Data() << R"("!)";
137 } else {
138 mPath = Form("%s/%s/%s", mLevel0.Data(), mLevel1.Data(), mLevel2.Data());
139 }
140
141 delete anArray;
142
143 init();
144}
145
146IdPath::~IdPath() = default;
147
148Bool_t IdPath::isWord(const TString& str)
149{
150 // check if string is a word
151
152 TRegexp pattern("^[a-zA-Z0-9_.-]+$");
153
154 return str.Contains(pattern);
155}
156
157void IdPath::init()
158{
159 // set mWildcard flag
160
161 mWildcard = mPath.MaybeWildcard();
162}
163
164Bool_t IdPath::doesLevel0Contain(const TString& str) const
165{
166 // check if Level0 is wildcard or is equal to str
167
168 if (mLevel0 == "*") {
169 return kTRUE;
170 }
171
172 return mLevel0 == str;
173}
174
175Bool_t IdPath::doesLevel1Contain(const TString& str) const
176{
177 // check if Level1 is wildcard or is equal to str
178
179 if (mLevel1 == "*") {
180 return kTRUE;
181 }
182
183 return mLevel1 == str;
184}
185
186Bool_t IdPath::doesLevel2Contain(const TString& str) const
187{
188 // check if Level2 is wildcard or is equal to str
189
190 if (mLevel2 == "*") {
191 return kTRUE;
192 }
193
194 return mLevel2 == str;
195}
196
198{
199 // check if path is wildcard and comprises other
200
201 return doesLevel0Contain(other.mLevel0) && doesLevel1Contain(other.mLevel1) && doesLevel2Contain(other.mLevel2);
202}
203
204const char* IdPath::getLevel(Int_t i) const
205{
206 // return level i of the path
207
208 switch (i) {
209 case 0:
210 return mLevel0.Data();
211 break;
212 case 1:
213 return mLevel1.Data();
214 break;
215 case 2:
216 return mLevel2.Data();
217 break;
218 default:
219 return nullptr;
220 }
221}
int32_t i
ClassImp(IdPath)
Bool_t doesLevel2Contain(const TString &str) const
Definition IdPath.cxx:186
Bool_t isSupersetOf(const IdPath &other) const
Definition IdPath.cxx:197
Bool_t doesLevel1Contain(const TString &str) const
Definition IdPath.cxx:175
Bool_t doesLevel0Contain(const TString &str) const
Definition IdPath.cxx:164
const char * getLevel(Int_t i) const
Definition IdPath.cxx:204
~IdPath() override
GLsizei const GLchar *const * path
Definition glcorearb.h:3591
information complementary to a CCDB object (path, metadata, startTimeValidity, endTimeValidity etc)
VectorOfTObjectPtrs other
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
std::array< uint16_t, 5 > pattern
const std::string str