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
27 #include "AliHLTGlobalHistoCollector.h"
28 #include "AliCDBEntry.h"
29 #include "AliCDBManager.h"
31 #include "TObjArray.h"
32 #include "TObjString.h"
34 #include "TTimeStamp.h"
37 ClassImp(AliHLTGlobalHistoCollector) //ROOT macro for the implementation of ROOT specific class methods
39 AliHLTGlobalHistoCollector::AliHLTGlobalHistoCollector()
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( kAliHLTDataTypeHistogram );
75 AliHLTComponentDataType AliHLTGlobalHistoCollector::GetOutputDataType()
77 // see header file for class documentation
78 return kAliHLTDataTypeHistogram;
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
103 TString configuration="";
105 for (int j=0; j<argc && iResult>=0; j++) {
108 if (!configuration.IsNull()) configuration+=" ";
109 configuration+=argument;
112 if (!configuration.IsNull()) {
113 iResult=Configure(configuration.Data());
115 iResult=Reconfigure(NULL, NULL);
122 int AliHLTGlobalHistoCollector::DoDeinit()
124 // see header file for class documentation
131 int AliHLTGlobalHistoCollector::Configure(const char* arguments)
133 // see header file for class documentation
136 if (!arguments) return iResult;
137 HLTInfo("parsing configuration string \'%s\'", arguments);
139 TString allArgs=arguments;
143 TObjArray* pTokens=allArgs.Tokenize(" ");
145 for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
146 argument=((TObjString*)pTokens->At(i))->GetString();
147 if (argument.IsNull()) continue;
149 //if (argument.CompareTo("-sum-noise-histograms")==0) {
150 //fNoiseHistograms = kTRUE;
151 //HLTInfo("got \'-sum-noise-histograms\': %s", ((TObjString*)pTokens->At(i))->GetString().Data());
154 HLTError("unknown argument %s", argument.Data());
165 HLTError("missing parameter for argument %s", argument.Data());
172 int AliHLTGlobalHistoCollector::Reconfigure(const char* cdbEntry, const char* chainId) {
173 // see header file for class documentation
175 return 0; // no CDB entry exist
178 const char* path="HLT/ConfigGlobal/GlobalHistoCollector";
179 const char* defaultNotify="";
182 defaultNotify=" (default)";
186 HLTInfo("reconfigure from entry %s%s, chain id %s", path, defaultNotify,(chainId!=NULL && chainId[0]!=0)?chainId:"<none>");
187 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
189 TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
191 HLTInfo("received configuration object string: \'%s\'", pString->GetString().Data());
192 iResult=Configure(pString->GetString().Data());
194 HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
197 HLTError("cannot fetch object \"%s\" from CDB", path);
204 void AliHLTGlobalHistoCollector::Clear()
208 for( unsigned int i=0; i<fStore.size(); i++ ){
209 for( unsigned int j=0; j<fStore[i].fHistos.size(); j++ ){
210 delete fStore[i].fHistos[j].fHisto;
212 delete fStore[i].fMergedHisto;
220 int AliHLTGlobalHistoCollector::DoEvent(const AliHLTComponentEventData & evtData, AliHLTComponentTriggerData& /*trigData*/)
222 // see header file for class documentation
224 if(GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR )) return 0;
228 fUID = ( gSystem->GetPid() + t.GetNanoSec())*10 + evtData.fEventID;
232 const TObject *iter = NULL;
233 for(iter = GetFirstInputObject(kAliHLTDataTypeHistogram); iter != NULL; iter = GetNextInputObject()){
235 if( !( GetDataType(iter) == kAliHLTDataTypeHistogram )) continue;
237 const TH1 *h = dynamic_cast<TH1*>(const_cast<TObject*>( iter ) );
239 //cout<<"received histo "<<h->GetName()<<" with id="<<GetSpecification(iter)<<endl;
240 // search for the base entry, if not exist then create a new entry
243 for( unsigned int i=0; i<fStore.size(); i++ ){
244 if( fStore[i].fDataType == GetDataType(iter) &&
245 TString(fStore[i].fMergedHisto->GetName()).CompareTo(h->GetName())==0){
252 AliHLTHistoBaseData b;
253 b.fDataType = GetDataType(iter);
254 b.fMergedHisto = (TH1*) iter->Clone();
256 iBase = fStore.size()-1;
259 // search for the specific entry, if not exist then create a new one
261 AliHLTHistoBaseData &b = fStore[iBase];
264 for( unsigned int i=0; i<fStore[iBase].fHistos.size(); i++ ){
265 AliHLTHistoData &d = b.fHistos[i];
266 if( d.fSpecification == GetSpecification(iter) ){
274 d.fSpecification = GetSpecification(iter);
275 d.fHisto = (TH1*) iter->Clone();
276 b.fHistos.push_back(d);
277 iSpec = b.fHistos.size()-1;
279 b.fHistos[iSpec].fHisto->Reset();
280 b.fHistos[iSpec].fHisto->Add( (TH1*)iter, 1);
281 //cout<<"index = "<<iBase<<","<<iSpec<<", nentr="<<b.fHistos[iSpec].fHisto->GetEntries()<<endl;
284 b.fMergedHisto->Reset();
286 for( unsigned int i=0; i<b.fHistos.size(); i++ ){
287 b.fMergedHisto->Add(b.fHistos[i].fHisto,1);
289 //cout<<" merged="<<b.fMergedHisto->GetEntries()<<endl;
291 } // end for loop over histogram blocks
293 for( unsigned int i=0; i<fStore.size(); i++ ){
294 PushBack((TObject*) fStore[i].fMergedHisto, fStore[i].fDataType, fUID );