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.8 2007/02/13 11:22:25 acolla
19 Shuttle getters and setters of main/local OCDB/Reference storages, temp and log
20 folders moved to AliShuttleInterface
22 Revision 1.6 2006/11/06 14:22:47 jgrosseo
23 major update (Alberto)
24 o) reading of run parameters from the logbook
25 o) online offline naming conversion
26 o) standalone DCSclient package
28 Revision 1.5 2006/10/02 12:58:52 jgrosseo
29 Small interface change in StoreReferenceData
31 Revision 1.4 2006/08/08 14:19:07 jgrosseo
32 Update to shuttle classes (Alberto)
34 - Possibility to set the full object's path in the Preprocessor's and
35 Shuttle's Store functions
36 - Possibility to extend the object's run validity in the same classes
37 ("startValidity" and "validityInfinite" parameters)
38 - Implementation of the StoreReferenceData function to store reference
39 data in a dedicated CDB storage.
41 Revision 1.3 2006/07/11 12:44:32 jgrosseo
42 adding parameters for extended validity range of data produced by preprocessor
44 Revision 1.2 2006/06/06 14:20:05 jgrosseo
45 o) updated test preprocessor (alberto)
46 o) added comments to example macro
47 o) test shuttle implements new interface
49 Revision 1.2 2006/03/07 07:52:34 hristov
50 New version (B.Yordanov)
52 Revision 1.3 2005/11/17 17:47:34 byordano
53 TList changed to TObjArray
55 Revision 1.2 2005/11/17 14:43:22 byordano
58 Revision 1.1.1.1 2005/10/28 07:33:58 hristov
59 Initial import as subdirectory in AliRoot
61 Revision 1.1.1.1 2005/09/12 22:11:40 byordano
64 Revision 1.2 2005/08/29 21:15:47 byordano
70 // test implementation of the AliShuttleInterface, to be used for local tests of preprocessors
72 // reads files from the local disk
73 // stores to local CDB
77 #include "AliTestShuttle.h"
80 #include "AliCDBManager.h"
81 #include "AliCDBStorage.h"
82 #include "AliCDBMetaData.h"
83 #include "AliCDBPath.h"
85 #include "AliPreprocessor.h"
89 #include <TObjString.h>
92 ClassImp(AliTestShuttle)
94 //______________________________________________________________________________________________
95 AliTestShuttle::AliTestShuttle(Int_t run, UInt_t startTime, UInt_t endTime) :
97 fStartTime(startTime),
107 fInputFiles = new TMap;
108 fRunParameters = new TMap;
109 fRunTypeMap = new TMap;
110 fPreprocessors = new TObjArray;
112 fInputFiles->SetOwner(1);
113 fRunParameters->SetOwner(1);
114 fRunTypeMap->SetOwner(1);
115 fPreprocessors->SetOwner(1);
118 //______________________________________________________________________________________________
119 AliTestShuttle::~AliTestShuttle()
126 delete fRunParameters;
132 delete fPreprocessors;
139 //______________________________________________________________________________________________
140 UInt_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 UInt_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 const char* AliTestShuttle::GetFile(Int_t system, const char* detector, const char* id, const char* source)
184 // This function retrieves a file from the given system (kDAQ, kDCS, kHLT) with the given file id
185 // and from the given source in the system.
186 // The function returnes the path to the local file.
188 // test implementation of GetFile
189 // takes files from the local disks, files are passen in a TMap in the constructor
192 key.Form("%s-%s-%s", fkSystemNames[system], detector, id);
193 TPair* sourceListPair = dynamic_cast<TPair*> (fInputFiles->FindObject(key.Data()));
194 TMap* sourceList = 0;
196 sourceList = dynamic_cast<TMap*> (sourceListPair->Value());
199 AliError(Form("Could not find any file in %s with id %s (%s)", fkSystemNames[system], id, key.Data()));
203 TPair* fileNamePair = dynamic_cast<TPair*> (sourceList->FindObject(source));
204 TObjString* fileName = dynamic_cast<TObjString*> (fileNamePair->Value());
207 AliError(Form("Could not find files from source %s in %s with id %s",
208 source, fkSystemNames[system], id));
212 return fileName->GetString().Data();
215 //______________________________________________________________________________________________
216 TList* AliTestShuttle::GetFileSources(Int_t system, const char* detector, const char* id)
218 // Returns a list of sources in a given system that saved a file with the given id
220 // test implementation of GetFileSources
221 // takes files from the local disks, files are passen in a TMap in the constructor
224 key.Form("%s-%s-%s", fkSystemNames[system], detector, id);
225 TPair* sourceListPair = dynamic_cast<TPair*> (fInputFiles->FindObject(key.Data()));
226 TMap* sourceList = 0;
228 sourceList = dynamic_cast<TMap*> (sourceListPair->Value());
231 AliError(Form("Could not find any file in %s with id %s (%s)", fkSystemNames[system], id, key.Data()));
235 TIterator* iter = sourceList->GetTable()->MakeIterator();
237 TList* list = new TList;
238 while ((obj = iter->Next()))
240 TPair* pair = dynamic_cast<TPair*> (obj);
242 list->Add(pair->Key());
250 //______________________________________________________________________________________________
251 void AliTestShuttle::Log(const char* detector, const char* message)
253 // test implementation of Log
254 // just prints to the screen
256 AliInfo(Form("%s: %s", detector, message));
259 //______________________________________________________________________________________________
260 void AliTestShuttle::AddInputFile(Int_t system, const char* detector, const char* id, const char* source, const char* fileName)
262 // This function adds a file to the list of input files
265 key.Form("%s-%s-%s", fkSystemNames[system], detector, id);
266 TPair* sourceListPair = dynamic_cast<TPair*> (fInputFiles->FindObject(key.Data()));
267 TMap* sourceList = 0;
269 sourceList = dynamic_cast<TMap*> (sourceListPair->Value());
272 sourceList = new TMap;
273 fInputFiles->Add(new TObjString(key), sourceList);
276 sourceList->Add(new TObjString(source), new TObjString(fileName));
279 //______________________________________________________________________________________________
280 Bool_t AliTestShuttle::AddInputCDBEntry(AliCDBEntry* entry)
282 // This function adds an object in the OCDB to be later retrieved with GetFromOCDB
284 AliCDBStorage *sto = AliCDBManager::Instance()->GetStorage(fgkMainCDB);
287 Log("SHUTTLE", "GetFromOCDB - Cannot activate main OCDB for query!");
291 return sto->Put(entry);
294 //______________________________________________________________________________________________
295 AliCDBEntry* AliTestShuttle::GetFromOCDB(const AliCDBPath& path)
297 // returns obiect from OCDB valid for current run
299 AliCDBStorage *sto = AliCDBManager::Instance()->GetStorage(fgkMainCDB);
302 Log("SHUTTLE", "GetFromOCDB - Cannot activate main OCDB for query!");
306 return (AliCDBEntry*) sto->Get(path, fRun);
309 //______________________________________________________________________________________________
310 void AliTestShuttle::Process()
312 // This function tests all preprocessors that are registered to it
313 // All preprocessors get the same dcs alias map and have access to the same list of files.
315 for (Int_t i=0; i<fPreprocessors->GetEntries(); ++i)
317 AliPreprocessor* preprocessor = dynamic_cast<AliPreprocessor*> (fPreprocessors->At(i));
320 preprocessor->Initialize(fRun, fStartTime, fEndTime);
321 preprocessor->Process(fDcsAliasMap);
326 //______________________________________________________________________________________________
327 void AliTestShuttle::RegisterPreprocessor(AliPreprocessor* preprocessor)
329 // registers a preprocessor
331 const char* detName = preprocessor->GetName();
332 if(strcmp("DET", detName) != 0) {
333 if(GetDetPos(detName) < 0)
334 AliFatal(Form("********** !!!!! Invalid detector name: %s !!!!! **********", detName));
337 fPreprocessors->Add(preprocessor);
340 //______________________________________________________________________________________________
341 void AliTestShuttle::AddInputRunParameter(const char* key, const char* value){
342 // set a run parameter (in reality it will be read from the DAQ logbook)
344 TObjString* keyObj = new TObjString(key);
345 if (fRunParameters->Contains(key)) {
346 AliWarning(Form("Parameter %s already existing and it will be replaced.", key));
347 delete fRunParameters->Remove(keyObj);
350 fRunParameters->Add(keyObj, new TObjString(value));
351 AliDebug(2, Form("Number of parameters: %d", fRunParameters->
355 //______________________________________________________________________________________________
356 void AliTestShuttle::AddInputRunType(const char* detCode, const char* runType){
357 // set a run type (in reality it will be read from the "run type" logbook)
359 if (strcmp("DET", detCode) != 0)
361 if (GetDetPos(detCode) < 0)
363 AliError(Form("Invalid detector name: %s", detCode));
367 TObjString* detObj = new TObjString(detCode);
368 if (fRunTypeMap->Contains(detCode)) {
369 AliWarning(Form("Detector %s already inserted: it will be replaced.", detCode));
370 delete fRunTypeMap->Remove(detObj);
373 fRunTypeMap->Add(detObj, new TObjString(runType));
374 AliDebug(2, Form("Number of detectors: %d", fRunTypeMap->GetEntries()));
377 //______________________________________________________________________________________________
378 const char* AliTestShuttle::GetRunType(const char* detCode){
379 // get a run parameter
381 TObjString* value = dynamic_cast<TObjString*> (fRunTypeMap->GetValue(detCode));
383 AliError(Form("Input run type not set for detector %s!", detCode));
386 return value->GetName();
389 //______________________________________________________________________________________________
390 const char* AliTestShuttle::GetRunParameter(const char* key){
391 // get a run parameter
393 TObjString* value = dynamic_cast<TObjString*> (fRunParameters->GetValue(key));
395 AliError(Form("No such parameter: %s", key));
398 return value->GetName();
401 //______________________________________________________________________________________________
402 void AliTestShuttle::SetShuttleTempDir(const char* tmpDir)
404 // sets Shuttle temp directory
406 fgkShuttleTempDir = gSystem->ExpandPathName(tmpDir);
409 //______________________________________________________________________________________________
410 void AliTestShuttle::SetShuttleLogDir(const char* logDir)
412 // sets Shuttle log directory
414 fgkShuttleLogDir = gSystem->ExpandPathName(logDir);