]>
Commit | Line | Data |
---|---|---|
2c8628dd | 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 | /* $Id$ */ | |
17 | ||
18 | /////////////////////////////////////////////////////////////////////////////// | |
19 | // // | |
fe913d8f | 20 | // Object meta data: full description of a run dependent database object // |
2c8628dd | 21 | // // |
22 | /////////////////////////////////////////////////////////////////////////////// | |
23 | ||
24 | ||
25 | #include <TRegexp.h> | |
fe913d8f | 26 | #include <TObjArray.h> |
27 | #include <TObjString.h> | |
28 | #include <TSystem.h> | |
2c8628dd | 29 | |
fe913d8f | 30 | #include "AliCDBMetaData.h" |
f05209ee | 31 | #include "AliLog.h" |
2c8628dd | 32 | |
33 | ||
fe913d8f | 34 | ClassImp(AliCDBMetaData) |
2c8628dd | 35 | |
36 | ||
37 | //_____________________________________________________________________________ | |
fe913d8f | 38 | AliCDBMetaData::AliCDBMetaData() : |
2c8628dd | 39 | TObject(), |
40 | fName(""), | |
41 | fFirstRun(-1), | |
42 | fLastRun(-1), | |
fe913d8f | 43 | fVersion(-1), |
44 | fPeriod(-1), | |
45 | fFormat(""), | |
46 | fResponsible("Duck, Donald"), | |
47 | fExtraInfo("") | |
2c8628dd | 48 | { |
49 | // default constructor | |
50 | // the default values mean no selection | |
f05209ee | 51 | DecodeName(); |
2c8628dd | 52 | } |
53 | ||
54 | //_____________________________________________________________________________ | |
fe913d8f | 55 | AliCDBMetaData::AliCDBMetaData |
56 | (const char* name, Int_t firstRun, Int_t lastRun, Int_t period, | |
57 | const char* objFormat, const char* responsible, | |
58 | const char* extraInfo): | |
2c8628dd | 59 | TObject(), |
60 | fName(name), | |
61 | fFirstRun(firstRun), | |
62 | fLastRun(lastRun), | |
fe913d8f | 63 | fVersion(-1), |
64 | fPeriod(period), | |
65 | fFormat(objFormat), | |
66 | fResponsible(responsible), | |
67 | fExtraInfo(extraInfo) | |
2c8628dd | 68 | { |
69 | // constructor | |
f05209ee | 70 | DecodeName(); |
2c8628dd | 71 | } |
72 | ||
2c8628dd | 73 | //_____________________________________________________________________________ |
fe913d8f | 74 | AliCDBMetaData::AliCDBMetaData(const AliCDBMetaData& entry) : |
2c8628dd | 75 | TObject(entry), |
76 | fName(entry.fName), | |
77 | fFirstRun(entry.fFirstRun), | |
78 | fLastRun(entry.fLastRun), | |
fe913d8f | 79 | fVersion(entry.fVersion), |
80 | fPeriod(entry.fPeriod), | |
81 | fFormat(entry.fFormat), | |
82 | fResponsible(entry.fResponsible), | |
83 | fExtraInfo(entry.fExtraInfo) | |
2c8628dd | 84 | { |
85 | // copy constructor | |
f05209ee | 86 | DecodeName(); |
2c8628dd | 87 | } |
88 | ||
89 | //_____________________________________________________________________________ | |
fe913d8f | 90 | AliCDBMetaData& AliCDBMetaData::operator = (const AliCDBMetaData& entry) |
2c8628dd | 91 | { |
92 | // assignment operator | |
2c8628dd | 93 | fName = entry.fName; |
94 | fFirstRun = entry.fFirstRun; | |
95 | fLastRun = entry.fLastRun; | |
96 | fVersion = entry.fVersion; | |
fe913d8f | 97 | fPeriod=entry.fPeriod; |
98 | fFormat=entry.fFormat; | |
99 | fResponsible=entry.fResponsible; | |
100 | fExtraInfo=entry.fExtraInfo; | |
f05209ee | 101 | DecodeName(); |
2c8628dd | 102 | return *this; |
103 | } | |
104 | ||
2c8628dd | 105 | //_____________________________________________________________________________ |
fe913d8f | 106 | void AliCDBMetaData::EncodeName(){ |
f05209ee | 107 | // Encode name from single elements ("Detector", "DBType", "DetSpecType" -> "Detector/DBType/DetSpecType") |
108 | fName = fDetector+'/'+fDBType+'/'+fDetSpecType; | |
109 | if(fDBType == "*" && fDetSpecType == "*") fName = fDetector+'/'+'*'; | |
110 | if(fDetector == "*" && fDBType == "*" && fDetSpecType == "*") fName = "*"; | |
111 | ||
112 | } | |
113 | ||
114 | //_____________________________________________________________________________ | |
fe913d8f | 115 | void AliCDBMetaData::DecodeName(){ |
f05209ee | 116 | // Decode name into single elements ("Detector/DBType/DetSpecType" -> "Detector", "DBType", "DetSpecType") |
117 | ||
118 | if(fName==""){fDetector=""; fDBType=""; fDetSpecType=""; return;} | |
119 | ||
120 | while(fName.EndsWith("/")) fName.Remove(fName.Last('/')); | |
121 | while(fName.BeginsWith("/")) fName.Remove(fName.First('/'),1); | |
122 | ||
123 | // fName= "fDetector/fDBType/fDetSpecType | |
124 | int nslashes=fName.CountChar('/'); | |
125 | ||
126 | if(nslashes>2){AliError("Wrong format!\n");fDetector=""; fDBType=""; fDetSpecType="";} | |
127 | ||
128 | if(nslashes == 0){ | |
129 | if(fName == "*"){fDetector="*"; fDBType="*"; fDetSpecType="*";} | |
130 | else{AliError("Wrong format!\n"); fDetector=""; fDBType=""; fDetSpecType="";} | |
131 | } | |
132 | if(nslashes == 1){ | |
133 | if(fName.EndsWith("*")) | |
134 | {fDetector=fName(0, fName.Index('/')); fDBType="*"; fDetSpecType="*";} | |
135 | else {AliError("Wrong format!\n"); fDetector=""; fDBType=""; fDetSpecType="";} | |
136 | } | |
137 | ||
138 | if(nslashes == 2){ | |
139 | int firstsl=fName.First('/'), lastsl=fName.Last('/'), lgth=fName.Length(); | |
140 | fDetector=fName(0, firstsl); | |
141 | fDBType=fName(firstsl+1, lastsl-(firstsl+1)); | |
142 | fDetSpecType=fName(lastsl+1, lgth-(lastsl+1)); | |
143 | } | |
144 | EncodeName(); | |
145 | } | |
146 | ||
147 | //_____________________________________________________________________________ | |
fe913d8f | 148 | Bool_t AliCDBMetaData::IsStrictlyValid(Int_t runNumber, AliCDBMetaData* metaData) const |
2c8628dd | 149 | { |
f05209ee | 150 | // check if the object is valid for runNumber. TRUE if metaData version is equal to this's version |
2c8628dd | 151 | |
152 | if ((fFirstRun >= 0) && (runNumber < fFirstRun)) return kFALSE; | |
153 | if ((fLastRun >= 0) && (runNumber > fLastRun)) return kFALSE; | |
154 | if (metaData) { | |
155 | if ((metaData->fVersion >= 0) && (metaData->fVersion != fVersion)) | |
156 | return kFALSE; | |
157 | } | |
158 | return kTRUE; | |
159 | } | |
160 | ||
f05209ee | 161 | //_____________________________________________________________________________ |
fe913d8f | 162 | Bool_t AliCDBMetaData::IsValid(Int_t runNumber, AliCDBMetaData* metaData) const |
f05209ee | 163 | { |
164 | // check if the object is valid for runNumber. TRUE if metaData version less or equal wrt to this's | |
165 | ||
166 | if ((fFirstRun >= 0) && (runNumber < fFirstRun)) return kFALSE; | |
167 | if ((fLastRun >= 0) && (runNumber > fLastRun)) return kFALSE; | |
168 | if (metaData) { | |
169 | if ((metaData->fVersion >= 0) && (metaData->fVersion < fVersion)) | |
170 | return kFALSE; | |
171 | } | |
172 | return kTRUE; | |
173 | } | |
174 | ||
2c8628dd | 175 | //_____________________________________________________________________________ |
fe913d8f | 176 | Int_t AliCDBMetaData::Compare(const TObject* object) const |
2c8628dd | 177 | { |
f05209ee | 178 | // check whether this is preferred to object |
2c8628dd | 179 | |
fe913d8f | 180 | if (!object || !object->InheritsFrom(AliCDBMetaData::Class())) return 1; |
181 | if (fVersion < ((AliCDBMetaData*)object)->GetVersion()) return -1; | |
182 | if (fVersion > ((AliCDBMetaData*)object)->GetVersion()) return 1; | |
2c8628dd | 183 | return 0; |
184 | } | |
185 | ||
186 | //_____________________________________________________________________________ | |
fe913d8f | 187 | Bool_t AliCDBMetaData::Matches(const char* name, Int_t runNumber) const |
2c8628dd | 188 | { |
189 | // check whether name and run number match with this meta data | |
190 | ||
191 | if ((fFirstRun >= 0) && (runNumber < fFirstRun)) return kFALSE; | |
192 | if ((fLastRun >= 0) && (runNumber > fLastRun)) return kFALSE; | |
f05209ee | 193 | if (!TString(name).Contains(TRegexp(fName))) return kFALSE; |
2c8628dd | 194 | return kTRUE; |
195 | } | |
196 | ||
197 | ||
198 | //_____________________________________________________________________________ | |
fe913d8f | 199 | Bool_t operator == (const AliCDBMetaData& entry1, const AliCDBMetaData& entry2) |
2c8628dd | 200 | { |
201 | // compare two DB entries | |
202 | ||
203 | if (strcmp(entry1.GetName(), entry2.GetName()) != 0) return kFALSE; | |
204 | if (entry1.GetFirstRun() != entry2.GetFirstRun()) return kFALSE; | |
205 | if (entry1.GetLastRun() != entry2.GetLastRun()) return kFALSE; | |
206 | if (entry1.GetVersion() != entry2.GetVersion()) return kFALSE; | |
207 | return kTRUE; | |
208 | } | |
f05209ee | 209 | |
fe913d8f | 210 |