]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/global/AliHLTGlobalEsdToFlatConverterComponent.cxx
Merge remote-tracking branch 'origin/flatdev' into mergeFlat2Master
[u/mrichter/AliRoot.git] / HLT / global / AliHLTGlobalEsdToFlatConverterComponent.cxx
1 //-*- Mode: C++ -*-
2 // $Id: AliHLTGlobalEsdToFlatConverterComponent.cxx $
3 /**************************************************************************
4  * This file is property of and copyright by the ALICE HLT Project        * 
5  * ALICE Experiment at CERN, All rights reserved.                         *
6  *                                                                        *
7  * Primary Authors: Steffen Weber                                         *
8  *                                                                        *
9  * Permission to use, copy, modify and distribute this software and its   *
10  * documentation strictly for non-commercial purposes is hereby granted   *
11  * without fee, provided that the above copyright notice appears in all   *
12  * copies and that both the copyright notice and this permission notice   *
13  * appear in the supporting documentation. The authors make no claims     *
14  * about the suitability of this software for any purpose. It is          *
15  * provided "as is" without express or implied warranty.                  *
16  **************************************************************************/
17
18 /** @file    AliHLTGlobalEsdToFlatConverterComponent.cxx
19     @author  Steffen Weber
20     @brief   Component to convert ESD objects to flatESD objects
21 */
22
23 #include "TMap.h"
24 #include "TSystem.h"
25 #include "TTimeStamp.h"
26 #include "TObjString.h"
27 #include "TList.h"
28 #include "AliESDEvent.h"
29 #include "AliFlatESDEvent.h"
30 #include "AliHLTErrorGuard.h"
31 #include "AliHLTDataTypes.h"
32 #include "AliHLTGlobalEsdToFlatConverterComponent.h"
33 #include "AliHLTITSClusterDataFormat.h"
34 #include "AliHLTTPCDefinitions.h"
35 #include "TTree.h"
36 #include "AliCDBEntry.h"
37 #include "AliCDBManager.h"
38
39 using namespace std;
40
41 /** ROOT macro for the implementation of ROOT specific class methods */
42 ClassImp(AliHLTGlobalEsdToFlatConverterComponent)
43
44 /*
45  * ---------------------------------------------------------------------------------
46  *                            Constructor / Destructor
47  * ---------------------------------------------------------------------------------
48  */
49
50 // #################################################################################
51 AliHLTGlobalEsdToFlatConverterComponent::AliHLTGlobalEsdToFlatConverterComponent() :
52   AliHLTProcessor()
53   {
54   // an example component which implements the ALICE HLT processor
55   // interface and does some analysis on the input raw data
56   //
57   // see header file for class documentation
58   // or
59   // refer to README to build package
60   // or
61   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
62   //
63   // NOTE: all helper classes should be instantiated in DoInit()
64 }
65
66 // #################################################################################
67 AliHLTGlobalEsdToFlatConverterComponent::~AliHLTGlobalEsdToFlatConverterComponent() {
68   // see header file for class documentation
69 }
70
71 /*
72  * ---------------------------------------------------------------------------------
73  * Public functions to implement AliHLTComponent's interface.
74  * These functions are required for the registration process
75  * ---------------------------------------------------------------------------------
76  */
77
78 // #################################################################################
79 const Char_t* AliHLTGlobalEsdToFlatConverterComponent::GetComponentID() { 
80   // see header file for class documentation
81   return "GlobalEsdToFlatConverter";
82 }
83
84 // #################################################################################
85 void AliHLTGlobalEsdToFlatConverterComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list) {
86   // see header file for class documentation
87         list.push_back(kAliHLTDataTypeESDTree|kAliHLTDataOriginOut );
88   list.push_back( kAliHLTDataTypeESDObject|kAliHLTDataOriginOut );
89   list.push_back( kAliHLTDataTypeESDfriendObject|kAliHLTDataOriginOut );
90 }
91
92 // #################################################################################
93 AliHLTComponentDataType AliHLTGlobalEsdToFlatConverterComponent::GetOutputDataType() {
94   // see header file for class documentation
95   return kAliHLTDataTypeFlatESD|kAliHLTDataOriginOut;
96 }
97
98 // #################################################################################
99 void AliHLTGlobalEsdToFlatConverterComponent::GetOutputDataSize( ULong_t& constBase, Double_t& inputMultiplier ) {
100   // see header file for class documentation
101   constBase = 100000;
102   inputMultiplier = 1.0;
103 }
104
105
106 // #################################################################################
107 AliHLTComponent* AliHLTGlobalEsdToFlatConverterComponent::Spawn() {
108   // see header file for class documentation
109   return new AliHLTGlobalEsdToFlatConverterComponent;
110 }
111
112 /*
113  * ---------------------------------------------------------------------------------
114  * Protected functions to implement AliHLTComponent's interface.
115  * These functions provide initialization as well as the actual processing
116  * capabilities of the component. 
117  * ---------------------------------------------------------------------------------
118  */
119
120 // #################################################################################
121 Int_t AliHLTGlobalEsdToFlatConverterComponent::DoInit( Int_t argc, const Char_t** argv ) {
122   // see header file for class documentation
123   printf("AliHLTGlobalEsdToFlatConverterComponent::DoInit\n");
124   // see header file for class documentation
125   int iResult=0;
126   TString argument="";
127   int bMissingParam=0;
128
129   // default list of skiped ESD objects
130   TString skipObjects=
131     // "AliESDRun,"
132     // "AliESDHeader,"
133     // "AliESDZDC,"
134     "AliESDFMD,"
135     // "AliESDVZERO,"
136     // "AliESDTZERO,"
137     // "TPCVertex,"
138     // "SPDVertex,"
139     // "PrimaryVertex,"
140     // "AliMultiplicity,"
141     // "PHOSTrigger,"
142     // "EMCALTrigger,"
143     // "SPDPileupVertices,"
144     // "TrkPileupVertices,"
145     "Cascades,"
146     "Kinks,"
147     "AliRawDataErrorLogs,"
148     "AliESDACORDE";
149
150   iResult=Reconfigure(NULL, NULL);
151   TString allArgs = "";
152   for ( int i = 0; i < argc; i++ ) {
153     if ( !allArgs.IsNull() ) allArgs += " ";
154     allArgs += argv[i];
155   }
156
157   TObjArray* pTokens=allArgs.Tokenize(" ");
158   if (pTokens) {
159     for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
160       argument=((TObjString*)pTokens->At(i))->String(); 
161       if (argument.IsNull()) continue;
162  if (argument.Contains("-skipobject=")) {
163         argument.ReplaceAll("-skipobject=", "");
164         skipObjects=argument;
165       } else {
166         HLTError("unknown argument %s", argument.Data());
167         iResult=-EINVAL;
168         break;
169       }
170     }
171   }
172   if (bMissingParam) {
173     HLTError("missing parameter for argument %s", argument.Data());
174     iResult=-EINVAL;
175   }
176
177
178   if (iResult>=0) {
179     SetupCTPData();
180   }
181
182   return iResult;
183 }
184
185
186
187 // #################################################################################
188 Int_t AliHLTGlobalEsdToFlatConverterComponent::DoDeinit() {
189   // see header file for class documentation
190
191         
192   return 0;
193 }
194
195 // #################################################################################
196 Int_t AliHLTGlobalEsdToFlatConverterComponent::DoEvent(const AliHLTComponentEventData& /*evtData*/,
197                                                     const AliHLTComponentBlockData* /*blocks*/, 
198                                                     AliHLTComponentTriggerData& /*trigData*/,
199                                                     AliHLTUInt8_t* /*outputPtr*/, 
200                                                     AliHLTUInt32_t& /*size*/,
201                                                     AliHLTComponentBlockDataList& outputBlocks) {
202   // see header file for class documentation
203
204   printf("AliHLTGlobalEsdToFlatConverterComponent::DoEvent\n");
205   Int_t iResult=0;
206
207   // -- Only use data event
208   if (!IsDataEvent()) 
209     return 0;
210   
211    AliESDEvent *esd;
212
213 #if 0
214   AliESDEvent *pEsd;
215   const TTree *tree;
216         
217         
218   for ( const TObject *iter = GetFirstInputObject(kAliHLTDataTypeESDTree | kAliHLTDataOriginOut); iter != NULL; iter = GetNextInputObject() ) {
219     cout<<"Found ESD tree in esd test component !!!"<<endl;
220                 
221     tree = dynamic_cast<const TTree*>(iter);
222                 if(tree)
223                         pEsd->ReadFromTree( const_cast< TTree*>(tree) );
224     if( pEsd ){
225       cout<<"N ESD tracks: "<<pEsd->GetNumberOfTracks()<<endl;
226                         iResult=1;
227     } else {
228       cout<<"ESD pointer is NULL "<<endl;
229     }
230                 
231                 
232                 
233   }
234         
235 #endif
236         
237         
238   for ( const TObject *iter = GetFirstInputObject(kAliHLTDataTypeESDObject | kAliHLTDataOriginOut); iter != NULL; iter = GetNextInputObject() ) {
239     cout<<"Found ESD in esd test component !!!"<<endl;
240     esd =dynamic_cast<AliESDEvent*>(const_cast<TObject*>(iter));
241     if( esd ){
242       esd->GetStdContent();
243       cout<<"N ESD tracks: "<<esd->GetNumberOfTracks()<<endl;
244                         iResult=1;
245     } else {
246       cout<<"ESD pointer is NULL "<<endl;
247     }
248   }
249
250    for ( const TObject *iter = GetFirstInputObject(kAliHLTDataTypeESDfriendObject | kAliHLTDataOriginOut); iter != NULL; iter = GetNextInputObject() ) {     
251      //fBenchmark.AddInput(pBlock->fSize);
252     cout<<"Found ESD friend in esd test component !!!"<<endl;
253     const AliESDfriend *esdFriend = dynamic_cast<const AliESDfriend*>(iter);
254     if( esdFriend ){
255       cout<<"N friend tracks: "<<esdFriend->GetNumberOfTracks()<<endl;
256     } else {
257       cout<<"ESD friend pointer is NULL "<<endl;
258     }
259   }
260   
261         /*
262         
263    if (iResult>=0) {            
264  
265                  
266   Bool_t useESDFriends = 0;
267  AliFlatESDEvent *flatEsd ;
268   Byte_t *mem = new Byte_t[AliFlatESDEvent::EstimateSize(const_cast<AliESDEvent*>(esd), useESDFriends)];
269
270     flatEsd = reinterpret_cast<AliFlatESDEvent*>(mem);
271     new (flatEsd) AliFlatESDEvent;
272 //  flatEsd->Fill(esd,useESDFriends);  
273                  
274                  
275                  
276                  
277                  
278                  
279     AliHLTComponentBlockData outBlock;
280     FillBlockData( outBlock );
281     outBlock.fOffset = size;
282     outBlock.fSize = flatEsd->GetSize();
283     outBlock.fDataType = kAliHLTDataTypeFlatESD|kAliHLTDataOriginOut;
284     outBlock.fSpecification = AliHLTTPCDefinitions::EncodeDataSpecification( 0, 35, 0, 5 );
285
286     outputBlocks.push_back( outBlock );
287       
288     size += outBlock.fSize;
289   }
290  */
291  
292  
293  
294   return iResult;
295 }
296
297
298 // #################################################################################
299 Int_t AliHLTGlobalEsdToFlatConverterComponent::ReadPreprocessorValues(const Char_t* /*modules*/) {
300   // see header file for class documentation
301   ALIHLTERRORGUARD(5, "ReadPreProcessorValues not implemented for this component");
302   return 0;
303 }
304
305
306 int AliHLTGlobalEsdToFlatConverterComponent::Configure(const char* arguments)
307 {
308   // see header file for class documentation
309   int iResult=0;
310   if (!arguments) return iResult;
311
312   TString allArgs=arguments;
313   TString argument;
314   int bMissingParam=0;
315
316   TObjArray* pTokens=allArgs.Tokenize(" ");
317   if (pTokens) {
318     for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
319       argument=((TObjString*)pTokens->At(i))->String(); 
320       if (argument.IsNull()) continue;      
321       HLTError("unknown argument %s", argument.Data());
322       iResult=-EINVAL;
323       break;
324     }  
325     delete pTokens;
326   }
327   if (bMissingParam) {
328     HLTError("missing parameter for argument %s", argument.Data());
329     iResult=-EINVAL;
330   }
331
332   return iResult;
333 }
334
335 int AliHLTGlobalEsdToFlatConverterComponent::Reconfigure(const char* cdbEntry, const char* chainId)
336 {
337   // see header file for class documentation
338   int iResult=0;
339   const char* path=NULL;
340   const char* defaultNotify="";
341   if (cdbEntry) {
342     path=cdbEntry;
343     defaultNotify=" (default)";
344   }
345   if (path) {
346     HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
347     AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
348     if (pEntry) {
349       TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
350       if (pString) {
351         HLTInfo("received configuration object string: \'%s\'", pString->String().Data());
352         iResult=Configure(pString->String().Data());
353       } else {
354         HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
355       }
356     } else {
357       HLTError("can not fetch object \"%s\" from CDB", path);
358     }
359   }
360   
361   return iResult;
362 }