]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/PHOS/AliHLTPHOSDigitMakerComponent.cxx
Fixing memory leaks (Christian)
[u/mrichter/AliRoot.git] / HLT / PHOS / AliHLTPHOSDigitMakerComponent.cxx
1 /**************************************************************************
2  * This file is property of and copyright by the ALICE HLT Project        *
3  * All rights reserved.                                                   *
4  *                                                                        *
5  * Primary Authors: Oystein Djuvsland                                     *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 #include "AliHLTPHOSDigitMakerComponent.h"
17 #include "AliHLTPHOSDigitMaker.h"
18 #include "TTree.h"
19 #include "AliHLTPHOSProcessor.h"
20 #include "AliHLTPHOSRcuCellEnergyDataStruct.h"
21 #include "AliHLTPHOSDigitContainerDataStruct.h"
22 #include "TClonesArray.h"
23 #include "TFile.h"
24 #include <sys/stat.h>
25 #include <sys/types.h>
26
27
28 /** 
29  * @file   AliHLTPHOSDigitMakerComponent.cxx
30  * @author Oystein Djuvsland
31  * @date   
32  * @brief  A digit maker component for PHOS HLT
33 */
34
35 // see below for class documentation
36 // or
37 // refer to README to build package
38 // or
39 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
40
41
42 const AliHLTComponentDataType AliHLTPHOSDigitMakerComponent::fgkInputDataTypes[]={kAliHLTVoidDataType,{0,"",""}};
43
44 AliHLTPHOSDigitMakerComponent gAliHLTPHOSDigitMakerComponent;
45
46 AliHLTPHOSDigitMakerComponent::AliHLTPHOSDigitMakerComponent() :
47   AliHLTPHOSProcessor(),
48   fDigitMakerPtr(0)
49   //  fEvtCnt(0)
50 {
51   //see header file for documentation
52 }
53
54 AliHLTPHOSDigitMakerComponent::~AliHLTPHOSDigitMakerComponent()
55 {
56   //see header file for documentation
57 }
58
59 int 
60 AliHLTPHOSDigitMakerComponent::Deinit()
61
62   //see header file for documentation
63   if(fDigitMakerPtr)
64     {
65       delete fDigitMakerPtr;
66       fDigitMakerPtr = 0;
67     }
68   return 0;
69 }
70
71 const char*
72 AliHLTPHOSDigitMakerComponent::GetComponentID()
73 {
74   //see header file for documentation
75   return "PhosDigitMaker";
76 }
77
78
79 void
80 AliHLTPHOSDigitMakerComponent::GetInputDataTypes(vector<AliHLTComponentDataType>& list)
81
82   //see header file for documentation
83   const AliHLTComponentDataType* pType=fgkInputDataTypes;
84   while (pType->fID!=0) {
85     list.push_back(*pType); 
86     pType++;
87   }
88 }
89
90 AliHLTComponentDataType 
91 AliHLTPHOSDigitMakerComponent::GetOutputDataType()
92 {
93   //see header file for documentation
94   return AliHLTPHOSDefinitions::fgkAliHLTDigitDataType;
95 }
96
97
98 void 
99 AliHLTPHOSDigitMakerComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier)
100 {
101   //see header file for documentation
102   constBase = 30;
103   inputMultiplier = 1;
104 }
105
106 int 
107 AliHLTPHOSDigitMakerComponent::DoEvent(const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
108                                         AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr, AliHLTUInt32_t& size,
109                                         std::vector<AliHLTComponentBlockData>& outputBlocks)
110 {
111   //see header file for documentation
112   UInt_t tSize            = 0;
113   UInt_t offset           = 0; 
114   UInt_t mysize           = 0;
115   Int_t digitCount = 0;
116
117   AliHLTUInt8_t* outBPtr;
118   outBPtr = outputPtr;
119   const AliHLTComponentBlockData* iter = 0; 
120   unsigned long ndx; 
121   fDigitContainerPtr = (AliHLTPHOSDigitContainerDataStruct*)outBPtr;
122   //fDigitMakerPtr->SetDigitContainerStruct(fDigitContainerPtr);
123   fDigitMakerPtr->SetDigitContainerStruct((AliHLTPHOSDigitContainerDataStruct*)outBPtr);
124
125   for( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
126     {
127       iter = blocks+ndx;
128       
129       if(iter->fDataType != AliHLTPHOSDefinitions::fgkCellEnergyDataType)
130         {
131           //      cout << "Warning: data type is not fgkCellEnergyDataType " << endl;
132           continue;
133
134         }
135       digitCount = fDigitMakerPtr->MakeDigits(reinterpret_cast<AliHLTPHOSRcuCellEnergyDataStruct*>(iter->fPtr));
136     }
137
138   fPhosEventCount++;
139   
140   mysize = 0;
141   offset = tSize;
142       
143   mysize += sizeof(AliHLTPHOSDigitContainerDataStruct);
144   ((AliHLTPHOSDigitContainerDataStruct*)outBPtr)->fNDigits = digitCount;
145   AliHLTComponentBlockData bd;
146   FillBlockData( bd );
147   bd.fOffset = offset;
148   bd.fSize = mysize;
149   bd.fDataType = AliHLTPHOSDefinitions::fgkAliHLTDigitDataType;
150   bd.fSpecification = 0xFFFFFFFF;
151   outputBlocks.push_back( bd );
152        
153   tSize += mysize;
154   outBPtr += mysize;
155       
156   if( tSize > size )
157     {
158       Logging( kHLTLogFatal, "HLT::AliHLTPHOSDigitMakerComponent::DoEvent", "Too much data",
159                "Data written over allowed buffer. Amount written: %lu, allowed amount: %lu."
160                , tSize, size );
161       return EMSGSIZE;
162     }
163       
164   fDigitMakerPtr->Reset();
165   
166   
167
168
169   if(fPhosEventCount % 10 == 0)
170     {
171       cout << "Event #: " << fPhosEventCount << endl;
172       cout << "  - Number of digits found: " << digitCount << endl;
173     }
174   
175   return 0;
176 }
177
178
179 int
180 AliHLTPHOSDigitMakerComponent::DoInit(int argc, const char** argv )
181 {
182   //see header file for documentation
183
184   fDigitMakerPtr = new AliHLTPHOSDigitMaker();
185   
186   for(int i = 0; i < argc; i++)
187     {
188       if(!strcmp("-threshold", argv[i]))
189         fDigitMakerPtr->SetDigitThreshold(atoi(argv[i+1]));
190       if(!strcmp("-presamples", argv[i]))
191         fDigitMakerPtr->SetNrPresamples(atoi(argv[i+1]));
192     }
193  
194   //fDigitMakerPtr->SetDigitThreshold(2);
195
196   return 0;
197 }
198
199 AliHLTComponent*
200 AliHLTPHOSDigitMakerComponent::Spawn()
201 {
202   //see header file for documentation
203   return new AliHLTPHOSDigitMakerComponent();
204 }