]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/global/AliHLTGlobalHistoCollector.cxx
Updated macros for PHOS alignment calculation
[u/mrichter/AliRoot.git] / HLT / global / AliHLTGlobalHistoCollector.cxx
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
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
34 using namespace std;
35
36 ClassImp(AliHLTGlobalHistoCollector) //ROOT macro for the implementation of ROOT specific class methods
37
38   AliHLTGlobalHistoCollector::AliHLTGlobalHistoCollector()
39     :    
40     fUID(0),
41     fStore(),
42     fBenchmark("GlobalHistoCollector")
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
51 AliHLTGlobalHistoCollector::~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
61 const char* AliHLTGlobalHistoCollector::GetComponentID() 
62
63   // see header file for class documentation
64   return "GlobalHistoCollector";
65 }
66
67 void AliHLTGlobalHistoCollector::GetInputDataTypes( vector<AliHLTComponentDataType>& list) 
68
69   // see header file for class documentation
70
71   list.clear(); 
72   list.push_back( kAliHLTAllDataTypes );
73 }
74
75 AliHLTComponentDataType AliHLTGlobalHistoCollector::GetOutputDataType() 
76
77   // see header file for class documentation
78   return kAliHLTAllDataTypes;
79 }
80
81
82 void AliHLTGlobalHistoCollector::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) 
83
84   // see header file for class documentation
85   constBase=0;
86   inputMultiplier=1.0;
87 }
88
89 AliHLTComponent* AliHLTGlobalHistoCollector::Spawn() 
90
91   // see header file for class documentation
92   return new AliHLTGlobalHistoCollector();
93 }
94         
95 int AliHLTGlobalHistoCollector::DoInit( int argc, const char** argv ) 
96
97   // see header file for class documentation
98
99   Clear(); 
100   fBenchmark.Reset();
101   fBenchmark.SetTimer(0,"total");
102   fBenchmark.SetTimer(1,"merging");
103
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
125 int AliHLTGlobalHistoCollector::DoDeinit() 
126
127   // see header file for class documentation 
128     
129   Clear();
130   fUID = 0;
131   return 0;
132 }
133
134 int 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
175 int AliHLTGlobalHistoCollector::Reconfigure(const char* /*cdbEntry*/, const char* /*chainId*/) { 
176   // see header file for class documentation
177   
178   return 0; // no CDB entry exist
179   /*
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>");
190     AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path);
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;
204 */
205 }
206
207
208 void AliHLTGlobalHistoCollector::Clear() 
209
210   // reset the store
211
212   for( unsigned int i=0; i<fStore.size(); i++ ){
213     for( unsigned int j=0; j<fStore[i].fInstances.size(); j++ ){
214       delete fStore[i].fInstances[j].fObject;
215     }
216     delete fStore[i].fMergedObject;
217   }
218   fStore.clear();
219 }
220
221
222
223
224 int AliHLTGlobalHistoCollector::DoEvent(const AliHLTComponentEventData & evtData, AliHLTComponentTriggerData& /*trigData*/)
225 {
226   // see header file for class documentation
227   //cout<<"\n\nDoEvent called"<<endl;
228
229   if(GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR )) return 0;
230
231   fBenchmark.StartNewEvent();
232   fBenchmark.Start(0);
233
234   if( fUID == 0 ){
235     TTimeStamp t;
236     fUID = ( gSystem->GetPid() + t.GetNanoSec())*10 + evtData.fEventID;
237   }
238
239   for( const AliHLTComponentBlockData *i= GetFirstInputBlock(); i!=NULL; i=GetNextInputBlock() ){
240     fBenchmark.AddInput(i->fSize);
241   }
242
243   const TObject *iter = NULL;
244   for(iter = GetFirstInputObject(); iter != NULL; iter = GetNextInputObject()){
245             
246     if( !iter->InheritsFrom(TH1::Class()) 
247         && !iter->InheritsFrom(TSeqCollection::Class()) ) continue;
248
249     //cout<<"received object "<<iter->GetName()<<" with id="<<GetSpecification(iter)<<endl;
250
251     //search for the base entry, if not exist then create a new entry   
252
253     int iColl = -1;
254     for( unsigned int i=0; i<fStore.size(); i++ ){
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;
261         break;
262       }
263     }
264     //cout<<"Collection found: "<<iColl<<endl;
265     if( iColl<0 ){
266       AliHLTGlobalHCCollection c;
267       c.fHLTDataType = GetDataType(iter);
268       c.fMergedObject = 0;
269       c.fNeedToMerge = 1;
270       fStore.push_back(c);
271       iColl = fStore.size()-1;
272     }else{
273       fStore[iColl].fNeedToMerge = 1;
274     }
275
276     // search for the specific entry, if not exist then create a new one
277     
278     AliHLTGlobalHCCollection &c = fStore[iColl];
279    
280     int iSpec=-1;
281     for( unsigned int i=0; i<c.fInstances.size(); i++ ){
282       AliHLTGlobalHCInstance &inst = c.fInstances[i];
283       if( inst.fHLTSpecification == GetSpecification(iter) ){
284         iSpec = i;
285         break;
286       }
287     }
288     //cout<<"Instance found:"<<iSpec<<endl;
289     if( iSpec<0 ){
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;
297     }
298
299     c.fInstances[iSpec].fObject = iter->Clone();
300     
301     //cout<<"index = "<<iColl<<","<<iSpec<<endl;
302
303   } // end for loop over input blocks
304
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;
314     delete c.fMergedObject;
315     c.fMergedObject = c.fInstances[0].fObject->Clone();
316     TList l;
317     for( unsigned int i=1; i<c.fInstances.size(); i++ ){
318       l.Add(c.fInstances[i].fObject);
319     }
320
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 
334
335   for( unsigned int i=0; i<fStore.size(); i++ ){
336     if( fStore[i].fMergedObject ){
337       PushBack((TObject*) fStore[i].fMergedObject, fStore[i].fHLTDataType, fUID );
338       fBenchmark.AddOutput(GetLastObjectSize());
339     }
340   }
341
342   fBenchmark.Stop(0);
343   HLTInfo(fBenchmark.GetStatistics());
344
345   return 0;
346 }
347