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