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