]> git.uio.no Git - u/mrichter/AliRoot.git/blame - SHUTTLE/TestShuttle/AliTestShuttle.cxx
new lookup table for sim. data with numberof TRMs
[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),
441b0e9c 101 fRunTypeMap(0),
36137ac1 102 fPreprocessors(0),
103 fDcsAliasMap(0)
5c6b40ae 104{
105 // constructor
36137ac1 106
107 fInputFiles = new TMap;
eba76848 108 fRunParameters = new TMap;
441b0e9c 109 fRunTypeMap = new TMap;
36137ac1 110 fPreprocessors = new TObjArray;
441b0e9c 111
112 fInputFiles->SetOwner(1);
113 fRunParameters->SetOwner(1);
114 fRunTypeMap->SetOwner(1);
115 fPreprocessors->SetOwner(1);
5c6b40ae 116}
117
36137ac1 118//______________________________________________________________________________________________
5c6b40ae 119AliTestShuttle::~AliTestShuttle()
120{
121 // destructor
36137ac1 122
123 delete fInputFiles;
124 fInputFiles = 0;
125
eba76848 126 delete fRunParameters;
127 fRunParameters = 0;
128
441b0e9c 129 delete fRunTypeMap;
130 fRunTypeMap = 0;
131
36137ac1 132 delete fPreprocessors;
133 fPreprocessors = 0;
134
135 delete fDcsAliasMap;
136 fDcsAliasMap = 0;
5c6b40ae 137}
138
36137ac1 139//______________________________________________________________________________________________
84090f85 140UInt_t AliTestShuttle::Store(const AliCDBPath& path, TObject* object, AliCDBMetaData* metaData,
141 Int_t validityStart, Bool_t validityInfinite)
5c6b40ae 142{
143 // Stores the CDB object
144 // This function should be called at the end of the preprocessor cycle
145 //
146 // This implementation just stores it on the local disk, the full AliShuttle
147 // puts it to the Grid FileCatalog
148
84090f85 149 Int_t startRun = fRun - validityStart;
150 if(startRun < 0) {
151 AliError("First valid run happens to be less than 0! Setting it to 0...");
152 startRun=0;
153 }
17111222 154
84090f85 155 Int_t endRun = -1;
156 if(validityInfinite) {
157 endRun = AliCDBRunRange::Infinity();
158 } else {
159 endRun = fRun;
160 }
17111222 161
84090f85 162 AliCDBId id(path, startRun, endRun);
17111222 163
e19c88ea 164 return AliCDBManager::Instance()->GetStorage(fgkMainCDB)->Put(object, id, metaData);
84090f85 165}
17111222 166
84090f85 167//______________________________________________________________________________________________
8c77aee7 168UInt_t AliTestShuttle::StoreReferenceData(const AliCDBPath& path, TObject* object, AliCDBMetaData* metaData)
84090f85 169{
170 // Stores the object as reference data
171 // This function should be called at the end of the preprocessor cycle
172 //
173 // This implementation just stores it on the local disk, the full AliShuttle
174 // puts it to the Grid FileCatalog
175
8c77aee7 176 AliCDBId id(path, fRun, fRun);
84090f85 177
e19c88ea 178 return AliCDBManager::Instance()->GetStorage(fgkMainRefStorage)->Put(object, id, metaData);
5c6b40ae 179}
180
36137ac1 181//______________________________________________________________________________________________
5c6b40ae 182const char* AliTestShuttle::GetFile(Int_t system, const char* detector, const char* id, const char* source)
183{
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.
187 //
188 // test implementation of GetFile
189 // takes files from the local disks, files are passen in a TMap in the constructor
190
191 TString key;
192 key.Form("%s-%s-%s", fkSystemNames[system], detector, id);
193 TPair* sourceListPair = dynamic_cast<TPair*> (fInputFiles->FindObject(key.Data()));
194 TMap* sourceList = 0;
195 if (sourceListPair)
196 sourceList = dynamic_cast<TMap*> (sourceListPair->Value());
197 if (!sourceList)
198 {
199 AliError(Form("Could not find any file in %s with id %s (%s)", fkSystemNames[system], id, key.Data()));
200 return 0;
201 }
202
203 TPair* fileNamePair = dynamic_cast<TPair*> (sourceList->FindObject(source));
204 TObjString* fileName = dynamic_cast<TObjString*> (fileNamePair->Value());
205 if (!fileName)
206 {
36137ac1 207 AliError(Form("Could not find files from source %s in %s with id %s",
208 source, fkSystemNames[system], id));
5c6b40ae 209 return 0;
210 }
211
212 return fileName->GetString().Data();
213}
214
36137ac1 215//______________________________________________________________________________________________
5c6b40ae 216TList* AliTestShuttle::GetFileSources(Int_t system, const char* detector, const char* id)
217{
218 // Returns a list of sources in a given system that saved a file with the given id
219 //
220 // test implementation of GetFileSources
221 // takes files from the local disks, files are passen in a TMap in the constructor
222
223 TString key;
224 key.Form("%s-%s-%s", fkSystemNames[system], detector, id);
225 TPair* sourceListPair = dynamic_cast<TPair*> (fInputFiles->FindObject(key.Data()));
226 TMap* sourceList = 0;
227 if (sourceListPair)
228 sourceList = dynamic_cast<TMap*> (sourceListPair->Value());
229 if (!sourceList)
230 {
231 AliError(Form("Could not find any file in %s with id %s (%s)", fkSystemNames[system], id, key.Data()));
232 return 0;
233 }
234
235 TIterator* iter = sourceList->GetTable()->MakeIterator();
236 TObject* obj = 0;
237 TList* list = new TList;
238 while ((obj = iter->Next()))
239 {
240 TPair* pair = dynamic_cast<TPair*> (obj);
241 if (pair)
242 list->Add(pair->Key());
243 }
244
245 delete iter;
246
247 return list;
248}
249
36137ac1 250//______________________________________________________________________________________________
5c6b40ae 251void AliTestShuttle::Log(const char* detector, const char* message)
252{
253 // test implementation of Log
254 // just prints to the screen
255
256 AliInfo(Form("%s: %s", detector, message));
257}
258
36137ac1 259//______________________________________________________________________________________________
260void AliTestShuttle::AddInputFile(Int_t system, const char* detector, const char* id, const char* source, const char* fileName)
261{
262 // This function adds a file to the list of input files
263
264 TString key;
265 key.Form("%s-%s-%s", fkSystemNames[system], detector, id);
266 TPair* sourceListPair = dynamic_cast<TPair*> (fInputFiles->FindObject(key.Data()));
267 TMap* sourceList = 0;
268 if (sourceListPair)
269 sourceList = dynamic_cast<TMap*> (sourceListPair->Value());
270 if (!sourceList)
271 {
272 sourceList = new TMap;
273 fInputFiles->Add(new TObjString(key), sourceList);
274 }
275
276 sourceList->Add(new TObjString(source), new TObjString(fileName));
277}
278
d461a8a7 279//______________________________________________________________________________________________
280Bool_t AliTestShuttle::AddInputCDBEntry(AliCDBEntry* entry)
281{
282 // This function adds an object in the OCDB to be later retrieved with GetFromOCDB
283
284 AliCDBStorage *sto = AliCDBManager::Instance()->GetStorage(fgkMainCDB);
285 if (!sto)
286 {
287 Log("SHUTTLE", "GetFromOCDB - Cannot activate main OCDB for query!");
288 return 0;
289 }
290
291 return sto->Put(entry);
292}
293
294//______________________________________________________________________________________________
295AliCDBEntry* AliTestShuttle::GetFromOCDB(const AliCDBPath& path)
296{
297// returns obiect from OCDB valid for current run
298
299 AliCDBStorage *sto = AliCDBManager::Instance()->GetStorage(fgkMainCDB);
300 if (!sto)
301 {
302 Log("SHUTTLE", "GetFromOCDB - Cannot activate main OCDB for query!");
303 return 0;
304 }
305
306 return (AliCDBEntry*) sto->Get(path, fRun);
307}
308
36137ac1 309//______________________________________________________________________________________________
310void AliTestShuttle::Process()
311{
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.
314
315 for (Int_t i=0; i<fPreprocessors->GetEntries(); ++i)
316 {
317 AliPreprocessor* preprocessor = dynamic_cast<AliPreprocessor*> (fPreprocessors->At(i));
318 if (preprocessor)
319 {
17111222 320 preprocessor->Initialize(fRun, fStartTime, fEndTime);
36137ac1 321 preprocessor->Process(fDcsAliasMap);
322 }
323 }
324}
325
326//______________________________________________________________________________________________
327void AliTestShuttle::RegisterPreprocessor(AliPreprocessor* preprocessor)
328{
329 // registers a preprocessor
330
eba76848 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));
441b0e9c 335 }
eba76848 336
337 fPreprocessors->Add(preprocessor);
338}
339
340//______________________________________________________________________________________________
341void AliTestShuttle::AddInputRunParameter(const char* key, const char* value){
342// set a run parameter (in reality it will be read from the DAQ logbook)
343
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);
348
349 }
350 fRunParameters->Add(keyObj, new TObjString(value));
351 AliDebug(2, Form("Number of parameters: %d", fRunParameters->
352 GetEntries()));
353}
354
441b0e9c 355//______________________________________________________________________________________________
356void AliTestShuttle::AddInputRunType(const char* detCode, const char* runType){
357// set a run type (in reality it will be read from the "run type" logbook)
358
359 if (strcmp("DET", detCode) != 0)
360 {
361 if (GetDetPos(detCode) < 0)
362 {
363 AliError(Form("Invalid detector name: %s", detCode));
364 return;
365 }
366 }
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);
371
372 }
373 fRunTypeMap->Add(detObj, new TObjString(runType));
374 AliDebug(2, Form("Number of detectors: %d", fRunTypeMap->GetEntries()));
375}
376
377//______________________________________________________________________________________________
378const char* AliTestShuttle::GetRunType(const char* detCode){
379// get a run parameter
380
381 TObjString* value = dynamic_cast<TObjString*> (fRunTypeMap->GetValue(detCode));
382 if(!value) {
383 AliError(Form("Input run type not set for detector %s!", detCode));
384 return 0;
385 }
386 return value->GetName();
387}
388
eba76848 389//______________________________________________________________________________________________
390const char* AliTestShuttle::GetRunParameter(const char* key){
391// get a run parameter
392
393 TObjString* value = dynamic_cast<TObjString*> (fRunParameters->GetValue(key));
394 if(!value) {
395 AliError(Form("No such parameter: %s", key));
396 return 0;
397 }
398 return value->GetName();
36137ac1 399}
e19c88ea 400
d461a8a7 401//______________________________________________________________________________________________
402void AliTestShuttle::SetShuttleTempDir(const char* tmpDir)
403{
404// sets Shuttle temp directory
405
406 fgkShuttleTempDir = gSystem->ExpandPathName(tmpDir);
407}
408
409//______________________________________________________________________________________________
410void AliTestShuttle::SetShuttleLogDir(const char* logDir)
411{
412// sets Shuttle log directory
413
414 fgkShuttleLogDir = gSystem->ExpandPathName(logDir);
415}
416