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