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.2 2005/09/13 08:41:15 byordano
19 default startTime endTime added
21 Revision 1.4 2005/08/30 09:13:02 byordano
24 Revision 1.3 2005/08/29 21:15:47 byordano
30 // This class is the main manager for AliShuttle.
31 // It organizes the data retrieval from DCS and call the
32 // interface methods of AliCDBPreProcessor.
33 // For every detector in AliShuttleConfgi (see AliShuttleConfig),
34 // data for its set of aliases is retrieved. If there is registered
35 // AliCDBPreProcessor for this detector than it will be used
36 // accroding to the schema (see AliCDBPreProcessor).
37 // If there isn't registered AliCDBPreProcessor than the retrieved
38 // data is stored automatically to the undelying AliCDBStorage.
39 // For detSpec is used the alias name.
42 #include "AliShuttle.h"
44 #include "AliCDBManager.h"
45 #include "AliCDBStorage.h"
47 #include "AliCDBPreProcessor.h"
48 #include "AliShuttleConfig.h"
49 #include "AliDCSClient.h"
52 #include <TObjString.h>
56 AliShuttle::AliShuttle(const AliShuttleConfig* config,
57 const char* cdbStorageURI, UInt_t timeout, Int_t retries):
58 fConfig(config), fStorage(NULL), fTimeout(timeout), fRetries(retries),
59 fCurrentRun(-1), fCurrentStartTime(0), fCurrentEndTime(0)
62 // config: AliShuttleConfig used
63 // cdbStorageURI: uri of the underlying AliCDBStorage
64 // timeout: timeout used for AliDCSClient connection
65 // retries: the number of retries in case of connection error.
68 fStorage = AliCDBManager::Instance()->GetStorage(cdbStorageURI);
70 AliError(Form("Can't get valid storage object for %s!",
75 AliShuttle::AliShuttle(const AliShuttleConfig* config,
76 const AliCDBParam* param, UInt_t timeout, Int_t retries):
77 fConfig(config), fStorage(NULL), fTimeout(timeout), fRetries(retries),
78 fCurrentRun(-1), fCurrentStartTime(0), fCurrentEndTime(0)
81 // config: AliShuttleConfig used
82 // param: param of the underlying AliCDBStorage
83 // timeout: timeout used for AliDCSClient connection
84 // retries: the number of retries in case of connection error.
87 fStorage = AliCDBManager::Instance()->GetStorage(param);
89 AliError(Form("Can't get valid storage object for %s!",
90 param->GetURI().Data()));
94 AliShuttle::~AliShuttle() {
95 fPreProcessorMap.DeleteAll();
98 void AliShuttle::RegisterCDBPreProcessor(AliCDBPreProcessor* processor) {
100 // Registers new AliCDBPreProcessor.
101 // It uses GetName() for indentificator of the pre processor.
102 // The pre processor is registered it there isn't any other
103 // with the same identificator (GetName()).
106 if (fPreProcessorMap.GetValue(processor->GetName())) {
107 AliWarning(Form("AliCDBPreProcessor %s is already registered!",
108 processor->GetName()));
112 fPreProcessorMap.Add(new TObjString(processor->GetName()), processor);
113 processor->SetShuttle(this);
116 Bool_t AliShuttle::Store(const char* detector, const char* specType,
117 TObject* object, AliCDBMetaData* metaData)
120 AliError("Invalid storage object!");
124 AliCDBId id(AliCDBPath(detector, "DCS", specType),
125 GetCurrentRun(), GetCurrentRun());
126 return fStorage->Put(object, id, metaData);
129 void AliShuttle::Process(Int_t run, UInt_t startTime, UInt_t endTime) {
131 // Makes data retrieval for all detectors in the configuration.
132 // run: is the run number used
133 // startTime: is the run start time
134 // endTime: is the run end time
137 TIter iter(fConfig->GetDetectors());
138 TObjString* aDetector;
139 while ((aDetector = (TObjString*) iter.Next())) {
140 Process(run, startTime, endTime, aDetector->String());
144 void AliShuttle::Process(Int_t run, UInt_t startTime, UInt_t endTime,
145 const char* detector)
148 // Makes data retrieval just for one specific detector.
149 // Threre should be a configuration for this detector.
150 // run: is the run number used
151 // startTime: is the run start time
152 // endTime: is the run end time
153 // detector: detector for which the retrieval will be made
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));
178 aPreProcessor->Initialize(run, startTime, endTime);
181 while ((anAlias = (TObjString*) iter.Next())) {
182 Bool_t result = GetValueSet(host, port,
183 anAlias->String(), valueSet);
185 aPreProcessor->Process(anAlias->String(), valueSet,
191 aPreProcessor->Finalize();
194 AliCDBMetaData metaData;
195 metaData.SetProperty("StartTime",
196 new AliSimpleValue(startTime));
197 metaData.SetProperty("EndTime",
198 new AliSimpleValue(endTime));
199 metaData.SetComment("Automatically stored by AliShuttle!");
202 while ((anAlias = (TObjString*) iter.Next())) {
203 if (GetValueSet(host, port, anAlias->String(),
205 if (!Store(detector, anAlias->String(),
206 &valueSet, &metaData)) {
207 AliError(Form("Can't store %s for %s!",
208 anAlias->String().Data(),
218 fCurrentStartTime = 0;
222 Bool_t AliShuttle::GetValueSet(const char* host, Int_t port, const char* alias,
225 AliDCSClient client(host, port, fTimeout, fRetries);
226 if (!client.IsConnected()) {
230 Int_t result = client.GetAliasValues(alias,
231 GetCurrentStartTime(), GetCurrentEndTime(), valueSet);
234 AliError(Form("Can't get '%s'! Reason: %s",
235 alias, AliDCSClient::GetErrorString(result)));
237 if (result == AliDCSClient::fgkServerError) {
238 AliError(Form("Server error: %s",
239 client.GetServerError().Data()));