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.4 2006/06/12 09:11:16 jgrosseo
19 coding conventions (Alberto)
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)
25 Revision 1.2 2006/03/07 07:52:34 hristov
26 New version (B.Yordanov)
28 Revision 1.6 2005/11/19 17:19:14 byordano
29 RetrieveDATEEntries and RetrieveConditionsData added
31 Revision 1.5 2005/11/19 11:09:27 byordano
32 AliShuttle declaration added
34 Revision 1.4 2005/11/17 17:47:34 byordano
35 TList changed to TObjArray
37 Revision 1.3 2005/11/17 14:43:23 byordano
40 Revision 1.1.1.1 2005/10/28 07:33:58 hristov
41 Initial import as subdirectory in AliRoot
43 Revision 1.2 2005/09/13 08:41:15 byordano
44 default startTime endTime added
46 Revision 1.4 2005/08/30 09:13:02 byordano
49 Revision 1.3 2005/08/29 21:15:47 byordano
55 // This class is the main manager for AliShuttle.
56 // It organizes the data retrieval from DCS and call the
57 // interface methods of AliPreprocessor.
58 // For every detector in AliShuttleConfgi (see AliShuttleConfig),
59 // data for its set of aliases is retrieved. If there is registered
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
63 // data is stored automatically to the undelying AliCDBStorage.
64 // For detSpec is used the alias name.
67 #include "AliShuttle.h"
69 #include "AliCDBManager.h"
70 #include "AliCDBStorage.h"
72 #include "AliShuttleConfig.h"
73 #include "AliDCSClient.h"
75 #include "AliPreprocessor.h"
76 #include "AliDefaultPreprocessor.h"
80 #include <TObjString.h>
84 TString AliShuttle::fgkLocalUri("local://ShuttleCDB");
86 //______________________________________________________________________________________________
87 AliShuttle::AliShuttle(const AliShuttleConfig* config,
88 UInt_t timeout, Int_t retries):
91 fRetries(retries), fCurrentRun(-1), fCurrentStartTime(0),
96 // config: AliShuttleConfig used
97 // mainStorage: underlying AliCDBStorage
98 // localStorage (local) CDB storage to be used if mainStorage is unavailable
99 // timeout: timeout used for AliDCSClient connection
100 // retries: the number of retries in case of connection error.
103 /*AliDefaultPreprocessor* pp = *///new AliDefaultPreprocessor("DEFAULT", this);
107 //______________________________________________________________________
108 AliShuttle::AliShuttle(const AliShuttle& /*other*/):
109 AliShuttleInterface()
111 // copy constructor (not implemented)
115 //______________________________________________________________________
116 AliShuttle &AliShuttle::operator=(const AliShuttle& /*other*/)
118 // assignment operator (not implemented)
123 //______________________________________________________________________________________________
124 AliShuttle::~AliShuttle()
128 fPreprocessorMap.DeleteAll();
131 //______________________________________________________________________________________________
132 void AliShuttle::RegisterPreprocessor(AliPreprocessor* preprocessor)
135 // Registers new AliPreprocessor.
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()).
141 if (fPreprocessorMap.GetValue(preprocessor->GetName())) {
142 AliWarning(Form("AliPreprocessor %s is already registered!",
143 preprocessor->GetName()));
147 fPreprocessorMap.Add(new TObjString(preprocessor->GetName()), preprocessor);
150 //______________________________________________________________________________________________
151 UInt_t AliShuttle::Store(const char* detector,
152 TObject* object, AliCDBMetaData* metaData)
154 // store data into CDB
156 // 1 if stored in main (Grid) storage
157 // 2 if stored in backup (Local) storage
159 if (!(AliCDBManager::Instance()->IsDefaultStorageSet())) {
160 AliError("No CDB storage set!");
164 AliCDBId id(AliCDBPath(detector, "DCS", "Data"),
165 GetCurrentRun(), GetCurrentRun());
167 UInt_t result = (UInt_t) AliCDBManager::Instance()->Put(object, id, metaData);
170 Log(detector, "Error while storing object in main storage!");
171 AliError("local storage will be used!");
173 // result = fLocalStorage->Put(object, id, metaData);
174 result = AliCDBManager::Instance()->GetStorage(fgkLocalUri)
175 ->Put(object, id, metaData);
180 Log(detector, "Can't store data!");
187 //______________________________________________________________________________________________
188 Bool_t AliShuttle::Process(Int_t run, UInt_t startTime, UInt_t endTime)
191 // Makes data retrieval for all detectors in the configuration.
192 // run: is the run number used
193 // startTime: is the run start time
194 // endTime: is the run end time
195 // Returns kFALSE in case of error occured and kTRUE otherwise
198 Bool_t hasError = kFALSE;
200 TIter iter(fConfig->GetDetectors());
201 TObjString* aDetector;
205 while ((aDetector = (TObjString*) iter.Next())) {
206 if(!fConfig->HostProcessDetector(aDetector->GetName())) continue;
207 if(!Process(run, startTime, endTime, aDetector->String())) {
212 if(fLog != "") StoreLog(run);
217 //______________________________________________________________________________________________
218 Bool_t AliShuttle::Process(Int_t run, UInt_t startTime, UInt_t endTime,
219 const char* detector)
222 // Makes data retrieval just for one specific detector.
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
228 // Returns kFALSE in case of error occured and kTRUE otherwise
231 AliInfo(Form("Retrieving values for %s, run %d", detector, run));
233 if (!fConfig->HasDetector(detector)) {
234 Log(detector, "There isn't any configuration for %s !");
239 fCurrentStartTime = startTime;
240 fCurrentEndTime = endTime;
242 TString host(fConfig->GetDCSHost(detector));
243 Int_t port = fConfig->GetDCSPort(detector);
245 TIter iter(fConfig->GetDCSAliases(detector));
249 Bool_t hasError = kFALSE;
250 Bool_t result=kFALSE;
252 while ((anAlias = (TObjString*) iter.Next())) {
254 result = GetValueSet(host, port, anAlias->String(), valueSet);
256 aliasMap.Add(anAlias->Clone(), valueSet.Clone());
258 TString message = Form("Error while retrieving alias %s !",
260 Log(detector, message.Data());
265 AliPreprocessor* aPreprocessor =
266 dynamic_cast<AliPreprocessor*> (fPreprocessorMap.GetValue(detector));
268 AliInfo(Form("No Preprocessor for %s: Using default Preprocessor!",detector));
269 aPreprocessor = dynamic_cast<AliPreprocessor*> (fPreprocessorMap.GetValue("DEFAULT"));
274 aPreprocessor->Initialize(run, startTime, endTime);
275 hasError = (aPreprocessor->Process(&aliasMap) != 0);
278 AliWarning(Form("No preprocessor for %s available", detector));
283 fCurrentStartTime = 0;
289 //______________________________________________________________________________________________
290 Bool_t AliShuttle::GetValueSet(const char* host, Int_t port, const char* alias,
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
298 AliDCSClient client(host, port, fTimeout, fRetries);
299 if (!client.IsConnected()) {
303 Int_t result = client.GetAliasValues(alias,
304 GetCurrentStartTime(), GetCurrentEndTime(), valueSet);
307 AliError(Form("Can't get '%s'! Reason: %s",
308 alias, AliDCSClient::GetErrorString(result)));
310 if (result == AliDCSClient::fgkServerError) {
311 AliError(Form("Server error: %s",
312 client.GetServerError().Data()));
321 //______________________________________________________________________________________________
322 const char* AliShuttle::GetFile(Int_t /*system*/, const char* /*detector*/,
323 const char* /*id*/, const char* /*source*/)
325 // Get calibration file from DAQ transient file system
327 AliInfo("You are in AliShuttle::GetFile!");
332 //______________________________________________________________________________________________
333 TList* AliShuttle::GetFileSources(Int_t /*system*/, const char* /*detector*/, const char* /*id*/)
335 // Get list of sources that provided the files to be retrieved from DAQ
337 AliInfo("You are in AliShuttle::GetFileSources!");
341 //______________________________________________________________________________________________
342 void AliShuttle::Log(const char* detector, const char* message)
344 // Fill log string with a message
346 TString toLog = Form("%s - %s", detector, message);
347 AliError(toLog.Data());
354 //______________________________________________________________________________________________
355 void AliShuttle::StoreLog(Int_t run)
357 // store error log string to SHUTTLE/SYSTEM/ERROR (on local storage)
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);