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.6 2006/07/10 13:01:41 jgrosseo
19 enhanced storing of last sucessfully processed run (alberto)
21 Revision 1.5 2006/07/04 14:59:57 jgrosseo
22 revision of AliDCSValue: Removed wrapper classes, reduced storage size per value by factor 2
24 Revision 1.4 2006/06/12 09:11:16 jgrosseo
25 coding conventions (Alberto)
27 Revision 1.3 2006/06/06 14:26:40 jgrosseo
28 o) removed files that were moved to STEER
29 o) shuttle updated to follow the new interface (Alberto)
31 Revision 1.2 2006/03/07 07:52:34 hristov
32 New version (B.Yordanov)
34 Revision 1.6 2005/11/19 17:19:14 byordano
35 RetrieveDATEEntries and RetrieveConditionsData added
37 Revision 1.5 2005/11/19 11:09:27 byordano
38 AliShuttle declaration added
40 Revision 1.4 2005/11/17 17:47:34 byordano
41 TList changed to TObjArray
43 Revision 1.3 2005/11/17 14:43:23 byordano
46 Revision 1.1.1.1 2005/10/28 07:33:58 hristov
47 Initial import as subdirectory in AliRoot
49 Revision 1.2 2005/09/13 08:41:15 byordano
50 default startTime endTime added
52 Revision 1.4 2005/08/30 09:13:02 byordano
55 Revision 1.3 2005/08/29 21:15:47 byordano
61 // This class is the main manager for AliShuttle.
62 // It organizes the data retrieval from DCS and call the
63 // interface methods of AliPreprocessor.
64 // For every detector in AliShuttleConfgi (see AliShuttleConfig),
65 // data for its set of aliases is retrieved. If there is registered
66 // AliPreprocessor for this detector then it will be used
67 // accroding to the schema (see AliPreprocessor).
68 // If there isn't registered AliPreprocessor than the retrieved
69 // data is stored automatically to the undelying AliCDBStorage.
70 // For detSpec is used the alias name.
73 #include "AliShuttle.h"
75 #include "AliCDBManager.h"
76 #include "AliCDBStorage.h"
78 #include "AliShuttleConfig.h"
79 #include "AliDCSClient.h"
81 #include "AliPreprocessor.h"
82 #include "AliDefaultPreprocessor.h"
86 #include <TObjString.h>
90 TString AliShuttle::fgkLocalUri("local://ShuttleCDB");
92 //______________________________________________________________________________________________
93 AliShuttle::AliShuttle(const AliShuttleConfig* config,
94 UInt_t timeout, Int_t retries):
97 fRetries(retries), fCurrentRun(-1), fCurrentStartTime(0),
102 // config: AliShuttleConfig used
103 // timeout: timeout used for AliDCSClient connection
104 // retries: the number of retries in case of connection error.
107 //new AliDefaultPreprocessor("DEFAULT", this);
111 //______________________________________________________________________
112 AliShuttle::AliShuttle(const AliShuttle& /*other*/):
113 AliShuttleInterface()
115 // copy constructor (not implemented)
119 //______________________________________________________________________
120 AliShuttle &AliShuttle::operator=(const AliShuttle& /*other*/)
122 // assignment operator (not implemented)
127 //______________________________________________________________________________________________
128 AliShuttle::~AliShuttle()
132 fPreprocessorMap.DeleteAll();
135 //______________________________________________________________________________________________
136 void AliShuttle::RegisterPreprocessor(AliPreprocessor* preprocessor)
139 // Registers new AliPreprocessor.
140 // It uses GetName() for indentificator of the pre processor.
141 // The pre processor is registered it there isn't any other
142 // with the same identificator (GetName()).
145 if (fPreprocessorMap.GetValue(preprocessor->GetName())) {
146 AliWarning(Form("AliPreprocessor %s is already registered!",
147 preprocessor->GetName()));
151 fPreprocessorMap.Add(new TObjString(preprocessor->GetName()), preprocessor);
154 //______________________________________________________________________________________________
155 UInt_t AliShuttle::Store(const char* detector,
156 TObject* object, AliCDBMetaData* metaData)
158 // store data into CDB
160 // 1 if stored in main (Grid) storage
161 // 2 if stored in backup (Local) storage
164 AliCDBId id(AliCDBPath(detector, "DCS", "Data"),
165 GetCurrentRun(), GetCurrentRun());
168 if (!(AliCDBManager::Instance()->IsDefaultStorageSet())) {
169 Log(detector, "No CDB storage set!");
171 result = (UInt_t) AliCDBManager::Instance()->Put(object, id, metaData);
175 Log(detector, "Error while storing object in main storage!");
176 AliError("local storage will be used!");
178 // result = fLocalStorage->Put(object, id, metaData);
179 result = AliCDBManager::Instance()->GetStorage(fgkLocalUri)
180 ->Put(object, id, metaData);
185 Log(detector, "Can't store data!");
192 //______________________________________________________________________________________________
193 Bool_t AliShuttle::Process(Int_t run, UInt_t startTime, UInt_t endTime)
196 // Makes data retrieval for all detectors in the configuration.
197 // run: is the run number used
198 // startTime: is the run start time
199 // endTime: is the run end time
200 // Returns kFALSE in case of error occured and kTRUE otherwise
203 Bool_t hasError = kFALSE;
205 TIter iter(fConfig->GetDetectors());
206 TObjString* aDetector;
210 while ((aDetector = (TObjString*) iter.Next())) {
211 if(!fConfig->HostProcessDetector(aDetector->GetName())) continue;
212 if(!Process(run, startTime, endTime, aDetector->String())) {
217 if(fLog != "") StoreLog(run);
219 return hasError == kFALSE;
222 //______________________________________________________________________________________________
223 Bool_t AliShuttle::Process(Int_t run, UInt_t startTime, UInt_t endTime,
224 const char* detector)
227 // Makes data retrieval just for one specific detector.
228 // Threre should be a configuration for this detector.
229 // run: is the run number used
230 // startTime: is the run start time
231 // endTime: is the run end time
232 // detector: detector for which the retrieval will be made
233 // Returns kFALSE in case of error occured and kTRUE otherwise
236 AliInfo(Form("Retrieving values for %s, run %d", detector, run));
238 if (!fConfig->HasDetector(detector)) {
239 Log(detector, "There isn't any configuration for %s !");
244 fCurrentStartTime = startTime;
245 fCurrentEndTime = endTime;
247 TString host(fConfig->GetDCSHost(detector));
248 Int_t port = fConfig->GetDCSPort(detector);
250 TIter iter(fConfig->GetDCSAliases(detector));
254 Bool_t hasError = kFALSE;
255 Bool_t result=kFALSE;
257 while ((anAlias = (TObjString*) iter.Next())) {
259 result = GetValueSet(host, port, anAlias->String(), valueSet);
260 //AliInfo(Form("Port = %d",port));
263 aliasMap.Add(anAlias->Clone(), valueSet.Clone());
265 TString message = Form("Error while retrieving alias %s !",
267 Log(detector, message.Data());
272 if(hasError) return kFALSE;
274 AliPreprocessor* aPreprocessor =
275 dynamic_cast<AliPreprocessor*> (fPreprocessorMap.GetValue(detector));
278 aPreprocessor->Initialize(run, startTime, endTime);
279 hasError = (aPreprocessor->Process(&aliasMap) == 0);
281 // TODO default behaviour?
282 AliInfo(Form("No Preprocessor for %s: storing TMap of DP arrays into CDB!",detector));
283 AliCDBMetaData metaData;
284 AliDCSValue dcsValue(startTime, endTime);
285 metaData.SetResponsible(Form("Duck, Donald"));
286 metaData.SetProperty("StartEndTime", &dcsValue);
287 metaData.SetComment("Automatically stored by Shuttle!");
288 hasError = (Store(detector, &aliasMap, &metaData) == 0);
295 fCurrentStartTime = 0;
298 return hasError == kFALSE;
301 //______________________________________________________________________________________________
302 Bool_t AliShuttle::GetValueSet(const char* host, Int_t port, const char* alias,
305 // Retrieve all "alias" data points from the DCS server
306 // host, port: TSocket connection parameters
307 // alias: name of the alias
308 // valueSet: array of retrieved AliDCSValue's
310 AliDCSClient client(host, port, fTimeout, fRetries);
311 if (!client.IsConnected()) {
315 Int_t result = client.GetAliasValues(alias,
316 GetCurrentStartTime(), GetCurrentEndTime(), valueSet);
319 AliError(Form("Can't get '%s'! Reason: %s",
320 alias, AliDCSClient::GetErrorString(result)));
322 if (result == AliDCSClient::fgkServerError) {
323 AliError(Form("Server error: %s",
324 client.GetServerError().Data()));
333 //______________________________________________________________________________________________
334 const char* AliShuttle::GetFile(Int_t /*system*/, const char* /*detector*/,
335 const char* /*id*/, const char* /*source*/)
337 // Get calibration file from DAQ transient file system
339 AliInfo("You are in AliShuttle::GetFile!");
344 //______________________________________________________________________________________________
345 TList* AliShuttle::GetFileSources(Int_t /*system*/, const char* /*detector*/, const char* /*id*/)
347 // Get list of sources that provided the files to be retrieved from DAQ
349 AliInfo("You are in AliShuttle::GetFileSources!");
353 //______________________________________________________________________________________________
354 void AliShuttle::Log(const char* detector, const char* message)
356 // Fill log string with a message
358 TString toLog = Form("%s - %s", detector, message);
359 AliError(toLog.Data());
366 //______________________________________________________________________________________________
367 void AliShuttle::StoreLog(Int_t run)
369 // store error log string to SHUTTLE/SYSTEM/ERROR (on local storage)
371 AliInfo("Printing fLog...");
372 AliInfo(fLog.Data());
373 // Storing log string for runs with errors in "SHUTTLE/SYSTEM/ERRORLOGS"
374 TObjString *logString = new TObjString(fLog);
375 AliCDBId badRunId("SHUTTLE/SYSTEM/ERRORLOGS",run,run);
376 AliCDBMetaData metaData;
377 AliCDBManager::Instance()->GetStorage(fgkLocalUri)
378 ->Put(logString, badRunId,&metaData);