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.2 2006/03/07 07:52:34 hristov
19 New version (B.Yordanov)
21 Revision 1.6 2005/11/19 17:19:14 byordano
22 RetrieveDATEEntries and RetrieveConditionsData added
24 Revision 1.5 2005/11/19 11:09:27 byordano
25 AliShuttle declaration added
27 Revision 1.4 2005/11/17 17:47:34 byordano
28 TList changed to TObjArray
30 Revision 1.3 2005/11/17 14:43:23 byordano
33 Revision 1.1.1.1 2005/10/28 07:33:58 hristov
34 Initial import as subdirectory in AliRoot
36 Revision 1.2 2005/09/13 08:41:15 byordano
37 default startTime endTime added
39 Revision 1.4 2005/08/30 09:13:02 byordano
42 Revision 1.3 2005/08/29 21:15:47 byordano
48 // This class is the main manager for AliShuttle.
49 // It organizes the data retrieval from DCS and call the
50 // interface methods of AliPreprocessor.
51 // For every detector in AliShuttleConfgi (see AliShuttleConfig),
52 // data for its set of aliases is retrieved. If there is registered
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
56 // data is stored automatically to the undelying AliCDBStorage.
57 // For detSpec is used the alias name.
60 #include "AliShuttle.h"
62 #include "AliCDBManager.h"
63 #include "AliCDBStorage.h"
65 #include "AliShuttleConfig.h"
66 #include "AliDCSClient.h"
68 #include "AliPreprocessor.h"
69 #include "AliDefaultPreprocessor.h"
72 #include <TObjString.h>
76 TString AliShuttle::fgkLocalUri("local://ShuttleCDB");
78 //______________________________________________________________________________________________
79 AliShuttle::AliShuttle(const AliShuttleConfig* config,
80 UInt_t timeout, Int_t retries):
83 fRetries(retries), fCurrentRun(-1), fCurrentStartTime(0),
88 // config: AliShuttleConfig used
89 // mainStorage: underlying AliCDBStorage
90 // localStorage (local) CDB storage to be used if mainStorage is unavailable
91 // timeout: timeout used for AliDCSClient connection
92 // retries: the number of retries in case of connection error.
95 RegisterPreprocessor(new AliDefaultPreprocessor("DEFAULT", 0));
99 //______________________________________________________________________________________________
100 AliShuttle::~AliShuttle() {
101 fPreprocessorMap.DeleteAll();
104 //______________________________________________________________________________________________
105 void AliShuttle::RegisterPreprocessor(AliPreprocessor* preprocessor) {
107 // Registers new AliPreprocessor.
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()).
113 if (fPreprocessorMap.GetValue(preprocessor->GetName())) {
114 AliWarning(Form("AliPreprocessor %s is already registered!",
115 preprocessor->GetName()));
119 fPreprocessorMap.Add(new TObjString(preprocessor->GetName()), preprocessor);
122 //______________________________________________________________________________________________
123 UInt_t AliShuttle::Store(const char* detector,
124 TObject* object, AliCDBMetaData* metaData)
126 // store data into CDB
128 // 1 if stored in main (Grid) storage
129 // 2 if stored in backup (Local) storage
131 if (!(AliCDBManager::Instance()->IsDefaultStorageSet())) {
132 AliError("No CDB storage set!");
136 AliCDBId id(AliCDBPath(detector, "DCS", "Data"),
137 GetCurrentRun(), GetCurrentRun());
139 UInt_t result = (UInt_t) AliCDBManager::Instance()->Put(object, id, metaData);
142 Log(detector, "Error while storing object in main storage!");
143 AliError("local storage will be used!");
145 // result = fLocalStorage->Put(object, id, metaData);
146 result = AliCDBManager::Instance()->GetStorage(fgkLocalUri)
147 ->Put(object, id, metaData);
152 Log(detector, "Can't store data!");
159 //______________________________________________________________________________________________
160 Bool_t AliShuttle::Process(Int_t run, UInt_t startTime, UInt_t endTime) {
162 // Makes data retrieval for all detectors in the configuration.
163 // run: is the run number used
164 // startTime: is the run start time
165 // endTime: is the run end time
166 // Returns kFALSE in case of error occured and kTRUE otherwise
169 Bool_t hasError = kFALSE;
171 TIter iter(fConfig->GetDetectors());
172 TObjString* aDetector;
176 while ((aDetector = (TObjString*) iter.Next())) {
177 if(!fConfig->HostProcessDetector(aDetector->GetName())) continue;
178 if(!Process(run, startTime, endTime, aDetector->String())) {
183 if(fLog != "") StoreLog(run);
188 //______________________________________________________________________________________________
189 Bool_t AliShuttle::Process(Int_t run, UInt_t startTime, UInt_t endTime,
190 const char* detector)
193 // Makes data retrieval just for one specific detector.
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
199 // Returns kFALSE in case of error occured and kTRUE otherwise
202 AliInfo(Form("Retrieving values for %s, run %d", detector, run));
204 if (!fConfig->HasDetector(detector)) {
205 Log(detector, "There isn't any configuration for %s !");
210 fCurrentStartTime = startTime;
211 fCurrentEndTime = endTime;
213 TString host(fConfig->GetDCSHost(detector));
214 Int_t port = fConfig->GetDCSPort(detector);
216 TIter iter(fConfig->GetDCSAliases(detector));
220 Bool_t hasError = kFALSE;
221 Bool_t result=kFALSE;
223 while ((anAlias = (TObjString*) iter.Next())) {
225 result = GetValueSet(host, port, anAlias->String(), valueSet);
227 aliasMap.Add(anAlias->Clone(), valueSet.Clone());
229 TString message = Form("Error while retrieving alias %s !",
231 Log(detector, message.Data());
236 AliPreprocessor* aPreprocessor =
237 dynamic_cast<AliPreprocessor*> (fPreprocessorMap.GetValue(detector));
239 AliInfo(Form("No Preprocessor for %s: Using default Preprocessor!",detector));
240 aPreprocessor = dynamic_cast<AliPreprocessor*> (fPreprocessorMap.GetValue("DEFAULT"));
243 aPreprocessor->Initialize(run, startTime, endTime);
244 hasError = (Bool_t) !(aPreprocessor->Process(&aliasMap));
249 fCurrentStartTime = 0;
255 //______________________________________________________________________________________________
256 Bool_t AliShuttle::GetValueSet(const char* host, Int_t port, const char* alias,
259 AliDCSClient client(host, port, fTimeout, fRetries);
260 if (!client.IsConnected()) {
264 Int_t result = client.GetAliasValues(alias,
265 GetCurrentStartTime(), GetCurrentEndTime(), valueSet);
268 AliError(Form("Can't get '%s'! Reason: %s",
269 alias, AliDCSClient::GetErrorString(result)));
271 if (result == AliDCSClient::fgkServerError) {
272 AliError(Form("Server error: %s",
273 client.GetServerError().Data()));
282 //______________________________________________________________________________________________
283 const char* AliShuttle::GetFile(Int_t /*system*/, const char* /*detector*/,
284 const char* /*id*/, const char* /*source*/)
287 AliInfo("You are in AliShuttle::GetFile!");
292 //______________________________________________________________________________________________
293 TList* AliShuttle::GetFileSources(Int_t /*system*/, const char* /*detector*/, const char* /*id*/)
296 AliInfo("You are in AliShuttle::GetFileSources!");
300 //______________________________________________________________________________________________
301 void AliShuttle::Log(const char* detector, const char* message)
304 TString toLog = Form("%s - %s", detector, message);
305 AliError(toLog.Data());
312 //______________________________________________________________________________________________
313 void AliShuttle::StoreLog(Int_t run){
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);