3 /**************************************************************************
4 * This file is property of and copyright by the ALICE HLT Project *
5 * ALICE Experiment at CERN, All rights reserved. *
7 * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8 * for The ALICE HLT Project. *
10 * Permission to use, copy, modify and distribute this software and its *
11 * documentation strictly for non-commercial purposes is hereby granted *
12 * without fee, provided that the above copyright notice appears in all *
13 * copies and that both the copyright notice and this permission notice *
14 * appear in the supporting documentation. The authors make no claims *
15 * about the suitability of this software for any purpose. It is *
16 * provided "as is" without express or implied warranty. *
17 **************************************************************************/
19 /** @file AliHLTSampleMonitoringComponent.cxx
20 @author Matthias Richter
22 @brief A sample monitoring component for the HLT.
25 #include "AliHLTSampleMonitoringComponent.h"
29 #include "TObjString.h"
30 #include "TObjArray.h"
31 #include "AliCDBEntry.h"
32 #include "AliCDBManager.h"
34 /** ROOT macro for the implementation of ROOT specific class methods */
35 ClassImp(AliHLTSampleMonitoringComponent)
37 AliHLTSampleMonitoringComponent::AliHLTSampleMonitoringComponent()
39 fPushHistograms(false),
41 fPushTObjArray(false),
45 // see header file for class documentation
47 // refer to README to build package
49 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
52 AliHLTSampleMonitoringComponent::~AliHLTSampleMonitoringComponent()
54 // see header file for class documentation
57 const char* AliHLTSampleMonitoringComponent::GetComponentID()
59 // see header file for class documentation
60 return "Sample-MonitoringComponent";
63 void AliHLTSampleMonitoringComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
65 // see header file for class documentation
66 list.push_back(kAliHLTAnyDataType);
69 AliHLTComponentDataType AliHLTSampleMonitoringComponent::GetOutputDataType()
71 // see header file for class documentation
72 return kAliHLTVoidDataType;
75 void AliHLTSampleMonitoringComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
77 // see header file for class documentation
82 AliHLTComponent* AliHLTSampleMonitoringComponent::Spawn()
84 // see header file for class documentation
85 return new AliHLTSampleMonitoringComponent;
88 int AliHLTSampleMonitoringComponent::DoInit( int argc, const char** argv )
90 // see header file for class documentation
94 TString configuration="";
97 for (int i=0; i<argc && iResult>=0; i++) {
99 if (argument.IsNull()) continue;
102 if (argument.CompareTo("-push-histograms")==0) {
103 fPushHistograms=true;
106 } else if (argument.CompareTo("-push-ttree")==0) {
110 } else if (argument.CompareTo("-push-array")==0) {
114 // the remaining arguments are treated as configuration
115 if (!configuration.IsNull()) configuration+=" ";
116 configuration+=argument;
120 HLTError("missing parameter for argument %s", argument.Data());
124 // choose fPushTTree as default if none is set
125 if (!(fPushTTree || fPushTObjArray || fPushHistograms)) fPushTTree=true;
127 // strictly speaking I would prefer to use local or dynamic variables
128 // locally in DoEvent, but there is a ROOT bug or feature (related to
129 // garbage collection) which causes seg faults after a while.
130 fHpx = new TH1F("hpx","px distribution",100,-4,4);
131 fHpy = new TH1F("hpy","py distribution",100,-10,10);
136 int AliHLTSampleMonitoringComponent::DoDeinit()
138 // see header file for class documentation
139 if (fHpx) delete fHpx;
141 if (fHpy) delete fHpy;
146 int AliHLTSampleMonitoringComponent::DoEvent( const AliHLTComponentEventData& /*evtData*/, AliHLTComponentTriggerData& /*trigData*/)
148 // see header file for class documentation
150 // the function ignores all input blocks and fakes some monitoring histogram
154 fHpx->FillRandom("gaus",100*(GetEventCount()+1));
157 fHpy->FillRandom("gaus",500*(GetEventCount()+1));
159 if (fPushHistograms) {
160 PushBack(fHpx, "ROOTTH1F", "EXPL", 0);
161 PushBack(fHpy, "ROOTTH1F", "EXPL", 1);
166 TTree *pTree = new TTree("T","A Root Tree");
168 pTree->SetDirectory(0);
169 event.Form("event_%d_hpx", GetEventCount());
170 pTree->Branch(event, "TH1F", &fHpx, 32000, 0);
171 event.Form("event_%d_hpy", GetEventCount());
172 pTree->Branch(event, "TH1F", &fHpy, 32000, 0);
174 PushBack(pTree, "ROOTTREE", "EXPL");
181 if (fPushTObjArray) {
182 TObjArray* pArray=new TObjArray;
187 PushBack(pArray, "ROOTOBJA", "EXPL");
195 int AliHLTSampleMonitoringComponent::Configure(const char* arguments)
197 // see header file for class documentation
199 if (!arguments) return iResult;
201 TString allArgs=arguments;
205 TObjArray* pTokens=allArgs.Tokenize(" ");
207 for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
208 argument=((TObjString*)pTokens->At(i))->GetString();
209 if (argument.IsNull()) continue;
212 if (argument.CompareTo("-reset")==0) {
215 HLTError("unknown argument %s", argument.Data());
223 HLTError("missing parameter for argument %s", argument.Data());
229 int AliHLTSampleMonitoringComponent::Reconfigure(const char* cdbEntry, const char* /*chainId*/)
231 // see header file for class documentation
233 const char* path=NULL;
235 const char* defaultNotify="";
240 defaultNotify=" (default)";
244 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
246 TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
248 iResult=Configure(pString->GetString().Data());
250 HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
253 HLTError("can not fetch object \"%s\" from CDB", path);