]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/SampleLib/AliHLTSampleMonitoringComponent.cxx
activating automatic emulation of TPC compressed clusters
[u/mrichter/AliRoot.git] / HLT / SampleLib / AliHLTSampleMonitoringComponent.cxx
1 // $Id$
2
3 /**************************************************************************
4  * This file is property of and copyright by the ALICE HLT Project        * 
5  * ALICE Experiment at CERN, All rights reserved.                         *
6  *                                                                        *
7  * Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no>        *
8  *                  for The ALICE HLT Project.                            *
9  *                                                                        *
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  **************************************************************************/
18
19 /** @file   AliHLTSampleMonitoringComponent.cxx
20     @author Matthias Richter
21     @date   
22     @brief  A sample monitoring component for the HLT.
23 */
24
25 #include "AliHLTSampleMonitoringComponent.h"
26 #include "TH1F.h"
27 #include "TTree.h"
28 #include "TString.h"
29 #include "TObjString.h"
30 #include "TObjArray.h"
31 #include "AliCDBEntry.h"
32 #include "AliCDBManager.h"
33
34 /** ROOT macro for the implementation of ROOT specific class methods */
35 ClassImp(AliHLTSampleMonitoringComponent)
36
37 AliHLTSampleMonitoringComponent::AliHLTSampleMonitoringComponent()
38   :
39   fPushHistograms(false),
40   fPushTTree(false),
41   fPushTObjArray(false),
42   fHpx(NULL),
43   fHpy(NULL)
44 {
45   // see header file for class documentation
46   // or
47   // refer to README to build package
48   // or
49   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
50 }
51
52 AliHLTSampleMonitoringComponent::~AliHLTSampleMonitoringComponent()
53 {
54   // see header file for class documentation
55 }
56
57 const char* AliHLTSampleMonitoringComponent::GetComponentID()
58 {
59   // see header file for class documentation
60   return "Sample-MonitoringComponent";
61 }
62
63 void AliHLTSampleMonitoringComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
64 {
65   // see header file for class documentation
66   list.push_back(kAliHLTAnyDataType);
67 }
68
69 AliHLTComponentDataType AliHLTSampleMonitoringComponent::GetOutputDataType()
70 {
71   // see header file for class documentation
72   return kAliHLTVoidDataType;
73 }
74
75 void AliHLTSampleMonitoringComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
76 {
77   // see header file for class documentation
78   constBase = 100000;
79   inputMultiplier = 0;
80 }
81
82 AliHLTComponent* AliHLTSampleMonitoringComponent::Spawn()
83 {
84   // see header file for class documentation
85   return new AliHLTSampleMonitoringComponent;
86 }
87
88 int AliHLTSampleMonitoringComponent::DoInit( int argc, const char** argv )
89 {
90   // see header file for class documentation
91   int iResult=0;
92
93   TString argument="";
94   TString configuration=""; 
95   int bMissingParam=0;
96
97   for (int i=0; i<argc && iResult>=0; i++) {
98     argument=argv[i];
99     if (argument.IsNull()) continue;
100
101     // -push-histograms
102     if (argument.CompareTo("-push-histograms")==0) {
103       fPushHistograms=true;
104
105     // -push-ttree
106     } else if (argument.CompareTo("-push-ttree")==0) {
107       fPushTTree=true;
108
109     // -push-array
110     } else if (argument.CompareTo("-push-array")==0) {
111       fPushTObjArray=true;
112
113     } else {
114       // the remaining arguments are treated as configuration
115       if (!configuration.IsNull()) configuration+=" ";
116       configuration+=argument;
117     }
118   }
119   if (bMissingParam) {
120     HLTError("missing parameter for argument %s", argument.Data());
121     iResult=-EINVAL;
122   }
123
124   // choose fPushTTree as default if none is set
125   if (!(fPushTTree || fPushTObjArray || fPushHistograms)) fPushTTree=true;
126
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);
132
133   return iResult;
134 }
135
136 int AliHLTSampleMonitoringComponent::DoDeinit()
137 {
138   // see header file for class documentation
139   if (fHpx) delete fHpx;
140   fHpx=NULL;
141   if (fHpy) delete fHpy;
142   fHpy=NULL;
143   return 0;
144 }
145
146 int AliHLTSampleMonitoringComponent::DoEvent( const AliHLTComponentEventData& /*evtData*/, AliHLTComponentTriggerData& /*trigData*/)
147 {
148   // see header file for class documentation
149
150   // the function ignores all input blocks and fakes some monitoring histogram
151   int iResult=0;
152
153   fHpx->Reset();
154   fHpx->FillRandom("gaus",100*(GetEventCount()+1));
155
156   fHpy->Reset();
157   fHpy->FillRandom("gaus",500*(GetEventCount()+1));
158
159   if (fPushHistograms) {
160     PushBack(fHpx, "ROOTTH1F", "EXPL", 0);
161     PushBack(fHpy, "ROOTTH1F", "EXPL", 1);
162   }
163
164   if (fPushTTree) {
165     TString event;
166     TTree *pTree = new TTree("T","A Root Tree");
167     if (pTree) {
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);
173
174       PushBack(pTree, "ROOTTREE", "EXPL");
175       delete pTree;
176     } else {
177       iResult=-ENOMEM;
178     }
179   }
180
181   if (fPushTObjArray) {
182     TObjArray* pArray=new TObjArray;
183     if (pArray) {
184       pArray->Add(fHpx);
185       pArray->Add(fHpy);
186       
187       PushBack(pArray, "ROOTOBJA", "EXPL");
188       delete pArray;
189     }
190   }
191
192   return iResult;
193 }
194
195 int AliHLTSampleMonitoringComponent::Configure(const char* arguments)
196 {
197   // see header file for class documentation
198   int iResult=0;
199   if (!arguments) return iResult;
200
201   TString allArgs=arguments;
202   TString argument;
203   int bMissingParam=0;
204
205   TObjArray* pTokens=allArgs.Tokenize(" ");
206   if (pTokens) {
207     for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
208       argument=((TObjString*)pTokens->At(i))->GetString();
209       if (argument.IsNull()) continue;
210
211       // -reset
212       if (argument.CompareTo("-reset")==0) {
213
214       } else {
215         HLTError("unknown argument %s", argument.Data());
216         iResult=-EINVAL;
217         break;
218       }
219     }
220     delete pTokens;
221   }
222   if (bMissingParam) {
223     HLTError("missing parameter for argument %s", argument.Data());
224     iResult=-EINVAL;
225   }
226   return iResult;
227 }
228
229 int AliHLTSampleMonitoringComponent::Reconfigure(const char* cdbEntry, const char* /*chainId*/)
230 {
231   // see header file for class documentation
232   int iResult=0;
233   const char* path=NULL;
234 #ifdef __DEBUG
235   const char* defaultNotify="";
236 #endif
237   if (cdbEntry) {
238     path=cdbEntry;
239 #ifdef __DEBUG
240     defaultNotify=" (default)";
241 #endif
242   }
243   if (path) {
244     AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
245     if (pEntry) {
246       TObjString* pString=dynamic_cast<TObjString*>(pEntry->GetObject());
247       if (pString) {
248         iResult=Configure(pString->GetString().Data());
249       } else {
250         HLTError("configuration object \"%s\" has wrong type, required TObjString", path);
251       }
252     } else {
253       HLTError("can not fetch object \"%s\" from CDB", path);
254     }
255   }
256   return iResult;
257 }