Function GetFromOCDB() added in AliPreprocessor. Getters of OCDB and reference storag...
[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$
e19c88ea 18Revision 1.6 2006/11/06 14:22:47 jgrosseo
19major update (Alberto)
20o) reading of run parameters from the logbook
21o) online offline naming conversion
22o) standalone DCSclient package
23
eba76848 24Revision 1.5 2006/10/02 12:58:52 jgrosseo
25Small interface change in StoreReferenceData
26
8c77aee7 27Revision 1.4 2006/08/08 14:19:07 jgrosseo
28Update to shuttle classes (Alberto)
29
30- Possibility to set the full object's path in the Preprocessor's and
31Shuttle'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
35data in a dedicated CDB storage.
36
84090f85 37Revision 1.3 2006/07/11 12:44:32 jgrosseo
38adding parameters for extended validity range of data produced by preprocessor
39
17111222 40Revision 1.2 2006/06/06 14:20:05 jgrosseo
41o) updated test preprocessor (alberto)
42o) added comments to example macro
43o) test shuttle implements new interface
44
5c6b40ae 45Revision 1.2 2006/03/07 07:52:34 hristov
46New version (B.Yordanov)
47
48Revision 1.3 2005/11/17 17:47:34 byordano
49TList changed to TObjArray
50
51Revision 1.2 2005/11/17 14:43:22 byordano
52import to local CVS
53
54Revision 1.1.1.1 2005/10/28 07:33:58 hristov
55Initial import as subdirectory in AliRoot
56
57Revision 1.1.1.1 2005/09/12 22:11:40 byordano
58SHUTTLE package
59
60Revision 1.2 2005/08/29 21:15:47 byordano
61some docs added
62
63*/
64
65//
66// test implementation of the AliShuttleInterface, to be used for local tests of preprocessors
67//
68// reads files from the local disk
69// stores to local CDB
70// logs to the screen
71//
72
73#include "AliTestShuttle.h"
74#include "AliLog.h"
75
76#include "AliCDBManager.h"
84090f85 77#include "AliCDBStorage.h"
5c6b40ae 78#include "AliCDBMetaData.h"
84090f85 79#include "AliCDBPath.h"
5c6b40ae 80#include "AliCDBId.h"
36137ac1 81#include "AliPreprocessor.h"
5c6b40ae 82
83#include <TMap.h>
84#include <TList.h>
5c6b40ae 85#include <TObjString.h>
e19c88ea 86#include <TSystem.h>
5c6b40ae 87
88ClassImp(AliTestShuttle)
89
36137ac1 90//______________________________________________________________________________________________
17111222 91AliTestShuttle::AliTestShuttle(Int_t run, UInt_t startTime, UInt_t endTime) :
92 fRun(run),
93 fStartTime(startTime),
94 fEndTime(endTime),
36137ac1 95 fInputFiles(0),
eba76848 96 fRunParameters(0),
36137ac1 97 fPreprocessors(0),
98 fDcsAliasMap(0)
5c6b40ae 99{
100 // constructor
36137ac1 101
102 fInputFiles = new TMap;
eba76848 103 fRunParameters = new TMap;
36137ac1 104 fPreprocessors = new TObjArray;
5c6b40ae 105}
106
36137ac1 107//______________________________________________________________________________________________
5c6b40ae 108AliTestShuttle::~AliTestShuttle()
109{
110 // destructor
36137ac1 111
112 delete fInputFiles;
113 fInputFiles = 0;
114
eba76848 115 delete fRunParameters;
116 fRunParameters = 0;
117
36137ac1 118 delete fPreprocessors;
119 fPreprocessors = 0;
120
121 delete fDcsAliasMap;
122 fDcsAliasMap = 0;
5c6b40ae 123}
124
36137ac1 125//______________________________________________________________________________________________
84090f85 126UInt_t AliTestShuttle::Store(const AliCDBPath& path, TObject* object, AliCDBMetaData* metaData,
127 Int_t validityStart, Bool_t validityInfinite)
5c6b40ae 128{
129 // Stores the CDB object
130 // This function should be called at the end of the preprocessor cycle
131 //
132 // This implementation just stores it on the local disk, the full AliShuttle
133 // puts it to the Grid FileCatalog
134
84090f85 135 Int_t startRun = fRun - validityStart;
136 if(startRun < 0) {
137 AliError("First valid run happens to be less than 0! Setting it to 0...");
138 startRun=0;
139 }
17111222 140
84090f85 141 Int_t endRun = -1;
142 if(validityInfinite) {
143 endRun = AliCDBRunRange::Infinity();
144 } else {
145 endRun = fRun;
146 }
17111222 147
84090f85 148 AliCDBId id(path, startRun, endRun);
17111222 149
e19c88ea 150 return AliCDBManager::Instance()->GetStorage(fgkMainCDB)->Put(object, id, metaData);
84090f85 151}
17111222 152
84090f85 153//______________________________________________________________________________________________
8c77aee7 154UInt_t AliTestShuttle::StoreReferenceData(const AliCDBPath& path, TObject* object, AliCDBMetaData* metaData)
84090f85 155{
156 // Stores the object as reference data
157 // This function should be called at the end of the preprocessor cycle
158 //
159 // This implementation just stores it on the local disk, the full AliShuttle
160 // puts it to the Grid FileCatalog
161
8c77aee7 162 AliCDBId id(path, fRun, fRun);
84090f85 163
e19c88ea 164 return AliCDBManager::Instance()->GetStorage(fgkMainRefStorage)->Put(object, id, metaData);
5c6b40ae 165}
166
36137ac1 167//______________________________________________________________________________________________
5c6b40ae 168const char* AliTestShuttle::GetFile(Int_t system, const char* detector, const char* id, const char* source)
169{
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.
173 //
174 // test implementation of GetFile
175 // takes files from the local disks, files are passen in a TMap in the constructor
176
177 TString key;
178 key.Form("%s-%s-%s", fkSystemNames[system], detector, id);
179 TPair* sourceListPair = dynamic_cast<TPair*> (fInputFiles->FindObject(key.Data()));
180 TMap* sourceList = 0;
181 if (sourceListPair)
182 sourceList = dynamic_cast<TMap*> (sourceListPair->Value());
183 if (!sourceList)
184 {
185 AliError(Form("Could not find any file in %s with id %s (%s)", fkSystemNames[system], id, key.Data()));
186 return 0;
187 }
188
189 TPair* fileNamePair = dynamic_cast<TPair*> (sourceList->FindObject(source));
190 TObjString* fileName = dynamic_cast<TObjString*> (fileNamePair->Value());
191 if (!fileName)
192 {
36137ac1 193 AliError(Form("Could not find files from source %s in %s with id %s",
194 source, fkSystemNames[system], id));
5c6b40ae 195 return 0;
196 }
197
198 return fileName->GetString().Data();
199}
200
36137ac1 201//______________________________________________________________________________________________
5c6b40ae 202TList* AliTestShuttle::GetFileSources(Int_t system, const char* detector, const char* id)
203{
204 // Returns a list of sources in a given system that saved a file with the given id
205 //
206 // test implementation of GetFileSources
207 // takes files from the local disks, files are passen in a TMap in the constructor
208
209 TString key;
210 key.Form("%s-%s-%s", fkSystemNames[system], detector, id);
211 TPair* sourceListPair = dynamic_cast<TPair*> (fInputFiles->FindObject(key.Data()));
212 TMap* sourceList = 0;
213 if (sourceListPair)
214 sourceList = dynamic_cast<TMap*> (sourceListPair->Value());
215 if (!sourceList)
216 {
217 AliError(Form("Could not find any file in %s with id %s (%s)", fkSystemNames[system], id, key.Data()));
218 return 0;
219 }
220
221 TIterator* iter = sourceList->GetTable()->MakeIterator();
222 TObject* obj = 0;
223 TList* list = new TList;
224 while ((obj = iter->Next()))
225 {
226 TPair* pair = dynamic_cast<TPair*> (obj);
227 if (pair)
228 list->Add(pair->Key());
229 }
230
231 delete iter;
232
233 return list;
234}
235
36137ac1 236//______________________________________________________________________________________________
5c6b40ae 237void AliTestShuttle::Log(const char* detector, const char* message)
238{
239 // test implementation of Log
240 // just prints to the screen
241
242 AliInfo(Form("%s: %s", detector, message));
243}
244
36137ac1 245//______________________________________________________________________________________________
246void AliTestShuttle::AddInputFile(Int_t system, const char* detector, const char* id, const char* source, const char* fileName)
247{
248 // This function adds a file to the list of input files
249
250 TString key;
251 key.Form("%s-%s-%s", fkSystemNames[system], detector, id);
252 TPair* sourceListPair = dynamic_cast<TPair*> (fInputFiles->FindObject(key.Data()));
253 TMap* sourceList = 0;
254 if (sourceListPair)
255 sourceList = dynamic_cast<TMap*> (sourceListPair->Value());
256 if (!sourceList)
257 {
258 sourceList = new TMap;
259 fInputFiles->Add(new TObjString(key), sourceList);
260 }
261
262 sourceList->Add(new TObjString(source), new TObjString(fileName));
263}
264
265//______________________________________________________________________________________________
266void AliTestShuttle::Process()
267{
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.
270
271 for (Int_t i=0; i<fPreprocessors->GetEntries(); ++i)
272 {
273 AliPreprocessor* preprocessor = dynamic_cast<AliPreprocessor*> (fPreprocessors->At(i));
274 if (preprocessor)
275 {
17111222 276 preprocessor->Initialize(fRun, fStartTime, fEndTime);
36137ac1 277 preprocessor->Process(fDcsAliasMap);
278 }
279 }
280}
281
282//______________________________________________________________________________________________
283void AliTestShuttle::RegisterPreprocessor(AliPreprocessor* preprocessor)
284{
285 // registers a preprocessor
286
eba76848 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));
291 }
292
293 fPreprocessors->Add(preprocessor);
294}
295
296//______________________________________________________________________________________________
297void AliTestShuttle::AddInputRunParameter(const char* key, const char* value){
298// set a run parameter (in reality it will be read from the DAQ logbook)
299
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);
304
305 }
306 fRunParameters->Add(keyObj, new TObjString(value));
307 AliDebug(2, Form("Number of parameters: %d", fRunParameters->
308 GetEntries()));
309}
310
311//______________________________________________________________________________________________
312const char* AliTestShuttle::GetRunParameter(const char* key){
313// get a run parameter
314
315 TObjString* value = dynamic_cast<TObjString*> (fRunParameters->GetValue(key));
316 if(!value) {
317 AliError(Form("No such parameter: %s", key));
318 return 0;
319 }
320 return value->GetName();
36137ac1 321}
e19c88ea 322