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