]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/PHOS/AliHLTPHOSDigitMakerComponent.cxx
- PHOS clusterizer component now inherits from CALO clusterizer component
[u/mrichter/AliRoot.git] / HLT / PHOS / AliHLTPHOSDigitMakerComponent.cxx
1  // $Id$
2
3  /**************************************************************************
4  * This file is property of and copyright by the ALICE HLT Project        *
5  * All rights reserved.                                                   *
6  *                                                                        *
7  * Primary Authors: Oystein Djuvsland                                     *
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 #include "AliHLTPHOSDigitMakerComponent.h"
19 #include "AliHLTCaloDigitMaker.h"
20 #include "AliHLTCaloDigitDataStruct.h"
21 #include "AliHLTPHOSMapper.h"
22 #include "AliHLTPHOSChannelDataHeaderStruct.h"
23 #include "AliHLTPHOSChannelDataStruct.h"
24 #include "TFile.h"
25 #include <sys/stat.h>
26 #include <sys/types.h>
27
28
29 /** 
30  * @file   AliHLTCaloDigitMakerComponent.cxx
31  * @author Oystein Djuvsland
32  * @date   
33  * @brief  A digit maker component for PHOS HLT
34 */
35
36 // see below for class documentation
37 // or
38 // refer to README to build package
39 // or
40 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
41
42
43 AliHLTPHOSDigitMakerComponent gAliHLTPHOSDigitMakerComponent;
44
45 AliHLTPHOSDigitMakerComponent::AliHLTPHOSDigitMakerComponent() :
46   AliHLTPHOSProcessor(),
47   fDigitMakerPtr(0),
48   fDigitContainerPtr(0)
49 {
50   //see header file for documentation
51 }
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   list.clear();
84   list.push_back(AliHLTPHOSDefinitions::fgkChannelDataType);
85 }
86
87 AliHLTComponentDataType 
88 AliHLTPHOSDigitMakerComponent::GetOutputDataType()
89 {
90   //see header file for documentation
91   return AliHLTPHOSDefinitions::fgkDigitDataType;
92 }
93
94
95 void 
96 AliHLTPHOSDigitMakerComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier)
97 {
98   //see header file for documentation
99   constBase = 0;
100   inputMultiplier = (float)sizeof(AliHLTCaloDigitDataStruct)/sizeof(AliHLTPHOSChannelDataStruct) + 1;
101 }
102
103 int 
104 AliHLTPHOSDigitMakerComponent::DoEvent(const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
105                                         AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr, AliHLTUInt32_t& size,
106                                         std::vector<AliHLTComponentBlockData>& outputBlocks)
107 {
108   //see header file for documentation
109   UInt_t offset           = 0; 
110   UInt_t mysize           = 0;
111   Int_t digitCount        = 0;
112   Int_t ret               = 0;
113
114   AliHLTUInt8_t* outBPtr;
115   outBPtr = outputPtr;
116   const AliHLTComponentBlockData* iter = 0; 
117   unsigned long ndx; 
118
119   UInt_t specification = 0;
120   AliHLTCaloChannelDataHeaderStruct* tmpChannelData = 0;
121   
122   //  fDigitMakerPtr->SetDigitHeaderPtr(reinterpret_cast<AliHLTCaloDigitHeaderStruct*>(outputPtr));
123
124   fDigitMakerPtr->SetDigitDataPtr(reinterpret_cast<AliHLTCaloDigitDataStruct*>(outputPtr));
125
126   for( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
127     {
128       iter = blocks+ndx;
129       
130       if(iter->fDataType != AliHLTPHOSDefinitions::fgkChannelDataType)
131         {
132           HLTDebug("Data block is not of type fgkChannelDataType");
133           continue;
134         }
135
136       specification |= iter->fSpecification;
137       tmpChannelData = reinterpret_cast<AliHLTCaloChannelDataHeaderStruct*>(iter->fPtr);
138     
139       ret = fDigitMakerPtr->MakeDigits(tmpChannelData, size-(digitCount*sizeof(AliHLTCaloDigitDataStruct)));
140       if(ret == -1) 
141         {
142           HLTError("Trying to write over buffer size");
143           return -ENOBUFS;
144         }
145       digitCount += ret; 
146     }
147   
148   mysize += digitCount*sizeof(AliHLTCaloDigitDataStruct);
149
150   HLTDebug("# of digits: %d, used memory size: %d, available size: %d", digitCount, mysize, size);
151
152   if(mysize > 0) 
153     {
154       AliHLTComponentBlockData bd;
155       FillBlockData( bd );
156       bd.fOffset = offset;
157       bd.fSize = mysize;
158       bd.fDataType = AliHLTPHOSDefinitions::fgkDigitDataType;
159       bd.fSpecification = specification;
160       outputBlocks.push_back(bd);
161     }
162
163   fDigitMakerPtr->Reset();
164
165   size = mysize; 
166
167   return 0;
168 }
169
170
171 int
172 AliHLTPHOSDigitMakerComponent::DoInit(int argc, const char** argv )
173 {
174   //see header file for documentation
175
176   fDigitMakerPtr = new AliHLTCaloDigitMaker("PHOS");
177
178   AliHLTCaloMapper *mapper = new AliHLTPHOSMapper();
179   fDigitMakerPtr->SetMapper(mapper);
180   
181   for(int i = 0; i < argc; i++)
182     {
183       if(!strcmp("-lowgainfactor", argv[i]))
184         {
185           fDigitMakerPtr->SetGlobalLowGainFactor(atof(argv[i+1]));
186         }
187       if(!strcmp("-highgainfactor", argv[i]))
188         {
189           fDigitMakerPtr->SetGlobalHighGainFactor(atof(argv[i+1]));
190         }
191     }
192  
193   //fDigitMakerPtr->SetDigitThreshold(2);
194
195   return 0;
196 }
197
198 AliHLTComponent*
199 AliHLTPHOSDigitMakerComponent::Spawn()
200 {
201   //see header file for documentation
202   return new AliHLTPHOSDigitMakerComponent();
203 }