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