]>
Commit | Line | Data |
---|---|---|
5c6b40ae | 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$ | |
9827400b | 18 | Revision 1.10 2007/02/28 10:41:01 acolla |
19 | Run type field added in SHUTTLE framework. Run type is read from "run type" logbook and retrieved by | |
20 | AliPreprocessor::GetRunType() function. | |
21 | Added some ldap definition files. | |
22 | ||
d461a8a7 | 23 | Revision 1.8 2007/02/13 11:22:25 acolla |
24 | Shuttle getters and setters of main/local OCDB/Reference storages, temp and log | |
25 | folders moved to AliShuttleInterface | |
26 | ||
e19c88ea | 27 | Revision 1.6 2006/11/06 14:22:47 jgrosseo |
28 | major update (Alberto) | |
29 | o) reading of run parameters from the logbook | |
30 | o) online offline naming conversion | |
31 | o) standalone DCSclient package | |
32 | ||
eba76848 | 33 | Revision 1.5 2006/10/02 12:58:52 jgrosseo |
34 | Small interface change in StoreReferenceData | |
35 | ||
8c77aee7 | 36 | Revision 1.4 2006/08/08 14:19:07 jgrosseo |
37 | Update to shuttle classes (Alberto) | |
38 | ||
39 | - Possibility to set the full object's path in the Preprocessor's and | |
40 | Shuttle's Store functions | |
41 | - Possibility to extend the object's run validity in the same classes | |
42 | ("startValidity" and "validityInfinite" parameters) | |
43 | - Implementation of the StoreReferenceData function to store reference | |
44 | data in a dedicated CDB storage. | |
45 | ||
84090f85 | 46 | Revision 1.3 2006/07/11 12:44:32 jgrosseo |
47 | adding parameters for extended validity range of data produced by preprocessor | |
48 | ||
17111222 | 49 | Revision 1.2 2006/06/06 14:20:05 jgrosseo |
50 | o) updated test preprocessor (alberto) | |
51 | o) added comments to example macro | |
52 | o) test shuttle implements new interface | |
53 | ||
5c6b40ae | 54 | Revision 1.2 2006/03/07 07:52:34 hristov |
55 | New version (B.Yordanov) | |
56 | ||
57 | Revision 1.3 2005/11/17 17:47:34 byordano | |
58 | TList changed to TObjArray | |
59 | ||
60 | Revision 1.2 2005/11/17 14:43:22 byordano | |
61 | import to local CVS | |
62 | ||
63 | Revision 1.1.1.1 2005/10/28 07:33:58 hristov | |
64 | Initial import as subdirectory in AliRoot | |
65 | ||
66 | Revision 1.1.1.1 2005/09/12 22:11:40 byordano | |
67 | SHUTTLE package | |
68 | ||
69 | Revision 1.2 2005/08/29 21:15:47 byordano | |
70 | some docs added | |
71 | ||
72 | */ | |
73 | ||
74 | // | |
75 | // test implementation of the AliShuttleInterface, to be used for local tests of preprocessors | |
76 | // | |
77 | // reads files from the local disk | |
78 | // stores to local CDB | |
79 | // logs to the screen | |
80 | // | |
81 | ||
82 | #include "AliTestShuttle.h" | |
83 | #include "AliLog.h" | |
84 | ||
85 | #include "AliCDBManager.h" | |
84090f85 | 86 | #include "AliCDBStorage.h" |
5c6b40ae | 87 | #include "AliCDBMetaData.h" |
84090f85 | 88 | #include "AliCDBPath.h" |
5c6b40ae | 89 | #include "AliCDBId.h" |
36137ac1 | 90 | #include "AliPreprocessor.h" |
5c6b40ae | 91 | |
92 | #include <TMap.h> | |
93 | #include <TList.h> | |
5c6b40ae | 94 | #include <TObjString.h> |
e19c88ea | 95 | #include <TSystem.h> |
5c6b40ae | 96 | |
97 | ClassImp(AliTestShuttle) | |
98 | ||
36137ac1 | 99 | //______________________________________________________________________________________________ |
17111222 | 100 | AliTestShuttle::AliTestShuttle(Int_t run, UInt_t startTime, UInt_t endTime) : |
101 | fRun(run), | |
102 | fStartTime(startTime), | |
103 | fEndTime(endTime), | |
36137ac1 | 104 | fInputFiles(0), |
eba76848 | 105 | fRunParameters(0), |
9827400b | 106 | fRunType(), |
36137ac1 | 107 | fPreprocessors(0), |
108 | fDcsAliasMap(0) | |
5c6b40ae | 109 | { |
110 | // constructor | |
36137ac1 | 111 | |
112 | fInputFiles = new TMap; | |
eba76848 | 113 | fRunParameters = new TMap; |
36137ac1 | 114 | fPreprocessors = new TObjArray; |
441b0e9c | 115 | |
116 | fInputFiles->SetOwner(1); | |
117 | fRunParameters->SetOwner(1); | |
441b0e9c | 118 | fPreprocessors->SetOwner(1); |
5c6b40ae | 119 | } |
120 | ||
36137ac1 | 121 | //______________________________________________________________________________________________ |
5c6b40ae | 122 | AliTestShuttle::~AliTestShuttle() |
123 | { | |
124 | // destructor | |
36137ac1 | 125 | |
126 | delete fInputFiles; | |
127 | fInputFiles = 0; | |
128 | ||
eba76848 | 129 | delete fRunParameters; |
130 | fRunParameters = 0; | |
131 | ||
36137ac1 | 132 | delete fPreprocessors; |
133 | fPreprocessors = 0; | |
134 | ||
135 | delete fDcsAliasMap; | |
136 | fDcsAliasMap = 0; | |
5c6b40ae | 137 | } |
138 | ||
36137ac1 | 139 | //______________________________________________________________________________________________ |
9827400b | 140 | Bool_t AliTestShuttle::Store(const AliCDBPath& path, TObject* object, AliCDBMetaData* metaData, |
84090f85 | 141 | Int_t validityStart, Bool_t validityInfinite) |
5c6b40ae | 142 | { |
143 | // Stores the CDB object | |
144 | // This function should be called at the end of the preprocessor cycle | |
145 | // | |
146 | // This implementation just stores it on the local disk, the full AliShuttle | |
147 | // puts it to the Grid FileCatalog | |
148 | ||
84090f85 | 149 | Int_t startRun = fRun - validityStart; |
150 | if(startRun < 0) { | |
151 | AliError("First valid run happens to be less than 0! Setting it to 0..."); | |
152 | startRun=0; | |
153 | } | |
17111222 | 154 | |
84090f85 | 155 | Int_t endRun = -1; |
156 | if(validityInfinite) { | |
157 | endRun = AliCDBRunRange::Infinity(); | |
158 | } else { | |
159 | endRun = fRun; | |
160 | } | |
17111222 | 161 | |
84090f85 | 162 | AliCDBId id(path, startRun, endRun); |
17111222 | 163 | |
e19c88ea | 164 | return AliCDBManager::Instance()->GetStorage(fgkMainCDB)->Put(object, id, metaData); |
84090f85 | 165 | } |
17111222 | 166 | |
84090f85 | 167 | //______________________________________________________________________________________________ |
9827400b | 168 | Bool_t AliTestShuttle::StoreReferenceData(const AliCDBPath& path, TObject* object, AliCDBMetaData* metaData) |
84090f85 | 169 | { |
170 | // Stores the object as reference data | |
171 | // This function should be called at the end of the preprocessor cycle | |
172 | // | |
173 | // This implementation just stores it on the local disk, the full AliShuttle | |
174 | // puts it to the Grid FileCatalog | |
175 | ||
8c77aee7 | 176 | AliCDBId id(path, fRun, fRun); |
84090f85 | 177 | |
e19c88ea | 178 | return AliCDBManager::Instance()->GetStorage(fgkMainRefStorage)->Put(object, id, metaData); |
5c6b40ae | 179 | } |
180 | ||
9827400b | 181 | //______________________________________________________________________________________________ |
182 | Bool_t AliTestShuttle::StoreReferenceFile(const char* detector, const char* localFile, const char* gridFileName) | |
183 | { | |
184 | // | |
185 | // Stores reference file directly (without opening it). | |
186 | // | |
187 | // This implementation just stores it on the local disk, the full AliShuttle | |
188 | // puts it to the Grid FileCatalog | |
189 | ||
190 | AliCDBManager* man = AliCDBManager::Instance(); | |
191 | AliCDBStorage* sto = man->GetStorage(fgkMainRefStorage); | |
192 | ||
193 | TString localBaseFolder = sto->GetBaseFolder(); | |
194 | ||
195 | TString targetDir; | |
196 | targetDir.Form("%s/%s", localBaseFolder.Data(), detector); | |
197 | ||
198 | TString target; | |
199 | target.Form("%s/%d_%s", targetDir.Data(), fRun, gridFileName); | |
200 | ||
201 | Int_t result = gSystem->GetPathInfo(targetDir, 0, (Long64_t*) 0, 0, 0); | |
202 | if (result) | |
203 | { | |
204 | result = gSystem->mkdir(targetDir, kTRUE); | |
205 | if (result != 0) | |
206 | { | |
207 | Log("SHUTTLE", Form("StoreReferenceFile - Error creating base directory %s", targetDir.Data())); | |
208 | return kFALSE; | |
209 | } | |
210 | } | |
211 | ||
212 | result = gSystem->CopyFile(localFile, target); | |
213 | ||
214 | if (result == 0) | |
215 | { | |
216 | Log("SHUTTLE", Form("StoreReferenceFile - Stored file %s locally to %s", localFile, target.Data())); | |
217 | return kTRUE; | |
218 | } | |
219 | else | |
220 | { | |
221 | Log("SHUTTLE", Form("StoreReferenceFile - Storing file %s locally to %s failed with %d", localFile, target.Data(), result)); | |
222 | return kFALSE; | |
223 | } | |
224 | } | |
225 | ||
36137ac1 | 226 | //______________________________________________________________________________________________ |
5c6b40ae | 227 | const char* AliTestShuttle::GetFile(Int_t system, const char* detector, const char* id, const char* source) |
228 | { | |
229 | // This function retrieves a file from the given system (kDAQ, kDCS, kHLT) with the given file id | |
230 | // and from the given source in the system. | |
231 | // The function returnes the path to the local file. | |
232 | // | |
233 | // test implementation of GetFile | |
234 | // takes files from the local disks, files are passen in a TMap in the constructor | |
235 | ||
236 | TString key; | |
237 | key.Form("%s-%s-%s", fkSystemNames[system], detector, id); | |
238 | TPair* sourceListPair = dynamic_cast<TPair*> (fInputFiles->FindObject(key.Data())); | |
239 | TMap* sourceList = 0; | |
240 | if (sourceListPair) | |
241 | sourceList = dynamic_cast<TMap*> (sourceListPair->Value()); | |
242 | if (!sourceList) | |
243 | { | |
244 | AliError(Form("Could not find any file in %s with id %s (%s)", fkSystemNames[system], id, key.Data())); | |
245 | return 0; | |
246 | } | |
247 | ||
248 | TPair* fileNamePair = dynamic_cast<TPair*> (sourceList->FindObject(source)); | |
249 | TObjString* fileName = dynamic_cast<TObjString*> (fileNamePair->Value()); | |
250 | if (!fileName) | |
251 | { | |
36137ac1 | 252 | AliError(Form("Could not find files from source %s in %s with id %s", |
253 | source, fkSystemNames[system], id)); | |
5c6b40ae | 254 | return 0; |
255 | } | |
256 | ||
257 | return fileName->GetString().Data(); | |
258 | } | |
259 | ||
36137ac1 | 260 | //______________________________________________________________________________________________ |
5c6b40ae | 261 | TList* AliTestShuttle::GetFileSources(Int_t system, const char* detector, const char* id) |
262 | { | |
263 | // Returns a list of sources in a given system that saved a file with the given id | |
264 | // | |
265 | // test implementation of GetFileSources | |
266 | // takes files from the local disks, files are passen in a TMap in the constructor | |
267 | ||
268 | TString key; | |
269 | key.Form("%s-%s-%s", fkSystemNames[system], detector, id); | |
270 | TPair* sourceListPair = dynamic_cast<TPair*> (fInputFiles->FindObject(key.Data())); | |
271 | TMap* sourceList = 0; | |
272 | if (sourceListPair) | |
273 | sourceList = dynamic_cast<TMap*> (sourceListPair->Value()); | |
274 | if (!sourceList) | |
275 | { | |
276 | AliError(Form("Could not find any file in %s with id %s (%s)", fkSystemNames[system], id, key.Data())); | |
277 | return 0; | |
278 | } | |
279 | ||
280 | TIterator* iter = sourceList->GetTable()->MakeIterator(); | |
281 | TObject* obj = 0; | |
282 | TList* list = new TList; | |
283 | while ((obj = iter->Next())) | |
284 | { | |
285 | TPair* pair = dynamic_cast<TPair*> (obj); | |
286 | if (pair) | |
287 | list->Add(pair->Key()); | |
288 | } | |
289 | ||
290 | delete iter; | |
291 | ||
292 | return list; | |
293 | } | |
294 | ||
36137ac1 | 295 | //______________________________________________________________________________________________ |
5c6b40ae | 296 | void AliTestShuttle::Log(const char* detector, const char* message) |
297 | { | |
298 | // test implementation of Log | |
299 | // just prints to the screen | |
300 | ||
301 | AliInfo(Form("%s: %s", detector, message)); | |
302 | } | |
303 | ||
36137ac1 | 304 | //______________________________________________________________________________________________ |
305 | void AliTestShuttle::AddInputFile(Int_t system, const char* detector, const char* id, const char* source, const char* fileName) | |
306 | { | |
307 | // This function adds a file to the list of input files | |
308 | ||
309 | TString key; | |
310 | key.Form("%s-%s-%s", fkSystemNames[system], detector, id); | |
311 | TPair* sourceListPair = dynamic_cast<TPair*> (fInputFiles->FindObject(key.Data())); | |
312 | TMap* sourceList = 0; | |
313 | if (sourceListPair) | |
314 | sourceList = dynamic_cast<TMap*> (sourceListPair->Value()); | |
315 | if (!sourceList) | |
316 | { | |
317 | sourceList = new TMap; | |
318 | fInputFiles->Add(new TObjString(key), sourceList); | |
319 | } | |
320 | ||
321 | sourceList->Add(new TObjString(source), new TObjString(fileName)); | |
322 | } | |
323 | ||
d461a8a7 | 324 | //______________________________________________________________________________________________ |
325 | Bool_t AliTestShuttle::AddInputCDBEntry(AliCDBEntry* entry) | |
326 | { | |
327 | // This function adds an object in the OCDB to be later retrieved with GetFromOCDB | |
328 | ||
329 | AliCDBStorage *sto = AliCDBManager::Instance()->GetStorage(fgkMainCDB); | |
330 | if (!sto) | |
331 | { | |
332 | Log("SHUTTLE", "GetFromOCDB - Cannot activate main OCDB for query!"); | |
333 | return 0; | |
334 | } | |
335 | ||
336 | return sto->Put(entry); | |
337 | } | |
338 | ||
339 | //______________________________________________________________________________________________ | |
9827400b | 340 | AliCDBEntry* AliTestShuttle::GetFromOCDB(const char* detector, const AliCDBPath& path) |
d461a8a7 | 341 | { |
342 | // returns obiect from OCDB valid for current run | |
343 | ||
344 | AliCDBStorage *sto = AliCDBManager::Instance()->GetStorage(fgkMainCDB); | |
345 | if (!sto) | |
346 | { | |
347 | Log("SHUTTLE", "GetFromOCDB - Cannot activate main OCDB for query!"); | |
348 | return 0; | |
349 | } | |
350 | ||
351 | return (AliCDBEntry*) sto->Get(path, fRun); | |
352 | } | |
353 | ||
36137ac1 | 354 | //______________________________________________________________________________________________ |
355 | void AliTestShuttle::Process() | |
356 | { | |
357 | // This function tests all preprocessors that are registered to it | |
358 | // All preprocessors get the same dcs alias map and have access to the same list of files. | |
359 | ||
360 | for (Int_t i=0; i<fPreprocessors->GetEntries(); ++i) | |
361 | { | |
362 | AliPreprocessor* preprocessor = dynamic_cast<AliPreprocessor*> (fPreprocessors->At(i)); | |
363 | if (preprocessor) | |
364 | { | |
17111222 | 365 | preprocessor->Initialize(fRun, fStartTime, fEndTime); |
36137ac1 | 366 | preprocessor->Process(fDcsAliasMap); |
367 | } | |
368 | } | |
369 | } | |
370 | ||
371 | //______________________________________________________________________________________________ | |
372 | void AliTestShuttle::RegisterPreprocessor(AliPreprocessor* preprocessor) | |
373 | { | |
374 | // registers a preprocessor | |
375 | ||
eba76848 | 376 | const char* detName = preprocessor->GetName(); |
377 | if(strcmp("DET", detName) != 0) { | |
378 | if(GetDetPos(detName) < 0) | |
379 | AliFatal(Form("********** !!!!! Invalid detector name: %s !!!!! **********", detName)); | |
441b0e9c | 380 | } |
eba76848 | 381 | |
382 | fPreprocessors->Add(preprocessor); | |
383 | } | |
384 | ||
385 | //______________________________________________________________________________________________ | |
386 | void AliTestShuttle::AddInputRunParameter(const char* key, const char* value){ | |
387 | // set a run parameter (in reality it will be read from the DAQ logbook) | |
388 | ||
389 | TObjString* keyObj = new TObjString(key); | |
390 | if (fRunParameters->Contains(key)) { | |
391 | AliWarning(Form("Parameter %s already existing and it will be replaced.", key)); | |
392 | delete fRunParameters->Remove(keyObj); | |
393 | ||
394 | } | |
395 | fRunParameters->Add(keyObj, new TObjString(value)); | |
396 | AliDebug(2, Form("Number of parameters: %d", fRunParameters-> | |
397 | GetEntries())); | |
398 | } | |
399 | ||
441b0e9c | 400 | //______________________________________________________________________________________________ |
9827400b | 401 | const char* AliTestShuttle::GetRunType() |
402 | { | |
403 | // | |
404 | // get a run parameter | |
405 | // | |
441b0e9c | 406 | |
9827400b | 407 | return fRunType; |
441b0e9c | 408 | } |
409 | ||
eba76848 | 410 | //______________________________________________________________________________________________ |
411 | const char* AliTestShuttle::GetRunParameter(const char* key){ | |
412 | // get a run parameter | |
413 | ||
414 | TObjString* value = dynamic_cast<TObjString*> (fRunParameters->GetValue(key)); | |
415 | if(!value) { | |
416 | AliError(Form("No such parameter: %s", key)); | |
417 | return 0; | |
418 | } | |
419 | return value->GetName(); | |
36137ac1 | 420 | } |
e19c88ea | 421 | |
d461a8a7 | 422 | //______________________________________________________________________________________________ |
423 | void AliTestShuttle::SetShuttleTempDir(const char* tmpDir) | |
424 | { | |
425 | // sets Shuttle temp directory | |
426 | ||
427 | fgkShuttleTempDir = gSystem->ExpandPathName(tmpDir); | |
428 | } | |
429 | ||
430 | //______________________________________________________________________________________________ | |
431 | void AliTestShuttle::SetShuttleLogDir(const char* logDir) | |
432 | { | |
433 | // sets Shuttle log directory | |
434 | ||
435 | fgkShuttleLogDir = gSystem->ExpandPathName(logDir); | |
436 | } | |
437 |