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