]> git.uio.no Git - u/mrichter/AliRoot.git/blob - SHUTTLE/TestShuttle/AliTestShuttle.cxx
Run type field added in SHUTTLE framework. Run type is read from "run type" logbook...
[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.8  2007/02/13 11:22:25  acolla
19 Shuttle getters and setters of main/local OCDB/Reference storages, temp and log
20 folders moved to AliShuttleInterface
21
22 Revision 1.6  2006/11/06 14:22:47  jgrosseo
23 major update (Alberto)
24 o) reading of run parameters from the logbook
25 o) online offline naming conversion
26 o) standalone DCSclient package
27
28 Revision 1.5  2006/10/02 12:58:52  jgrosseo
29 Small interface change in StoreReferenceData
30
31 Revision 1.4  2006/08/08 14:19:07  jgrosseo
32 Update to shuttle classes (Alberto)
33
34 - Possibility to set the full object's path in the Preprocessor's and
35 Shuttle's  Store functions
36 - Possibility to extend the object's run validity in the same classes
37 ("startValidity" and "validityInfinite" parameters)
38 - Implementation of the StoreReferenceData function to store reference
39 data in a dedicated CDB storage.
40
41 Revision 1.3  2006/07/11 12:44:32  jgrosseo
42 adding parameters for extended validity range of data produced by preprocessor
43
44 Revision 1.2  2006/06/06 14:20:05  jgrosseo
45 o) updated test preprocessor (alberto)
46 o) added comments to example macro
47 o) test shuttle implements new interface
48
49 Revision 1.2  2006/03/07 07:52:34  hristov
50 New version (B.Yordanov)
51
52 Revision 1.3  2005/11/17 17:47:34  byordano
53 TList changed to TObjArray
54
55 Revision 1.2  2005/11/17 14:43:22  byordano
56 import to local CVS
57
58 Revision 1.1.1.1  2005/10/28 07:33:58  hristov
59 Initial import as subdirectory in AliRoot
60
61 Revision 1.1.1.1  2005/09/12 22:11:40  byordano
62 SHUTTLE package
63
64 Revision 1.2  2005/08/29 21:15:47  byordano
65 some docs added
66
67 */
68
69 //
70 // test implementation of the AliShuttleInterface, to be used for local tests of preprocessors
71 //
72 // reads files from the local disk
73 // stores to local CDB
74 // logs to the screen
75 //
76
77 #include "AliTestShuttle.h"
78 #include "AliLog.h"
79
80 #include "AliCDBManager.h"
81 #include "AliCDBStorage.h"
82 #include "AliCDBMetaData.h"
83 #include "AliCDBPath.h"
84 #include "AliCDBId.h"
85 #include "AliPreprocessor.h"
86
87 #include <TMap.h>
88 #include <TList.h>
89 #include <TObjString.h>
90 #include <TSystem.h>
91
92 ClassImp(AliTestShuttle)
93
94 //______________________________________________________________________________________________
95 AliTestShuttle::AliTestShuttle(Int_t run, UInt_t startTime, UInt_t endTime) :
96   fRun(run),
97   fStartTime(startTime),
98   fEndTime(endTime),
99   fInputFiles(0),
100   fRunParameters(0),
101   fRunTypeMap(0),
102   fPreprocessors(0),
103   fDcsAliasMap(0)
104 {
105   // constructor
106
107   fInputFiles = new TMap;
108   fRunParameters = new TMap;
109   fRunTypeMap = new TMap;
110   fPreprocessors = new TObjArray;
111
112   fInputFiles->SetOwner(1);
113   fRunParameters->SetOwner(1);
114   fRunTypeMap->SetOwner(1);
115   fPreprocessors->SetOwner(1);
116 }
117
118 //______________________________________________________________________________________________
119 AliTestShuttle::~AliTestShuttle()
120 {
121   // destructor
122
123   delete fInputFiles;
124   fInputFiles = 0;
125
126   delete fRunParameters;
127   fRunParameters = 0;
128
129   delete fRunTypeMap;
130   fRunTypeMap = 0;
131
132   delete fPreprocessors;
133   fPreprocessors = 0;
134
135   delete fDcsAliasMap;
136   fDcsAliasMap = 0;
137 }
138
139 //______________________________________________________________________________________________
140 UInt_t AliTestShuttle::Store(const AliCDBPath& path, TObject* object, AliCDBMetaData* metaData,
141                                 Int_t validityStart, Bool_t validityInfinite)
142 {
143   // Stores the CDB object
144   // This function should be called at the end of the preprocessor cycle
145   //
146   // This implementation just stores it on the local disk, the full AliShuttle
147   // puts it to the Grid FileCatalog
148
149   Int_t startRun = fRun - validityStart;
150   if(startRun < 0) {
151         AliError("First valid run happens to be less than 0! Setting it to 0...");
152         startRun=0;
153   }
154
155   Int_t endRun = -1;
156   if(validityInfinite) {
157         endRun = AliCDBRunRange::Infinity();
158   } else {
159         endRun = fRun;
160   }
161
162   AliCDBId id(path, startRun, endRun);
163
164   return AliCDBManager::Instance()->GetStorage(fgkMainCDB)->Put(object, id, metaData);
165 }
166
167 //______________________________________________________________________________________________
168 UInt_t AliTestShuttle::StoreReferenceData(const AliCDBPath& path, TObject* object, AliCDBMetaData* metaData)
169 {
170   // Stores the object as reference data
171   // This function should be called at the end of the preprocessor cycle
172   //
173   // This implementation just stores it on the local disk, the full AliShuttle
174   // puts it to the Grid FileCatalog
175
176   AliCDBId id(path, fRun, fRun);
177
178   return AliCDBManager::Instance()->GetStorage(fgkMainRefStorage)->Put(object, id, metaData);
179 }
180
181 //______________________________________________________________________________________________
182 const char* AliTestShuttle::GetFile(Int_t system, const char* detector, const char* id, const char* source)
183 {
184   // This function retrieves a file from the given system (kDAQ, kDCS, kHLT) with the given file id
185   // and from the given source in the system.
186   // The function returnes the path to the local file.
187   //
188   // test implementation of GetFile
189   // takes files from the local disks, files are passen in a TMap in the constructor
190
191   TString key;
192   key.Form("%s-%s-%s", fkSystemNames[system], detector, id);
193   TPair* sourceListPair = dynamic_cast<TPair*> (fInputFiles->FindObject(key.Data()));
194   TMap* sourceList = 0;
195   if (sourceListPair)
196     sourceList = dynamic_cast<TMap*> (sourceListPair->Value());
197   if (!sourceList)
198   {
199     AliError(Form("Could not find any file in %s with id %s (%s)", fkSystemNames[system], id, key.Data()));
200     return 0;
201   }
202
203   TPair* fileNamePair = dynamic_cast<TPair*> (sourceList->FindObject(source));
204   TObjString* fileName = dynamic_cast<TObjString*> (fileNamePair->Value());
205   if (!fileName)
206   {
207     AliError(Form("Could not find files from source %s in %s with id %s",
208                         source, fkSystemNames[system], id));
209     return 0;
210   }
211
212   return fileName->GetString().Data();
213 }
214
215 //______________________________________________________________________________________________
216 TList* AliTestShuttle::GetFileSources(Int_t system, const char* detector, const char* id)
217 {
218   // Returns a list of sources in a given system that saved a file with the given id
219   //
220   // test implementation of GetFileSources
221   // takes files from the local disks, files are passen in a TMap in the constructor
222
223   TString key;
224   key.Form("%s-%s-%s", fkSystemNames[system], detector, id);
225   TPair* sourceListPair = dynamic_cast<TPair*> (fInputFiles->FindObject(key.Data()));
226   TMap* sourceList = 0;
227   if (sourceListPair)
228     sourceList = dynamic_cast<TMap*> (sourceListPair->Value());
229   if (!sourceList)
230   {
231     AliError(Form("Could not find any file in %s with id %s (%s)", fkSystemNames[system], id, key.Data()));
232     return 0;
233   }
234
235   TIterator* iter = sourceList->GetTable()->MakeIterator();
236   TObject* obj = 0;
237   TList* list = new TList;
238   while ((obj = iter->Next()))
239   {
240     TPair* pair = dynamic_cast<TPair*> (obj);
241     if (pair)
242       list->Add(pair->Key());
243   }
244
245   delete iter;
246
247   return list;
248 }
249
250 //______________________________________________________________________________________________
251 void AliTestShuttle::Log(const char* detector, const char* message)
252 {
253   // test implementation of Log
254   // just prints to the screen
255
256   AliInfo(Form("%s: %s", detector, message));
257 }
258
259 //______________________________________________________________________________________________
260 void AliTestShuttle::AddInputFile(Int_t system, const char* detector, const char* id, const char* source, const char* fileName)
261 {
262   // This function adds a file to the list of input files
263
264   TString key;
265   key.Form("%s-%s-%s", fkSystemNames[system], detector, id);
266   TPair* sourceListPair = dynamic_cast<TPair*> (fInputFiles->FindObject(key.Data()));
267   TMap* sourceList = 0;
268   if (sourceListPair)
269     sourceList = dynamic_cast<TMap*> (sourceListPair->Value());
270   if (!sourceList)
271   {
272     sourceList = new TMap;
273     fInputFiles->Add(new TObjString(key), sourceList);
274   }
275
276   sourceList->Add(new TObjString(source), new TObjString(fileName));
277 }
278
279 //______________________________________________________________________________________________
280 Bool_t AliTestShuttle::AddInputCDBEntry(AliCDBEntry* entry)
281 {
282   // This function adds an object in the OCDB to be later retrieved with GetFromOCDB
283
284         AliCDBStorage *sto = AliCDBManager::Instance()->GetStorage(fgkMainCDB);
285         if (!sto)
286         {
287                 Log("SHUTTLE", "GetFromOCDB - Cannot activate main OCDB for query!");
288                 return 0;
289         }
290
291         return sto->Put(entry);
292 }
293
294 //______________________________________________________________________________________________
295 AliCDBEntry* AliTestShuttle::GetFromOCDB(const AliCDBPath& path)
296 {
297 // returns obiect from OCDB valid for current run
298
299         AliCDBStorage *sto = AliCDBManager::Instance()->GetStorage(fgkMainCDB);
300         if (!sto)
301         {
302                 Log("SHUTTLE", "GetFromOCDB - Cannot activate main OCDB for query!");
303                 return 0;
304         }
305
306         return (AliCDBEntry*) sto->Get(path, fRun);
307 }
308
309 //______________________________________________________________________________________________
310 void AliTestShuttle::Process()
311 {
312   // This function tests all preprocessors that are registered to it
313   // All preprocessors get the same dcs alias map and have access to the same list of files.
314
315   for (Int_t i=0; i<fPreprocessors->GetEntries(); ++i)
316   {
317     AliPreprocessor* preprocessor = dynamic_cast<AliPreprocessor*> (fPreprocessors->At(i));
318     if (preprocessor)
319     {
320       preprocessor->Initialize(fRun, fStartTime, fEndTime);
321       preprocessor->Process(fDcsAliasMap);
322     }
323   }
324 }
325
326 //______________________________________________________________________________________________
327 void AliTestShuttle::RegisterPreprocessor(AliPreprocessor* preprocessor)
328 {
329   // registers a preprocessor
330
331         const char* detName = preprocessor->GetName();
332         if(strcmp("DET", detName) != 0) {
333                 if(GetDetPos(detName) < 0)
334                         AliFatal(Form("********** !!!!! Invalid detector name: %s !!!!! **********", detName));
335         }
336
337         fPreprocessors->Add(preprocessor);
338 }
339
340 //______________________________________________________________________________________________
341 void AliTestShuttle::AddInputRunParameter(const char* key, const char* value){
342 // set a run parameter (in reality it will be read from the DAQ logbook)
343
344         TObjString* keyObj = new TObjString(key);
345         if (fRunParameters->Contains(key)) {
346                 AliWarning(Form("Parameter %s already existing and it will be replaced.", key));
347                 delete fRunParameters->Remove(keyObj);
348
349         }
350         fRunParameters->Add(keyObj, new TObjString(value));
351         AliDebug(2, Form("Number of parameters: %d", fRunParameters->
352         GetEntries()));
353 }
354
355 //______________________________________________________________________________________________
356 void AliTestShuttle::AddInputRunType(const char* detCode, const char* runType){
357 // set a run type (in reality it will be read from the "run type" logbook)
358
359         if (strcmp("DET", detCode) != 0)
360         {
361                 if (GetDetPos(detCode) < 0)
362                 {
363                         AliError(Form("Invalid detector name: %s", detCode));
364                         return;
365                 }
366         }
367         TObjString* detObj = new TObjString(detCode);
368         if (fRunTypeMap->Contains(detCode)) {
369                 AliWarning(Form("Detector %s already inserted: it will be replaced.", detCode));
370                 delete fRunTypeMap->Remove(detObj);
371
372         }
373         fRunTypeMap->Add(detObj, new TObjString(runType));
374         AliDebug(2, Form("Number of detectors: %d", fRunTypeMap->GetEntries()));
375 }
376
377 //______________________________________________________________________________________________
378 const char* AliTestShuttle::GetRunType(const char* detCode){
379 // get a run parameter
380
381         TObjString* value = dynamic_cast<TObjString*> (fRunTypeMap->GetValue(detCode));
382         if(!value) {
383                 AliError(Form("Input run type not set for detector %s!", detCode));
384                 return 0;
385         }
386         return value->GetName();
387 }
388
389 //______________________________________________________________________________________________
390 const char* AliTestShuttle::GetRunParameter(const char* key){
391 // get a run parameter
392
393         TObjString* value = dynamic_cast<TObjString*> (fRunParameters->GetValue(key));
394         if(!value) {
395                 AliError(Form("No such parameter: %s", key));
396                 return 0;
397         }
398         return value->GetName();
399 }
400
401 //______________________________________________________________________________________________
402 void AliTestShuttle::SetShuttleTempDir(const char* tmpDir)
403 {
404 // sets Shuttle temp directory
405
406         fgkShuttleTempDir = gSystem->ExpandPathName(tmpDir);
407 }
408
409 //______________________________________________________________________________________________
410 void AliTestShuttle::SetShuttleLogDir(const char* logDir)
411 {
412 // sets Shuttle log directory
413
414         fgkShuttleLogDir = gSystem->ExpandPathName(logDir);
415 }
416