]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/PHOS/AliHLTPHOSDigitMakerComponent.cxx
fix bug in calculation of signals and npads for clusters
[u/mrichter/AliRoot.git] / HLT / PHOS / AliHLTPHOSDigitMakerComponent.cxx
CommitLineData
87434909 1 // $Id$
1b41ab20 2
25b7f84c 3 /**************************************************************************
ab38011b 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 **************************************************************************/
209a4703 17
18#include "AliHLTPHOSDigitMakerComponent.h"
f137c3c5 19#include "AliHLTCaloDigitMaker.h"
20#include "AliHLTCaloDigitDataStruct.h"
21#include "AliHLTPHOSMapper.h"
a9705807 22#include "AliHLTCaloChannelDataHeaderStruct.h"
23#include "AliHLTCaloChannelDataStruct.h"
c1e4a18c 24#include "AliPHOSEmcBadChannelsMap.h"
25#include "AliPHOSEmcCalibData.h"
209a4703 26#include "TFile.h"
c1e4a18c 27#include "AliCDBEntry.h"
28#include "AliCDBPath.h"
29#include "AliCDBManager.h"
209a4703 30#include <sys/stat.h>
31#include <sys/types.h>
32
2374af72 33
34/**
ea54e1c8 35 * @file AliHLTPHOSDigitMakerComponent.cxx
2374af72 36 * @author Oystein Djuvsland
37 * @date
38 * @brief A digit maker component for PHOS HLT
39*/
40
41// see below for class documentation
42// or
43// refer to README to build package
44// or
45// visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
46
cc244597 47ClassImp(AliHLTPHOSDigitMakerComponent);
2374af72 48
209a4703 49AliHLTPHOSDigitMakerComponent gAliHLTPHOSDigitMakerComponent;
50
51AliHLTPHOSDigitMakerComponent::AliHLTPHOSDigitMakerComponent() :
bc304d87 52 AliHLTCaloProcessor(),
c1e4a18c 53 AliHLTCaloConstantsHandler("PHOS"),
25b7f84c 54 fDigitMakerPtr(0),
c1e4a18c 55 fDigitContainerPtr(0),
56 fBadChannelMap(0),
57 fCalibData(0),
58 fBCMInitialised(true),
59 fGainsInitialised(true)
209a4703 60{
2374af72 61 //see header file for documentation
209a4703 62}
63
e304ea31 64
209a4703 65AliHLTPHOSDigitMakerComponent::~AliHLTPHOSDigitMakerComponent()
66{
2374af72 67 //see header file for documentation
209a4703 68}
69
70int
71AliHLTPHOSDigitMakerComponent::Deinit()
72{
2374af72 73 //see header file for documentation
209a4703 74 if(fDigitMakerPtr)
75 {
76 delete fDigitMakerPtr;
77 fDigitMakerPtr = 0;
78 }
52be7fb0 79 return 0;
209a4703 80}
81
82const char*
83AliHLTPHOSDigitMakerComponent::GetComponentID()
84{
2374af72 85 //see header file for documentation
209a4703 86 return "PhosDigitMaker";
87}
88
209a4703 89
af6a2273 90void
209a4703 91AliHLTPHOSDigitMakerComponent::GetInputDataTypes(vector<AliHLTComponentDataType>& list)
92{
2374af72 93 //see header file for documentation
94594220 94 list.clear();
95 list.push_back(AliHLTPHOSDefinitions::fgkChannelDataType);
209a4703 96}
97
98AliHLTComponentDataType
99AliHLTPHOSDigitMakerComponent::GetOutputDataType()
100{
2374af72 101 //see header file for documentation
25b7f84c 102 return AliHLTPHOSDefinitions::fgkDigitDataType;
209a4703 103}
104
105
106void
107AliHLTPHOSDigitMakerComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier)
108{
2374af72 109 //see header file for documentation
e304ea31 110 constBase = 0;
a9705807 111 inputMultiplier = (float)sizeof(AliHLTCaloDigitDataStruct)/sizeof(AliHLTCaloChannelDataStruct) + 1;
209a4703 112}
113
114int
115AliHLTPHOSDigitMakerComponent::DoEvent(const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
116 AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr, AliHLTUInt32_t& size,
117 std::vector<AliHLTComponentBlockData>& outputBlocks)
118{
2374af72 119 //see header file for documentation
209a4703 120 UInt_t offset = 0;
121 UInt_t mysize = 0;
e304ea31 122 Int_t digitCount = 0;
123 Int_t ret = 0;
209a4703 124
209a4703 125 const AliHLTComponentBlockData* iter = 0;
126 unsigned long ndx;
d949e02e 127
128 UInt_t specification = 0;
f137c3c5 129 AliHLTCaloChannelDataHeaderStruct* tmpChannelData = 0;
d949e02e 130
f137c3c5 131 // fDigitMakerPtr->SetDigitHeaderPtr(reinterpret_cast<AliHLTCaloDigitHeaderStruct*>(outputPtr));
132
133 fDigitMakerPtr->SetDigitDataPtr(reinterpret_cast<AliHLTCaloDigitDataStruct*>(outputPtr));
5c6cac96 134
209a4703 135 for( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
136 {
c1e4a18c 137
209a4703 138 iter = blocks+ndx;
139
94594220 140 if(iter->fDataType != AliHLTPHOSDefinitions::fgkChannelDataType)
209a4703 141 {
c1e4a18c 142// HLTDebug("Data block is not of type fgkChannelDataType");
209a4703 143 continue;
209a4703 144 }
c1e4a18c 145 if(!fBCMInitialised)
146 {
147 AliHLTPHOSMapper mapper;
148 Int_t module = mapper.GetModuleFromSpec(iter->fSpecification);
149 for(Int_t x = 0; x < fCaloConstants->GetNXCOLUMNSMOD(); x++)
150 {
151 for(Int_t z = 0; z < fCaloConstants->GetNZROWSMOD(); z++)
152 {
153 fDigitMakerPtr->SetBadChannel(x, z, fBadChannelMap->IsBadChannel(5-module, z+1, x+1));
154 }
155 }
156 //delete fBadChannelMap;
157 fBCMInitialised = true;
158 }
159 if(!fGainsInitialised)
160 {
161 AliHLTPHOSMapper mapper;
162 Int_t module = mapper.GetModuleFromSpec(iter->fSpecification);
163 for(Int_t x = 0; x < fCaloConstants->GetNXCOLUMNSMOD(); x++)
164 {
165 for(Int_t z = 0; z < fCaloConstants->GetNZROWSMOD(); z++)
166 {
ca232979 167 fDigitMakerPtr->SetGain(x, z, fCalibData->GetHighLowRatioEmc(5-module, z+1, x+1), fCalibData->GetADCchannelEmc(5-module, z+1, x+1));
c1e4a18c 168 }
169 }
170 fGainsInitialised = true;
171 }
e304ea31 172
173 specification |= iter->fSpecification;
f137c3c5 174 tmpChannelData = reinterpret_cast<AliHLTCaloChannelDataHeaderStruct*>(iter->fPtr);
94594220 175
f137c3c5 176 ret = fDigitMakerPtr->MakeDigits(tmpChannelData, size-(digitCount*sizeof(AliHLTCaloDigitDataStruct)));
e304ea31 177 if(ret == -1)
178 {
cc244597 179 HLTError("Trying to write over buffer size");
e304ea31 180 return -ENOBUFS;
181 }
182 digitCount += ret;
209a4703 183 }
209a4703 184
f137c3c5 185 mysize += digitCount*sizeof(AliHLTCaloDigitDataStruct);
e304ea31 186
cc244597 187 HLTDebug("# of digits: %d, used memory size: %d, available size: %d", digitCount, mysize, size);
87434909 188
87434909 189 if(mysize > 0)
209a4703 190 {
87434909 191 AliHLTComponentBlockData bd;
192 FillBlockData( bd );
193 bd.fOffset = offset;
194 bd.fSize = mysize;
195 bd.fDataType = AliHLTPHOSDefinitions::fgkDigitDataType;
196 bd.fSpecification = specification;
197 outputBlocks.push_back(bd);
209a4703 198 }
ab521ae4 199
94594220 200 fDigitMakerPtr->Reset();
9bf87c6f 201
202 size = mysize;
203
209a4703 204 return 0;
205}
206
209a4703 207int
208AliHLTPHOSDigitMakerComponent::DoInit(int argc, const char** argv )
209{
2374af72 210 //see header file for documentation
209a4703 211
f137c3c5 212 fDigitMakerPtr = new AliHLTCaloDigitMaker("PHOS");
213
214 AliHLTCaloMapper *mapper = new AliHLTPHOSMapper();
215 fDigitMakerPtr->SetMapper(mapper);
209a4703 216
7173b37b 217 Float_t mintime = 0.;
218 Float_t maxtime =50.;
219
209a4703 220 for(int i = 0; i < argc; i++)
221 {
d949e02e 222 if(!strcmp("-lowgainfactor", argv[i]))
223 {
224 fDigitMakerPtr->SetGlobalLowGainFactor(atof(argv[i+1]));
d949e02e 225 }
226 if(!strcmp("-highgainfactor", argv[i]))
227 {
228 fDigitMakerPtr->SetGlobalHighGainFactor(atof(argv[i+1]));
d949e02e 229 }
7173b37b 230 if(!strcmp("-mintime", argv[i]))
231 {
232 mintime = atof(argv[i+1]);
233 }
234 if(!strcmp("-maxtime", argv[i]))
235 {
236 maxtime = atof(argv[i+1]);
237 }
209a4703 238 }
239
7173b37b 240 fDigitMakerPtr->SetTimeWindow(mintime, maxtime);
241
c1e4a18c 242 if(GetBCMFromCDB()) return -1;
243 if(GetGainsFromCDB()) return -1;
244
209a4703 245 //fDigitMakerPtr->SetDigitThreshold(2);
246
247 return 0;
248}
249
c1e4a18c 250
251int AliHLTPHOSDigitMakerComponent::GetBCMFromCDB()
252{
253 fBCMInitialised = false;
254
255// HLTInfo("Getting bad channel map...");
256
257 AliCDBPath path("PHOS","Calib","EmcBadChannels");
258 if(path.GetPath())
259 {
260 // HLTInfo("configure from entry %s", path.GetPath());
261 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
c1e4a18c 262 if (pEntry)
263 {
264 fBadChannelMap = (AliPHOSEmcBadChannelsMap*)pEntry->GetObject();
265 }
266 else
267 {
398dc010 268 HLTError("can not fetch object \"%s\" from CDB", path.GetPath().Data());
c1e4a18c 269 return -1;
270 }
271 }
272 if(!fBadChannelMap) return -1;
273 return 0;
274}
275
276int AliHLTPHOSDigitMakerComponent::GetGainsFromCDB()
277{
278 fGainsInitialised = false;
279
280// HLTInfo("Getting bad channel map...");
281
282 AliCDBPath path("PHOS","Calib","EmcGainPedestals");
283 if(path.GetPath())
284 {
285 // HLTInfo("configure from entry %s", path.GetPath());*/
286 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
287 if (pEntry)
288 {
289 fCalibData = (AliPHOSEmcCalibData*)pEntry->GetObject();
290 }
291 else
292 {
398dc010 293 HLTError("can not fetch object \"%s\" from CDB", path.GetPath().Data());
c1e4a18c 294 return -1;
295 }
296 }
297
298 if(!fCalibData) return -1;
299 return 0;
300
301}
302
303
209a4703 304AliHLTComponent*
305AliHLTPHOSDigitMakerComponent::Spawn()
306{
2374af72 307 //see header file for documentation
209a4703 308 return new AliHLTPHOSDigitMakerComponent();
309}