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