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.12 2007/04/27 07:06:48 jgrosseo
19 GetFileSources returns empty list in case of no files, but successful query
20 No mails sent in testmode
22 Revision 1.11 2007/04/04 10:33:36 jgrosseo
23 1) 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.
24 In case of an error with the Grid, the Shuttle will retry the storing later, the preprocessor does not need to be run again.
26 2) 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.
28 3) New function StoreReferenceFile to _directly_ store a file (without opening it) to the reference storage.
30 4) The memory usage of the preprocessor is monitored. If it exceeds 2 GB it is terminated.
32 5) 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.
33 If you always need DCS data (like before), you do not need to implement it.
35 6) The run type has been added to the monitoring page
37 Revision 1.10 2007/02/28 10:41:01 acolla
38 Run type field added in SHUTTLE framework. Run type is read from "run type" logbook and retrieved by
39 AliPreprocessor::GetRunType() function.
40 Added some ldap definition files.
42 Revision 1.8 2007/02/13 11:22:25 acolla
43 Shuttle getters and setters of main/local OCDB/Reference storages, temp and log
44 folders moved to AliShuttleInterface
46 Revision 1.6 2006/11/06 14:22:47 jgrosseo
47 major update (Alberto)
48 o) reading of run parameters from the logbook
49 o) online offline naming conversion
50 o) standalone DCSclient package
52 Revision 1.5 2006/10/02 12:58:52 jgrosseo
53 Small interface change in StoreReferenceData
55 Revision 1.4 2006/08/08 14:19:07 jgrosseo
56 Update to shuttle classes (Alberto)
58 - Possibility to set the full object's path in the Preprocessor's and
59 Shuttle's Store functions
60 - Possibility to extend the object's run validity in the same classes
61 ("startValidity" and "validityInfinite" parameters)
62 - Implementation of the StoreReferenceData function to store reference
63 data in a dedicated CDB storage.
65 Revision 1.3 2006/07/11 12:44:32 jgrosseo
66 adding parameters for extended validity range of data produced by preprocessor
68 Revision 1.2 2006/06/06 14:20:05 jgrosseo
69 o) updated test preprocessor (alberto)
70 o) added comments to example macro
71 o) test shuttle implements new interface
73 Revision 1.2 2006/03/07 07:52:34 hristov
74 New version (B.Yordanov)
76 Revision 1.3 2005/11/17 17:47:34 byordano
77 TList changed to TObjArray
79 Revision 1.2 2005/11/17 14:43:22 byordano
82 Revision 1.1.1.1 2005/10/28 07:33:58 hristov
83 Initial import as subdirectory in AliRoot
85 Revision 1.1.1.1 2005/09/12 22:11:40 byordano
88 Revision 1.2 2005/08/29 21:15:47 byordano
94 // test implementation of the AliShuttleInterface, to be used for local tests of preprocessors
96 // reads files from the local disk
97 // stores to local CDB
101 #include "AliTestShuttle.h"
104 #include "AliCDBManager.h"
105 #include "AliCDBStorage.h"
106 #include "AliCDBMetaData.h"
107 #include "AliCDBPath.h"
108 #include "AliCDBId.h"
109 #include "AliPreprocessor.h"
113 #include <TObjString.h>
116 ClassImp(AliTestShuttle)
118 //______________________________________________________________________________________________
119 AliTestShuttle::AliTestShuttle(Int_t run, UInt_t startTime, UInt_t endTime) :
121 fStartTime(startTime),
131 fInputFiles = new TMap;
132 fRunParameters = new TMap;
133 fPreprocessors = new TObjArray;
135 fInputFiles->SetOwner(1);
136 fRunParameters->SetOwner(1);
137 fPreprocessors->SetOwner(1);
140 //______________________________________________________________________________________________
141 AliTestShuttle::~AliTestShuttle()
148 delete fRunParameters;
151 delete fPreprocessors;
158 //______________________________________________________________________________________________
159 Bool_t AliTestShuttle::Store(const AliCDBPath& path, TObject* object, AliCDBMetaData* metaData,
160 Int_t validityStart, Bool_t validityInfinite)
162 // Stores the CDB object
163 // This function should be called at the end of the preprocessor cycle
165 // This implementation just stores it on the local disk, the full AliShuttle
166 // puts it to the Grid FileCatalog
168 Int_t startRun = fRun - validityStart;
170 AliError("First valid run happens to be less than 0! Setting it to 0...");
175 if(validityInfinite) {
176 endRun = AliCDBRunRange::Infinity();
181 AliCDBId id(path, startRun, endRun);
183 return AliCDBManager::Instance()->GetStorage(fgkMainCDB)->Put(object, id, metaData);
186 //______________________________________________________________________________________________
187 Bool_t AliTestShuttle::StoreReferenceData(const AliCDBPath& path, TObject* object, AliCDBMetaData* metaData)
189 // Stores the object as reference data
190 // This function should be called at the end of the preprocessor cycle
192 // This implementation just stores it on the local disk, the full AliShuttle
193 // puts it to the Grid FileCatalog
195 AliCDBId id(path, fRun, fRun);
197 return AliCDBManager::Instance()->GetStorage(fgkMainRefStorage)->Put(object, id, metaData);
200 //______________________________________________________________________________________________
201 Bool_t AliTestShuttle::StoreReferenceFile(const char* detector, const char* localFile, const char* gridFileName)
204 // Stores reference file directly (without opening it).
206 // This implementation just stores it on the local disk, the full AliShuttle
207 // puts it to the Grid FileCatalog
209 AliCDBManager* man = AliCDBManager::Instance();
210 AliCDBStorage* sto = man->GetStorage(fgkMainRefStorage);
212 TString localBaseFolder = sto->GetBaseFolder();
215 targetDir.Form("%s/%s", localBaseFolder.Data(), detector);
218 target.Form("%s/%d_%s", targetDir.Data(), fRun, gridFileName);
220 Int_t result = gSystem->GetPathInfo(targetDir, 0, (Long64_t*) 0, 0, 0);
223 result = gSystem->mkdir(targetDir, kTRUE);
226 Log("SHUTTLE", Form("StoreReferenceFile - Error creating base directory %s", targetDir.Data()));
231 result = gSystem->CopyFile(localFile, target);
235 Log("SHUTTLE", Form("StoreReferenceFile - Stored file %s locally to %s", localFile, target.Data()));
240 Log("SHUTTLE", Form("StoreReferenceFile - Storing file %s locally to %s failed with %d", localFile, target.Data(), result));
245 //______________________________________________________________________________________________
246 const char* AliTestShuttle::GetFile(Int_t system, const char* detector, const char* id, const char* source)
248 // This function retrieves a file from the given system (kDAQ, kDCS, kHLT) with the given file id
249 // and from the given source in the system.
250 // The function returnes the path to the local file.
252 // test implementation of GetFile
253 // takes files from the local disks, files are passen in a TMap in the constructor
256 key.Form("%s-%s-%s", fkSystemNames[system], detector, id);
257 TPair* sourceListPair = dynamic_cast<TPair*> (fInputFiles->FindObject(key.Data()));
258 TMap* sourceList = 0;
260 sourceList = dynamic_cast<TMap*> (sourceListPair->Value());
263 AliError(Form("Could not find any file in %s with id %s (%s)", fkSystemNames[system], id, key.Data()));
267 TObjString* fileName = 0;
268 TPair* fileNamePair = dynamic_cast<TPair*> (sourceList->FindObject(source));
270 fileName = dynamic_cast<TObjString*> (fileNamePair->Value());
273 AliError(Form("Could not find files from source %s in %s with id %s",
274 source, fkSystemNames[system], id));
278 return fileName->GetString().Data();
281 //______________________________________________________________________________________________
282 TList* AliTestShuttle::GetFileSources(Int_t system, const char* detector, const char* id)
284 // Returns a list of sources in a given system that saved a file with the given id
286 // test implementation of GetFileSources
287 // takes files from the local disks, files are passen in a TMap in the constructor
291 key.Form("%s-%s-%s", fkSystemNames[system], detector, id);
293 key.Form("%s-%s", fkSystemNames[system], detector);
295 TList* list = new TList;
297 TIterator* iter = fInputFiles->MakeIterator();
299 while ((obj = iter->Next()))
301 TObjString* objStr = dynamic_cast<TObjString*> (obj);
304 Bool_t found = kFALSE;
307 found = (objStr->String().CompareTo(key) == 0);
310 found = objStr->String().BeginsWith(key);
314 TPair* sourceListPair = dynamic_cast<TPair*> (fInputFiles->FindObject(objStr->String().Data()));
315 TMap* sourceList = dynamic_cast<TMap*> (sourceListPair->Value());
317 TIterator* iter2 = sourceList->GetTable()->MakeIterator();
319 while ((obj2 = iter2->Next()))
321 TPair* pair = dynamic_cast<TPair*> (obj2);
324 if (!list->FindObject(pair->Key()))
325 list->Add(new TObjString(pair->Key()->GetName()));
334 if (list->GetEntries() == 0)
335 AliInfo(Form("Could not find any file in %s with id %s (%s)", fkSystemNames[system], id, key.Data()));
340 //______________________________________________________________________________________________
341 TList* AliTestShuttle::GetFileIDs(Int_t system, const char* detector, const char* source)
343 // Returns a list of ids in a given system that saved a file with the given source
345 // test implementation of GetFileSources
346 // takes files from the local disks, files are passen in a TMap in the constructor
350 key.Form("%s-%s", fkSystemNames[system], detector);
352 TList* list = new TList;
354 TIterator* iter = fInputFiles->MakeIterator();
356 while ((obj = iter->Next()))
358 TObjString* objStr = dynamic_cast<TObjString*> (obj);
361 if (objStr->String().BeginsWith(key))
363 Bool_t found = kFALSE;
365 TPair* sourceListPair = dynamic_cast<TPair*> (fInputFiles->FindObject(objStr->String().Data()));
366 TMap* sourceList = dynamic_cast<TMap*> (sourceListPair->Value());
368 TIterator* iter2 = sourceList->GetTable()->MakeIterator();
370 while ((obj2 = iter2->Next()))
372 TPair* pair = dynamic_cast<TPair*> (obj2);
375 if (strcmp(pair->Key()->GetName(), source) == 0)
384 TObjArray* tokens = objStr->String().Tokenize("-");
385 if (tokens->GetEntries() == 3)
387 TObjString* id = dynamic_cast<TObjString*> (tokens->At(2));
388 if (id && !list->FindObject(id->String()))
389 list->Add(new TObjString(id->String()));
399 if (list->GetEntries() == 0)
400 AliInfo(Form("Could not find any file in %s with source %s (%s)", fkSystemNames[system], source, key.Data()));
405 //______________________________________________________________________________________________
406 void AliTestShuttle::Log(const char* detector, const char* message)
408 // test implementation of Log
409 // just prints to the screen
411 AliInfo(Form("%s: %s", detector, message));
414 //______________________________________________________________________________________________
415 void AliTestShuttle::AddInputFile(Int_t system, const char* detector, const char* id, const char* source, const char* fileName)
418 // This function adds a file to the list of input files
419 // the list is stored in fInputFiles
420 // fInputFiles: TMap (key -> value)
421 // <system>-<detector>-<id> -> TMap (key -> value)
422 // <source> -> <filename>
426 key.Form("%s-%s-%s", fkSystemNames[system], detector, id);
427 TPair* sourceListPair = dynamic_cast<TPair*> (fInputFiles->FindObject(key.Data()));
428 TMap* sourceList = 0;
430 sourceList = dynamic_cast<TMap*> (sourceListPair->Value());
433 sourceList = new TMap;
434 fInputFiles->Add(new TObjString(key), sourceList);
437 sourceList->Add(new TObjString(source), new TObjString(fileName));
440 //______________________________________________________________________________________________
441 Bool_t AliTestShuttle::AddInputCDBEntry(AliCDBEntry* entry)
443 // This function adds an object in the OCDB to be later retrieved with GetFromOCDB
445 AliCDBStorage *sto = AliCDBManager::Instance()->GetStorage(fgkMainCDB);
448 Log("SHUTTLE", "GetFromOCDB - Cannot activate main OCDB for query!");
452 return sto->Put(entry);
455 //______________________________________________________________________________________________
456 AliCDBEntry* AliTestShuttle::GetFromOCDB(const char* detector, const AliCDBPath& path)
458 // returns obiect from OCDB valid for current run
460 AliCDBStorage *sto = AliCDBManager::Instance()->GetStorage(fgkMainCDB);
463 Log("SHUTTLE", "GetFromOCDB - Cannot activate main OCDB for query!");
467 return (AliCDBEntry*) sto->Get(path, fRun);
470 //______________________________________________________________________________________________
471 void AliTestShuttle::Process()
473 // This function tests all preprocessors that are registered to it
474 // All preprocessors get the same dcs alias map and have access to the same list of files.
476 for (Int_t i=0; i<fPreprocessors->GetEntries(); ++i)
478 AliPreprocessor* preprocessor = dynamic_cast<AliPreprocessor*> (fPreprocessors->At(i));
481 preprocessor->Initialize(fRun, fStartTime, fEndTime);
482 preprocessor->Process(fDcsAliasMap);
487 //______________________________________________________________________________________________
488 void AliTestShuttle::RegisterPreprocessor(AliPreprocessor* preprocessor)
490 // registers a preprocessor
492 const char* detName = preprocessor->GetName();
493 if(strcmp("DET", detName) != 0) {
494 if(GetDetPos(detName) < 0)
495 AliFatal(Form("********** !!!!! Invalid detector name: %s !!!!! **********", detName));
498 fPreprocessors->Add(preprocessor);
501 //______________________________________________________________________________________________
502 void AliTestShuttle::AddInputRunParameter(const char* key, const char* value){
503 // set a run parameter (in reality it will be read from the DAQ logbook)
505 TObjString* keyObj = new TObjString(key);
506 if (fRunParameters->Contains(key)) {
507 AliWarning(Form("Parameter %s already existing and it will be replaced.", key));
508 delete fRunParameters->Remove(keyObj);
511 fRunParameters->Add(keyObj, new TObjString(value));
512 AliDebug(2, Form("Number of parameters: %d", fRunParameters->
516 //______________________________________________________________________________________________
517 const char* AliTestShuttle::GetRunType()
520 // get a run parameter
526 //______________________________________________________________________________________________
527 const char* AliTestShuttle::GetRunParameter(const char* key){
528 // get a run parameter
530 TObjString* value = dynamic_cast<TObjString*> (fRunParameters->GetValue(key));
532 AliError(Form("No such parameter: %s", key));
535 return value->GetName();
538 //______________________________________________________________________________________________
539 void AliTestShuttle::SetShuttleTempDir(const char* tmpDir)
541 // sets Shuttle temp directory
543 fgkShuttleTempDir = gSystem->ExpandPathName(tmpDir);
546 //______________________________________________________________________________________________
547 void AliTestShuttle::SetShuttleLogDir(const char* logDir)
549 // sets Shuttle log directory
551 fgkShuttleLogDir = gSystem->ExpandPathName(logDir);