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