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.3 2006/06/06 14:26:40 jgrosseo
19 o) removed files that were moved to STEER
20 o) shuttle updated to follow the new interface (Alberto)
22 Revision 1.2 2006/03/07 07:52:34 hristov
23 New version (B.Yordanov)
25 Revision 1.6 2005/11/19 17:19:14 byordano
26 RetrieveDATEEntries and RetrieveConditionsData added
28 Revision 1.5 2005/11/19 11:09:27 byordano
29 AliShuttle declaration added
31 Revision 1.4 2005/11/17 17:47:34 byordano
32 TList changed to TObjArray
34 Revision 1.3 2005/11/17 14:43:23 byordano
37 Revision 1.1.1.1 2005/10/28 07:33:58 hristov
38 Initial import as subdirectory in AliRoot
40 Revision 1.2 2005/09/13 08:41:15 byordano
41 default startTime endTime added
43 Revision 1.4 2005/08/30 09:13:02 byordano
46 Revision 1.3 2005/08/29 21:15:47 byordano
52 // This class is the main manager for AliShuttle.
53 // It organizes the data retrieval from DCS and call the
54 // interface methods of AliPreprocessor.
55 // For every detector in AliShuttleConfgi (see AliShuttleConfig),
56 // data for its set of aliases is retrieved. If there is registered
57 // AliPreprocessor for this detector then it will be used
58 // accroding to the schema (see AliPreprocessor).
59 // If there isn't registered AliPreprocessor than the retrieved
60 // data is stored automatically to the undelying AliCDBStorage.
61 // For detSpec is used the alias name.
64 #include "AliShuttle.h"
66 #include "AliCDBManager.h"
67 #include "AliCDBStorage.h"
69 #include "AliShuttleConfig.h"
70 #include "AliDCSClient.h"
72 #include "AliPreprocessor.h"
73 #include "AliDefaultPreprocessor.h"
77 #include <TObjString.h>
81 TString AliShuttle::fgkLocalUri("local://ShuttleCDB");
83 //______________________________________________________________________________________________
84 AliShuttle::AliShuttle(const AliShuttleConfig* config,
85 UInt_t timeout, Int_t retries):
88 fRetries(retries), fCurrentRun(-1), fCurrentStartTime(0),
93 // config: AliShuttleConfig used
94 // mainStorage: underlying AliCDBStorage
95 // localStorage (local) CDB storage to be used if mainStorage is unavailable
96 // timeout: timeout used for AliDCSClient connection
97 // retries: the number of retries in case of connection error.
100 RegisterPreprocessor(new AliDefaultPreprocessor("DEFAULT", 0));
104 //______________________________________________________________________
105 AliShuttle::AliShuttle(const AliShuttle& /*other*/):
106 AliShuttleInterface()
108 // copy constructor (not implemented)
112 //______________________________________________________________________
113 AliShuttle &AliShuttle::operator=(const AliShuttle& /*other*/)
115 // assignment operator (not implemented)
120 //______________________________________________________________________________________________
121 AliShuttle::~AliShuttle()
125 fPreprocessorMap.DeleteAll();
128 //______________________________________________________________________________________________
129 void AliShuttle::RegisterPreprocessor(AliPreprocessor* preprocessor)
132 // Registers new AliPreprocessor.
133 // It uses GetName() for indentificator of the pre processor.
134 // The pre processor is registered it there isn't any other
135 // with the same identificator (GetName()).
138 if (fPreprocessorMap.GetValue(preprocessor->GetName())) {
139 AliWarning(Form("AliPreprocessor %s is already registered!",
140 preprocessor->GetName()));
144 fPreprocessorMap.Add(new TObjString(preprocessor->GetName()), preprocessor);
147 //______________________________________________________________________________________________
148 UInt_t AliShuttle::Store(const char* detector,
149 TObject* object, AliCDBMetaData* metaData)
151 // store data into CDB
153 // 1 if stored in main (Grid) storage
154 // 2 if stored in backup (Local) storage
156 if (!(AliCDBManager::Instance()->IsDefaultStorageSet())) {
157 AliError("No CDB storage set!");
161 AliCDBId id(AliCDBPath(detector, "DCS", "Data"),
162 GetCurrentRun(), GetCurrentRun());
164 UInt_t result = (UInt_t) AliCDBManager::Instance()->Put(object, id, metaData);
167 Log(detector, "Error while storing object in main storage!");
168 AliError("local storage will be used!");
170 // result = fLocalStorage->Put(object, id, metaData);
171 result = AliCDBManager::Instance()->GetStorage(fgkLocalUri)
172 ->Put(object, id, metaData);
177 Log(detector, "Can't store data!");
184 //______________________________________________________________________________________________
185 Bool_t AliShuttle::Process(Int_t run, UInt_t startTime, UInt_t endTime)
188 // Makes data retrieval for all detectors in the configuration.
189 // run: is the run number used
190 // startTime: is the run start time
191 // endTime: is the run end time
192 // Returns kFALSE in case of error occured and kTRUE otherwise
195 Bool_t hasError = kFALSE;
197 TIter iter(fConfig->GetDetectors());
198 TObjString* aDetector;
202 while ((aDetector = (TObjString*) iter.Next())) {
203 if(!fConfig->HostProcessDetector(aDetector->GetName())) continue;
204 if(!Process(run, startTime, endTime, aDetector->String())) {
209 if(fLog != "") StoreLog(run);
214 //______________________________________________________________________________________________
215 Bool_t AliShuttle::Process(Int_t run, UInt_t startTime, UInt_t endTime,
216 const char* detector)
219 // Makes data retrieval just for one specific detector.
220 // Threre should be a configuration for this detector.
221 // run: is the run number used
222 // startTime: is the run start time
223 // endTime: is the run end time
224 // detector: detector for which the retrieval will be made
225 // Returns kFALSE in case of error occured and kTRUE otherwise
228 AliInfo(Form("Retrieving values for %s, run %d", detector, run));
230 if (!fConfig->HasDetector(detector)) {
231 Log(detector, "There isn't any configuration for %s !");
236 fCurrentStartTime = startTime;
237 fCurrentEndTime = endTime;
239 TString host(fConfig->GetDCSHost(detector));
240 Int_t port = fConfig->GetDCSPort(detector);
242 TIter iter(fConfig->GetDCSAliases(detector));
246 Bool_t hasError = kFALSE;
247 Bool_t result=kFALSE;
249 while ((anAlias = (TObjString*) iter.Next())) {
251 result = GetValueSet(host, port, anAlias->String(), valueSet);
253 aliasMap.Add(anAlias->Clone(), valueSet.Clone());
255 TString message = Form("Error while retrieving alias %s !",
257 Log(detector, message.Data());
262 AliPreprocessor* aPreprocessor =
263 dynamic_cast<AliPreprocessor*> (fPreprocessorMap.GetValue(detector));
265 AliInfo(Form("No Preprocessor for %s: Using default Preprocessor!",detector));
266 aPreprocessor = dynamic_cast<AliPreprocessor*> (fPreprocessorMap.GetValue("DEFAULT"));
269 aPreprocessor->Initialize(run, startTime, endTime);
270 hasError = (Bool_t) !(aPreprocessor->Process(&aliasMap));
275 fCurrentStartTime = 0;
281 //______________________________________________________________________________________________
282 Bool_t AliShuttle::GetValueSet(const char* host, Int_t port, const char* alias,
285 // Retrieve all "alias" data points from the DCS server
286 // host, port: TSocket connection parameters
287 // alias: name of the alias
288 // valueSet: array of retrieved AliDCSValue's
290 AliDCSClient client(host, port, fTimeout, fRetries);
291 if (!client.IsConnected()) {
295 Int_t result = client.GetAliasValues(alias,
296 GetCurrentStartTime(), GetCurrentEndTime(), valueSet);
299 AliError(Form("Can't get '%s'! Reason: %s",
300 alias, AliDCSClient::GetErrorString(result)));
302 if (result == AliDCSClient::fgkServerError) {
303 AliError(Form("Server error: %s",
304 client.GetServerError().Data()));
313 //______________________________________________________________________________________________
314 const char* AliShuttle::GetFile(Int_t /*system*/, const char* /*detector*/,
315 const char* /*id*/, const char* /*source*/)
317 // Get calibration file from DAQ transient file system
319 AliInfo("You are in AliShuttle::GetFile!");
324 //______________________________________________________________________________________________
325 TList* AliShuttle::GetFileSources(Int_t /*system*/, const char* /*detector*/, const char* /*id*/)
327 // Get list of sources that provided the files to be retrieved from DAQ
329 AliInfo("You are in AliShuttle::GetFileSources!");
333 //______________________________________________________________________________________________
334 void AliShuttle::Log(const char* detector, const char* message)
336 // Fill log string with a message
338 TString toLog = Form("%s - %s", detector, message);
339 AliError(toLog.Data());
346 //______________________________________________________________________________________________
347 void AliShuttle::StoreLog(Int_t run)
349 // store error log string to SHUTTLE/SYSTEM/ERROR (on local storage)
351 AliInfo("Printing fLog...");
352 AliInfo(fLog.Data());
353 // Storing log string for runs with errors in "SHUTTLE/SYSTEM/ERRORLOGS"
354 TObjString *logString = new TObjString(fLog);
355 AliCDBId badRunId("SHUTTLE/SYSTEM/ERRORLOGS",run,run);
356 AliCDBMetaData metaData;
357 AliCDBManager::Instance()->GetStorage(fgkLocalUri)
358 ->Put(logString, badRunId,&metaData);