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.5 2006/07/04 14:59:57 jgrosseo
19 revision of AliDCSValue: Removed wrapper classes, reduced storage size per value by factor 2
21 Revision 1.4 2006/06/12 09:11:16 jgrosseo
22 coding conventions (Alberto)
24 Revision 1.3 2006/06/06 14:26:40 jgrosseo
25 o) removed files that were moved to STEER
26 o) shuttle updated to follow the new interface (Alberto)
28 Revision 1.2 2006/03/07 07:52:34 hristov
29 New version (B.Yordanov)
31 Revision 1.6 2005/11/19 17:19:14 byordano
32 RetrieveDATEEntries and RetrieveConditionsData added
34 Revision 1.5 2005/11/19 11:09:27 byordano
35 AliShuttle declaration added
37 Revision 1.4 2005/11/17 17:47:34 byordano
38 TList changed to TObjArray
40 Revision 1.3 2005/11/17 14:43:23 byordano
43 Revision 1.1.1.1 2005/10/28 07:33:58 hristov
44 Initial import as subdirectory in AliRoot
46 Revision 1.2 2005/09/13 08:41:15 byordano
47 default startTime endTime added
49 Revision 1.4 2005/08/30 09:13:02 byordano
52 Revision 1.3 2005/08/29 21:15:47 byordano
58 // This class is the main manager for AliShuttle.
59 // It organizes the data retrieval from DCS and call the
60 // interface methods of AliPreprocessor.
61 // For every detector in AliShuttleConfgi (see AliShuttleConfig),
62 // data for its set of aliases is retrieved. If there is registered
63 // AliPreprocessor for this detector then it will be used
64 // accroding to the schema (see AliPreprocessor).
65 // If there isn't registered AliPreprocessor than the retrieved
66 // data is stored automatically to the undelying AliCDBStorage.
67 // For detSpec is used the alias name.
70 #include "AliShuttle.h"
72 #include "AliCDBManager.h"
73 #include "AliCDBStorage.h"
75 #include "AliShuttleConfig.h"
76 #include "AliDCSClient.h"
78 #include "AliPreprocessor.h"
79 #include "AliDefaultPreprocessor.h"
83 #include <TObjString.h>
87 TString AliShuttle::fgkLocalUri("local://ShuttleCDB");
89 //______________________________________________________________________________________________
90 AliShuttle::AliShuttle(const AliShuttleConfig* config,
91 UInt_t timeout, Int_t retries):
94 fRetries(retries), fCurrentRun(-1), fCurrentStartTime(0),
99 // config: AliShuttleConfig used
100 // timeout: timeout used for AliDCSClient connection
101 // retries: the number of retries in case of connection error.
104 //new AliDefaultPreprocessor("DEFAULT", this);
108 //______________________________________________________________________
109 AliShuttle::AliShuttle(const AliShuttle& /*other*/):
110 AliShuttleInterface()
112 // copy constructor (not implemented)
116 //______________________________________________________________________
117 AliShuttle &AliShuttle::operator=(const AliShuttle& /*other*/)
119 // assignment operator (not implemented)
124 //______________________________________________________________________________________________
125 AliShuttle::~AliShuttle()
129 fPreprocessorMap.DeleteAll();
132 //______________________________________________________________________________________________
133 void AliShuttle::RegisterPreprocessor(AliPreprocessor* preprocessor)
136 // Registers new AliPreprocessor.
137 // It uses GetName() for indentificator of the pre processor.
138 // The pre processor is registered it there isn't any other
139 // with the same identificator (GetName()).
142 if (fPreprocessorMap.GetValue(preprocessor->GetName())) {
143 AliWarning(Form("AliPreprocessor %s is already registered!",
144 preprocessor->GetName()));
148 fPreprocessorMap.Add(new TObjString(preprocessor->GetName()), preprocessor);
151 //______________________________________________________________________________________________
152 UInt_t AliShuttle::Store(const char* detector,
153 TObject* object, AliCDBMetaData* metaData)
155 // store data into CDB
157 // 1 if stored in main (Grid) storage
158 // 2 if stored in backup (Local) storage
161 AliCDBId id(AliCDBPath(detector, "DCS", "Data"),
162 GetCurrentRun(), GetCurrentRun());
165 if (!(AliCDBManager::Instance()->IsDefaultStorageSet())) {
166 Log(detector, "No CDB storage set!");
168 result = (UInt_t) AliCDBManager::Instance()->Put(object, id, metaData);
172 Log(detector, "Error while storing object in main storage!");
173 AliError("local storage will be used!");
175 // result = fLocalStorage->Put(object, id, metaData);
176 result = AliCDBManager::Instance()->GetStorage(fgkLocalUri)
177 ->Put(object, id, metaData);
182 Log(detector, "Can't store data!");
189 //______________________________________________________________________________________________
190 Bool_t AliShuttle::Process(Int_t run, UInt_t startTime, UInt_t endTime)
193 // Makes data retrieval for all detectors in the configuration.
194 // run: is the run number used
195 // startTime: is the run start time
196 // endTime: is the run end time
197 // Returns kFALSE in case of error occured and kTRUE otherwise
200 Bool_t hasError = kFALSE;
202 TIter iter(fConfig->GetDetectors());
203 TObjString* aDetector;
207 while ((aDetector = (TObjString*) iter.Next())) {
208 if(!fConfig->HostProcessDetector(aDetector->GetName())) continue;
209 if(!Process(run, startTime, endTime, aDetector->String())) {
214 if(fLog != "") StoreLog(run);
216 return hasError == kFALSE;
219 //______________________________________________________________________________________________
220 Bool_t AliShuttle::Process(Int_t run, UInt_t startTime, UInt_t endTime,
221 const char* detector)
224 // Makes data retrieval just for one specific detector.
225 // Threre should be a configuration for this detector.
226 // run: is the run number used
227 // startTime: is the run start time
228 // endTime: is the run end time
229 // detector: detector for which the retrieval will be made
230 // Returns kFALSE in case of error occured and kTRUE otherwise
233 AliInfo(Form("Retrieving values for %s, run %d", detector, run));
235 if (!fConfig->HasDetector(detector)) {
236 Log(detector, "There isn't any configuration for %s !");
241 fCurrentStartTime = startTime;
242 fCurrentEndTime = endTime;
244 TString host(fConfig->GetDCSHost(detector));
245 Int_t port = fConfig->GetDCSPort(detector);
247 TIter iter(fConfig->GetDCSAliases(detector));
251 Bool_t hasError = kFALSE;
252 Bool_t result=kFALSE;
254 while ((anAlias = (TObjString*) iter.Next())) {
256 result = GetValueSet(host, port, anAlias->String(), valueSet);
257 //AliInfo(Form("Port = %d",port));
260 aliasMap.Add(anAlias->Clone(), valueSet.Clone());
262 TString message = Form("Error while retrieving alias %s !",
264 Log(detector, message.Data());
269 if(hasError) return kFALSE;
271 AliPreprocessor* aPreprocessor =
272 dynamic_cast<AliPreprocessor*> (fPreprocessorMap.GetValue(detector));
275 aPreprocessor->Initialize(run, startTime, endTime);
276 hasError = (aPreprocessor->Process(&aliasMap) == 0);
278 AliInfo(Form("No Preprocessor for %s: storing TMap of DP arrays into CDB!",detector));
279 AliCDBMetaData metaData;
280 metaData.SetResponsible(Form("Duck, Donald"));
281 metaData.SetProperty("StartEndTime",
282 new AliDCSValue(startTime, endTime));
283 metaData.SetComment("Automatically stored by Shuttle!");
284 hasError = (Store(detector, &aliasMap, &metaData) == 0);
291 fCurrentStartTime = 0;
294 return hasError == kFALSE;
297 //______________________________________________________________________________________________
298 Bool_t AliShuttle::GetValueSet(const char* host, Int_t port, const char* alias,
301 // Retrieve all "alias" data points from the DCS server
302 // host, port: TSocket connection parameters
303 // alias: name of the alias
304 // valueSet: array of retrieved AliDCSValue's
306 AliDCSClient client(host, port, fTimeout, fRetries);
307 if (!client.IsConnected()) {
311 Int_t result = client.GetAliasValues(alias,
312 GetCurrentStartTime(), GetCurrentEndTime(), valueSet);
315 AliError(Form("Can't get '%s'! Reason: %s",
316 alias, AliDCSClient::GetErrorString(result)));
318 if (result == AliDCSClient::fgkServerError) {
319 AliError(Form("Server error: %s",
320 client.GetServerError().Data()));
329 //______________________________________________________________________________________________
330 const char* AliShuttle::GetFile(Int_t /*system*/, const char* /*detector*/,
331 const char* /*id*/, const char* /*source*/)
333 // Get calibration file from DAQ transient file system
335 AliInfo("You are in AliShuttle::GetFile!");
340 //______________________________________________________________________________________________
341 TList* AliShuttle::GetFileSources(Int_t /*system*/, const char* /*detector*/, const char* /*id*/)
343 // Get list of sources that provided the files to be retrieved from DAQ
345 AliInfo("You are in AliShuttle::GetFileSources!");
349 //______________________________________________________________________________________________
350 void AliShuttle::Log(const char* detector, const char* message)
352 // Fill log string with a message
354 TString toLog = Form("%s - %s", detector, message);
355 AliError(toLog.Data());
362 //______________________________________________________________________________________________
363 void AliShuttle::StoreLog(Int_t run)
365 // store error log string to SHUTTLE/SYSTEM/ERROR (on local storage)
367 AliInfo("Printing fLog...");
368 AliInfo(fLog.Data());
369 // Storing log string for runs with errors in "SHUTTLE/SYSTEM/ERRORLOGS"
370 TObjString *logString = new TObjString(fLog);
371 AliCDBId badRunId("SHUTTLE/SYSTEM/ERRORLOGS",run,run);
372 AliCDBMetaData metaData;
373 AliCDBManager::Instance()->GetStorage(fgkLocalUri)
374 ->Put(logString, badRunId,&metaData);