]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliCDBPath.cxx
The default thickness of the chips is set to 150 mkm (D.Elia). Removing some obsolete...
[u/mrichter/AliRoot.git] / STEER / AliCDBPath.cxx
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
34 ClassImp(AliCDBPath)
35
36 //_____________________________________________________________________________
37 AliCDBPath::AliCDBPath() :
38 fIsValid(kTRUE),
39 fIsWildcard(kFALSE)
40 {
41 // default constructor
42
43 }
44
45 //_____________________________________________________________________________
46 AliCDBPath::AliCDBPath(const AliCDBPath& other):
47 TObject(other),
48 fPath(other.fPath)
49 {
50 // constructor
51         Init();
52         InitPath();
53
54 }
55
56 //_____________________________________________________________________________
57 AliCDBPath::AliCDBPath(const char* level0, const char* level1,
58         const char* level2):
59 fLevel0(level0), 
60 fLevel1(level1), 
61 fLevel2(level2)
62 {
63 // constructor
64
65         fPath += level0;
66         fPath += '/';
67         fPath += level1;
68         fPath += '/';
69         fPath += level2;
70
71         if ((IsWord(fLevel0) || fLevel0 == "*")
72                 && (IsWord(fLevel1) || fLevel1 == "*")
73                 && (IsWord(fLevel2) || fLevel2 == "*")) {
74
75                 fIsValid = kTRUE;
76         } else {
77                 fIsValid = kFALSE;
78                 AliError(Form("Invalid AliCDBPath <%s/%s/%s>!", 
79                         level0, level1, level2));
80         }
81
82         Init();
83 }
84
85 //_____________________________________________________________________________
86 AliCDBPath::AliCDBPath(const char* path):
87 fPath(path)
88 {
89 // constructor
90
91         Init();
92         InitPath();     
93 }
94
95 //_____________________________________________________________________________
96 AliCDBPath::AliCDBPath(const TString& path):
97 fPath(path)
98 {
99         Init();
100         InitPath();
101 }
102
103 //_____________________________________________________________________________
104 void AliCDBPath::InitPath() {
105 // sets fLevel0, fLevel1, fLevel2, validity flagss from fPath
106
107         TSubString strippedString = fPath.Strip(TString::kBoth);
108         TString aString(strippedString);
109         strippedString = aString.Strip(TString::kBoth, '/');
110
111         TObjArray* anArray = TString(strippedString).Tokenize("/");
112         Int_t paramCount = anArray->GetEntriesFast();
113         
114         if (paramCount == 1) {
115                 if (fPath == "*") {
116                         fLevel0 = "*";
117                         fLevel1 = "*";
118                         fLevel2 = "*";
119                         
120                         fIsValid = kTRUE;
121                 } else {
122                         fIsValid = kFALSE;
123                 }
124
125         } else if (paramCount == 2) {
126                 fLevel0 = ((TObjString*) anArray->At(0))->GetString();
127                 TString aString =  ((TObjString*) anArray->At(1))->GetString();
128
129                 if (IsWord(fLevel0) && aString == "*") {
130                         fLevel1 = "*";
131                         fLevel2 = "*";
132                 
133                         fIsValid = kTRUE;                       
134
135                 } else {
136                         fIsValid = kFALSE;
137                 }
138                 
139         } else if (paramCount == 3) {
140                 fLevel0 = ((TObjString*) anArray->At(0))->GetString();
141                 fLevel1 = ((TObjString*) anArray->At(1))->GetString();
142                 fLevel2 = ((TObjString*) anArray->At(2))->GetString();
143
144                 if ((IsWord(fLevel0) || fLevel0 == "*")
145                         && (IsWord(fLevel1) || fLevel1 == "*")
146                         && (IsWord(fLevel2) || fLevel2 == "*")) {
147                         
148                         fIsValid = kTRUE;
149                 } else {
150                         fIsValid = kFALSE;
151                 }
152
153         } else {
154                 fIsValid = kFALSE;
155
156         }
157         
158         if (!fIsValid) {
159                 AliInfo(Form("Invalid AliCDBPath <%s>!", fPath.Data()));
160         }
161         
162         delete anArray;
163
164         Init();
165 }
166
167 //_____________________________________________________________________________
168 AliCDBPath::~AliCDBPath() {
169 // destructor
170
171 }
172
173 //_____________________________________________________________________________
174 Bool_t AliCDBPath::IsWord(const TString& str) {
175 // check if string is a word
176
177         TRegexp pattern("^[a-zA-Z0-9_.]+$");
178
179         return str.Contains(pattern);   
180 }
181
182 //_____________________________________________________________________________
183 void AliCDBPath::Init() {
184 // set fIsWildcard flag
185
186         fIsWildcard = fPath.MaybeWildcard();    
187 }
188
189 //_____________________________________________________________________________
190 Bool_t AliCDBPath::Level0Comprises(const TString& str) const {
191 // check if Level0 is wildcard or is equal to str
192         
193         if (fLevel0 == "*") {
194                 return kTRUE;
195         }
196
197         return fLevel0 == str;
198 }
199
200 //_____________________________________________________________________________
201 Bool_t AliCDBPath::Level1Comprises(const TString& str) const {
202 // check if Level1 is wildcard or is equal to str
203
204         if (fLevel1 == "*") {
205                 return kTRUE;
206         }
207
208         return fLevel1 == str;
209 }
210
211 //_____________________________________________________________________________
212 Bool_t AliCDBPath::Level2Comprises(const TString& str) const {
213 // check if Level2 is wildcard or is equal to str
214         
215         if (fLevel2 == "*") {
216                 return kTRUE;
217         }
218
219         return fLevel2 == str;
220 }
221
222 //_____________________________________________________________________________
223 Bool_t AliCDBPath::Comprises(const AliCDBPath& other) const {
224 // check if path is wildcard and comprises other
225
226         return Level0Comprises(other.fLevel0) 
227                 && Level1Comprises(other.fLevel1)
228                 && Level2Comprises(other.fLevel2);
229 }