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