1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 Revision 1.7 2006/07/10 14:37:09 jgrosseo
19 small fix + todo comment
21 Revision 1.6 2006/07/10 13:01:41 jgrosseo
22 enhanced storing of last sucessfully processed run (alberto)
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
27 Revision 1.4 2006/06/12 09:11:16 jgrosseo
28 coding conventions (Alberto)
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)
34 Revision 1.2 2006/03/07 07:52:34 hristov
35 New version (B.Yordanov)
37 Revision 1.6 2005/11/19 17:19:14 byordano
38 RetrieveDATEEntries and RetrieveConditionsData added
40 Revision 1.5 2005/11/19 11:09:27 byordano
41 AliShuttle declaration added
43 Revision 1.4 2005/11/17 17:47:34 byordano
44 TList changed to TObjArray
46 Revision 1.3 2005/11/17 14:43:23 byordano
49 Revision 1.1.1.1 2005/10/28 07:33:58 hristov
50 Initial import as subdirectory in AliRoot
52 Revision 1.2 2005/09/13 08:41:15 byordano
53 default startTime endTime added
55 Revision 1.4 2005/08/30 09:13:02 byordano
58 Revision 1.3 2005/08/29 21:15:47 byordano
64 // This class is the main manager for AliShuttle.
65 // It organizes the data retrieval from DCS and call the
66 // interface methods of AliPreprocessor.
67 // For every detector in AliShuttleConfgi (see AliShuttleConfig),
68 // data for its set of aliases is retrieved. If there is registered
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
72 // data is stored automatically to the undelying AliCDBStorage.
73 // For detSpec is used the alias name.
76 #include "AliShuttle.h"
78 #include "AliCDBManager.h"
79 #include "AliCDBStorage.h"
81 #include "AliShuttleConfig.h"
82 #include "AliDCSClient.h"
84 #include "AliPreprocessor.h"
85 #include "AliDefaultPreprocessor.h"
89 #include <TObjString.h>
93 TString AliShuttle::fgkLocalUri("local://ShuttleCDB");
95 //______________________________________________________________________________________________
96 AliShuttle::AliShuttle(const AliShuttleConfig* config,
97 UInt_t timeout, Int_t retries):
100 fRetries(retries), fCurrentRun(-1), fCurrentStartTime(0),
105 // config: AliShuttleConfig used
106 // timeout: timeout used for AliDCSClient connection
107 // retries: the number of retries in case of connection error.
110 //new AliDefaultPreprocessor("DEFAULT", this);
114 //______________________________________________________________________
115 AliShuttle::AliShuttle(const AliShuttle& /*other*/):
116 AliShuttleInterface()
118 // copy constructor (not implemented)
122 //______________________________________________________________________
123 AliShuttle &AliShuttle::operator=(const AliShuttle& /*other*/)
125 // assignment operator (not implemented)
130 //______________________________________________________________________________________________
131 AliShuttle::~AliShuttle()
135 fPreprocessorMap.DeleteAll();
138 //______________________________________________________________________________________________
139 void AliShuttle::RegisterPreprocessor(AliPreprocessor* preprocessor)
142 // Registers new AliPreprocessor.
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()).
148 if (fPreprocessorMap.GetValue(preprocessor->GetName())) {
149 AliWarning(Form("AliPreprocessor %s is already registered!",
150 preprocessor->GetName()));
154 fPreprocessorMap.Add(new TObjString(preprocessor->GetName()), preprocessor);
157 //______________________________________________________________________________________________
158 UInt_t AliShuttle::Store(const char* detector,
159 TObject* object, AliCDBMetaData* metaData, Int_t /*validityStart*/, Bool_t /*validityInfinite*/)
161 // store data into CDB
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)
167 // 1 if stored in main (Grid) storage
168 // 2 if stored in backup (Local) storage
170 // TODO implement use of two parameters
172 // TODO shouldn't the path be given by the preprocessor???
173 AliCDBId id(AliCDBPath(detector, "DCS", "Data"),
174 GetCurrentRun(), GetCurrentRun());
177 if (!(AliCDBManager::Instance()->IsDefaultStorageSet())) {
178 Log(detector, "No CDB storage set!");
180 result = (UInt_t) AliCDBManager::Instance()->Put(object, id, metaData);
184 Log(detector, "Error while storing object in main storage!");
185 AliError("local storage will be used!");
187 // result = fLocalStorage->Put(object, id, metaData);
188 result = AliCDBManager::Instance()->GetStorage(fgkLocalUri)
189 ->Put(object, id, metaData);
194 Log(detector, "Can't store data!");
201 //______________________________________________________________________________________________
202 Bool_t AliShuttle::Process(Int_t run, UInt_t startTime, UInt_t endTime)
205 // Makes data retrieval for all detectors in the configuration.
206 // run: is the run number used
207 // startTime: is the run start time
208 // endTime: is the run end time
209 // Returns kFALSE in case of error occured and kTRUE otherwise
212 Bool_t hasError = kFALSE;
214 TIter iter(fConfig->GetDetectors());
215 TObjString* aDetector;
219 while ((aDetector = (TObjString*) iter.Next())) {
220 if(!fConfig->HostProcessDetector(aDetector->GetName())) continue;
221 if(!Process(run, startTime, endTime, aDetector->String())) {
226 if(fLog != "") StoreLog(run);
228 return hasError == kFALSE;
231 //______________________________________________________________________________________________
232 Bool_t AliShuttle::Process(Int_t run, UInt_t startTime, UInt_t endTime,
233 const char* detector)
236 // Makes data retrieval just for one specific detector.
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
242 // Returns kFALSE in case of error occured and kTRUE otherwise
245 AliInfo(Form("Retrieving values for %s, run %d", detector, run));
247 if (!fConfig->HasDetector(detector)) {
248 Log(detector, "There isn't any configuration for %s !");
253 fCurrentStartTime = startTime;
254 fCurrentEndTime = endTime;
256 TString host(fConfig->GetDCSHost(detector));
257 Int_t port = fConfig->GetDCSPort(detector);
259 TIter iter(fConfig->GetDCSAliases(detector));
263 Bool_t hasError = kFALSE;
264 Bool_t result=kFALSE;
266 while ((anAlias = (TObjString*) iter.Next())) {
268 result = GetValueSet(host, port, anAlias->String(), valueSet);
269 //AliInfo(Form("Port = %d",port));
272 aliasMap.Add(anAlias->Clone(), valueSet.Clone());
274 TString message = Form("Error while retrieving alias %s !",
276 Log(detector, message.Data());
281 if(hasError) return kFALSE;
283 AliPreprocessor* aPreprocessor =
284 dynamic_cast<AliPreprocessor*> (fPreprocessorMap.GetValue(detector));
287 aPreprocessor->Initialize(run, startTime, endTime);
288 hasError = (aPreprocessor->Process(&aliasMap) == 0);
290 // TODO default behaviour?
291 AliInfo(Form("No Preprocessor for %s: storing TMap of DP arrays into CDB!",detector));
292 AliCDBMetaData metaData;
293 AliDCSValue dcsValue(startTime, endTime);
294 metaData.SetResponsible(Form("Duck, Donald"));
295 metaData.SetProperty("StartEndTime", &dcsValue);
296 metaData.SetComment("Automatically stored by Shuttle!");
297 hasError = (Store(detector, &aliasMap, &metaData) == 0);
304 fCurrentStartTime = 0;
307 return hasError == kFALSE;
310 //______________________________________________________________________________________________
311 Bool_t AliShuttle::GetValueSet(const char* host, Int_t port, const char* alias,
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
319 AliDCSClient client(host, port, fTimeout, fRetries);
320 if (!client.IsConnected()) {
324 Int_t result = client.GetAliasValues(alias,
325 GetCurrentStartTime(), GetCurrentEndTime(), valueSet);
328 AliError(Form("Can't get '%s'! Reason: %s",
329 alias, AliDCSClient::GetErrorString(result)));
331 if (result == AliDCSClient::fgkServerError) {
332 AliError(Form("Server error: %s",
333 client.GetServerError().Data()));
342 //______________________________________________________________________________________________
343 const char* AliShuttle::GetFile(Int_t /*system*/, const char* /*detector*/,
344 const char* /*id*/, const char* /*source*/)
346 // Get calibration file from DAQ transient file system
348 AliInfo("You are in AliShuttle::GetFile!");
353 //______________________________________________________________________________________________
354 TList* AliShuttle::GetFileSources(Int_t /*system*/, const char* /*detector*/, const char* /*id*/)
356 // Get list of sources that provided the files to be retrieved from DAQ
358 AliInfo("You are in AliShuttle::GetFileSources!");
362 //______________________________________________________________________________________________
363 void AliShuttle::Log(const char* detector, const char* message)
365 // Fill log string with a message
367 TString toLog = Form("%s - %s", detector, message);
368 AliError(toLog.Data());
375 //______________________________________________________________________________________________
376 void AliShuttle::StoreLog(Int_t run)
378 // store error log string to SHUTTLE/SYSTEM/ERROR (on local storage)
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);