]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/global/AliHLTGlobalEsdToFlatConverterComponent.cxx
changes in benchmarks and Read macro
[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 #include "AliSysInfo.h"
39
40 using namespace std;
41
42 /** ROOT macro for the implementation of ROOT specific class methods */
43 ClassImp(AliHLTGlobalEsdToFlatConverterComponent)
44
45 /*
46  * ---------------------------------------------------------------------------------
47  *                            Constructor / Destructor
48  * ---------------------------------------------------------------------------------
49  */
50
51 // #################################################################################
52 AliHLTGlobalEsdToFlatConverterComponent::AliHLTGlobalEsdToFlatConverterComponent() :
53   AliHLTProcessor()
54   {
55   // an example component which implements the ALICE HLT processor
56   // interface and does some analysis on the input raw data
57   //
58   // see header file for class documentation
59   // or
60   // refer to README to build package
61   // or
62   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
63   //
64   // NOTE: all helper classes should be instantiated in DoInit()
65 }
66
67 // #################################################################################
68 AliHLTGlobalEsdToFlatConverterComponent::~AliHLTGlobalEsdToFlatConverterComponent() {
69   // see header file for class documentation
70 }
71
72 /*
73  * ---------------------------------------------------------------------------------
74  * Public functions to implement AliHLTComponent's interface.
75  * These functions are required for the registration process
76  * ---------------------------------------------------------------------------------
77  */
78
79 // #################################################################################
80 const Char_t* AliHLTGlobalEsdToFlatConverterComponent::GetComponentID() { 
81   // see header file for class documentation
82   return "GlobalEsdToFlatConverter";
83 }
84
85 // #################################################################################
86 void AliHLTGlobalEsdToFlatConverterComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list) {
87   // see header file for class documentation
88         list.push_back(kAliHLTDataTypeESDTree|kAliHLTDataOriginOut );
89   list.push_back( kAliHLTDataTypeESDObject|kAliHLTDataOriginOut );
90   list.push_back( kAliHLTDataTypeESDfriendObject|kAliHLTDataOriginOut );
91 }
92
93 // #################################################################################
94 AliHLTComponentDataType AliHLTGlobalEsdToFlatConverterComponent::GetOutputDataType() {
95   // see header file for class documentation
96   return kAliHLTDataTypeFlatESD|kAliHLTDataOriginOut;
97 }
98
99 // #################################################################################
100 void AliHLTGlobalEsdToFlatConverterComponent::GetOutputDataSize( ULong_t& constBase, Double_t& inputMultiplier ) {
101   // see header file for class documentation
102   constBase = 10000;
103   inputMultiplier = 10.0;
104 }
105
106
107 // #################################################################################
108 AliHLTComponent* AliHLTGlobalEsdToFlatConverterComponent::Spawn() {
109   // see header file for class documentation
110   return new AliHLTGlobalEsdToFlatConverterComponent;
111 }
112
113 /*
114  * ---------------------------------------------------------------------------------
115  * Protected functions to implement AliHLTComponent's interface.
116  * These functions provide initialization as well as the actual processing
117  * capabilities of the component. 
118  * ---------------------------------------------------------------------------------
119  */
120
121 // #################################################################################
122 Int_t AliHLTGlobalEsdToFlatConverterComponent::DoInit( Int_t argc, const Char_t** argv ) {
123   // see header file for class documentation
124   printf("AliHLTGlobalEsdToFlatConverterComponent::DoInit\n");
125   // see header file for class documentation
126   int iResult=0;
127   TString argument="";
128   int bMissingParam=0;
129
130   // default list of skiped ESD objects
131   TString skipObjects=
132     // "AliESDRun,"
133     // "AliESDHeader,"
134     // "AliESDZDC,"
135     "AliESDFMD,"
136     // "AliESDVZERO,"
137     // "AliESDTZERO,"
138     // "TPCVertex,"
139     // "SPDVertex,"
140     // "PrimaryVertex,"
141     // "AliMultiplicity,"
142     // "PHOSTrigger,"
143     // "EMCALTrigger,"
144     // "SPDPileupVertices,"
145     // "TrkPileupVertices,"
146     "Cascades,"
147     "Kinks,"
148     "AliRawDataErrorLogs,"
149     "AliESDACORDE";
150
151   iResult=Reconfigure(NULL, NULL);
152   TString allArgs = "";
153   for ( int i = 0; i < argc; i++ ) {
154     if ( !allArgs.IsNull() ) allArgs += " ";
155     allArgs += argv[i];
156   }
157
158   TObjArray* pTokens=allArgs.Tokenize(" ");
159   if (pTokens) {
160     for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
161       argument=((TObjString*)pTokens->At(i))->String(); 
162       if (argument.IsNull()) continue;
163  if (argument.Contains("-skipobject=")) {
164         argument.ReplaceAll("-skipobject=", "");
165         skipObjects=argument;
166       } else {
167         HLTError("unknown argument %s", argument.Data());
168         iResult=-EINVAL;
169         break;
170       }
171     }
172   }
173   if (bMissingParam) {
174     HLTError("missing parameter for argument %s", argument.Data());
175     iResult=-EINVAL;
176   }
177
178
179   if (iResult>=0) {
180     SetupCTPData();
181   }
182
183   return iResult;
184 }
185
186
187
188 // #################################################################################
189 Int_t AliHLTGlobalEsdToFlatConverterComponent::DoDeinit() {
190   // see header file for class documentation
191
192         
193   return 0;
194 }
195
196 // #################################################################################
197 Int_t AliHLTGlobalEsdToFlatConverterComponent::DoEvent(const AliHLTComponentEventData& /*evtData*/,
198                                                     const AliHLTComponentBlockData* /*blocks*/, 
199                                                     AliHLTComponentTriggerData& /*trigData*/,
200                                                     AliHLTUInt8_t* outputPtr, 
201                                                     AliHLTUInt32_t& size,
202                                                     AliHLTComponentBlockDataList& outputBlocks) {
203   // see header file for class documentation
204
205         
206         
207         
208   AliSysInfo::AddStamp("AliHLTGlobalEsdToFlatConverterComponent::DoEvent.Start");
209   Int_t iResult=0;
210
211         
212         
213   size_t maxOutputSize = size;
214   size = 0;
215         
216   // -- Only use data event
217   if (!IsDataEvent()) 
218     return 0;
219   
220    AliESDEvent *esd;
221         
222         
223   for ( const TObject *iter = GetFirstInputObject(kAliHLTDataTypeESDObject | kAliHLTDataOriginOut); iter != NULL; iter = GetNextInputObject() ) {
224     esd =dynamic_cast<AliESDEvent*>(const_cast<TObject*>(iter));
225     if( esd ){
226       esd->GetStdContent();
227                         iResult=1;
228     } else {
229     }
230   }
231
232    for ( const TObject *iter = GetFirstInputObject(kAliHLTDataTypeESDfriendObject | kAliHLTDataOriginOut); iter != NULL; iter = GetNextInputObject() ) {     
233      //fBenchmark.AddInput(pBlock->fSize);
234     const AliESDfriend *esdFriend = dynamic_cast<const AliESDfriend*>(iter);
235     if( esdFriend ){
236     } else {
237     }
238   }
239            
240  
241  AliFlatESDEvent *flatEsd ;
242
243     flatEsd = reinterpret_cast<AliFlatESDEvent*>(outputPtr);
244     new (flatEsd) AliFlatESDEvent;
245   flatEsd->SetFromESD(AliFlatESDEvent::EstimateSize(esd),esd, kTRUE); 
246                  
247         
248         if( maxOutputSize > flatEsd->GetSize() ){
249         
250     AliHLTComponentBlockData outBlock;
251     FillBlockData( outBlock );
252     outBlock.fOffset = size;
253     outBlock.fSize = flatEsd->GetSize();
254     outBlock.fDataType = kAliHLTDataTypeFlatESD|kAliHLTDataOriginOut;
255     outBlock.fSpecification = AliHLTTPCDefinitions::EncodeDataSpecification( 0, 35, 0, 5 );
256
257     outputBlocks.push_back( outBlock );
258
259     size += outBlock.fSize;
260                 
261         }
262         
263         else {
264                 
265         return 0;       
266         }
267  
268  
269         
270   AliSysInfo::AddStamp("AliHLTGlobalEsdToFlatConverterComponent::DoEvent.Stop",0, flatEsd->GetSize(),flatEsd->GetNumberOfV0s(),flatEsd->GetNumberOfTracks());
271  
272  
273   return iResult;
274 }
275
276
277 // #################################################################################
278 Int_t AliHLTGlobalEsdToFlatConverterComponent::ReadPreprocessorValues(const Char_t* /*modules*/) {
279   // see header file for class documentation
280   ALIHLTERRORGUARD(5, "ReadPreProcessorValues not implemented for this component");
281   return 0;
282 }
283
284
285 int AliHLTGlobalEsdToFlatConverterComponent::Configure(const char* arguments)
286 {
287   // see header file for class documentation
288   int iResult=0;
289   if (!arguments) return iResult;
290
291   TString allArgs=arguments;
292   TString argument;
293   int bMissingParam=0;
294
295   TObjArray* pTokens=allArgs.Tokenize(" ");
296   if (pTokens) {
297     for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
298       argument=((TObjString*)pTokens->At(i))->String(); 
299       if (argument.IsNull()) continue;      
300       HLTError("unknown argument %s", argument.Data());
301       iResult=-EINVAL;
302       break;
303     }  
304     delete pTokens;
305   }
306   if (bMissingParam) {
307     HLTError("missing parameter for argument %s", argument.Data());
308     iResult=-EINVAL;
309   }
310
311   return iResult;
312 }
313
314 int AliHLTGlobalEsdToFlatConverterComponent::Reconfigure(const char* cdbEntry, const char* chainId)
315 {
316   // see header file for class documentation
317   int iResult=0;
318   const char* path=NULL;
319   const char* defaultNotify="";
320   if (cdbEntry) {
321     path=cdbEntry;
322     defaultNotify=" (default)";
323   }
324   if (path) {
325     HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
326     AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
327     if (pEntry) {
328       TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
329       if (pString) {
330         HLTInfo("received configuration object string: \'%s\'", pString->String().Data());
331         iResult=Configure(pString->String().Data());
332       } else {
333         HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
334       }
335     } else {
336       HLTError("can not fetch object \"%s\" from CDB", path);
337     }
338   }
339   
340   return iResult;
341 }