]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/PHOS/AliHLTPHOSDigitMakerComponent.cxx
a59462ed9bc7cd581bb951958f441a7f0d6d740e
[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          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          //delete fBadChannelMap;
157          fBCMInitialised = true;
158       }
159       if(!fGainsInitialised)
160       {
161          AliHLTPHOSMapper mapper;
162          Int_t module = mapper.GetModuleFromSpec(iter->fSpecification);
163          for(Int_t x = 0; x < fCaloConstants->GetNXCOLUMNSMOD(); x++)
164          {
165             for(Int_t z = 0; z < fCaloConstants->GetNZROWSMOD(); z++)
166             {
167                 fDigitMakerPtr->SetGain(x, z, fCalibData->GetHighLowRatioEmc(module, z+1, x+1), fCalibData->GetADCchannelEmc(module, z+1, x+1));
168             }
169          }
170          fGainsInitialised = true;
171       }
172
173       specification |= iter->fSpecification;
174       tmpChannelData = reinterpret_cast<AliHLTCaloChannelDataHeaderStruct*>(iter->fPtr);
175     
176       ret = fDigitMakerPtr->MakeDigits(tmpChannelData, size-(digitCount*sizeof(AliHLTCaloDigitDataStruct)));
177       if(ret == -1) 
178         {
179           HLTError("Trying to write over buffer size");
180           return -ENOBUFS;
181         }
182       digitCount += ret; 
183     }
184   
185   mysize += digitCount*sizeof(AliHLTCaloDigitDataStruct);
186
187   HLTDebug("# of digits: %d, used memory size: %d, available size: %d", digitCount, mysize, size);
188
189   if(mysize > 0) 
190     {
191       AliHLTComponentBlockData bd;
192       FillBlockData( bd );
193       bd.fOffset = offset;
194       bd.fSize = mysize;
195       bd.fDataType = AliHLTPHOSDefinitions::fgkDigitDataType;
196       bd.fSpecification = specification;
197       outputBlocks.push_back(bd);
198     }
199
200   fDigitMakerPtr->Reset();
201
202   size = mysize; 
203
204   return 0;
205 }
206
207 int
208 AliHLTPHOSDigitMakerComponent::DoInit(int argc, const char** argv )
209 {
210   //see header file for documentation
211
212   fDigitMakerPtr = new AliHLTCaloDigitMaker("PHOS");
213
214   AliHLTCaloMapper *mapper = new AliHLTPHOSMapper();
215   fDigitMakerPtr->SetMapper(mapper);
216   
217   Float_t mintime = 0.;
218   Float_t maxtime =50.;
219   
220   for(int i = 0; i < argc; i++)
221     {
222       if(!strcmp("-lowgainfactor", argv[i]))
223         {
224           fDigitMakerPtr->SetGlobalLowGainFactor(atof(argv[i+1]));
225         }
226       if(!strcmp("-highgainfactor", argv[i]))
227         {
228           fDigitMakerPtr->SetGlobalHighGainFactor(atof(argv[i+1]));
229         }
230         if(!strcmp("-mintime", argv[i]))
231         {
232            mintime = atof(argv[i+1]);
233         }
234         if(!strcmp("-maxtime", argv[i]))
235         {
236            maxtime = atof(argv[i+1]);
237         }
238     }
239  
240  fDigitMakerPtr->SetTimeWindow(mintime, maxtime);
241
242  if(GetBCMFromCDB()) return -1;
243  if(GetGainsFromCDB()) return -1;
244   
245   //fDigitMakerPtr->SetDigitThreshold(2);
246
247   return 0;
248 }
249
250
251 int AliHLTPHOSDigitMakerComponent::GetBCMFromCDB()
252 {
253    fBCMInitialised = false;
254    
255 //   HLTInfo("Getting bad channel map...");
256
257   AliCDBPath path("PHOS","Calib","EmcBadChannels");
258   if(path.GetPath())
259     {
260       //      HLTInfo("configure from entry %s", path.GetPath());
261       AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
262         if (pEntry) 
263         {
264             fBadChannelMap = (AliPHOSEmcBadChannelsMap*)pEntry->GetObject();
265         }
266       else
267         {
268             HLTError("can not fetch object \"%s\" from CDB", path.GetPath().Data());
269             return -1;
270         }
271     }
272    if(!fBadChannelMap) return -1;
273    return 0;
274 }
275
276 int AliHLTPHOSDigitMakerComponent::GetGainsFromCDB()
277 {
278    fGainsInitialised = false;
279    
280 //   HLTInfo("Getting bad channel map...");
281
282   AliCDBPath path("PHOS","Calib","EmcGainPedestals");
283   if(path.GetPath())
284     {
285       //      HLTInfo("configure from entry %s", path.GetPath());*/
286       AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
287       if (pEntry) 
288         {
289             fCalibData = (AliPHOSEmcCalibData*)pEntry->GetObject();
290         }
291       else      
292         {
293             HLTError("can not fetch object \"%s\" from CDB", path.GetPath().Data());
294             return -1;
295         }
296     }
297     
298     if(!fCalibData) return -1;
299    return 0;
300    
301 }
302
303
304 AliHLTComponent*
305 AliHLTPHOSDigitMakerComponent::Spawn()
306 {
307   //see header file for documentation
308   return new AliHLTPHOSDigitMakerComponent();
309 }