]> git.uio.no Git - u/mrichter/AliRoot.git/blob - SHUTTLE/TestShuttle/AliTestShuttle.cxx
8a02b06a5229e4e5dfce0028b5bd688be7995548
[u/mrichter/AliRoot.git] / SHUTTLE / TestShuttle / AliTestShuttle.cxx
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$
18 Revision 1.3  2006/07/11 12:44:32  jgrosseo
19 adding parameters for extended validity range of data produced by preprocessor
20
21 Revision 1.2  2006/06/06 14:20:05  jgrosseo
22 o) updated test preprocessor (alberto)
23 o) added comments to example macro
24 o) test shuttle implements new interface
25
26 Revision 1.2  2006/03/07 07:52:34  hristov
27 New version (B.Yordanov)
28
29 Revision 1.3  2005/11/17 17:47:34  byordano
30 TList changed to TObjArray
31
32 Revision 1.2  2005/11/17 14:43:22  byordano
33 import to local CVS
34
35 Revision 1.1.1.1  2005/10/28 07:33:58  hristov
36 Initial import as subdirectory in AliRoot
37
38 Revision 1.1.1.1  2005/09/12 22:11:40  byordano
39 SHUTTLE package
40
41 Revision 1.2  2005/08/29 21:15:47  byordano
42 some 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"
58 #include "AliCDBStorage.h"
59 #include "AliCDBMetaData.h"
60 #include "AliCDBPath.h"
61 #include "AliCDBId.h"
62 #include "AliPreprocessor.h"
63
64 #include <TMap.h>
65 #include <TList.h>
66 #include <TString.h>
67 #include <TObjString.h>
68
69 ClassImp(AliTestShuttle)
70
71 //______________________________________________________________________________________________
72 AliTestShuttle::AliTestShuttle(Int_t run, UInt_t startTime, UInt_t endTime) :
73   fRun(run),
74   fStartTime(startTime),
75   fEndTime(endTime),
76   fInputFiles(0),
77   fPreprocessors(0),
78   fDcsAliasMap(0)
79 {
80   // constructor
81
82   fInputFiles = new TMap;
83   fPreprocessors = new TObjArray;
84 }
85
86 //______________________________________________________________________________________________
87 AliTestShuttle::~AliTestShuttle()
88 {
89   // destructor
90
91   delete fInputFiles;
92   fInputFiles = 0;
93
94   delete fPreprocessors;
95   fPreprocessors = 0;
96
97   delete fDcsAliasMap;
98   fDcsAliasMap = 0;
99 }
100
101 //______________________________________________________________________________________________
102 UInt_t AliTestShuttle::Store(const AliCDBPath& path, TObject* object, AliCDBMetaData* metaData,
103                                 Int_t validityStart, Bool_t validityInfinite)
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
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   }
116
117   Int_t endRun = -1;
118   if(validityInfinite) {
119         endRun = AliCDBRunRange::Infinity();
120   } else {
121         endRun = fRun;
122   }
123
124   AliCDBId id(path, startRun, endRun);
125
126   return AliCDBManager::Instance()->Put(object, id, metaData);
127 }
128
129 //______________________________________________________________________________________________
130 UInt_t AliTestShuttle::StoreReferenceData(const AliCDBPath& path, TObject* object, AliCDBMetaData* metaData,
131                                 Int_t validityStart, Bool_t validityInfinite)
132
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);
156 }
157
158 //______________________________________________________________________________________________
159 const 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   {
184     AliError(Form("Could not find files from source %s in %s with id %s",
185                         source, fkSystemNames[system], id));
186     return 0;
187   }
188
189   return fileName->GetString().Data();
190 }
191
192 //______________________________________________________________________________________________
193 TList* 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
227 //______________________________________________________________________________________________
228 void 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
236 //______________________________________________________________________________________________
237 void 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 //______________________________________________________________________________________________
257 void 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     {
267       preprocessor->Initialize(fRun, fStartTime, fEndTime);
268       preprocessor->Process(fDcsAliasMap);
269     }
270   }
271 }
272
273 //______________________________________________________________________________________________
274 void AliTestShuttle::RegisterPreprocessor(AliPreprocessor* preprocessor)
275 {
276   // registers a preprocessor
277
278   fPreprocessors->Add(preprocessor);
279 }