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.13 2007/05/30 06:35:21 jgrosseo
19 Adding functionality to the Shuttle/TestShuttle:
20 o) Function to retrieve list of sources from a given system (GetFileSources with id=0)
21 o) Function to retrieve list of IDs for a given source (GetFileIDs)
22 These functions are needed for dealing with the tag files that are saved for the GRP preprocessor
23 Example code has been added to the TestProcessor in TestShuttle
25 Revision 1.12 2007/04/27 07:06:48 jgrosseo
26 GetFileSources returns empty list in case of no files, but successful query
27 No mails sent in testmode
29 Revision 1.11 2007/04/04 10:33:36 jgrosseo
30 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.
31 In case of an error with the Grid, the Shuttle will retry the storing later, the preprocessor does not need to be run again.
33 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.
35 3) New function StoreReferenceFile to _directly_ store a file (without opening it) to the reference storage.
37 4) The memory usage of the preprocessor is monitored. If it exceeds 2 GB it is terminated.
39 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.
40 If you always need DCS data (like before), you do not need to implement it.
42 6) The run type has been added to the monitoring page
44 Revision 1.10 2007/02/28 10:41:01 acolla
45 Run type field added in SHUTTLE framework. Run type is read from "run type" logbook and retrieved by
46 AliPreprocessor::GetRunType() function.
47 Added some ldap definition files.
49 Revision 1.8 2007/02/13 11:22:25 acolla
50 Shuttle getters and setters of main/local OCDB/Reference storages, temp and log
51 folders moved to AliShuttleInterface
53 Revision 1.6 2006/11/06 14:22:47 jgrosseo
54 major update (Alberto)
55 o) reading of run parameters from the logbook
56 o) online offline naming conversion
57 o) standalone DCSclient package
59 Revision 1.5 2006/10/02 12:58:52 jgrosseo
60 Small interface change in StoreReferenceData
62 Revision 1.4 2006/08/08 14:19:07 jgrosseo
63 Update to shuttle classes (Alberto)
65 - Possibility to set the full object's path in the Preprocessor's and
66 Shuttle's Store functions
67 - Possibility to extend the object's run validity in the same classes
68 ("startValidity" and "validityInfinite" parameters)
69 - Implementation of the StoreReferenceData function to store reference
70 data in a dedicated CDB storage.
72 Revision 1.3 2006/07/11 12:44:32 jgrosseo
73 adding parameters for extended validity range of data produced by preprocessor
75 Revision 1.2 2006/06/06 14:20:05 jgrosseo
76 o) updated test preprocessor (alberto)
77 o) added comments to example macro
78 o) test shuttle implements new interface
80 Revision 1.2 2006/03/07 07:52:34 hristov
81 New version (B.Yordanov)
83 Revision 1.3 2005/11/17 17:47:34 byordano
84 TList changed to TObjArray
86 Revision 1.2 2005/11/17 14:43:22 byordano
89 Revision 1.1.1.1 2005/10/28 07:33:58 hristov
90 Initial import as subdirectory in AliRoot
92 Revision 1.1.1.1 2005/09/12 22:11:40 byordano
95 Revision 1.2 2005/08/29 21:15:47 byordano
101 // test implementation of the AliShuttleInterface, to be used for local tests of preprocessors
103 // reads files from the local disk
104 // stores to local CDB
105 // logs to the screen
108 #include "AliTestShuttle.h"
111 #include "AliCDBManager.h"
112 #include "AliCDBStorage.h"
113 #include "AliCDBMetaData.h"
114 #include "AliCDBPath.h"
115 #include "AliCDBId.h"
116 #include "AliPreprocessor.h"
120 #include <TObjString.h>
123 ClassImp(AliTestShuttle)
125 //______________________________________________________________________________________________
126 AliTestShuttle::AliTestShuttle(Int_t run, UInt_t startTime, UInt_t endTime) :
128 fStartTime(startTime),
138 fInputFiles = new TMap;
139 fRunParameters = new TMap;
140 fPreprocessors = new TObjArray;
142 fInputFiles->SetOwner(1);
143 fRunParameters->SetOwner(1);
144 fPreprocessors->SetOwner(1);
147 //______________________________________________________________________________________________
148 AliTestShuttle::~AliTestShuttle()
155 delete fRunParameters;
158 delete fPreprocessors;
165 //______________________________________________________________________________________________
166 Bool_t AliTestShuttle::Store(const AliCDBPath& path, TObject* object, AliCDBMetaData* metaData,
167 Int_t validityStart, Bool_t validityInfinite)
169 // Stores the CDB object
170 // This function should be called at the end of the preprocessor cycle
172 // This implementation just stores it on the local disk, the full AliShuttle
173 // puts it to the Grid FileCatalog
175 Int_t startRun = fRun - validityStart;
177 AliError("First valid run happens to be less than 0! Setting it to 0...");
182 if(validityInfinite) {
183 endRun = AliCDBRunRange::Infinity();
188 AliCDBId id(path, startRun, endRun);
190 return AliCDBManager::Instance()->GetStorage(fgkMainCDB)->Put(object, id, metaData);
193 //______________________________________________________________________________________________
194 Bool_t AliTestShuttle::StoreReferenceData(const AliCDBPath& path, TObject* object, AliCDBMetaData* metaData)
196 // Stores the object as reference data
197 // This function should be called at the end of the preprocessor cycle
199 // This implementation just stores it on the local disk, the full AliShuttle
200 // puts it to the Grid FileCatalog
202 AliCDBId id(path, fRun, fRun);
204 return AliCDBManager::Instance()->GetStorage(fgkMainRefStorage)->Put(object, id, metaData);
207 //______________________________________________________________________________________________
208 Bool_t AliTestShuttle::StoreReferenceFile(const char* detector, const char* localFile, const char* gridFileName)
211 // Stores reference file directly (without opening it).
213 // This implementation just stores it on the local disk, the full AliShuttle
214 // puts it to the Grid FileCatalog
216 AliCDBManager* man = AliCDBManager::Instance();
217 AliCDBStorage* sto = man->GetStorage(fgkMainRefStorage);
219 TString localBaseFolder = sto->GetBaseFolder();
222 targetDir.Form("%s/%s", localBaseFolder.Data(), detector);
225 target.Form("%s/%d_%s", targetDir.Data(), fRun, gridFileName);
227 Int_t result = gSystem->GetPathInfo(targetDir, 0, (Long64_t*) 0, 0, 0);
230 result = gSystem->mkdir(targetDir, kTRUE);
233 Log("SHUTTLE", Form("StoreReferenceFile - Error creating base directory %s", targetDir.Data()));
238 result = gSystem->CopyFile(localFile, target);
242 Log("SHUTTLE", Form("StoreReferenceFile - Stored file %s locally to %s", localFile, target.Data()));
247 Log("SHUTTLE", Form("StoreReferenceFile - Storing file %s locally to %s failed with %d", localFile, target.Data(), result));
252 //______________________________________________________________________________________________
253 const char* AliTestShuttle::GetFile(Int_t system, const char* detector, const char* id, const char* source)
255 // This function retrieves a file from the given system (kDAQ, kDCS, kHLT) with the given file id
256 // and from the given source in the system.
257 // The function returnes the path to the local file.
259 // test implementation of GetFile
260 // takes files from the local disks, files are passen in a TMap in the constructor
263 key.Form("%s-%s-%s", fkSystemNames[system], detector, id);
264 TPair* sourceListPair = dynamic_cast<TPair*> (fInputFiles->FindObject(key.Data()));
265 TMap* sourceList = 0;
267 sourceList = dynamic_cast<TMap*> (sourceListPair->Value());
270 AliError(Form("Could not find any file in %s with id %s (%s)", fkSystemNames[system], id, key.Data()));
274 TObjString* fileName = 0;
275 TPair* fileNamePair = dynamic_cast<TPair*> (sourceList->FindObject(source));
277 fileName = dynamic_cast<TObjString*> (fileNamePair->Value());
280 AliError(Form("Could not find files from source %s in %s with id %s",
281 source, fkSystemNames[system], id));
285 return fileName->GetString().Data();
288 //______________________________________________________________________________________________
289 TList* AliTestShuttle::GetFileSources(Int_t system, const char* detector, const char* id)
291 // Returns a list of sources in a given system that saved a file with the given id
293 // test implementation of GetFileSources
294 // takes files from the local disks, files are passen in a TMap in the constructor
298 key.Form("%s-%s-%s", fkSystemNames[system], detector, id);
300 key.Form("%s-%s", fkSystemNames[system], detector);
302 TList* list = new TList;
304 TIterator* iter = fInputFiles->MakeIterator();
306 while ((obj = iter->Next()))
308 TObjString* objStr = dynamic_cast<TObjString*> (obj);
311 Bool_t found = kFALSE;
314 found = (objStr->String().CompareTo(key) == 0);
317 found = objStr->String().BeginsWith(key);
321 TPair* sourceListPair = dynamic_cast<TPair*> (fInputFiles->FindObject(objStr->String().Data()));
322 TMap* sourceList = dynamic_cast<TMap*> (sourceListPair->Value());
324 TIterator* iter2 = sourceList->GetTable()->MakeIterator();
326 while ((obj2 = iter2->Next()))
328 TPair* pair = dynamic_cast<TPair*> (obj2);
331 if (!list->FindObject(pair->Key()))
332 list->Add(new TObjString(pair->Key()->GetName()));
341 if (list->GetEntries() == 0)
342 AliInfo(Form("Could not find any file in %s with id %s (%s)", fkSystemNames[system], id, key.Data()));
347 //______________________________________________________________________________________________
348 TList* AliTestShuttle::GetFileIDs(Int_t system, const char* detector, const char* source)
350 // Returns a list of ids in a given system that saved a file with the given source
352 // test implementation of GetFileSources
353 // takes files from the local disks, files are passen in a TMap in the constructor
357 key.Form("%s-%s", fkSystemNames[system], detector);
359 TList* list = new TList;
361 TIterator* iter = fInputFiles->MakeIterator();
363 while ((obj = iter->Next()))
365 TObjString* objStr = dynamic_cast<TObjString*> (obj);
368 if (objStr->String().BeginsWith(key))
370 Bool_t found = kFALSE;
372 TPair* sourceListPair = dynamic_cast<TPair*> (fInputFiles->FindObject(objStr->String().Data()));
373 TMap* sourceList = dynamic_cast<TMap*> (sourceListPair->Value());
375 TIterator* iter2 = sourceList->GetTable()->MakeIterator();
377 while ((obj2 = iter2->Next()))
379 TPair* pair = dynamic_cast<TPair*> (obj2);
382 if (strcmp(pair->Key()->GetName(), source) == 0)
391 TObjArray* tokens = objStr->String().Tokenize("-");
392 if (tokens->GetEntries() == 3)
394 TObjString* id = dynamic_cast<TObjString*> (tokens->At(2));
395 if (id && !list->FindObject(id->String()))
396 list->Add(new TObjString(id->String()));
406 if (list->GetEntries() == 0)
407 AliInfo(Form("Could not find any file in %s with source %s (%s)", fkSystemNames[system], source, key.Data()));
412 //______________________________________________________________________________________________
413 void AliTestShuttle::Log(const char* detector, const char* message)
415 // test implementation of Log
416 // just prints to the screen
418 AliInfo(Form("%s: %s", detector, message));
421 //______________________________________________________________________________________________
422 void AliTestShuttle::AddInputFile(Int_t system, const char* detector, const char* id, const char* source, const char* fileName)
425 // This function adds a file to the list of input files
426 // the list is stored in fInputFiles
427 // fInputFiles: TMap (key -> value)
428 // <system>-<detector>-<id> -> TMap (key -> value)
429 // <source> -> <filename>
433 key.Form("%s-%s-%s", fkSystemNames[system], detector, id);
434 TPair* sourceListPair = dynamic_cast<TPair*> (fInputFiles->FindObject(key.Data()));
435 TMap* sourceList = 0;
437 sourceList = dynamic_cast<TMap*> (sourceListPair->Value());
440 sourceList = new TMap;
441 fInputFiles->Add(new TObjString(key), sourceList);
444 sourceList->Add(new TObjString(source), new TObjString(fileName));
447 //______________________________________________________________________________________________
448 Bool_t AliTestShuttle::AddInputCDBEntry(AliCDBEntry* entry)
450 // This function adds an object in the OCDB to be later retrieved with GetFromOCDB
452 AliCDBStorage *sto = AliCDBManager::Instance()->GetStorage(fgkMainCDB);
455 Log("SHUTTLE", "GetFromOCDB - Cannot activate main OCDB for query!");
459 return sto->Put(entry);
462 //______________________________________________________________________________________________
463 AliCDBEntry* AliTestShuttle::GetFromOCDB(const char* detector, const AliCDBPath& path)
465 // returns obiect from OCDB valid for current run
467 AliCDBStorage *sto = AliCDBManager::Instance()->GetStorage(fgkMainCDB);
470 Log("SHUTTLE", "GetFromOCDB - Cannot activate main OCDB for query!");
474 return (AliCDBEntry*) sto->Get(path, fRun);
477 //______________________________________________________________________________________________
478 void AliTestShuttle::Process()
480 // This function tests all preprocessors that are registered to it
481 // All preprocessors get the same dcs alias map and have access to the same list of files.
483 for (Int_t i=0; i<fPreprocessors->GetEntries(); ++i)
485 AliPreprocessor* preprocessor = dynamic_cast<AliPreprocessor*> (fPreprocessors->At(i));
488 preprocessor->Initialize(fRun, fStartTime, fEndTime);
489 preprocessor->Process(fDcsAliasMap);
494 //______________________________________________________________________________________________
495 void AliTestShuttle::RegisterPreprocessor(AliPreprocessor* preprocessor)
497 // registers a preprocessor
499 const char* detName = preprocessor->GetName();
500 if(strcmp("DET", detName) != 0) {
501 if(GetDetPos(detName) < 0)
502 AliFatal(Form("********** !!!!! Invalid detector name: %s !!!!! **********", detName));
505 fPreprocessors->Add(preprocessor);
508 //______________________________________________________________________________________________
509 void AliTestShuttle::AddInputRunParameter(const char* key, const char* value){
510 // set a run parameter (in reality it will be read from the DAQ logbook)
512 TObjString* keyObj = new TObjString(key);
513 if (fRunParameters->Contains(key)) {
514 AliWarning(Form("Parameter %s already existing and it will be replaced.", key));
515 delete fRunParameters->Remove(keyObj);
518 fRunParameters->Add(keyObj, new TObjString(value));
519 AliDebug(2, Form("Number of parameters: %d", fRunParameters->
523 //______________________________________________________________________________________________
524 const char* AliTestShuttle::GetRunType()
527 // get a run parameter
530 return fRunType.Data();
533 //______________________________________________________________________________________________
534 const char* AliTestShuttle::GetRunParameter(const char* key){
535 // get a run parameter
537 TObjString* value = dynamic_cast<TObjString*> (fRunParameters->GetValue(key));
539 AliError(Form("No such parameter: %s", key));
542 return value->GetName();
545 //______________________________________________________________________________________________
546 void AliTestShuttle::SetShuttleTempDir(const char* tmpDir)
548 // sets Shuttle temp directory
550 fgkShuttleTempDir = gSystem->ExpandPathName(tmpDir);
553 //______________________________________________________________________________________________
554 void AliTestShuttle::SetShuttleLogDir(const char* logDir)
556 // sets Shuttle log directory
558 fgkShuttleLogDir = gSystem->ExpandPathName(logDir);