make AliVVevent abstract (=0)
[u/mrichter/AliRoot.git] / HLT / global / AliHLTGlobalHistoCollector.cxx
CommitLineData
e419c1ae 1
2//**************************************************************************
3//* This file is property of and copyright by the ALICE HLT Project *
4//* ALICE Experiment at CERN, All rights reserved. *
5//* *
6//* Primary Authors: Kalliopi Kanaki <Kalliopi.Kanaki@ift.uib.no> *
7//* for The ALICE HLT Project. *
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 AliHLTGlobalHistoCollector.cxx
19 @author Kalliopi Kanaki
20 @date
21 @brief The Histogram Handler component
22*/
23
e419c1ae 24#include "AliHLTGlobalHistoCollector.h"
25#include "AliCDBEntry.h"
26#include "AliCDBManager.h"
27#include "TString.h"
28#include "TObjArray.h"
29#include "TObjString.h"
30#include "TH1.h"
31#include "TTimeStamp.h"
32#include "TSystem.h"
33
a7f38894 34using namespace std;
35
e419c1ae 36ClassImp(AliHLTGlobalHistoCollector) //ROOT macro for the implementation of ROOT specific class methods
37
38 AliHLTGlobalHistoCollector::AliHLTGlobalHistoCollector()
39 :
40 fUID(0),
776446ad 41 fStore(),
42 fBenchmark("GlobalHistoCollector")
e419c1ae 43{
44 // see header file for class documentation
45 // or
46 // refer to README to build package
47 // or
48 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
49}
50
51AliHLTGlobalHistoCollector::~AliHLTGlobalHistoCollector() {
52 // see header file for class documentation
53 Clear();
54}
55
56
57
58// Public functions to implement AliHLTComponent's interface.
59// These functions are required for the registration process
60
61const char* AliHLTGlobalHistoCollector::GetComponentID()
62{
63 // see header file for class documentation
64 return "GlobalHistoCollector";
65}
66
67void AliHLTGlobalHistoCollector::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
68{
69 // see header file for class documentation
70
71 list.clear();
776446ad 72 list.push_back( kAliHLTAllDataTypes );
e419c1ae 73}
74
75AliHLTComponentDataType AliHLTGlobalHistoCollector::GetOutputDataType()
76{
77 // see header file for class documentation
776446ad 78 return kAliHLTAllDataTypes;
e419c1ae 79}
80
81
82void AliHLTGlobalHistoCollector::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
83{
84 // see header file for class documentation
85 constBase=0;
86 inputMultiplier=1.0;
87}
88
89AliHLTComponent* AliHLTGlobalHistoCollector::Spawn()
90{
91 // see header file for class documentation
92 return new AliHLTGlobalHistoCollector();
93}
94
95int AliHLTGlobalHistoCollector::DoInit( int argc, const char** argv )
96{
97 // see header file for class documentation
98
99 Clear();
776446ad 100 fBenchmark.Reset();
101 fBenchmark.SetTimer(0,"total");
102 fBenchmark.SetTimer(1,"merging");
103
e419c1ae 104 int iResult=0;
105
106 TString configuration="";
107 TString argument="";
108 for (int j=0; j<argc && iResult>=0; j++) {
109
110 argument=argv[j];
111 if (!configuration.IsNull()) configuration+=" ";
112 configuration+=argument;
113 }
114
115 if (!configuration.IsNull()) {
116 iResult=Configure(configuration.Data());
117 } else {
118 iResult=Reconfigure(NULL, NULL);
119 }
120 fUID = 0;
121 return iResult;
122}
123
124
125int AliHLTGlobalHistoCollector::DoDeinit()
126{
127 // see header file for class documentation
128
129 Clear();
130 fUID = 0;
131 return 0;
132}
133
134int AliHLTGlobalHistoCollector::Configure(const char* arguments)
135{
136 // see header file for class documentation
137
138 int iResult=0;
139 if (!arguments) return iResult;
140 HLTInfo("parsing configuration string \'%s\'", arguments);
141
142 TString allArgs=arguments;
143 TString argument;
144 int bMissingParam=0;
145
146 TObjArray* pTokens=allArgs.Tokenize(" ");
147 if (pTokens) {
148 for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
149 argument=((TObjString*)pTokens->At(i))->GetString();
150 if (argument.IsNull()) continue;
151
152 //if (argument.CompareTo("-sum-noise-histograms")==0) {
153 //fNoiseHistograms = kTRUE;
154 //HLTInfo("got \'-sum-noise-histograms\': %s", ((TObjString*)pTokens->At(i))->GetString().Data());
155 //else
156 {
157 HLTError("unknown argument %s", argument.Data());
158 iResult=-EINVAL;
159 break;
160 }
161 } // end for
162
163 delete pTokens;
164
165 } // end if pTokens
166
167 if (bMissingParam) {
168 HLTError("missing parameter for argument %s", argument.Data());
169 iResult=-EINVAL;
170 }
171 return iResult;
172}
173
174
412559b1 175int AliHLTGlobalHistoCollector::Reconfigure(const char* /*cdbEntry*/, const char* /*chainId*/) {
e419c1ae 176 // see header file for class documentation
177
178 return 0; // no CDB entry exist
09a5aeb5 179 /*
e419c1ae 180 int iResult=0;
181 const char* path="HLT/ConfigGlobal/GlobalHistoCollector";
182 const char* defaultNotify="";
183 if (cdbEntry) {
184 path=cdbEntry;
185 defaultNotify=" (default)";
186 }
187
188 if (path) {
189 HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
412559b1 190 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path);
e419c1ae 191 if (pEntry) {
192 TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
193 if (pString) {
194 HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
195 iResult=Configure(pString->GetString().Data());
196 } else {
197 HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
198 }
199 } else {
200 HLTError("cannot fetch object \"%s\" from CDB", path);
201 }
202 }
203 return iResult;
09a5aeb5 204*/
e419c1ae 205}
206
207
208void AliHLTGlobalHistoCollector::Clear()
209{
210 // reset the store
211
212 for( unsigned int i=0; i<fStore.size(); i++ ){
dcb913a8 213 for( unsigned int j=0; j<fStore[i].fInstances.size(); j++ ){
214 delete fStore[i].fInstances[j].fObject;
e419c1ae 215 }
dcb913a8 216 delete fStore[i].fMergedObject;
e419c1ae 217 }
218 fStore.clear();
219}
220
221
222
223
224int AliHLTGlobalHistoCollector::DoEvent(const AliHLTComponentEventData & evtData, AliHLTComponentTriggerData& /*trigData*/)
225{
226 // see header file for class documentation
776446ad 227 //cout<<"\n\nDoEvent called"<<endl;
e419c1ae 228
229 if(GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR )) return 0;
230
776446ad 231 fBenchmark.StartNewEvent();
232 fBenchmark.Start(0);
233
e419c1ae 234 if( fUID == 0 ){
235 TTimeStamp t;
236 fUID = ( gSystem->GetPid() + t.GetNanoSec())*10 + evtData.fEventID;
237 }
238
776446ad 239 for( const AliHLTComponentBlockData *i= GetFirstInputBlock(); i!=NULL; i=GetNextInputBlock() ){
240 fBenchmark.AddInput(i->fSize);
241 }
242
dcb913a8 243 const TObject *iter = NULL;
244 for(iter = GetFirstInputObject(); iter != NULL; iter = GetNextInputObject()){
09a5aeb5 245
776446ad 246 if( !iter->InheritsFrom(TH1::Class())
247 && !iter->InheritsFrom(TSeqCollection::Class()) ) continue;
dcb913a8 248
776446ad 249 //cout<<"received object "<<iter->GetName()<<" with id="<<GetSpecification(iter)<<endl;
dcb913a8 250
251 //search for the base entry, if not exist then create a new entry
e419c1ae 252
776446ad 253 int iColl = -1;
e419c1ae 254 for( unsigned int i=0; i<fStore.size(); i++ ){
776446ad 255 if( fStore[i].fHLTDataType != GetDataType(iter) ) continue;
256 if( fStore[i].fInstances.size()<1 ) continue;
257 TObject * obj = fStore[i].fInstances[0].fObject;
258 if( !obj ) continue;
259 if( TString(obj->GetName()).CompareTo(iter->GetName())==0){
260 iColl = i;
e419c1ae 261 break;
262 }
263 }
776446ad 264 //cout<<"Collection found: "<<iColl<<endl;
265 if( iColl<0 ){
dcb913a8 266 AliHLTGlobalHCCollection c;
267 c.fHLTDataType = GetDataType(iter);
776446ad 268 c.fMergedObject = 0;
269 c.fNeedToMerge = 1;
dcb913a8 270 fStore.push_back(c);
776446ad 271 iColl = fStore.size()-1;
272 }else{
273 fStore[iColl].fNeedToMerge = 1;
e419c1ae 274 }
275
276 // search for the specific entry, if not exist then create a new one
dcb913a8 277
776446ad 278 AliHLTGlobalHCCollection &c = fStore[iColl];
279
e419c1ae 280 int iSpec=-1;
dcb913a8 281 for( unsigned int i=0; i<c.fInstances.size(); i++ ){
282 AliHLTGlobalHCInstance &inst = c.fInstances[i];
283 if( inst.fHLTSpecification == GetSpecification(iter) ){
e419c1ae 284 iSpec = i;
285 break;
286 }
287 }
776446ad 288 //cout<<"Instance found:"<<iSpec<<endl;
e419c1ae 289 if( iSpec<0 ){
dcb913a8 290 AliHLTGlobalHCInstance inst;
291 inst.fHLTSpecification = GetSpecification(iter);
292 inst.fObject = 0;
293 c.fInstances.push_back(inst);
294 iSpec = c.fInstances.size()-1;
295 }else{
296 delete c.fInstances[iSpec].fObject;
e419c1ae 297 }
dcb913a8 298
dcb913a8 299 c.fInstances[iSpec].fObject = iter->Clone();
300
776446ad 301 //cout<<"index = "<<iColl<<","<<iSpec<<endl;
302
303 } // end for loop over input blocks
e419c1ae 304
776446ad 305 fBenchmark.Start(1);
306
307
308 // merge histos
309
310 for( unsigned int iColl = 0; iColl<fStore.size(); iColl++){
311 AliHLTGlobalHCCollection &c = fStore[iColl];
312 if( !c.fNeedToMerge && c.fMergedObject ) continue;
313 if( c.fInstances.size() <1 ) continue;
dcb913a8 314 delete c.fMergedObject;
315 c.fMergedObject = c.fInstances[0].fObject->Clone();
776446ad 316 TList l;
dcb913a8 317 for( unsigned int i=1; i<c.fInstances.size(); i++ ){
776446ad 318 l.Add(c.fInstances[i].fObject);
e419c1ae 319 }
e419c1ae 320
776446ad 321 if( c.fMergedObject->InheritsFrom(TH1::Class()) ){
322 TH1 *histo = dynamic_cast<TH1*>(c.fMergedObject);
323 if( histo ) histo->Merge(&l);
324 }
325 else if( c.fMergedObject->InheritsFrom(TSeqCollection::Class()) ){
326 TSeqCollection *list = dynamic_cast<TSeqCollection*>(c.fMergedObject);
327 if( list ) list->Merge(&l);
328 }
329 c.fNeedToMerge = 0;
330 }
331 fBenchmark.Stop(1);
332
333 // send output
e419c1ae 334
335 for( unsigned int i=0; i<fStore.size(); i++ ){
776446ad 336 if( fStore[i].fMergedObject ){
337 PushBack((TObject*) fStore[i].fMergedObject, fStore[i].fHLTDataType, fUID );
338 fBenchmark.AddOutput(GetLastObjectSize());
339 }
e419c1ae 340 }
776446ad 341
342 fBenchmark.Stop(0);
343 HLTInfo(fBenchmark.GetStatistics());
344
e419c1ae 345 return 0;
346}
347