This commit was generated by cvs2svn to compensate for changes in r12269,
[u/mrichter/AliRoot.git] / SHUTTLE / AliShuttle.cxx
CommitLineData
73abe331 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
16/*
17$Log$
18Revision 1.2 2005/09/13 08:41:15 byordano
19default startTime endTime added
20
21Revision 1.4 2005/08/30 09:13:02 byordano
22some docs added
23
24Revision 1.3 2005/08/29 21:15:47 byordano
25some docs added
26
27*/
28
29//
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.
40//
41
42#include "AliShuttle.h"
43
44#include "AliCDBManager.h"
45#include "AliCDBStorage.h"
46#include "AliCDBId.h"
47#include "AliCDBPreProcessor.h"
48#include "AliShuttleConfig.h"
49#include "AliDCSClient.h"
50#include "AliLog.h"
51
52#include <TObjString.h>
53
54ClassImp(AliShuttle)
55
56AliShuttle::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)
60{
61 //
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.
66 //
67
68 fStorage = AliCDBManager::Instance()->GetStorage(cdbStorageURI);
69 if (!fStorage) {
70 AliError(Form("Can't get valid storage object for %s!",
71 cdbStorageURI));
72 }
73}
74
75AliShuttle::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)
79{
80 //
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.
85 //
86
87 fStorage = AliCDBManager::Instance()->GetStorage(param);
88 if (!fStorage) {
89 AliError(Form("Can't get valid storage object for %s!",
90 param->GetURI().Data()));
91 }
92}
93
94AliShuttle::~AliShuttle() {
95 fPreProcessorMap.DeleteAll();
96}
97
98void AliShuttle::RegisterCDBPreProcessor(AliCDBPreProcessor* processor) {
99 //
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()).
104 //
105
106 if (fPreProcessorMap.GetValue(processor->GetName())) {
107 AliWarning(Form("AliCDBPreProcessor %s is already registered!",
108 processor->GetName()));
109 return;
110 }
111
112 fPreProcessorMap.Add(new TObjString(processor->GetName()), processor);
113 processor->SetShuttle(this);
114}
115
116Bool_t AliShuttle::Store(const char* detector, const char* specType,
117 TObject* object, AliCDBMetaData* metaData)
118{
119 if (!fStorage) {
120 AliError("Invalid storage object!");
121 return kFALSE;
122 }
123
124 AliCDBId id(AliCDBPath(detector, "DCS", specType),
125 GetCurrentRun(), GetCurrentRun());
126 return fStorage->Put(object, id, metaData);
127}
128
129void AliShuttle::Process(Int_t run, UInt_t startTime, UInt_t endTime) {
130 //
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
135 //
136
137 TIter iter(fConfig->GetDetectors());
138 TObjString* aDetector;
139 while ((aDetector = (TObjString*) iter.Next())) {
140 Process(run, startTime, endTime, aDetector->String());
141 }
142}
143
144void AliShuttle::Process(Int_t run, UInt_t startTime, UInt_t endTime,
145 const char* detector)
146{
147 //
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
154 //
155
156 AliInfo(Form("Retrieving values for %s, run %d", detector, run));
157
158 if (!fConfig->HasDetector(detector)) {
159 AliError(Form("There isn't any configuration for %s",
160 detector));
161 return;
162 }
163
164 fCurrentRun = run;
165 fCurrentStartTime = startTime;
166 fCurrentEndTime = endTime;
167
168 TString host(fConfig->GetHost(detector));
169 Int_t port = fConfig->GetPort(detector);
170
171 AliCDBPreProcessor* aPreProcessor =
172 (AliCDBPreProcessor*) fPreProcessorMap.GetValue(detector);
173
174 TIter iter(fConfig->GetAliases(detector));
175 TObjString* anAlias;
176
177 if (aPreProcessor) {
178 aPreProcessor->Initialize(run, startTime, endTime);
179
180 TList valueSet;
181 while ((anAlias = (TObjString*) iter.Next())) {
182 Bool_t result = GetValueSet(host, port,
183 anAlias->String(), valueSet);
184
185 aPreProcessor->Process(anAlias->String(), valueSet,
186 !result);
187
188 valueSet.Delete();
189 }
190
191 aPreProcessor->Finalize();
192
193 } else {
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!");
200
201 TList valueSet;
202 while ((anAlias = (TObjString*) iter.Next())) {
203 if (GetValueSet(host, port, anAlias->String(),
204 valueSet)) {
205 if (!Store(detector, anAlias->String(),
206 &valueSet, &metaData)) {
207 AliError(Form("Can't store %s for %s!",
208 anAlias->String().Data(),
209 detector));
210 }
211 }
212
213 valueSet.Delete();
214 }
215 }
216
217 fCurrentRun = -1;
218 fCurrentStartTime = 0;
219 fCurrentEndTime = 0;
220}
221
222Bool_t AliShuttle::GetValueSet(const char* host, Int_t port, const char* alias,
223 TList& valueSet)
224{
225 AliDCSClient client(host, port, fTimeout, fRetries);
226 if (!client.IsConnected()) {
227 return kFALSE;
228 }
229
230 Int_t result = client.GetAliasValues(alias,
231 GetCurrentStartTime(), GetCurrentEndTime(), valueSet);
232
233 if (result < 0) {
234 AliError(Form("Can't get '%s'! Reason: %s",
235 alias, AliDCSClient::GetErrorString(result)));
236
237 if (result == AliDCSClient::fgkServerError) {
238 AliError(Form("Server error: %s",
239 client.GetServerError().Data()));
240 }
241
242 return kFALSE;
243 }
244
245 return kTRUE;
246}