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