]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TRD/AliHLTTRDHistoMergerComponent.cxx
correcting small memory leak, removing unnecessary pointer checks (Theo)
[u/mrichter/AliRoot.git] / HLT / TRD / AliHLTTRDHistoMergerComponent.cxx
1 // $Id$
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:                                                       *
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   AliHLTTRDHistoMergerComponent.cxx
19     @author Theodor Rascanu
20     @brief  Component for adding histos of partition wise working histo components
21 */
22
23 #if __GNUC__>= 3
24 using namespace std;
25 #endif
26
27 #include "TFile.h"
28 #include "TString.h"
29 #include "TObjString.h"
30 #include "TObjArray.h"
31 #include "TH1F.h"
32
33 #include "AliHLTTRDHistoMergerComponent.h"
34 #include "AliHLTTRDDefinitions.h"
35 #include "AliHLTTRDUtils.h"
36
37 #define stringCompare(a,b) !(strcmp(a,b))
38
39 //#include "AliHLTTRD.h"
40 //#include <stdlib.h>
41 //#include <cerrno>
42
43 /** ROOT macro for the implementation of ROOT specific class methods */
44 ClassImp(AliHLTTRDHistoMergerComponent)
45
46 AliHLTTRDHistoMergerComponent::AliHLTTRDHistoMergerComponent()
47 : AliHLTProcessor(),
48   fOutputSize(500000)
49 {
50   // see header file for class documentation
51   // or
52   // refer to README to build package
53   // or
54   // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
55
56   for(int i=0; i<9; i++)
57     fHistoArr[i]=NULL;
58
59   for(int i=0; i<18; i++)
60     fIncSM[i]=kFALSE;
61
62 }
63
64 AliHLTTRDHistoMergerComponent::~AliHLTTRDHistoMergerComponent()
65 {
66   // see header file for class documentation
67 }
68
69 // Public functions to implement AliHLTComponent's interface.
70 // These functions are required for the registration process
71
72 const char* AliHLTTRDHistoMergerComponent::GetComponentID()
73 {
74   // see header file for class documentation
75   
76   return "TRDHistoMerger";
77 }
78
79 void AliHLTTRDHistoMergerComponent::GetInputDataTypes(AliHLTComponentDataTypeList& list)
80 {
81   // see header file for class documentation
82   list.clear();
83   list.push_back(kAliHLTDataTypeHistogram | kAliHLTDataOriginTRD);
84 }
85
86 AliHLTComponentDataType AliHLTTRDHistoMergerComponent::GetOutputDataType()
87 {
88   // see header file for class documentation
89   return kAliHLTDataTypeHistogram | kAliHLTDataOriginTRD;
90
91 }
92
93 void AliHLTTRDHistoMergerComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
94 {
95   // see header file for class documentation
96   constBase = fOutputSize;
97   inputMultiplier = 0;
98 }
99
100 AliHLTComponent* AliHLTTRDHistoMergerComponent::Spawn()
101 {
102   // see header file for class documentation
103   return new AliHLTTRDHistoMergerComponent;
104 }
105
106 int AliHLTTRDHistoMergerComponent::DoInit(int argc, const char** argv)
107 {
108
109   int iResult=0;
110   
111   TString configuration="";
112   TString argument="";
113   for (int i=0; i<argc && iResult>=0; i++) {
114     argument=argv[i];
115     if (!configuration.IsNull()) configuration+=" ";
116     configuration+=argument;
117   }
118
119   if (!configuration.IsNull()) {
120     iResult=Configure(configuration.Data());
121   }
122
123   for(int i=0; i<9; i++)
124     fHistoArr[i]=NULL;
125
126   for(int i=0; i<18; i++)
127     fIncSM[i]=kFALSE;
128  
129   return 0;
130 }
131   
132 int AliHLTTRDHistoMergerComponent::DoDeinit()
133 {
134   // see header file for class documentation
135
136   return 0;
137 }
138
139 int AliHLTTRDHistoMergerComponent::DoEvent(const AliHLTComponentEventData& /*evtData*/,
140                                             AliHLTComponentTriggerData& /*trigData*/)
141 {
142   if(!IsDataEvent())return 0;
143
144   int histNr = 0;
145   int lastSM = -1;
146
147   for(const TObject* iter = GetFirstInputObject(kAliHLTDataTypeHistogram | kAliHLTDataOriginTRD);
148         iter != NULL; iter = GetNextInputObject() ) {
149
150     if(!dynamic_cast<const TH1*>(iter))
151       continue;
152
153     AliHLTUInt32_t spec = GetSpecification(iter);
154     int SM = AliHLTTRDUtils::GetSM(spec);
155
156     if(SM!=lastSM){
157       if(fIncSM[SM]){
158         for(int i = 0; fHistoArr[i]; i++){
159           PushBack((TObject*)fHistoArr[i], kAliHLTDataTypeHistogram | kAliHLTDataOriginTRD, 0);
160           delete fHistoArr[i];
161           fHistoArr[i] = NULL;
162         }
163         for(int i=0; i<18; i++)
164           fIncSM[i]=kFALSE;
165       }
166       lastSM = SM;
167       histNr = 0;
168       fIncSM[SM]=kTRUE;
169     }
170
171     if(histNr>9){
172       HLTError("Got more histogramms than expected.");
173       return 0;
174     }
175
176     if(!fHistoArr[histNr]) fHistoArr[histNr] = (TH1*)iter->Clone();
177     else if(stringCompare(fHistoArr[histNr]->GetName(),iter->GetName()))
178       fHistoArr[histNr]->Add((TH1*)iter);
179
180     histNr++;
181   }
182
183   return 0;
184 }
185
186 int AliHLTTRDHistoMergerComponent::Configure(const char* arguments){
187   int iResult=0;
188   if (!arguments) return iResult;
189   
190   TString allArgs=arguments;
191   TString argument;
192   int bMissingParam=0;
193
194   TObjArray* pTokens=allArgs.Tokenize(" ");
195   if (pTokens) {
196     for (int i=0; i<pTokens->GetEntries() && iResult>=0; i++) {
197       argument=((TObjString*)pTokens->At(i))->GetString();
198       if (argument.IsNull()) continue;
199       
200       if (argument.CompareTo("output_size")==0) {
201         if ((bMissingParam=(++i>=pTokens->GetEntries()))) break;
202         HLTInfo("Setting output size to: %s", ((TObjString*)pTokens->At(i))->GetString().Data());
203         fOutputSize=((TObjString*)pTokens->At(i))->GetString().Atoi();
204         continue;
205       } 
206       else {
207         HLTError("unknown argument: %s", argument.Data());
208         iResult=-EINVAL;
209         break;
210       }
211     }
212     delete pTokens;
213   }
214   if (bMissingParam) {
215     HLTError("missing parameter for argument %s", argument.Data());
216     iResult=-EINVAL;
217   }
218   return iResult;
219 }