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