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.6 2006/11/06 14:22:47 jgrosseo
19 major update (Alberto)
20 o) reading of run parameters from the logbook
21 o) online offline naming conversion
22 o) standalone DCSclient package
24 Revision 1.5 2006/10/02 12:58:52 jgrosseo
25 Small interface change in StoreReferenceData
27 Revision 1.4 2006/08/08 14:19:07 jgrosseo
28 Update to shuttle classes (Alberto)
30 - Possibility to set the full object's path in the Preprocessor's and
31 Shuttle's Store functions
32 - Possibility to extend the object's run validity in the same classes
33 ("startValidity" and "validityInfinite" parameters)
34 - Implementation of the StoreReferenceData function to store reference
35 data in a dedicated CDB storage.
37 Revision 1.3 2006/07/11 12:44:32 jgrosseo
38 adding parameters for extended validity range of data produced by preprocessor
40 Revision 1.2 2006/06/06 14:20:05 jgrosseo
41 o) updated test preprocessor (alberto)
42 o) added comments to example macro
43 o) test shuttle implements new interface
45 Revision 1.2 2006/03/07 07:52:34 hristov
46 New version (B.Yordanov)
48 Revision 1.3 2005/11/17 17:47:34 byordano
49 TList changed to TObjArray
51 Revision 1.2 2005/11/17 14:43:22 byordano
54 Revision 1.1.1.1 2005/10/28 07:33:58 hristov
55 Initial import as subdirectory in AliRoot
57 Revision 1.1.1.1 2005/09/12 22:11:40 byordano
60 Revision 1.2 2005/08/29 21:15:47 byordano
66 // test implementation of the AliShuttleInterface, to be used for local tests of preprocessors
68 // reads files from the local disk
69 // stores to local CDB
73 #include "AliTestShuttle.h"
76 #include "AliCDBManager.h"
77 #include "AliCDBStorage.h"
78 #include "AliCDBMetaData.h"
79 #include "AliCDBPath.h"
81 #include "AliPreprocessor.h"
85 #include <TObjString.h>
88 ClassImp(AliTestShuttle)
90 //______________________________________________________________________________________________
91 AliTestShuttle::AliTestShuttle(Int_t run, UInt_t startTime, UInt_t endTime) :
93 fStartTime(startTime),
102 fInputFiles = new TMap;
103 fRunParameters = new TMap;
104 fPreprocessors = new TObjArray;
107 //______________________________________________________________________________________________
108 AliTestShuttle::~AliTestShuttle()
115 delete fRunParameters;
118 delete fPreprocessors;
125 //______________________________________________________________________________________________
126 UInt_t AliTestShuttle::Store(const AliCDBPath& path, TObject* object, AliCDBMetaData* metaData,
127 Int_t validityStart, Bool_t validityInfinite)
129 // Stores the CDB object
130 // This function should be called at the end of the preprocessor cycle
132 // This implementation just stores it on the local disk, the full AliShuttle
133 // puts it to the Grid FileCatalog
135 Int_t startRun = fRun - validityStart;
137 AliError("First valid run happens to be less than 0! Setting it to 0...");
142 if(validityInfinite) {
143 endRun = AliCDBRunRange::Infinity();
148 AliCDBId id(path, startRun, endRun);
150 return AliCDBManager::Instance()->GetStorage(fgkMainCDB)->Put(object, id, metaData);
153 //______________________________________________________________________________________________
154 UInt_t AliTestShuttle::StoreReferenceData(const AliCDBPath& path, TObject* object, AliCDBMetaData* metaData)
156 // Stores the object as reference data
157 // This function should be called at the end of the preprocessor cycle
159 // This implementation just stores it on the local disk, the full AliShuttle
160 // puts it to the Grid FileCatalog
162 AliCDBId id(path, fRun, fRun);
164 return AliCDBManager::Instance()->GetStorage(fgkMainRefStorage)->Put(object, id, metaData);
167 //______________________________________________________________________________________________
168 const char* AliTestShuttle::GetFile(Int_t system, const char* detector, const char* id, const char* source)
170 // This function retrieves a file from the given system (kDAQ, kDCS, kHLT) with the given file id
171 // and from the given source in the system.
172 // The function returnes the path to the local file.
174 // test implementation of GetFile
175 // takes files from the local disks, files are passen in a TMap in the constructor
178 key.Form("%s-%s-%s", fkSystemNames[system], detector, id);
179 TPair* sourceListPair = dynamic_cast<TPair*> (fInputFiles->FindObject(key.Data()));
180 TMap* sourceList = 0;
182 sourceList = dynamic_cast<TMap*> (sourceListPair->Value());
185 AliError(Form("Could not find any file in %s with id %s (%s)", fkSystemNames[system], id, key.Data()));
189 TPair* fileNamePair = dynamic_cast<TPair*> (sourceList->FindObject(source));
190 TObjString* fileName = dynamic_cast<TObjString*> (fileNamePair->Value());
193 AliError(Form("Could not find files from source %s in %s with id %s",
194 source, fkSystemNames[system], id));
198 return fileName->GetString().Data();
201 //______________________________________________________________________________________________
202 TList* AliTestShuttle::GetFileSources(Int_t system, const char* detector, const char* id)
204 // Returns a list of sources in a given system that saved a file with the given id
206 // test implementation of GetFileSources
207 // takes files from the local disks, files are passen in a TMap in the constructor
210 key.Form("%s-%s-%s", fkSystemNames[system], detector, id);
211 TPair* sourceListPair = dynamic_cast<TPair*> (fInputFiles->FindObject(key.Data()));
212 TMap* sourceList = 0;
214 sourceList = dynamic_cast<TMap*> (sourceListPair->Value());
217 AliError(Form("Could not find any file in %s with id %s (%s)", fkSystemNames[system], id, key.Data()));
221 TIterator* iter = sourceList->GetTable()->MakeIterator();
223 TList* list = new TList;
224 while ((obj = iter->Next()))
226 TPair* pair = dynamic_cast<TPair*> (obj);
228 list->Add(pair->Key());
236 //______________________________________________________________________________________________
237 void AliTestShuttle::Log(const char* detector, const char* message)
239 // test implementation of Log
240 // just prints to the screen
242 AliInfo(Form("%s: %s", detector, message));
245 //______________________________________________________________________________________________
246 void AliTestShuttle::AddInputFile(Int_t system, const char* detector, const char* id, const char* source, const char* fileName)
248 // This function adds a file to the list of input files
251 key.Form("%s-%s-%s", fkSystemNames[system], detector, id);
252 TPair* sourceListPair = dynamic_cast<TPair*> (fInputFiles->FindObject(key.Data()));
253 TMap* sourceList = 0;
255 sourceList = dynamic_cast<TMap*> (sourceListPair->Value());
258 sourceList = new TMap;
259 fInputFiles->Add(new TObjString(key), sourceList);
262 sourceList->Add(new TObjString(source), new TObjString(fileName));
265 //______________________________________________________________________________________________
266 void AliTestShuttle::Process()
268 // This function tests all preprocessors that are registered to it
269 // All preprocessors get the same dcs alias map and have access to the same list of files.
271 for (Int_t i=0; i<fPreprocessors->GetEntries(); ++i)
273 AliPreprocessor* preprocessor = dynamic_cast<AliPreprocessor*> (fPreprocessors->At(i));
276 preprocessor->Initialize(fRun, fStartTime, fEndTime);
277 preprocessor->Process(fDcsAliasMap);
282 //______________________________________________________________________________________________
283 void AliTestShuttle::RegisterPreprocessor(AliPreprocessor* preprocessor)
285 // registers a preprocessor
287 const char* detName = preprocessor->GetName();
288 if(strcmp("DET", detName) != 0) {
289 if(GetDetPos(detName) < 0)
290 AliFatal(Form("********** !!!!! Invalid detector name: %s !!!!! **********", detName));
293 fPreprocessors->Add(preprocessor);
296 //______________________________________________________________________________________________
297 void AliTestShuttle::AddInputRunParameter(const char* key, const char* value){
298 // set a run parameter (in reality it will be read from the DAQ logbook)
300 TObjString* keyObj = new TObjString(key);
301 if (fRunParameters->Contains(key)) {
302 AliWarning(Form("Parameter %s already existing and it will be replaced.", key));
303 delete fRunParameters->Remove(keyObj);
306 fRunParameters->Add(keyObj, new TObjString(value));
307 AliDebug(2, Form("Number of parameters: %d", fRunParameters->
311 //______________________________________________________________________________________________
312 const char* AliTestShuttle::GetRunParameter(const char* key){
313 // get a run parameter
315 TObjString* value = dynamic_cast<TObjString*> (fRunParameters->GetValue(key));
317 AliError(Form("No such parameter: %s", key));
320 return value->GetName();