]>
Commit | Line | Data |
---|---|---|
73abe331 | 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 | $Log$ | |
b948db8d | 18 | Revision 1.2 2006/03/07 07:52:34 hristov |
19 | New version (B.Yordanov) | |
20 | ||
d477ad88 | 21 | Revision 1.6 2005/11/19 17:19:14 byordano |
22 | RetrieveDATEEntries and RetrieveConditionsData added | |
23 | ||
24 | Revision 1.5 2005/11/19 11:09:27 byordano | |
25 | AliShuttle declaration added | |
26 | ||
27 | Revision 1.4 2005/11/17 17:47:34 byordano | |
28 | TList changed to TObjArray | |
29 | ||
30 | Revision 1.3 2005/11/17 14:43:23 byordano | |
31 | import to local CVS | |
32 | ||
33 | Revision 1.1.1.1 2005/10/28 07:33:58 hristov | |
34 | Initial import as subdirectory in AliRoot | |
35 | ||
73abe331 | 36 | Revision 1.2 2005/09/13 08:41:15 byordano |
37 | default startTime endTime added | |
38 | ||
39 | Revision 1.4 2005/08/30 09:13:02 byordano | |
40 | some docs added | |
41 | ||
42 | Revision 1.3 2005/08/29 21:15:47 byordano | |
43 | some docs added | |
44 | ||
45 | */ | |
46 | ||
47 | // | |
48 | // This class is the main manager for AliShuttle. | |
49 | // It organizes the data retrieval from DCS and call the | |
b948db8d | 50 | // interface methods of AliPreprocessor. |
73abe331 | 51 | // For every detector in AliShuttleConfgi (see AliShuttleConfig), |
52 | // data for its set of aliases is retrieved. If there is registered | |
b948db8d | 53 | // AliPreprocessor for this detector then it will be used |
54 | // accroding to the schema (see AliPreprocessor). | |
55 | // If there isn't registered AliPreprocessor than the retrieved | |
73abe331 | 56 | // data is stored automatically to the undelying AliCDBStorage. |
57 | // For detSpec is used the alias name. | |
58 | // | |
59 | ||
60 | #include "AliShuttle.h" | |
61 | ||
62 | #include "AliCDBManager.h" | |
63 | #include "AliCDBStorage.h" | |
64 | #include "AliCDBId.h" | |
73abe331 | 65 | #include "AliShuttleConfig.h" |
66 | #include "AliDCSClient.h" | |
67 | #include "AliLog.h" | |
b948db8d | 68 | #include "AliPreprocessor.h" |
69 | #include "AliDefaultPreprocessor.h" | |
73abe331 | 70 | |
b948db8d | 71 | #include <TString.h> |
73abe331 | 72 | #include <TObjString.h> |
73 | ||
74 | ClassImp(AliShuttle) | |
75 | ||
b948db8d | 76 | TString AliShuttle::fgkLocalUri("local://ShuttleCDB"); |
77 | ||
78 | //______________________________________________________________________________________________ | |
79 | AliShuttle::AliShuttle(const AliShuttleConfig* config, | |
80 | UInt_t timeout, Int_t retries): | |
81 | fConfig(config), | |
82 | fTimeout(timeout), | |
83 | fRetries(retries), fCurrentRun(-1), fCurrentStartTime(0), | |
84 | fCurrentEndTime(0), | |
85 | fLog("") | |
73abe331 | 86 | { |
87 | // | |
88 | // config: AliShuttleConfig used | |
b948db8d | 89 | // mainStorage: underlying AliCDBStorage |
90 | // localStorage (local) CDB storage to be used if mainStorage is unavailable | |
73abe331 | 91 | // timeout: timeout used for AliDCSClient connection |
92 | // retries: the number of retries in case of connection error. | |
93 | // | |
94 | ||
b948db8d | 95 | RegisterPreprocessor(new AliDefaultPreprocessor("DEFAULT", 0)); |
96 | ||
73abe331 | 97 | } |
98 | ||
b948db8d | 99 | //______________________________________________________________________________________________ |
73abe331 | 100 | AliShuttle::~AliShuttle() { |
b948db8d | 101 | fPreprocessorMap.DeleteAll(); |
73abe331 | 102 | } |
103 | ||
b948db8d | 104 | //______________________________________________________________________________________________ |
105 | void AliShuttle::RegisterPreprocessor(AliPreprocessor* preprocessor) { | |
73abe331 | 106 | // |
b948db8d | 107 | // Registers new AliPreprocessor. |
73abe331 | 108 | // It uses GetName() for indentificator of the pre processor. |
109 | // The pre processor is registered it there isn't any other | |
110 | // with the same identificator (GetName()). | |
111 | // | |
112 | ||
b948db8d | 113 | if (fPreprocessorMap.GetValue(preprocessor->GetName())) { |
114 | AliWarning(Form("AliPreprocessor %s is already registered!", | |
115 | preprocessor->GetName())); | |
73abe331 | 116 | return; |
117 | } | |
118 | ||
b948db8d | 119 | fPreprocessorMap.Add(new TObjString(preprocessor->GetName()), preprocessor); |
73abe331 | 120 | } |
121 | ||
b948db8d | 122 | //______________________________________________________________________________________________ |
123 | UInt_t AliShuttle::Store(const char* detector, | |
73abe331 | 124 | TObject* object, AliCDBMetaData* metaData) |
125 | { | |
b948db8d | 126 | // store data into CDB |
127 | // returns 0 if fail | |
128 | // 1 if stored in main (Grid) storage | |
129 | // 2 if stored in backup (Local) storage | |
130 | ||
131 | if (!(AliCDBManager::Instance()->IsDefaultStorageSet())) { | |
132 | AliError("No CDB storage set!"); | |
133 | return 0; | |
73abe331 | 134 | } |
135 | ||
b948db8d | 136 | AliCDBId id(AliCDBPath(detector, "DCS", "Data"), |
73abe331 | 137 | GetCurrentRun(), GetCurrentRun()); |
b948db8d | 138 | |
139 | UInt_t result = (UInt_t) AliCDBManager::Instance()->Put(object, id, metaData); | |
140 | if(!result) { | |
141 | ||
142 | Log(detector, "Error while storing object in main storage!"); | |
143 | AliError("local storage will be used!"); | |
144 | ||
145 | // result = fLocalStorage->Put(object, id, metaData); | |
146 | result = AliCDBManager::Instance()->GetStorage(fgkLocalUri) | |
147 | ->Put(object, id, metaData); | |
148 | ||
149 | if(result) { | |
150 | result = 2; | |
151 | }else{ | |
152 | Log(detector, "Can't store data!"); | |
153 | } | |
154 | } | |
155 | return result; | |
156 | ||
73abe331 | 157 | } |
158 | ||
b948db8d | 159 | //______________________________________________________________________________________________ |
d477ad88 | 160 | Bool_t AliShuttle::Process(Int_t run, UInt_t startTime, UInt_t endTime) { |
73abe331 | 161 | // |
b948db8d | 162 | // Makes data retrieval for all detectors in the configuration. |
73abe331 | 163 | // run: is the run number used |
164 | // startTime: is the run start time | |
165 | // endTime: is the run end time | |
d477ad88 | 166 | // Returns kFALSE in case of error occured and kTRUE otherwise |
73abe331 | 167 | // |
168 | ||
d477ad88 | 169 | Bool_t hasError = kFALSE; |
170 | ||
b948db8d | 171 | TIter iter(fConfig->GetDetectors()); |
73abe331 | 172 | TObjString* aDetector; |
b948db8d | 173 | |
174 | ClearLog(); | |
175 | ||
73abe331 | 176 | while ((aDetector = (TObjString*) iter.Next())) { |
b948db8d | 177 | if(!fConfig->HostProcessDetector(aDetector->GetName())) continue; |
d477ad88 | 178 | if(!Process(run, startTime, endTime, aDetector->String())) { |
179 | hasError = kTRUE; | |
180 | } | |
73abe331 | 181 | } |
d477ad88 | 182 | |
b948db8d | 183 | if(fLog != "") StoreLog(run); |
184 | ||
d477ad88 | 185 | return !hasError; |
73abe331 | 186 | } |
187 | ||
b948db8d | 188 | //______________________________________________________________________________________________ |
d477ad88 | 189 | Bool_t AliShuttle::Process(Int_t run, UInt_t startTime, UInt_t endTime, |
73abe331 | 190 | const char* detector) |
191 | { | |
192 | // | |
b948db8d | 193 | // Makes data retrieval just for one specific detector. |
73abe331 | 194 | // Threre should be a configuration for this detector. |
195 | // run: is the run number used | |
196 | // startTime: is the run start time | |
197 | // endTime: is the run end time | |
198 | // detector: detector for which the retrieval will be made | |
d477ad88 | 199 | // Returns kFALSE in case of error occured and kTRUE otherwise |
73abe331 | 200 | // |
201 | ||
202 | AliInfo(Form("Retrieving values for %s, run %d", detector, run)); | |
203 | ||
204 | if (!fConfig->HasDetector(detector)) { | |
b948db8d | 205 | Log(detector, "There isn't any configuration for %s !"); |
d477ad88 | 206 | return kFALSE; |
73abe331 | 207 | } |
208 | ||
209 | fCurrentRun = run; | |
210 | fCurrentStartTime = startTime; | |
211 | fCurrentEndTime = endTime; | |
212 | ||
b948db8d | 213 | TString host(fConfig->GetDCSHost(detector)); |
214 | Int_t port = fConfig->GetDCSPort(detector); | |
73abe331 | 215 | |
b948db8d | 216 | TIter iter(fConfig->GetDCSAliases(detector)); |
73abe331 | 217 | TObjString* anAlias; |
b948db8d | 218 | TMap aliasMap; |
73abe331 | 219 | |
d477ad88 | 220 | Bool_t hasError = kFALSE; |
b948db8d | 221 | Bool_t result=kFALSE; |
d477ad88 | 222 | |
b948db8d | 223 | while ((anAlias = (TObjString*) iter.Next())) { |
d477ad88 | 224 | TObjArray valueSet; |
b948db8d | 225 | result = GetValueSet(host, port, anAlias->String(), valueSet); |
226 | if(result) { | |
227 | aliasMap.Add(anAlias->Clone(), valueSet.Clone()); | |
228 | }else{ | |
229 | TString message = Form("Error while retrieving alias %s !", | |
230 | anAlias->GetName()); | |
231 | Log(detector, message.Data()); | |
232 | hasError = kTRUE; | |
73abe331 | 233 | } |
234 | } | |
b948db8d | 235 | |
236 | AliPreprocessor* aPreprocessor = | |
237 | dynamic_cast<AliPreprocessor*> (fPreprocessorMap.GetValue(detector)); | |
238 | if(!aPreprocessor){ | |
239 | AliInfo(Form("No Preprocessor for %s: Using default Preprocessor!",detector)); | |
240 | aPreprocessor = dynamic_cast<AliPreprocessor*> (fPreprocessorMap.GetValue("DEFAULT")); | |
241 | } | |
242 | ||
243 | aPreprocessor->Initialize(run, startTime, endTime); | |
244 | hasError = (Bool_t) !(aPreprocessor->Process(&aliasMap)); | |
245 | ||
246 | aliasMap.Delete(); | |
247 | ||
73abe331 | 248 | fCurrentRun = -1; |
249 | fCurrentStartTime = 0; | |
250 | fCurrentEndTime = 0; | |
d477ad88 | 251 | |
252 | return !hasError; | |
73abe331 | 253 | } |
254 | ||
b948db8d | 255 | //______________________________________________________________________________________________ |
73abe331 | 256 | Bool_t AliShuttle::GetValueSet(const char* host, Int_t port, const char* alias, |
d477ad88 | 257 | TObjArray& valueSet) |
73abe331 | 258 | { |
259 | AliDCSClient client(host, port, fTimeout, fRetries); | |
260 | if (!client.IsConnected()) { | |
b948db8d | 261 | return kFALSE; |
73abe331 | 262 | } |
263 | ||
264 | Int_t result = client.GetAliasValues(alias, | |
265 | GetCurrentStartTime(), GetCurrentEndTime(), valueSet); | |
266 | ||
267 | if (result < 0) { | |
268 | AliError(Form("Can't get '%s'! Reason: %s", | |
269 | alias, AliDCSClient::GetErrorString(result))); | |
270 | ||
271 | if (result == AliDCSClient::fgkServerError) { | |
272 | AliError(Form("Server error: %s", | |
273 | client.GetServerError().Data())); | |
274 | } | |
275 | ||
276 | return kFALSE; | |
277 | } | |
278 | ||
279 | return kTRUE; | |
280 | } | |
b948db8d | 281 | |
282 | //______________________________________________________________________________________________ | |
283 | const char* AliShuttle::GetFile(Int_t /*system*/, const char* /*detector*/, | |
284 | const char* /*id*/, const char* /*source*/) | |
285 | { | |
286 | ||
287 | AliInfo("You are in AliShuttle::GetFile!"); | |
288 | return 0; | |
289 | } | |
290 | ||
291 | ||
292 | //______________________________________________________________________________________________ | |
293 | TList* AliShuttle::GetFileSources(Int_t /*system*/, const char* /*detector*/, const char* /*id*/) | |
294 | { | |
295 | ||
296 | AliInfo("You are in AliShuttle::GetFileSources!"); | |
297 | return 0; | |
298 | } | |
299 | ||
300 | //______________________________________________________________________________________________ | |
301 | void AliShuttle::Log(const char* detector, const char* message) | |
302 | { | |
303 | ||
304 | TString toLog = Form("%s - %s", detector, message); | |
305 | AliError(toLog.Data()); | |
306 | ||
307 | fLog += toLog; | |
308 | fLog += "\n"; | |
309 | ||
310 | } | |
311 | ||
312 | //______________________________________________________________________________________________ | |
313 | void AliShuttle::StoreLog(Int_t run){ | |
314 | ||
315 | AliInfo("Printing fLog..."); | |
316 | AliInfo(fLog.Data()); | |
317 | // Storing log string for runs with errors in "SHUTTLE/SYSTEM/ERRORLOGS" | |
318 | TObjString *logString = new TObjString(fLog); | |
319 | AliCDBId badRunId("SHUTTLE/SYSTEM/ERRORLOGS",run,run); | |
320 | AliCDBMetaData metaData; | |
321 | AliCDBManager::Instance()->GetStorage(fgkLocalUri) | |
322 | ->Put(logString, badRunId,&metaData); | |
323 | delete logString; | |
324 | ||
325 | ||
326 | } |