]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/EMCAL/AliHLTEMCALDigitMakerComponent.cxx
cashing of EMCALMapper instances to avoid unnecessary allocations; removing global...
[u/mrichter/AliRoot.git] / HLT / EMCAL / AliHLTEMCALDigitMakerComponent.cxx
CommitLineData
ca071d0a 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 **************************************************************************/
ca071d0a 17#include "AliHLTEMCALDigitMakerComponent.h"
18#include "AliHLTCaloDigitMaker.h"
19#include "AliHLTCaloDigitDataStruct.h"
20#include "AliHLTCaloChannelDataHeaderStruct.h"
21#include "AliHLTCaloChannelDataStruct.h"
22#include "AliHLTEMCALMapper.h"
23#include "AliHLTEMCALDefinitions.h"
7b3a0a0e 24#include "AliCaloCalibPedestal.h"
25#include "AliEMCALCalibData.h"
26#include "AliCDBEntry.h"
27#include "AliCDBPath.h"
28#include "AliCDBManager.h"
117c143c 29#include "AliRawDataHeader.h"
ca071d0a 30#include "TFile.h"
31#include <sys/stat.h>
32#include <sys/types.h>
33
dc3d3428 34//#include "AliHLTEMCALConstant.h"
35#include "AliHLTCaloConstants.h"
36
37using EMCAL::NZROWSMOD;
38using EMCAL::NXCOLUMNSMOD;
72752456 39using CALO::HGLGFACTOR;
ca071d0a 40
41/**
42 * @file AliHLTEMCALDigitMakerComponent.cxx
43 * @author Oystein Djuvsland
44 * @date
45 * @brief A digit maker component for EMCAL HLT
46*/
47
48// see below for class documentation
49// or
50// refer to README to build package
51// or
52// visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
53
54
8daca632 55ClassImp(AliHLTEMCALDigitMakerComponent)
56
ca071d0a 57AliHLTEMCALDigitMakerComponent gAliHLTEMCALDigitMakerComponent;
58
59AliHLTEMCALDigitMakerComponent::AliHLTEMCALDigitMakerComponent() :
60 AliHLTCaloProcessor(),
dc3d3428 61 // AliHLTCaloConstantsHandler("EMCAL"),
ca071d0a 62 fDigitMakerPtr(0),
7b3a0a0e 63 fDigitContainerPtr(0),
64 fPedestalData(0),
65 fCalibData(0),
66 fBCMInitialised(true),
67 fGainsInitialised(true)
ca071d0a 68{
dc3d3428 69
ca071d0a 70 //see header file for documentation
71}
72
73
74AliHLTEMCALDigitMakerComponent::~AliHLTEMCALDigitMakerComponent()
75{
76 //see header file for documentation
77}
78
79int
80AliHLTEMCALDigitMakerComponent::Deinit()
81{
82 //see header file for documentation
83 if(fDigitMakerPtr)
84 {
85 delete fDigitMakerPtr;
86 fDigitMakerPtr = 0;
87 }
88 return 0;
89}
90
91const char*
92AliHLTEMCALDigitMakerComponent::GetComponentID()
93{
94 //see header file for documentation
95 return "EmcalDigitMaker";
96}
97
98
99void
100AliHLTEMCALDigitMakerComponent::GetInputDataTypes(vector<AliHLTComponentDataType>& list)
101{
102 //see header file for documentation
103 list.clear();
104 list.push_back(AliHLTEMCALDefinitions::fgkChannelDataType);
105}
106
107AliHLTComponentDataType
108AliHLTEMCALDigitMakerComponent::GetOutputDataType()
109{
110 //see header file for documentation
bb29f0e9 111// return AliHLTCaloDefinitions::fgkDigitDataType|kAliHLTDataOriginEMCAL;
ca071d0a 112 return AliHLTEMCALDefinitions::fgkDigitDataType;
113}
114
115
116void
117AliHLTEMCALDigitMakerComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier)
118{
119 //see header file for documentation
120 constBase = 0;
121 inputMultiplier = (float)sizeof(AliHLTCaloDigitDataStruct)/sizeof(AliHLTCaloChannelDataStruct) + 1;
122}
123
bdaaafe2 124
125
ca071d0a 126int
127AliHLTEMCALDigitMakerComponent::DoEvent(const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
117c143c 128 AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr, AliHLTUInt32_t& size,
ca071d0a 129 std::vector<AliHLTComponentBlockData>& outputBlocks)
130{
117c143c 131
132 //patch in order to skip calib events
133 const AliRawDataHeader* cdh = NULL;
134 ExtractTriggerData(trigData, NULL, NULL, &cdh, NULL, true);
135 AliHLTUInt64_t triggerMask = cdh->GetTriggerClasses();
136 if(triggerMask == 0) return 0;
137
138
ca071d0a 139 //see header file for documentation
140 UInt_t offset = 0;
141 UInt_t mysize = 0;
142 Int_t digitCount = 0;
143 Int_t ret = 0;
6e339f57 144
ca071d0a 145 const AliHLTComponentBlockData* iter = 0;
146 unsigned long ndx;
6e339f57 147
ca071d0a 148 UInt_t specification = 0;
149 AliHLTCaloChannelDataHeaderStruct* tmpChannelData = 0;
150
151 // fDigitMakerPtr->SetDigitHeaderPtr(reinterpret_cast<AliHLTCaloDigitHeaderStruct*>(outputPtr));
6e339f57 152
ca071d0a 153 fDigitMakerPtr->SetDigitDataPtr(reinterpret_cast<AliHLTCaloDigitDataStruct*>(outputPtr));
6e339f57 154
ca071d0a 155 for( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
156 {
157 iter = blocks+ndx;
158
159 if(iter->fDataType != AliHLTEMCALDefinitions::fgkChannelDataType)
160 {
ca071d0a 161 continue;
162 }
dc3d3428 163
1a619ed3 164 Int_t module = 0;
72752456 165
7b3a0a0e 166 if(!fBCMInitialised)
72752456 167 {
168 AliHLTEMCALMapper mapper(iter->fSpecification);
6e339f57 169 module = mapper.GetModuleFromSpec(iter->fSpecification);
170
171 if (module>=0) {
72752456 172
f022ce7e 173 for(Int_t x = 0; x < NXCOLUMNSMOD ; x++) // PTH
f022ce7e 174 for(Int_t z = 0; z < NZROWSMOD ; z++) // PTH
3a42b4ed 175 // FR
176 fDigitMakerPtr->SetBadChannel(x, z, fPedestalData->IsBadChannel(module, z, x));
6e339f57 177 //delete fBadChannelMap;
178 fBCMInitialised = true;
179 }
180 else
181 HLTError("Error setting pedestal with module value of %d", module);
f022ce7e 182
f022ce7e 183 }
184
7b3a0a0e 185 if(!fGainsInitialised)
72752456 186 {
6e339f57 187
f022ce7e 188 AliHLTEMCALMapper mapper(iter->fSpecification);
6e339f57 189 module = mapper.GetModuleFromSpec(iter->fSpecification);
f022ce7e 190
6e339f57 191 if (module>=0) {
192
193 for(Int_t x = 0; x < NXCOLUMNSMOD; x++) //PTH
194 for(Int_t z = 0; z < NZROWSMOD; z++) //PTH
195 // FR setting gains
196 fDigitMakerPtr->SetGain(x, z, HGLGFACTOR, fCalibData->GetADCchannel(module, z, x));
197
198 fGainsInitialised = true;
199 }
200 else
201 HLTError("Error setting gains with module value of %d", module);
f022ce7e 202 }
203
ca071d0a 204 specification |= iter->fSpecification;
205 tmpChannelData = reinterpret_cast<AliHLTCaloChannelDataHeaderStruct*>(iter->fPtr);
206
207 ret = fDigitMakerPtr->MakeDigits(tmpChannelData, size-(digitCount*sizeof(AliHLTCaloDigitDataStruct)));
f022ce7e 208
ca071d0a 209 if(ret == -1)
210 {
211 HLTError("Trying to write over buffer size");
212 return -ENOBUFS;
213 }
214 digitCount += ret;
215 }
216
217 mysize += digitCount*sizeof(AliHLTCaloDigitDataStruct);
218
219 HLTDebug("# of digits: %d, used memory size: %d, available size: %d", digitCount, mysize, size);
220
221 if(mysize > 0)
222 {
223 AliHLTComponentBlockData bd;
224 FillBlockData( bd );
225 bd.fOffset = offset;
226 bd.fSize = mysize;
227 bd.fDataType = AliHLTEMCALDefinitions::fgkDigitDataType;
228 bd.fSpecification = specification;
229 outputBlocks.push_back(bd);
230 }
231
232 fDigitMakerPtr->Reset();
233
234 size = mysize;
235
236 return 0;
237}
238
239
240int
241AliHLTEMCALDigitMakerComponent::DoInit(int argc, const char** argv )
242{
243 //see header file for documentation
244
245 fDigitMakerPtr = new AliHLTCaloDigitMaker("EMCAL");
246
247 AliHLTCaloMapper *mapper = new AliHLTEMCALMapper(2);
248 fDigitMakerPtr->SetMapper(mapper);
249
250 for(int i = 0; i < argc; i++)
251 {
252 if(!strcmp("-lowgainfactor", argv[i]))
253 {
254 fDigitMakerPtr->SetGlobalLowGainFactor(atof(argv[i+1]));
255 }
256 if(!strcmp("-highgainfactor", argv[i]))
257 {
258 fDigitMakerPtr->SetGlobalHighGainFactor(atof(argv[i+1]));
259 }
72752456 260
ca071d0a 261 }
72752456 262
263
264 if (GetBCMFromCDB())
265 return -1;
266
267 if (GetGainsFromCDB())
268 return -1;
269
270 //GetBCMFromCDB();
ca071d0a 271 //fDigitMakerPtr->SetDigitThreshold(2);
272
273 return 0;
274}
275
dc3d3428 276
12308f2d 277int AliHLTEMCALDigitMakerComponent::GetBCMFromCDB()
278{
279 // See header file for class documentation
dc3d3428 280 fBCMInitialised = false;
281 // HLTInfo("Getting bad channel map...");
7b3a0a0e 282 AliCDBPath path("EMCAL","Calib","Pedestals");
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 fPedestalData = (AliCaloCalibPedestal*)pEntry->GetObject();
290 }
291 else
292 {
293// HLTError("can not fetch object \"%s\" from CDB", path);
294 return -1;
295 }
296 }
297 if(!fPedestalData)
298 {
299 return -1;
300 }
12308f2d 301
302 return 0;
303}
304
dc3d3428 305
12308f2d 306int AliHLTEMCALDigitMakerComponent::GetGainsFromCDB()
307{
308 // See header file for class documentation
dc3d3428 309 fGainsInitialised = false;
310 // HLTInfo("Getting bad channel map...");
7b3a0a0e 311
312 AliCDBPath path("EMCAL","Calib","Data");
313 if(path.GetPath())
314 {
315 // HLTInfo("configure from entry %s", path.GetPath());
316 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
317 if (pEntry)
318 {
319 fCalibData = (AliEMCALCalibData*)pEntry->GetObject();
320 }
321 else
322 {
323// HLTError("can not fetch object \"%s\" from CDB", path);
324 return -1;
325 }
326 }
327 if(!fCalibData) return -1;
12308f2d 328 return 0;
329}
330
331
ca071d0a 332AliHLTComponent*
333AliHLTEMCALDigitMakerComponent::Spawn()
334{
335 //see header file for documentation
336 return new AliHLTEMCALDigitMakerComponent();
337}