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