2 //**************************************************************************
3 //* This file is property of and copyright by the ALICE HLT Project *
4 //* ALICE Experiment at CERN, All rights reserved. *
6 //* Primary Authors: Kalliopi Kanaki <Kalliopi.Kanaki@ift.uib.no> *
7 //* for The ALICE HLT Project. *
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 //**************************************************************************
18 /** @file AliHLTGlobalHistoCollector.cxx
19 @author Kalliopi Kanaki
21 @brief The Histogram Handler component
24 #include "AliHLTGlobalHistoCollector.h"
25 #include "AliCDBEntry.h"
26 #include "AliCDBManager.h"
28 #include "TObjArray.h"
29 #include "TObjString.h"
31 #include "TTimeStamp.h"
36 ClassImp(AliHLTGlobalHistoCollector) //ROOT macro for the implementation of ROOT specific class methods
38 AliHLTGlobalHistoCollector::AliHLTGlobalHistoCollector()
42 fBenchmark("GlobalHistoCollector")
44 // see header file for class documentation
46 // refer to README to build package
48 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
51 AliHLTGlobalHistoCollector::~AliHLTGlobalHistoCollector() {
52 // see header file for class documentation
58 // Public functions to implement AliHLTComponent's interface.
59 // These functions are required for the registration process
61 const char* AliHLTGlobalHistoCollector::GetComponentID()
63 // see header file for class documentation
64 return "GlobalHistoCollector";
67 void AliHLTGlobalHistoCollector::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
69 // see header file for class documentation
72 list.push_back( kAliHLTAllDataTypes );
75 AliHLTComponentDataType AliHLTGlobalHistoCollector::GetOutputDataType()
77 // see header file for class documentation
78 return kAliHLTAllDataTypes;
82 void AliHLTGlobalHistoCollector::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
84 // see header file for class documentation
89 AliHLTComponent* AliHLTGlobalHistoCollector::Spawn()
91 // see header file for class documentation
92 return new AliHLTGlobalHistoCollector();
95 int AliHLTGlobalHistoCollector::DoInit( int argc, const char** argv )
97 // see header file for class documentation
101 fBenchmark.SetTimer(0,"total");
102 fBenchmark.SetTimer(1,"merging");
106 TString configuration="";
108 for (int j=0; j<argc && iResult>=0; j++) {
111 if (!configuration.IsNull()) configuration+=" ";
112 configuration+=argument;
115 if (!configuration.IsNull()) {
116 iResult=Configure(configuration.Data());
118 iResult=Reconfigure(NULL, NULL);
125 int AliHLTGlobalHistoCollector::DoDeinit()
127 // see header file for class documentation
134 int AliHLTGlobalHistoCollector::Configure(const char* arguments)
136 // see header file for class documentation
139 if (!arguments) return iResult;
140 HLTInfo("parsing configuration string \'%s\'", arguments);
142 TString allArgs=arguments;
146 TObjArray* pTokens=allArgs.Tokenize(" ");
148 for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
149 argument=((TObjString*)pTokens->At(i))->GetString();
150 if (argument.IsNull()) continue;
152 //if (argument.CompareTo("-sum-noise-histograms")==0) {
153 //fNoiseHistograms = kTRUE;
154 //HLTInfo("got \'-sum-noise-histograms\': %s", ((TObjString*)pTokens->At(i))->GetString().Data());
157 HLTError("unknown argument %s", argument.Data());
168 HLTError("missing parameter for argument %s", argument.Data());
175 int AliHLTGlobalHistoCollector::Reconfigure(const char* /*cdbEntry*/, const char* /*chainId*/) {
176 // see header file for class documentation
178 return 0; // no CDB entry exist
181 const char* path="HLT/ConfigGlobal/GlobalHistoCollector";
182 const char* defaultNotify="";
185 defaultNotify=" (default)";
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);
192 TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
194 HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
195 iResult=Configure(pString->GetString().Data());
197 HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
200 HLTError("cannot fetch object \"%s\" from CDB", path);
208 void AliHLTGlobalHistoCollector::Clear()
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;
216 delete fStore[i].fMergedObject;
224 int AliHLTGlobalHistoCollector::DoEvent(const AliHLTComponentEventData & evtData, AliHLTComponentTriggerData& /*trigData*/)
226 // see header file for class documentation
227 //cout<<"\n\nDoEvent called"<<endl;
229 if(GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR )) return 0;
231 fBenchmark.StartNewEvent();
236 fUID = ( gSystem->GetPid() + t.GetNanoSec())*10 + evtData.fEventID;
239 for( const AliHLTComponentBlockData *i= GetFirstInputBlock(); i!=NULL; i=GetNextInputBlock() ){
240 fBenchmark.AddInput(i->fSize);
243 const TObject *iter = NULL;
244 for(iter = GetFirstInputObject(); iter != NULL; iter = GetNextInputObject()){
246 if( !iter->InheritsFrom(TH1::Class())
247 && !iter->InheritsFrom(TSeqCollection::Class()) ) continue;
249 //cout<<"received object "<<iter->GetName()<<" with id="<<GetSpecification(iter)<<endl;
251 //search for the base entry, if not exist then create a new entry
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;
259 if( TString(obj->GetName()).CompareTo(iter->GetName())==0){
264 //cout<<"Collection found: "<<iColl<<endl;
266 AliHLTGlobalHCCollection c;
267 c.fHLTDataType = GetDataType(iter);
271 iColl = fStore.size()-1;
273 fStore[iColl].fNeedToMerge = 1;
276 // search for the specific entry, if not exist then create a new one
278 AliHLTGlobalHCCollection &c = fStore[iColl];
281 for( unsigned int i=0; i<c.fInstances.size(); i++ ){
282 AliHLTGlobalHCInstance &inst = c.fInstances[i];
283 if( inst.fHLTSpecification == GetSpecification(iter) ){
288 //cout<<"Instance found:"<<iSpec<<endl;
290 AliHLTGlobalHCInstance inst;
291 inst.fHLTSpecification = GetSpecification(iter);
293 c.fInstances.push_back(inst);
294 iSpec = c.fInstances.size()-1;
296 delete c.fInstances[iSpec].fObject;
299 c.fInstances[iSpec].fObject = iter->Clone();
301 //cout<<"index = "<<iColl<<","<<iSpec<<endl;
303 } // end for loop over input blocks
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();
317 for( unsigned int i=1; i<c.fInstances.size(); i++ ){
318 l.Add(c.fInstances[i].fObject);
321 if( c.fMergedObject->InheritsFrom(TH1::Class()) ){
322 TH1 *histo = dynamic_cast<TH1*>(c.fMergedObject);
323 if( histo ) histo->Merge(&l);
325 else if( c.fMergedObject->InheritsFrom(TSeqCollection::Class()) ){
326 TSeqCollection *list = dynamic_cast<TSeqCollection*>(c.fMergedObject);
327 if( list ) list->Merge(&l);
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());
343 HLTInfo(fBenchmark.GetStatistics());