3 /**************************************************************************
4 * This file is property of and copyright by the ALICE HLT Project *
5 * All rights reserved. *
7 * Primary Authors: Oystein Djuvsland *
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 **************************************************************************/
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"
27 #include "AliCDBEntry.h"
28 #include "AliCDBPath.h"
29 #include "AliCDBManager.h"
31 #include <sys/types.h>
35 * @file AliHLTPHOSDigitMakerComponent.cxx
36 * @author Oystein Djuvsland
38 * @brief A digit maker component for PHOS HLT
41 // see below for class documentation
43 // refer to README to build package
45 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
47 ClassImp(AliHLTPHOSDigitMakerComponent);
49 AliHLTPHOSDigitMakerComponent::AliHLTPHOSDigitMakerComponent() :
50 AliHLTCaloProcessor(),
51 AliHLTCaloConstantsHandler("PHOS"),
53 fDigitContainerPtr(0),
56 fBCMInitialised(true),
57 fGainsInitialised(true)
59 //see header file for documentation
63 AliHLTPHOSDigitMakerComponent::~AliHLTPHOSDigitMakerComponent()
65 //see header file for documentation
69 AliHLTPHOSDigitMakerComponent::Deinit()
71 //see header file for documentation
74 delete fDigitMakerPtr;
81 AliHLTPHOSDigitMakerComponent::GetComponentID()
83 //see header file for documentation
84 return "PhosDigitMaker";
89 AliHLTPHOSDigitMakerComponent::GetInputDataTypes(vector<AliHLTComponentDataType>& list)
91 //see header file for documentation
93 list.push_back(AliHLTPHOSDefinitions::fgkChannelDataType);
96 AliHLTComponentDataType
97 AliHLTPHOSDigitMakerComponent::GetOutputDataType()
99 //see header file for documentation
100 return AliHLTPHOSDefinitions::fgkDigitDataType;
105 AliHLTPHOSDigitMakerComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier)
107 //see header file for documentation
109 inputMultiplier = (float)sizeof(AliHLTCaloDigitDataStruct)/sizeof(AliHLTCaloChannelDataStruct) + 1;
113 AliHLTPHOSDigitMakerComponent::DoEvent(const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks,
114 AliHLTComponentTriggerData& /*trigData*/, AliHLTUInt8_t* outputPtr, AliHLTUInt32_t& size,
115 std::vector<AliHLTComponentBlockData>& outputBlocks)
117 //see header file for documentation
120 Int_t digitCount = 0;
123 const AliHLTComponentBlockData* iter = 0;
126 UInt_t specification = 0;
127 AliHLTCaloChannelDataHeaderStruct* tmpChannelData = 0;
129 // fDigitMakerPtr->SetDigitHeaderPtr(reinterpret_cast<AliHLTCaloDigitHeaderStruct*>(outputPtr));
131 fDigitMakerPtr->SetDigitDataPtr(reinterpret_cast<AliHLTCaloDigitDataStruct*>(outputPtr));
133 for( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
138 if(iter->fDataType != AliHLTPHOSDefinitions::fgkChannelDataType)
140 // HLTDebug("Data block is not of type fgkChannelDataType");
145 AliHLTPHOSMapper mapper;
146 Int_t module = mapper.GetModuleFromSpec(iter->fSpecification);
149 for(Int_t x = 0; x < fCaloConstants->GetNXCOLUMNSMOD(); x++)
151 for(Int_t z = 0; z < fCaloConstants->GetNZROWSMOD(); z++)
153 fDigitMakerPtr->SetBadChannel(x, z, fBadChannelMap->IsBadChannel(5-module, z+1, x+1));
157 //delete fBadChannelMap;
158 fBCMInitialised = true;
160 if(!fGainsInitialised)
162 AliHLTPHOSMapper mapper;
163 Int_t module = mapper.GetModuleFromSpec(iter->fSpecification);
164 if(module >= 0 && module < 5)
166 for(Int_t x = 0; x < fCaloConstants->GetNXCOLUMNSMOD(); x++)
168 for(Int_t z = 0; z < fCaloConstants->GetNZROWSMOD(); z++)
170 fDigitMakerPtr->SetGain(x, z, fCalibData->GetHighLowRatioEmc(5-module, z+1, x+1), fCalibData->GetADCchannelEmc(5-module, z+1, x+1));
173 fGainsInitialised = true;
178 specification |= iter->fSpecification;
179 tmpChannelData = reinterpret_cast<AliHLTCaloChannelDataHeaderStruct*>(iter->fPtr);
181 ret = fDigitMakerPtr->MakeDigits(tmpChannelData, size-(digitCount*sizeof(AliHLTCaloDigitDataStruct)));
184 HLTError("Trying to write over buffer size");
190 mysize += digitCount*sizeof(AliHLTCaloDigitDataStruct);
192 HLTDebug("# of digits: %d, used memory size: %d, available size: %d", digitCount, mysize, size);
196 AliHLTComponentBlockData bd;
200 bd.fDataType = AliHLTPHOSDefinitions::fgkDigitDataType;
201 bd.fSpecification = specification;
202 outputBlocks.push_back(bd);
205 fDigitMakerPtr->Reset();
213 AliHLTPHOSDigitMakerComponent::DoInit(int argc, const char** argv )
215 //see header file for documentation
217 fDigitMakerPtr = new AliHLTCaloDigitMaker("PHOS");
219 AliHLTCaloMapper *mapper = new AliHLTPHOSMapper();
220 fDigitMakerPtr->SetMapper(mapper);
222 Float_t mintime = 0.;
223 Float_t maxtime =50.;
225 for(int i = 0; i < argc; i++)
227 if(!strcmp("-lowgainfactor", argv[i]))
229 fDigitMakerPtr->SetGlobalLowGainFactor(atof(argv[i+1]));
231 if(!strcmp("-highgainfactor", argv[i]))
233 fDigitMakerPtr->SetGlobalHighGainFactor(atof(argv[i+1]));
235 if(!strcmp("-mintime", argv[i]))
237 mintime = atof(argv[i+1]);
239 if(!strcmp("-maxtime", argv[i]))
241 maxtime = atof(argv[i+1]);
245 fDigitMakerPtr->SetTimeWindow(mintime, maxtime);
247 if(GetBCMFromCDB()) return -1;
248 if(GetGainsFromCDB()) return -1;
250 //fDigitMakerPtr->SetDigitThreshold(2);
256 int AliHLTPHOSDigitMakerComponent::GetBCMFromCDB()
258 fBCMInitialised = false;
260 // HLTInfo("Getting bad channel map...");
262 AliCDBPath path("PHOS","Calib","EmcBadChannels");
265 // HLTInfo("configure from entry %s", path.GetPath());
266 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
269 fBadChannelMap = (AliPHOSEmcBadChannelsMap*)pEntry->GetObject();
273 HLTError("can not fetch object \"%s\" from CDB", path.GetPath().Data());
277 if(!fBadChannelMap) return -1;
281 int AliHLTPHOSDigitMakerComponent::GetGainsFromCDB()
283 fGainsInitialised = false;
285 // HLTInfo("Getting bad channel map...");
287 AliCDBPath path("PHOS","Calib","EmcGainPedestals");
290 // HLTInfo("configure from entry %s", path.GetPath());*/
291 AliCDBEntry *pEntry = AliCDBManager::Instance()->Get(path/*,GetRunNo()*/);
294 fCalibData = (AliPHOSEmcCalibData*)pEntry->GetObject();
298 HLTError("can not fetch object \"%s\" from CDB", path.GetPath().Data());
303 if(!fCalibData) return -1;
310 AliHLTPHOSDigitMakerComponent::Spawn()
312 //see header file for documentation
313 return new AliHLTPHOSDigitMakerComponent();