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.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.
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
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
33 Revision 1.5 2006/10/02 12:58:52 jgrosseo
34 Small interface change in StoreReferenceData
36 Revision 1.4 2006/08/08 14:19:07 jgrosseo
37 Update to shuttle classes (Alberto)
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.
46 Revision 1.3 2006/07/11 12:44:32 jgrosseo
47 adding parameters for extended validity range of data produced by preprocessor
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
54 Revision 1.2 2006/03/07 07:52:34 hristov
55 New version (B.Yordanov)
57 Revision 1.3 2005/11/17 17:47:34 byordano
58 TList changed to TObjArray
60 Revision 1.2 2005/11/17 14:43:22 byordano
63 Revision 1.1.1.1 2005/10/28 07:33:58 hristov
64 Initial import as subdirectory in AliRoot
66 Revision 1.1.1.1 2005/09/12 22:11:40 byordano
69 Revision 1.2 2005/08/29 21:15:47 byordano
75 // test implementation of the AliShuttleInterface, to be used for local tests of preprocessors
77 // reads files from the local disk
78 // stores to local CDB
82 #include "AliTestShuttle.h"
85 #include "AliCDBManager.h"
86 #include "AliCDBStorage.h"
87 #include "AliCDBMetaData.h"
88 #include "AliCDBPath.h"
90 #include "AliPreprocessor.h"
94 #include <TObjString.h>
97 ClassImp(AliTestShuttle)
99 //______________________________________________________________________________________________
100 AliTestShuttle::AliTestShuttle(Int_t run, UInt_t startTime, UInt_t endTime) :
102 fStartTime(startTime),
112 fInputFiles = new TMap;
113 fRunParameters = new TMap;
114 fPreprocessors = new TObjArray;
116 fInputFiles->SetOwner(1);
117 fRunParameters->SetOwner(1);
118 fPreprocessors->SetOwner(1);
121 //______________________________________________________________________________________________
122 AliTestShuttle::~AliTestShuttle()
129 delete fRunParameters;
132 delete fPreprocessors;
139 //______________________________________________________________________________________________
140 Bool_t AliTestShuttle::Store(const AliCDBPath& path, TObject* object, AliCDBMetaData* metaData,
141 Int_t validityStart, Bool_t validityInfinite)
143 // Stores the CDB object
144 // This function should be called at the end of the preprocessor cycle
146 // This implementation just stores it on the local disk, the full AliShuttle
147 // puts it to the Grid FileCatalog
149 Int_t startRun = fRun - validityStart;
151 AliError("First valid run happens to be less than 0! Setting it to 0...");
156 if(validityInfinite) {
157 endRun = AliCDBRunRange::Infinity();
162 AliCDBId id(path, startRun, endRun);
164 return AliCDBManager::Instance()->GetStorage(fgkMainCDB)->Put(object, id, metaData);
167 //______________________________________________________________________________________________
168 Bool_t AliTestShuttle::StoreReferenceData(const AliCDBPath& path, TObject* object, AliCDBMetaData* metaData)
170 // Stores the object as reference data
171 // This function should be called at the end of the preprocessor cycle
173 // This implementation just stores it on the local disk, the full AliShuttle
174 // puts it to the Grid FileCatalog
176 AliCDBId id(path, fRun, fRun);
178 return AliCDBManager::Instance()->GetStorage(fgkMainRefStorage)->Put(object, id, metaData);
181 //______________________________________________________________________________________________
182 Bool_t AliTestShuttle::StoreReferenceFile(const char* detector, const char* localFile, const char* gridFileName)
185 // Stores reference file directly (without opening it).
187 // This implementation just stores it on the local disk, the full AliShuttle
188 // puts it to the Grid FileCatalog
190 AliCDBManager* man = AliCDBManager::Instance();
191 AliCDBStorage* sto = man->GetStorage(fgkMainRefStorage);
193 TString localBaseFolder = sto->GetBaseFolder();
196 targetDir.Form("%s/%s", localBaseFolder.Data(), detector);
199 target.Form("%s/%d_%s", targetDir.Data(), fRun, gridFileName);
201 Int_t result = gSystem->GetPathInfo(targetDir, 0, (Long64_t*) 0, 0, 0);
204 result = gSystem->mkdir(targetDir, kTRUE);
207 Log("SHUTTLE", Form("StoreReferenceFile - Error creating base directory %s", targetDir.Data()));
212 result = gSystem->CopyFile(localFile, target);
216 Log("SHUTTLE", Form("StoreReferenceFile - Stored file %s locally to %s", localFile, target.Data()));
221 Log("SHUTTLE", Form("StoreReferenceFile - Storing file %s locally to %s failed with %d", localFile, target.Data(), result));
226 //______________________________________________________________________________________________
227 const char* AliTestShuttle::GetFile(Int_t system, const char* detector, const char* id, const char* source)
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.
233 // test implementation of GetFile
234 // takes files from the local disks, files are passen in a TMap in the constructor
237 key.Form("%s-%s-%s", fkSystemNames[system], detector, id);
238 TPair* sourceListPair = dynamic_cast<TPair*> (fInputFiles->FindObject(key.Data()));
239 TMap* sourceList = 0;
241 sourceList = dynamic_cast<TMap*> (sourceListPair->Value());
244 AliError(Form("Could not find any file in %s with id %s (%s)", fkSystemNames[system], id, key.Data()));
248 TPair* fileNamePair = dynamic_cast<TPair*> (sourceList->FindObject(source));
249 TObjString* fileName = dynamic_cast<TObjString*> (fileNamePair->Value());
252 AliError(Form("Could not find files from source %s in %s with id %s",
253 source, fkSystemNames[system], id));
257 return fileName->GetString().Data();
260 //______________________________________________________________________________________________
261 TList* AliTestShuttle::GetFileSources(Int_t system, const char* detector, const char* id)
263 // Returns a list of sources in a given system that saved a file with the given id
265 // test implementation of GetFileSources
266 // takes files from the local disks, files are passen in a TMap in the constructor
269 key.Form("%s-%s-%s", fkSystemNames[system], detector, id);
270 TPair* sourceListPair = dynamic_cast<TPair*> (fInputFiles->FindObject(key.Data()));
271 TMap* sourceList = 0;
273 sourceList = dynamic_cast<TMap*> (sourceListPair->Value());
276 AliError(Form("Could not find any file in %s with id %s (%s)", fkSystemNames[system], id, key.Data()));
280 TIterator* iter = sourceList->GetTable()->MakeIterator();
282 TList* list = new TList;
283 while ((obj = iter->Next()))
285 TPair* pair = dynamic_cast<TPair*> (obj);
287 list->Add(pair->Key());
295 //______________________________________________________________________________________________
296 void AliTestShuttle::Log(const char* detector, const char* message)
298 // test implementation of Log
299 // just prints to the screen
301 AliInfo(Form("%s: %s", detector, message));
304 //______________________________________________________________________________________________
305 void AliTestShuttle::AddInputFile(Int_t system, const char* detector, const char* id, const char* source, const char* fileName)
307 // This function adds a file to the list of input files
310 key.Form("%s-%s-%s", fkSystemNames[system], detector, id);
311 TPair* sourceListPair = dynamic_cast<TPair*> (fInputFiles->FindObject(key.Data()));
312 TMap* sourceList = 0;
314 sourceList = dynamic_cast<TMap*> (sourceListPair->Value());
317 sourceList = new TMap;
318 fInputFiles->Add(new TObjString(key), sourceList);
321 sourceList->Add(new TObjString(source), new TObjString(fileName));
324 //______________________________________________________________________________________________
325 Bool_t AliTestShuttle::AddInputCDBEntry(AliCDBEntry* entry)
327 // This function adds an object in the OCDB to be later retrieved with GetFromOCDB
329 AliCDBStorage *sto = AliCDBManager::Instance()->GetStorage(fgkMainCDB);
332 Log("SHUTTLE", "GetFromOCDB - Cannot activate main OCDB for query!");
336 return sto->Put(entry);
339 //______________________________________________________________________________________________
340 AliCDBEntry* AliTestShuttle::GetFromOCDB(const char* detector, const AliCDBPath& path)
342 // returns obiect from OCDB valid for current run
344 AliCDBStorage *sto = AliCDBManager::Instance()->GetStorage(fgkMainCDB);
347 Log("SHUTTLE", "GetFromOCDB - Cannot activate main OCDB for query!");
351 return (AliCDBEntry*) sto->Get(path, fRun);
354 //______________________________________________________________________________________________
355 void AliTestShuttle::Process()
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.
360 for (Int_t i=0; i<fPreprocessors->GetEntries(); ++i)
362 AliPreprocessor* preprocessor = dynamic_cast<AliPreprocessor*> (fPreprocessors->At(i));
365 preprocessor->Initialize(fRun, fStartTime, fEndTime);
366 preprocessor->Process(fDcsAliasMap);
371 //______________________________________________________________________________________________
372 void AliTestShuttle::RegisterPreprocessor(AliPreprocessor* preprocessor)
374 // registers a preprocessor
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));
382 fPreprocessors->Add(preprocessor);
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)
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);
395 fRunParameters->Add(keyObj, new TObjString(value));
396 AliDebug(2, Form("Number of parameters: %d", fRunParameters->
400 //______________________________________________________________________________________________
401 const char* AliTestShuttle::GetRunType()
404 // get a run parameter
410 //______________________________________________________________________________________________
411 const char* AliTestShuttle::GetRunParameter(const char* key){
412 // get a run parameter
414 TObjString* value = dynamic_cast<TObjString*> (fRunParameters->GetValue(key));
416 AliError(Form("No such parameter: %s", key));
419 return value->GetName();
422 //______________________________________________________________________________________________
423 void AliTestShuttle::SetShuttleTempDir(const char* tmpDir)
425 // sets Shuttle temp directory
427 fgkShuttleTempDir = gSystem->ExpandPathName(tmpDir);
430 //______________________________________________________________________________________________
431 void AliTestShuttle::SetShuttleLogDir(const char* logDir)
433 // sets Shuttle log directory
435 fgkShuttleLogDir = gSystem->ExpandPathName(logDir);