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