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