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