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 2005/11/19 17:19:14 byordano
19 RetrieveDATEEntries and RetrieveConditionsData added
21 Revision 1.5 2005/11/19 11:09:27 byordano
22 AliShuttle declaration added
24 Revision 1.4 2005/11/17 17:47:34 byordano
25 TList changed to TObjArray
27 Revision 1.3 2005/11/17 14:43:23 byordano
30 Revision 1.1.1.1 2005/10/28 07:33:58 hristov
31 Initial import as subdirectory in AliRoot
33 Revision 1.2 2005/09/13 08:41:15 byordano
34 default startTime endTime added
36 Revision 1.4 2005/08/30 09:13:02 byordano
39 Revision 1.3 2005/08/29 21:15:47 byordano
45 // This class is the main manager for AliShuttle.
46 // It organizes the data retrieval from DCS and call the
47 // interface methods of AliCDBPreProcessor.
48 // For every detector in AliShuttleConfgi (see AliShuttleConfig),
49 // data for its set of aliases is retrieved. If there is registered
50 // AliCDBPreProcessor for this detector than it will be used
51 // accroding to the schema (see AliCDBPreProcessor).
52 // If there isn't registered AliCDBPreProcessor than the retrieved
53 // data is stored automatically to the undelying AliCDBStorage.
54 // For detSpec is used the alias name.
57 #include "AliShuttle.h"
59 #include "AliCDBManager.h"
60 #include "AliCDBStorage.h"
62 #include "AliCDBPreProcessor.h"
63 #include "AliShuttleConfig.h"
64 #include "AliDCSClient.h"
67 #include <TObjString.h>
71 AliShuttle::AliShuttle(const AliShuttleConfig* config,
72 AliCDBStorage* cdbStorage, UInt_t timeout, Int_t retries):
73 fConfig(config), fStorage(cdbStorage), fTimeout(timeout),
74 fRetries(retries), fCurrentRun(-1), fCurrentStartTime(0),
78 // config: AliShuttleConfig used
79 // cdbStorage: underlying AliCDBStorage
80 // timeout: timeout used for AliDCSClient connection
81 // retries: the number of retries in case of connection error.
86 AliShuttle::~AliShuttle() {
87 fPreProcessorMap.DeleteAll();
90 void AliShuttle::RegisterCDBPreProcessor(AliCDBPreProcessor* processor) {
92 // Registers new AliCDBPreProcessor.
93 // It uses GetName() for indentificator of the pre processor.
94 // The pre processor is registered it there isn't any other
95 // with the same identificator (GetName()).
98 if (fPreProcessorMap.GetValue(processor->GetName())) {
99 AliWarning(Form("AliCDBPreProcessor %s is already registered!",
100 processor->GetName()));
104 fPreProcessorMap.Add(new TObjString(processor->GetName()), processor);
105 processor->SetShuttle(this);
108 Bool_t AliShuttle::Store(const char* detector, const char* specType,
109 TObject* object, AliCDBMetaData* metaData)
112 AliError("Invalid storage object!");
116 AliCDBId id(AliCDBPath(detector, "DCS", specType),
117 GetCurrentRun(), GetCurrentRun());
118 return fStorage->Put(object, id, metaData);
121 Bool_t AliShuttle::Process(Int_t run, UInt_t startTime, UInt_t endTime) {
123 // Makes data retrieval for all detectors in the configuration.
124 // run: is the run number used
125 // startTime: is the run start time
126 // endTime: is the run end time
127 // Returns kFALSE in case of error occured and kTRUE otherwise
130 Bool_t hasError = kFALSE;
132 TIter iter(fConfig->GetDetectors());
133 TObjString* aDetector;
134 while ((aDetector = (TObjString*) iter.Next())) {
135 if(!Process(run, startTime, endTime, aDetector->String())) {
143 Bool_t AliShuttle::Process(Int_t run, UInt_t startTime, UInt_t endTime,
144 const char* detector)
147 // Makes data retrieval just for one specific detector.
148 // Threre should be a configuration for this detector.
149 // run: is the run number used
150 // startTime: is the run start time
151 // endTime: is the run end time
152 // detector: detector for which the retrieval will be made
153 // Returns kFALSE in case of error occured and kTRUE otherwise
156 AliInfo(Form("Retrieving values for %s, run %d", detector, run));
158 if (!fConfig->HasDetector(detector)) {
159 AliError(Form("There isn't any configuration for %s",
165 fCurrentStartTime = startTime;
166 fCurrentEndTime = endTime;
168 TString host(fConfig->GetHost(detector));
169 Int_t port = fConfig->GetPort(detector);
171 AliCDBPreProcessor* aPreProcessor =
172 (AliCDBPreProcessor*) fPreProcessorMap.GetValue(detector);
174 TIter iter(fConfig->GetAliases(detector));
177 Bool_t hasError = kFALSE;
180 aPreProcessor->Initialize(run, startTime, endTime);
183 while ((anAlias = (TObjString*) iter.Next())) {
184 Bool_t result = GetValueSet(host, port,
185 anAlias->String(), valueSet);
187 aPreProcessor->Process(anAlias->String(), valueSet,
193 aPreProcessor->Finalize();
196 AliCDBMetaData metaData;
197 metaData.SetProperty("StartTime",
198 new AliSimpleValue(startTime));
199 metaData.SetProperty("EndTime",
200 new AliSimpleValue(endTime));
201 metaData.SetComment("Automatically stored by AliShuttle!");
204 while ((anAlias = (TObjString*) iter.Next())) {
205 if (GetValueSet(host, port, anAlias->String(),
207 if (!Store(detector, anAlias->String(),
208 &valueSet, &metaData)) {
209 AliError(Form("Can't store %s for %s!",
210 anAlias->String().Data(),
221 fCurrentStartTime = 0;
227 Bool_t AliShuttle::GetValueSet(const char* host, Int_t port, const char* alias,
230 AliDCSClient client(host, port, fTimeout, fRetries);
231 if (!client.IsConnected()) {
235 Int_t result = client.GetAliasValues(alias,
236 GetCurrentStartTime(), GetCurrentEndTime(), valueSet);
239 AliError(Form("Can't get '%s'! Reason: %s",
240 alias, AliDCSClient::GetErrorString(result)));
242 if (result == AliDCSClient::fgkServerError) {
243 AliError(Form("Server error: %s",
244 client.GetServerError().Data()));