]>
Commit | Line | Data |
---|---|---|
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$ | |
d477ad88 | 18 | Revision 1.6 2005/11/19 17:19:14 byordano |
19 | RetrieveDATEEntries and RetrieveConditionsData added | |
20 | ||
21 | Revision 1.5 2005/11/19 11:09:27 byordano | |
22 | AliShuttle declaration added | |
23 | ||
24 | Revision 1.4 2005/11/17 17:47:34 byordano | |
25 | TList changed to TObjArray | |
26 | ||
27 | Revision 1.3 2005/11/17 14:43:23 byordano | |
28 | import to local CVS | |
29 | ||
30 | Revision 1.1.1.1 2005/10/28 07:33:58 hristov | |
31 | Initial import as subdirectory in AliRoot | |
32 | ||
73abe331 | 33 | Revision 1.2 2005/09/13 08:41:15 byordano |
34 | default startTime endTime added | |
35 | ||
36 | Revision 1.4 2005/08/30 09:13:02 byordano | |
37 | some docs added | |
38 | ||
39 | Revision 1.3 2005/08/29 21:15:47 byordano | |
40 | some docs added | |
41 | ||
42 | */ | |
43 | ||
44 | // | |
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. | |
55 | // | |
56 | ||
57 | #include "AliShuttle.h" | |
58 | ||
59 | #include "AliCDBManager.h" | |
60 | #include "AliCDBStorage.h" | |
61 | #include "AliCDBId.h" | |
62 | #include "AliCDBPreProcessor.h" | |
63 | #include "AliShuttleConfig.h" | |
64 | #include "AliDCSClient.h" | |
65 | #include "AliLog.h" | |
66 | ||
67 | #include <TObjString.h> | |
68 | ||
69 | ClassImp(AliShuttle) | |
70 | ||
71 | AliShuttle::AliShuttle(const AliShuttleConfig* config, | |
d477ad88 | 72 | AliCDBStorage* cdbStorage, UInt_t timeout, Int_t retries): |
73 | fConfig(config), fStorage(cdbStorage), fTimeout(timeout), | |
74 | fRetries(retries), fCurrentRun(-1), fCurrentStartTime(0), | |
75 | fCurrentEndTime(0) | |
73abe331 | 76 | { |
77 | // | |
78 | // config: AliShuttleConfig used | |
d477ad88 | 79 | // cdbStorage: underlying AliCDBStorage |
73abe331 | 80 | // timeout: timeout used for AliDCSClient connection |
81 | // retries: the number of retries in case of connection error. | |
82 | // | |
83 | ||
73abe331 | 84 | } |
85 | ||
86 | AliShuttle::~AliShuttle() { | |
87 | fPreProcessorMap.DeleteAll(); | |
88 | } | |
89 | ||
90 | void AliShuttle::RegisterCDBPreProcessor(AliCDBPreProcessor* processor) { | |
91 | // | |
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()). | |
96 | // | |
97 | ||
98 | if (fPreProcessorMap.GetValue(processor->GetName())) { | |
99 | AliWarning(Form("AliCDBPreProcessor %s is already registered!", | |
100 | processor->GetName())); | |
101 | return; | |
102 | } | |
103 | ||
104 | fPreProcessorMap.Add(new TObjString(processor->GetName()), processor); | |
105 | processor->SetShuttle(this); | |
106 | } | |
107 | ||
108 | Bool_t AliShuttle::Store(const char* detector, const char* specType, | |
109 | TObject* object, AliCDBMetaData* metaData) | |
110 | { | |
111 | if (!fStorage) { | |
112 | AliError("Invalid storage object!"); | |
113 | return kFALSE; | |
114 | } | |
115 | ||
116 | AliCDBId id(AliCDBPath(detector, "DCS", specType), | |
117 | GetCurrentRun(), GetCurrentRun()); | |
118 | return fStorage->Put(object, id, metaData); | |
119 | } | |
120 | ||
d477ad88 | 121 | Bool_t AliShuttle::Process(Int_t run, UInt_t startTime, UInt_t endTime) { |
73abe331 | 122 | // |
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 | |
d477ad88 | 127 | // Returns kFALSE in case of error occured and kTRUE otherwise |
73abe331 | 128 | // |
129 | ||
d477ad88 | 130 | Bool_t hasError = kFALSE; |
131 | ||
73abe331 | 132 | TIter iter(fConfig->GetDetectors()); |
133 | TObjString* aDetector; | |
134 | while ((aDetector = (TObjString*) iter.Next())) { | |
d477ad88 | 135 | if(!Process(run, startTime, endTime, aDetector->String())) { |
136 | hasError = kTRUE; | |
137 | } | |
73abe331 | 138 | } |
d477ad88 | 139 | |
140 | return !hasError; | |
73abe331 | 141 | } |
142 | ||
d477ad88 | 143 | Bool_t AliShuttle::Process(Int_t run, UInt_t startTime, UInt_t endTime, |
73abe331 | 144 | const char* detector) |
145 | { | |
146 | // | |
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 | |
d477ad88 | 153 | // Returns kFALSE in case of error occured and kTRUE otherwise |
73abe331 | 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)); | |
d477ad88 | 161 | return kFALSE; |
73abe331 | 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 | ||
d477ad88 | 177 | Bool_t hasError = kFALSE; |
178 | ||
73abe331 | 179 | if (aPreProcessor) { |
180 | aPreProcessor->Initialize(run, startTime, endTime); | |
181 | ||
d477ad88 | 182 | TObjArray valueSet; |
73abe331 | 183 | while ((anAlias = (TObjString*) iter.Next())) { |
184 | Bool_t result = GetValueSet(host, port, | |
185 | anAlias->String(), valueSet); | |
186 | ||
187 | aPreProcessor->Process(anAlias->String(), valueSet, | |
188 | !result); | |
189 | ||
190 | valueSet.Delete(); | |
191 | } | |
192 | ||
193 | aPreProcessor->Finalize(); | |
194 | ||
195 | } else { | |
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!"); | |
202 | ||
d477ad88 | 203 | TObjArray valueSet; |
73abe331 | 204 | while ((anAlias = (TObjString*) iter.Next())) { |
205 | if (GetValueSet(host, port, anAlias->String(), | |
206 | valueSet)) { | |
207 | if (!Store(detector, anAlias->String(), | |
208 | &valueSet, &metaData)) { | |
209 | AliError(Form("Can't store %s for %s!", | |
210 | anAlias->String().Data(), | |
211 | detector)); | |
d477ad88 | 212 | hasError = kTRUE; |
73abe331 | 213 | } |
214 | } | |
215 | ||
216 | valueSet.Delete(); | |
217 | } | |
218 | } | |
219 | ||
220 | fCurrentRun = -1; | |
221 | fCurrentStartTime = 0; | |
222 | fCurrentEndTime = 0; | |
d477ad88 | 223 | |
224 | return !hasError; | |
73abe331 | 225 | } |
226 | ||
227 | Bool_t AliShuttle::GetValueSet(const char* host, Int_t port, const char* alias, | |
d477ad88 | 228 | TObjArray& valueSet) |
73abe331 | 229 | { |
230 | AliDCSClient client(host, port, fTimeout, fRetries); | |
231 | if (!client.IsConnected()) { | |
232 | return kFALSE; | |
233 | } | |
234 | ||
235 | Int_t result = client.GetAliasValues(alias, | |
236 | GetCurrentStartTime(), GetCurrentEndTime(), valueSet); | |
237 | ||
238 | if (result < 0) { | |
239 | AliError(Form("Can't get '%s'! Reason: %s", | |
240 | alias, AliDCSClient::GetErrorString(result))); | |
241 | ||
242 | if (result == AliDCSClient::fgkServerError) { | |
243 | AliError(Form("Server error: %s", | |
244 | client.GetServerError().Data())); | |
245 | } | |
246 | ||
247 | return kFALSE; | |
248 | } | |
249 | ||
250 | return kTRUE; | |
251 | } |