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