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