]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/global/physics/AliHLTdNdPtAnalysisMergerComponent.cxx
adding PrimaryVertexFinder and V0Finder component to registration, to be consolidated...
[u/mrichter/AliRoot.git] / HLT / global / physics / AliHLTdNdPtAnalysisMergerComponent.cxx
1 //**************************************************************************
2 //* This file is property of and copyright by the ALICE HLT Project        * 
3 //* ALICE Experiment at CERN, All rights reserved.                         *
4 //*                                                                        *
5 //* Primary Authors: S.Gorbunov <sergey.gorbunov@kip.uni-heidelberg.de>    *
6 //*                  for The ALICE HLT Project.                            *
7 //*                                                                        *
8 //* Permission to use, copy, modify and distribute this software and its   *
9 //* documentation strictly for non-commercial purposes is hereby granted   *
10 //* without fee, provided that the above copyright notice appears in all   *
11 //* copies and that both the copyright notice and this permission notice   *
12 //* appear in the supporting documentation. The authors make no claims     *
13 //* about the suitability of this software for any purpose. It is          *
14 //* provided "as is" without express or implied warranty.                  *
15 //**************************************************************************
16
17 /** @file   AliHLTdNdPtAnalysisMergerComponent.cxx
18     @author Sergey Gorbunov
19     @brief  Component for ploting charge in clusters
20 */
21
22 #if __GNUC__>= 3
23 using namespace std;
24 #endif
25
26 #include "AliHLTdNdPtAnalysisMergerComponent.h"
27 #include "AlidNdPtAnalysisPbPb.h"
28
29 #include "AliCDBEntry.h"
30 #include "AliCDBManager.h"
31 #include <TFile.h>
32 #include <TString.h>
33 #include "TObjString.h"
34 #include "TObjArray.h"
35 #include "TH1F.h"
36 #include "TH2F.h"
37 #include "TSystem.h"
38 #include "AliESDEvent.h"
39 #include "AliESDtrack.h"
40 #include "AliESDv0.h"
41 #include "AliHLTMessage.h"
42 #include "TTimeStamp.h"
43
44 //#include "AliHLTTPC.h"
45 //#include <stdlib.h>
46 //#include <cerrno>
47
48
49 AliHLTdNdPtAnalysisMergerComponent::AliHLTdNdPtAnalysisMergerComponent() :
50   fUID(0),
51   fBenchmark("dNdPtMerger"),
52   fAnalysis(0)
53 {
54   // see header file for class documentation
55   // or
56   // refer to README to build package
57   // or
58   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
59
60 }
61
62 AliHLTdNdPtAnalysisMergerComponent::~AliHLTdNdPtAnalysisMergerComponent()
63 {
64   // see header file for class documentation
65
66   if( fAnalysis ) delete fAnalysis;
67 }
68
69 // Public functions to implement AliHLTComponent's interface.
70 // These functions are required for the registration process
71
72 const char* AliHLTdNdPtAnalysisMergerComponent::GetComponentID()
73 {
74   // see header file for class documentation
75   
76   return "dNdPtAnalysisMerger";
77 }
78
79 void AliHLTdNdPtAnalysisMergerComponent::GetInputDataTypes(AliHLTComponentDataTypeList& list)
80 {
81   // see header file for class documentation
82   list.clear();
83   list.push_back( kAliHLTDataTypedNdPt|kAliHLTDataOriginAny );
84 }
85
86 AliHLTComponentDataType AliHLTdNdPtAnalysisMergerComponent::GetOutputDataType()
87 {
88   // see header file for class documentation
89   return kAliHLTDataTypedNdPt  | kAliHLTDataOriginOut;
90 }
91
92 void AliHLTdNdPtAnalysisMergerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
93 {
94   // see header file for class documentation
95   // XXX TODO: Find more realistic values.
96   constBase = 80000;
97   inputMultiplier = 0;
98 }
99
100 AliHLTComponent* AliHLTdNdPtAnalysisMergerComponent::Spawn()
101 {
102   // see header file for class documentation
103   return new AliHLTdNdPtAnalysisMergerComponent;
104 }
105
106 void AliHLTdNdPtAnalysisMergerComponent::SetDefaultConfiguration()
107 {
108   // Set default configuration for the CA merger component
109   // Some parameters can be later overwritten from the OCDB
110
111   fBenchmark.Reset();
112   fBenchmark.SetTimer(0,"total");
113   fBenchmark.SetTimer(1,"reco");  
114 }
115
116
117
118 int AliHLTdNdPtAnalysisMergerComponent::ReadConfigurationString(  const char* arguments )
119 {
120   // Set configuration parameters for the CA merger component from the string
121
122   int iResult = 0;
123   if ( !arguments ) return iResult;
124
125   TString allArgs = arguments;
126   TString argument;
127   int bMissingParam = 0;
128
129   TObjArray* pTokens = allArgs.Tokenize( " " );
130
131   int nArgs =  pTokens ? pTokens->GetEntries() : 0;
132
133   for ( int i = 0; i < nArgs; i++ ) {
134     argument = ( ( TObjString* )pTokens->At( i ) )->GetString();
135     if ( argument.IsNull() ) continue;
136     HLTError( "Unknown option \"%s\"", argument.Data() );
137     iResult = -EINVAL;
138   }
139   delete pTokens;
140   
141   if ( bMissingParam ) {
142     HLTError( "Specifier missed for parameter \"%s\"", argument.Data() );
143     iResult = -EINVAL;
144   }
145
146   return iResult;
147 }
148
149 int AliHLTdNdPtAnalysisMergerComponent::ReadCDBEntry( const char* cdbEntry, const char* chainId )
150 {
151   // see header file for class documentation
152   
153   const char* defaultNotify = "";
154   
155   if ( !cdbEntry ) {
156     return 0;
157     cdbEntry = "HLT/ConfigAnalysis/dNdPtAnalysisMerger";
158     defaultNotify = " (default)";
159     chainId = 0;
160   }
161
162   HLTInfo( "configure from entry \"%s\"%s, chain id %s", cdbEntry, defaultNotify, ( chainId != NULL && chainId[0] != 0 ) ? chainId : "<none>" );
163   AliCDBEntry *pEntry = AliCDBManager::Instance()->Get( cdbEntry );//,GetRunNo());
164
165   if ( !pEntry ) {
166     HLTError( "cannot fetch object \"%s\" from CDB", cdbEntry );
167     return -EINVAL;
168   }
169
170   TObjString* pString = dynamic_cast<TObjString*>( pEntry->GetObject() );
171
172   if ( !pString ) {
173     HLTError( "configuration object \"%s\" has wrong type, required TObjString", cdbEntry );
174     return -EINVAL;
175   }
176
177   HLTInfo( "received configuration object string: \"%s\"", pString->GetString().Data() );
178
179   return  ReadConfigurationString( pString->GetString().Data() );
180 }
181
182 int AliHLTdNdPtAnalysisMergerComponent::Configure( const char* cdbEntry, const char* chainId, const char *commandLine )
183 {
184   // Configure the component
185   // There are few levels of configuration,
186   // parameters which are set on one step can be overwritten on the next step
187
188
189   //* read hard-coded values
190   
191   SetDefaultConfiguration();
192
193   //* read the default CDB entry
194
195   int iResult1 = ReadCDBEntry( NULL, chainId );
196
197   //* read the actual CDB entry if required
198
199   int iResult2 = ( cdbEntry ) ? ReadCDBEntry( cdbEntry, chainId ) : 0;
200
201   //* read extra parameters from input (if they are)
202
203   int iResult3 = 0;
204
205   if ( commandLine && commandLine[0] != '\0' ) {
206     HLTInfo( "received configuration string from HLT framework: \"%s\"", commandLine );
207     iResult3 = ReadConfigurationString( commandLine );
208   }
209
210   return iResult1 ? iResult1 : ( iResult2 ? iResult2 : iResult3 );
211 }
212
213 int AliHLTdNdPtAnalysisMergerComponent::Reconfigure( const char* cdbEntry, const char* chainId )
214 {
215   // Reconfigure the component from OCDB
216
217   return Configure( cdbEntry, chainId, NULL );
218 }
219
220
221 int AliHLTdNdPtAnalysisMergerComponent::DoInit( int argc, const char** argv ) 
222 {
223   // init
224
225   fUID = 0;
226   fBenchmark.Reset();
227   fBenchmark.SetTimer(0,"total");
228   fBenchmark.SetTimer(1,"reco");
229
230   TString arguments = "";
231   for ( int i = 0; i < argc; i++ ) {
232     if ( !arguments.IsNull() ) arguments += " ";
233     arguments += argv[i];
234   }
235
236   int iResult = Configure( NULL, NULL, arguments.Data()  );
237
238   return iResult; 
239 }
240   
241 int AliHLTdNdPtAnalysisMergerComponent::DoDeinit()
242 {
243   // see header file for class documentation
244   fUID = 0;
245   if( fAnalysis ) delete fAnalysis;
246   fAnalysis = 0;
247   return 0;
248 }
249
250
251 int AliHLTdNdPtAnalysisMergerComponent::DoEvent(const AliHLTComponentEventData& evtData, AliHLTComponentTriggerData& /*trigData*/)
252 {
253   if ( GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR ) ) {
254     return 0;
255   }
256
257   fBenchmark.StartNewEvent();
258   fBenchmark.Start(0);
259
260   if( fUID == 0 ){
261     TTimeStamp t;
262     fUID = ( gSystem->GetPid() + t.GetNanoSec())*10 + evtData.fEventID;
263   }
264
265   for( const AliHLTComponentBlockData *i= GetFirstInputBlock(); i!=NULL; i=GetNextInputBlock() ){
266     fBenchmark.AddInput(i->fSize);
267   }
268
269   TList *list = new TList();
270
271   for ( const TObject *iter = GetFirstInputObject(kAliHLTDataTypedNdPt); iter != NULL; iter = GetNextInputObject() ) {
272
273     AlidNdPtAnalysisPbPb *instance = dynamic_cast<AlidNdPtAnalysisPbPb*>(const_cast<TObject*>( iter ) );
274     if( !instance ){ 
275       HLTWarning("Wrong AlidNdPtAnalysisPbPb object received");
276       continue;
277     }
278     list->Add(instance); 
279   }
280
281   fBenchmark.Start(1);
282   if( !list->IsEmpty() ){
283     delete fAnalysis;
284     fAnalysis = new AlidNdPtAnalysisPbPb;
285     if( !fAnalysis ){
286       HLTError("Out of memory");
287       return -ENOMEM;
288     }
289     fAnalysis->Init();  
290     fAnalysis->Merge(list);
291   }
292   fBenchmark.Stop(1);
293
294   if( fAnalysis ) PushBack( (TObject*) fAnalysis, kAliHLTDataTypedNdPt,fUID);
295   delete list;
296
297   fBenchmark.Stop(0);
298   HLTInfo(fBenchmark.GetStatistics());
299   return 0;
300 }
301
302