]> git.uio.no Git - u/mrichter/AliRoot.git/blob - SHUTTLE/TestShuttle/AliTestShuttle.cxx
a9c87d0893922aee99e5860a53056d2beae3efdf
[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.6  2006/11/06 14:22:47  jgrosseo
19 major update (Alberto)
20 o) reading of run parameters from the logbook
21 o) online offline naming conversion
22 o) standalone DCSclient package
23
24 Revision 1.5  2006/10/02 12:58:52  jgrosseo
25 Small interface change in StoreReferenceData
26
27 Revision 1.4  2006/08/08 14:19:07  jgrosseo
28 Update to shuttle classes (Alberto)
29
30 - Possibility to set the full object's path in the Preprocessor's and
31 Shuttle'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
35 data in a dedicated CDB storage.
36
37 Revision 1.3  2006/07/11 12:44:32  jgrosseo
38 adding parameters for extended validity range of data produced by preprocessor
39
40 Revision 1.2  2006/06/06 14:20:05  jgrosseo
41 o) updated test preprocessor (alberto)
42 o) added comments to example macro
43 o) test shuttle implements new interface
44
45 Revision 1.2  2006/03/07 07:52:34  hristov
46 New version (B.Yordanov)
47
48 Revision 1.3  2005/11/17 17:47:34  byordano
49 TList changed to TObjArray
50
51 Revision 1.2  2005/11/17 14:43:22  byordano
52 import to local CVS
53
54 Revision 1.1.1.1  2005/10/28 07:33:58  hristov
55 Initial import as subdirectory in AliRoot
56
57 Revision 1.1.1.1  2005/09/12 22:11:40  byordano
58 SHUTTLE package
59
60 Revision 1.2  2005/08/29 21:15:47  byordano
61 some 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"
77 #include "AliCDBStorage.h"
78 #include "AliCDBMetaData.h"
79 #include "AliCDBPath.h"
80 #include "AliCDBId.h"
81 #include "AliPreprocessor.h"
82
83 #include <TMap.h>
84 #include <TList.h>
85 #include <TObjString.h>
86 #include <TSystem.h>
87
88 ClassImp(AliTestShuttle)
89
90 //______________________________________________________________________________________________
91 AliTestShuttle::AliTestShuttle(Int_t run, UInt_t startTime, UInt_t endTime) :
92   fRun(run),
93   fStartTime(startTime),
94   fEndTime(endTime),
95   fInputFiles(0),
96   fRunParameters(0),
97   fPreprocessors(0),
98   fDcsAliasMap(0)
99 {
100   // constructor
101
102   fInputFiles = new TMap;
103   fRunParameters = new TMap;
104   fPreprocessors = new TObjArray;
105 }
106
107 //______________________________________________________________________________________________
108 AliTestShuttle::~AliTestShuttle()
109 {
110   // destructor
111
112   delete fInputFiles;
113   fInputFiles = 0;
114
115   delete fRunParameters;
116   fRunParameters = 0;
117
118   delete fPreprocessors;
119   fPreprocessors = 0;
120
121   delete fDcsAliasMap;
122   fDcsAliasMap = 0;
123 }
124
125 //______________________________________________________________________________________________
126 UInt_t AliTestShuttle::Store(const AliCDBPath& path, TObject* object, AliCDBMetaData* metaData,
127                                 Int_t validityStart, Bool_t validityInfinite)
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
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   }
140
141   Int_t endRun = -1;
142   if(validityInfinite) {
143         endRun = AliCDBRunRange::Infinity();
144   } else {
145         endRun = fRun;
146   }
147
148   AliCDBId id(path, startRun, endRun);
149
150   return AliCDBManager::Instance()->GetStorage(fgkMainCDB)->Put(object, id, metaData);
151 }
152
153 //______________________________________________________________________________________________
154 UInt_t AliTestShuttle::StoreReferenceData(const AliCDBPath& path, TObject* object, AliCDBMetaData* metaData)
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
162   AliCDBId id(path, fRun, fRun);
163
164   return AliCDBManager::Instance()->GetStorage(fgkMainRefStorage)->Put(object, id, metaData);
165 }
166
167 //______________________________________________________________________________________________
168 const 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   {
193     AliError(Form("Could not find files from source %s in %s with id %s",
194                         source, fkSystemNames[system], id));
195     return 0;
196   }
197
198   return fileName->GetString().Data();
199 }
200
201 //______________________________________________________________________________________________
202 TList* 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
236 //______________________________________________________________________________________________
237 void 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
245 //______________________________________________________________________________________________
246 void 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 //______________________________________________________________________________________________
266 void 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     {
276       preprocessor->Initialize(fRun, fStartTime, fEndTime);
277       preprocessor->Process(fDcsAliasMap);
278     }
279   }
280 }
281
282 //______________________________________________________________________________________________
283 void AliTestShuttle::RegisterPreprocessor(AliPreprocessor* preprocessor)
284 {
285   // registers a preprocessor
286
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 //______________________________________________________________________________________________
297 void 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 //______________________________________________________________________________________________
312 const 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();
321 }
322