]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STEER/AliCDBPath.cxx
Small bugfix (A.Colla)
[u/mrichter/AliRoot.git] / STEER / AliCDBPath.cxx
CommitLineData
9e1ceb13 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16/////////////////////////////////////////////////////////////////////
17// //
18// class AliCDBPath //
19// Path string identifying the object: //
20// "level0/level1/level2" //
21// (was: "Detector/DBType/DetSpecType") //
22// (example: "ZDC/Calib/Pedestals") //
23// //
24/////////////////////////////////////////////////////////////////////
25
26#include "AliCDBPath.h"
27
28#include <TObjArray.h>
29#include <TObjString.h>
30#include <TRegexp.h>
31
32#include "AliLog.h"
33
34ClassImp(AliCDBPath)
35
36//_____________________________________________________________________________
37AliCDBPath::AliCDBPath() {
38// default constructor
39
40}
41
42//_____________________________________________________________________________
43AliCDBPath::AliCDBPath(const AliCDBPath& other):
44TObject(),
45fPath(other.fPath)
46{
47// constructor
48 Init();
49 InitPath();
50
51}
52
53//_____________________________________________________________________________
54AliCDBPath::AliCDBPath(const char* level0, const char* level1,
55 const char* level2):
56fLevel0(level0),
57fLevel1(level1),
58fLevel2(level2)
59{
60// constructor
61
62 fPath += level0;
63 fPath += '/';
64 fPath += level1;
65 fPath += '/';
66 fPath += level2;
67
68 if ((IsWord(fLevel0) || fLevel0 == "*")
69 && (IsWord(fLevel1) || fLevel1 == "*")
70 && (IsWord(fLevel2) || fLevel2 == "*")) {
71
72 fIsValid = kTRUE;
73 } else {
74 fIsValid = kFALSE;
75 AliError(Form("Invalid AliCDBPath <%s/%s/%s>!",
76 level0, level1, level2));
77 }
78
79 Init();
80}
81
82//_____________________________________________________________________________
83AliCDBPath::AliCDBPath(const char* path):
84fPath(path)
85{
86// constructor
87
88 Init();
89 InitPath();
90}
91
92//_____________________________________________________________________________
93AliCDBPath::AliCDBPath(const TString& path):
94fPath(path)
95{
96 Init();
97 InitPath();
98}
99
100//_____________________________________________________________________________
101void AliCDBPath::InitPath() {
102// sets fLevel0, fLevel1, fLevel2, validity flagss from fPath
103
104 TSubString strippedString = fPath.Strip(TString::kBoth);
105 TString aString(strippedString);
106 strippedString = aString.Strip(TString::kBoth, '/');
107
108 TObjArray* anArray = TString(strippedString).Tokenize("/");
109 Int_t paramCount = anArray->GetEntriesFast();
110
111 if (paramCount == 1) {
112 if (fPath == "*") {
113 fLevel0 = "*";
114 fLevel1 = "*";
115 fLevel2 = "*";
116
117 fIsValid = kTRUE;
118 } else {
119 fIsValid = kFALSE;
120 }
121
122 } else if (paramCount == 2) {
123 fLevel0 = ((TObjString*) anArray->At(0))->GetString();
124 TString aString = ((TObjString*) anArray->At(1))->GetString();
125
126 if (IsWord(fLevel0) && aString == "*") {
127 fLevel1 = "*";
128 fLevel2 = "*";
129
130 fIsValid = kTRUE;
131
132 } else {
133 fIsValid = kFALSE;
134 }
135
136 } else if (paramCount == 3) {
137 fLevel0 = ((TObjString*) anArray->At(0))->GetString();
138 fLevel1 = ((TObjString*) anArray->At(1))->GetString();
139 fLevel2 = ((TObjString*) anArray->At(2))->GetString();
140
141 if ((IsWord(fLevel0) || fLevel0 == "*")
142 && (IsWord(fLevel1) || fLevel1 == "*")
143 && (IsWord(fLevel2) || fLevel2 == "*")) {
144
145 fIsValid = kTRUE;
146 } else {
147 fIsValid = kFALSE;
148 }
149
150 } else {
151 fIsValid = kFALSE;
152
153 }
154
155 if (!fIsValid) {
156 AliInfo(Form("Invalid AliCDBPath <%s>!", fPath.Data()));
157 }
158
159 delete anArray;
160
161 Init();
162}
163
164//_____________________________________________________________________________
165AliCDBPath::~AliCDBPath() {
166// destructor
167
168}
169
170//_____________________________________________________________________________
171Bool_t AliCDBPath::IsWord(const TString& str) {
172// check if string is a word
173
174 TRegexp pattern("^[a-zA-Z0-9_]+$");
175
176 return str.Contains(pattern);
177}
178
179//_____________________________________________________________________________
180void AliCDBPath::Init() {
181// set fIsWildcard flag
182
183 fIsWildcard = fPath.MaybeWildcard();
184}
185
186//_____________________________________________________________________________
187Bool_t AliCDBPath::Level0Comprises(const TString& str) const {
188// check if Level0 is wildcard or is equal to str
189
190 if (fLevel0 == "*") {
191 return kTRUE;
192 }
193
194 return fLevel0 == str;
195}
196
197//_____________________________________________________________________________
198Bool_t AliCDBPath::Level1Comprises(const TString& str) const {
199// check if Level1 is wildcard or is equal to str
200
201 if (fLevel1 == "*") {
202 return kTRUE;
203 }
204
205 return fLevel1 == str;
206}
207
208//_____________________________________________________________________________
209Bool_t AliCDBPath::Level2Comprises(const TString& str) const {
210// check if Level2 is wildcard or is equal to str
211
212 if (fLevel2 == "*") {
213 return kTRUE;
214 }
215
216 return fLevel2 == str;
217}
218
219//_____________________________________________________________________________
220Bool_t AliCDBPath::Comprises(const AliCDBPath& other) const {
221// check if path is wildcard and comprises other
222
223 return Level0Comprises(other.fLevel0)
224 && Level1Comprises(other.fLevel1)
225 && Level2Comprises(other.fLevel2);
226}