]> git.uio.no Git - u/mrichter/AliRoot.git/blame - SHUTTLE/TestShuttle/AliTestShuttle.cxx
Record changes.
[u/mrichter/AliRoot.git] / SHUTTLE / TestShuttle / AliTestShuttle.cxx
CommitLineData
5c6b40ae 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
16/*
17$Log$
d461a8a7 18Revision 1.8 2007/02/13 11:22:25 acolla
19Shuttle getters and setters of main/local OCDB/Reference storages, temp and log
20folders moved to AliShuttleInterface
21
e19c88ea 22Revision 1.6 2006/11/06 14:22:47 jgrosseo
23major update (Alberto)
24o) reading of run parameters from the logbook
25o) online offline naming conversion
26o) standalone DCSclient package
27
eba76848 28Revision 1.5 2006/10/02 12:58:52 jgrosseo
29Small interface change in StoreReferenceData
30
8c77aee7 31Revision 1.4 2006/08/08 14:19:07 jgrosseo
32Update to shuttle classes (Alberto)
33
34- Possibility to set the full object's path in the Preprocessor's and
35Shuttle'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
39data in a dedicated CDB storage.
40
84090f85 41Revision 1.3 2006/07/11 12:44:32 jgrosseo
42adding parameters for extended validity range of data produced by preprocessor
43
17111222 44Revision 1.2 2006/06/06 14:20:05 jgrosseo
45o) updated test preprocessor (alberto)
46o) added comments to example macro
47o) test shuttle implements new interface
48
5c6b40ae 49Revision 1.2 2006/03/07 07:52:34 hristov
50New version (B.Yordanov)
51
52Revision 1.3 2005/11/17 17:47:34 byordano
53TList changed to TObjArray
54
55Revision 1.2 2005/11/17 14:43:22 byordano
56import to local CVS
57
58Revision 1.1.1.1 2005/10/28 07:33:58 hristov
59Initial import as subdirectory in AliRoot
60
61Revision 1.1.1.1 2005/09/12 22:11:40 byordano
62SHUTTLE package
63
64Revision 1.2 2005/08/29 21:15:47 byordano
65some docs added
66
67*/
68
69//
70// test implementation of the AliShuttleInterface, to be used for local tests of preprocessors
71//
72// reads files from the local disk
73// stores to local CDB
74// logs to the screen
75//
76
77#include "AliTestShuttle.h"
78#include "AliLog.h"
79
80#include "AliCDBManager.h"
84090f85 81#include "AliCDBStorage.h"
5c6b40ae 82#include "AliCDBMetaData.h"
84090f85 83#include "AliCDBPath.h"
5c6b40ae 84#include "AliCDBId.h"
36137ac1 85#include "AliPreprocessor.h"
5c6b40ae 86
87#include <TMap.h>
88#include <TList.h>
5c6b40ae 89#include <TObjString.h>
e19c88ea 90#include <TSystem.h>
5c6b40ae 91
92ClassImp(AliTestShuttle)
93
36137ac1 94//______________________________________________________________________________________________
17111222 95AliTestShuttle::AliTestShuttle(Int_t run, UInt_t startTime, UInt_t endTime) :
96 fRun(run),
97 fStartTime(startTime),
98 fEndTime(endTime),
36137ac1 99 fInputFiles(0),
eba76848 100 fRunParameters(0),
36137ac1 101 fPreprocessors(0),
102 fDcsAliasMap(0)
5c6b40ae 103{
104 // constructor
36137ac1 105
106 fInputFiles = new TMap;
eba76848 107 fRunParameters = new TMap;
36137ac1 108 fPreprocessors = new TObjArray;
5c6b40ae 109}
110
36137ac1 111//______________________________________________________________________________________________
5c6b40ae 112AliTestShuttle::~AliTestShuttle()
113{
114 // destructor
36137ac1 115
116 delete fInputFiles;
117 fInputFiles = 0;
118
eba76848 119 delete fRunParameters;
120 fRunParameters = 0;
121
36137ac1 122 delete fPreprocessors;
123 fPreprocessors = 0;
124
125 delete fDcsAliasMap;
126 fDcsAliasMap = 0;
5c6b40ae 127}
128
36137ac1 129//______________________________________________________________________________________________
84090f85 130UInt_t AliTestShuttle::Store(const AliCDBPath& path, TObject* object, AliCDBMetaData* metaData,
131 Int_t validityStart, Bool_t validityInfinite)
5c6b40ae 132{
133 // Stores the CDB object
134 // This function should be called at the end of the preprocessor cycle
135 //
136 // This implementation just stores it on the local disk, the full AliShuttle
137 // puts it to the Grid FileCatalog
138
84090f85 139 Int_t startRun = fRun - validityStart;
140 if(startRun < 0) {
141 AliError("First valid run happens to be less than 0! Setting it to 0...");
142 startRun=0;
143 }
17111222 144
84090f85 145 Int_t endRun = -1;
146 if(validityInfinite) {
147 endRun = AliCDBRunRange::Infinity();
148 } else {
149 endRun = fRun;
150 }
17111222 151
84090f85 152 AliCDBId id(path, startRun, endRun);
17111222 153
e19c88ea 154 return AliCDBManager::Instance()->GetStorage(fgkMainCDB)->Put(object, id, metaData);
84090f85 155}
17111222 156
84090f85 157//______________________________________________________________________________________________
8c77aee7 158UInt_t AliTestShuttle::StoreReferenceData(const AliCDBPath& path, TObject* object, AliCDBMetaData* metaData)
84090f85 159{
160 // Stores the object as reference data
161 // This function should be called at the end of the preprocessor cycle
162 //
163 // This implementation just stores it on the local disk, the full AliShuttle
164 // puts it to the Grid FileCatalog
165
8c77aee7 166 AliCDBId id(path, fRun, fRun);
84090f85 167
e19c88ea 168 return AliCDBManager::Instance()->GetStorage(fgkMainRefStorage)->Put(object, id, metaData);
5c6b40ae 169}
170
36137ac1 171//______________________________________________________________________________________________
5c6b40ae 172const char* AliTestShuttle::GetFile(Int_t system, const char* detector, const char* id, const char* source)
173{
174 // This function retrieves a file from the given system (kDAQ, kDCS, kHLT) with the given file id
175 // and from the given source in the system.
176 // The function returnes the path to the local file.
177 //
178 // test implementation of GetFile
179 // takes files from the local disks, files are passen in a TMap in the constructor
180
181 TString key;
182 key.Form("%s-%s-%s", fkSystemNames[system], detector, id);
183 TPair* sourceListPair = dynamic_cast<TPair*> (fInputFiles->FindObject(key.Data()));
184 TMap* sourceList = 0;
185 if (sourceListPair)
186 sourceList = dynamic_cast<TMap*> (sourceListPair->Value());
187 if (!sourceList)
188 {
189 AliError(Form("Could not find any file in %s with id %s (%s)", fkSystemNames[system], id, key.Data()));
190 return 0;
191 }
192
193 TPair* fileNamePair = dynamic_cast<TPair*> (sourceList->FindObject(source));
194 TObjString* fileName = dynamic_cast<TObjString*> (fileNamePair->Value());
195 if (!fileName)
196 {
36137ac1 197 AliError(Form("Could not find files from source %s in %s with id %s",
198 source, fkSystemNames[system], id));
5c6b40ae 199 return 0;
200 }
201
202 return fileName->GetString().Data();
203}
204
36137ac1 205//______________________________________________________________________________________________
5c6b40ae 206TList* AliTestShuttle::GetFileSources(Int_t system, const char* detector, const char* id)
207{
208 // Returns a list of sources in a given system that saved a file with the given id
209 //
210 // test implementation of GetFileSources
211 // takes files from the local disks, files are passen in a TMap in the constructor
212
213 TString key;
214 key.Form("%s-%s-%s", fkSystemNames[system], detector, id);
215 TPair* sourceListPair = dynamic_cast<TPair*> (fInputFiles->FindObject(key.Data()));
216 TMap* sourceList = 0;
217 if (sourceListPair)
218 sourceList = dynamic_cast<TMap*> (sourceListPair->Value());
219 if (!sourceList)
220 {
221 AliError(Form("Could not find any file in %s with id %s (%s)", fkSystemNames[system], id, key.Data()));
222 return 0;
223 }
224
225 TIterator* iter = sourceList->GetTable()->MakeIterator();
226 TObject* obj = 0;
227 TList* list = new TList;
228 while ((obj = iter->Next()))
229 {
230 TPair* pair = dynamic_cast<TPair*> (obj);
231 if (pair)
232 list->Add(pair->Key());
233 }
234
235 delete iter;
236
237 return list;
238}
239
36137ac1 240//______________________________________________________________________________________________
5c6b40ae 241void AliTestShuttle::Log(const char* detector, const char* message)
242{
243 // test implementation of Log
244 // just prints to the screen
245
246 AliInfo(Form("%s: %s", detector, message));
247}
248
36137ac1 249//______________________________________________________________________________________________
250void AliTestShuttle::AddInputFile(Int_t system, const char* detector, const char* id, const char* source, const char* fileName)
251{
252 // This function adds a file to the list of input files
253
254 TString key;
255 key.Form("%s-%s-%s", fkSystemNames[system], detector, id);
256 TPair* sourceListPair = dynamic_cast<TPair*> (fInputFiles->FindObject(key.Data()));
257 TMap* sourceList = 0;
258 if (sourceListPair)
259 sourceList = dynamic_cast<TMap*> (sourceListPair->Value());
260 if (!sourceList)
261 {
262 sourceList = new TMap;
263 fInputFiles->Add(new TObjString(key), sourceList);
264 }
265
266 sourceList->Add(new TObjString(source), new TObjString(fileName));
267}
268
d461a8a7 269//______________________________________________________________________________________________
270Bool_t AliTestShuttle::AddInputCDBEntry(AliCDBEntry* entry)
271{
272 // This function adds an object in the OCDB to be later retrieved with GetFromOCDB
273
274 AliCDBStorage *sto = AliCDBManager::Instance()->GetStorage(fgkMainCDB);
275 if (!sto)
276 {
277 Log("SHUTTLE", "GetFromOCDB - Cannot activate main OCDB for query!");
278 return 0;
279 }
280
281 return sto->Put(entry);
282}
283
284//______________________________________________________________________________________________
285AliCDBEntry* AliTestShuttle::GetFromOCDB(const AliCDBPath& path)
286{
287// returns obiect from OCDB valid for current run
288
289 AliCDBStorage *sto = AliCDBManager::Instance()->GetStorage(fgkMainCDB);
290 if (!sto)
291 {
292 Log("SHUTTLE", "GetFromOCDB - Cannot activate main OCDB for query!");
293 return 0;
294 }
295
296 return (AliCDBEntry*) sto->Get(path, fRun);
297}
298
36137ac1 299//______________________________________________________________________________________________
300void AliTestShuttle::Process()
301{
302 // This function tests all preprocessors that are registered to it
303 // All preprocessors get the same dcs alias map and have access to the same list of files.
304
305 for (Int_t i=0; i<fPreprocessors->GetEntries(); ++i)
306 {
307 AliPreprocessor* preprocessor = dynamic_cast<AliPreprocessor*> (fPreprocessors->At(i));
308 if (preprocessor)
309 {
17111222 310 preprocessor->Initialize(fRun, fStartTime, fEndTime);
36137ac1 311 preprocessor->Process(fDcsAliasMap);
312 }
313 }
314}
315
316//______________________________________________________________________________________________
317void AliTestShuttle::RegisterPreprocessor(AliPreprocessor* preprocessor)
318{
319 // registers a preprocessor
320
eba76848 321 const char* detName = preprocessor->GetName();
322 if(strcmp("DET", detName) != 0) {
323 if(GetDetPos(detName) < 0)
324 AliFatal(Form("********** !!!!! Invalid detector name: %s !!!!! **********", detName));
325 }
326
327 fPreprocessors->Add(preprocessor);
328}
329
330//______________________________________________________________________________________________
331void AliTestShuttle::AddInputRunParameter(const char* key, const char* value){
332// set a run parameter (in reality it will be read from the DAQ logbook)
333
334 TObjString* keyObj = new TObjString(key);
335 if (fRunParameters->Contains(key)) {
336 AliWarning(Form("Parameter %s already existing and it will be replaced.", key));
337 delete fRunParameters->Remove(keyObj);
338
339 }
340 fRunParameters->Add(keyObj, new TObjString(value));
341 AliDebug(2, Form("Number of parameters: %d", fRunParameters->
342 GetEntries()));
343}
344
345//______________________________________________________________________________________________
346const char* AliTestShuttle::GetRunParameter(const char* key){
347// get a run parameter
348
349 TObjString* value = dynamic_cast<TObjString*> (fRunParameters->GetValue(key));
350 if(!value) {
351 AliError(Form("No such parameter: %s", key));
352 return 0;
353 }
354 return value->GetName();
36137ac1 355}
e19c88ea 356
d461a8a7 357//______________________________________________________________________________________________
358void AliTestShuttle::SetShuttleTempDir(const char* tmpDir)
359{
360// sets Shuttle temp directory
361
362 fgkShuttleTempDir = gSystem->ExpandPathName(tmpDir);
363}
364
365//______________________________________________________________________________________________
366void AliTestShuttle::SetShuttleLogDir(const char* logDir)
367{
368// sets Shuttle log directory
369
370 fgkShuttleLogDir = gSystem->ExpandPathName(logDir);
371}
372