Coding rules
[u/mrichter/AliRoot.git] / HLT / TRD / AliHLTTRDCalibrationComponent.cxx
CommitLineData
95259bbb 1// $Id$
2
3/**************************************************************************
4 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
5 * *
6 * Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
7 * Timm Steinbeck <timm@kip.uni-heidelberg.de> *
8 * for The ALICE Off-line Project. *
9 * *
10 * Permission to use, copy, modify and distribute this software and its *
11 * documentation strictly for non-commercial purposes is hereby granted *
12 * without fee, provided that the above copyright notice appears in all *
13 * copies and that both the copyright notice and this permission notice *
14 * appear in the supporting documentation. The authors make no claims *
15 * about the suitability of this software for any purpose. It is *
16 * provided "as is" without express or implied warranty. *
17 **************************************************************************/
18
19/** @file AliHLTTRDCalibrationComponent.cxx
20 @author Timm Steinbeck, Matthias Richter
dc2e6604 21 @date
95259bbb 22 @brief A TRDCalibration processing component for the HLT. */
23
24#if __GNUC__ >= 3
dc2e6604 25 using namespace std;
95259bbb 26#endif
27
28#include "TTree.h"
29#include "TFile.h"
30#include "TBranch.h"
31
32#include "AliHLTTRDCalibrationComponent.h"
33#include "AliHLTTRDDefinitions.h"
dc2e6604 34#include "AliHLTTRDUtils.h"
95259bbb 35
36#include "AliCDBManager.h"
95259bbb 37#include "AliRawReaderMemory.h"
9aea5deb 38#include "AliTRDCalibraFillHisto.h"
dc2e6604 39#include "AliTRDtrackV1.h"
95259bbb 40
41#include <cstdlib>
42#include <cerrno>
43#include <string>
44
45// this is a global object used for automatic component registration, do not use this
46AliHLTTRDCalibrationComponent gAliHLTTRDCalibrationComponent;
47
48ClassImp(AliHLTTRDCalibrationComponent);
dc2e6604 49
d679dd6c 50AliHLTTRDCalibrationComponent::AliHLTTRDCalibrationComponent():
dc2e6604 51 AliHLTCalibrationProcessor(),
52 fTRDCalibraFillHisto(NULL),
53 fOutputPercentage(100), // By default we copy to the output exactly what we got as input
54 fStrorageDBpath("local://$ALICE_ROOT/OCDB"),
55 fCDB(NULL)
95259bbb 56{
dc2e6604 57 // Default constructor
95259bbb 58}
59
60AliHLTTRDCalibrationComponent::~AliHLTTRDCalibrationComponent()
61{
dc2e6604 62 // Destructor
63 ;
95259bbb 64}
65
66const char* AliHLTTRDCalibrationComponent::GetComponentID()
67{
dc2e6604 68 // Return the component ID const char *
69 return "TRDCalibration"; // The ID of this component
95259bbb 70}
71
72void AliHLTTRDCalibrationComponent::GetInputDataTypes( vector<AliHLTComponent_DataType>& list)
73{
dc2e6604 74 // Get the list of input data
75 list.clear(); // We do not have any requirements for our input data type(s).
76 list.push_back( AliHLTTRDDefinitions::fgkTRDSATracksDataType );
95259bbb 77}
78
79AliHLTComponent_DataType AliHLTTRDCalibrationComponent::GetOutputDataType()
80{
dc2e6604 81 // Get the output data type
82 return AliHLTTRDDefinitions::fgkCalibrationDataType;
95259bbb 83}
84
85void AliHLTTRDCalibrationComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
86{
dc2e6604 87 // Get the output data size
88 constBase = 0;
89 inputMultiplier = ((double)fOutputPercentage)/100.0;
95259bbb 90}
91
92AliHLTComponent* AliHLTTRDCalibrationComponent::Spawn()
93{
dc2e6604 94 // Spawn function, return new instance of this class
95 return new AliHLTTRDCalibrationComponent;
95259bbb 96};
97
98Int_t AliHLTTRDCalibrationComponent::ScanArgument( int argc, const char** argv )
99{
dc2e6604 100 // perform initialization. We check whether our relative output size is specified in the arguments.
101 int i = 0;
102 char* cpErr;
103 while ( i < argc )
104 {
105 HLTDebug("argv[%d] == %s", i, argv[i] );
106 if ( !strcmp( argv[i], "output_percentage" ) )
107 {
108 if ( i+1>=argc )
109 {
110 HLTError("Missing output_percentage parameter");
111 return ENOTSUP;
112 }
113 HLTDebug("argv[%d+1] == %s", i, argv[i+1] );
114 fOutputPercentage = strtoul( argv[i+1], &cpErr, 0 );
115 if ( *cpErr )
116 {
117 HLTError("Cannot convert output_percentage parameter '%s'", argv[i+1] );
118 return EINVAL;
119 }
120 HLTInfo("Output percentage set to %lu %%", fOutputPercentage );
121 i += 2;
122 continue;
123 }
124 else if ( strcmp( argv[i], "-cdb" ) == 0)
125 {
126 if ( i+1 >= argc )
127 {
128 HLTError("Missing -cdb argument");
129 return ENOTSUP;
130 }
131 fStrorageDBpath = argv[i+1];
132 HLTInfo("DB storage is %s", fStrorageDBpath.c_str() );
133 i += 2;
134 continue;
135 }
136 else {
137 HLTError("Unknown option '%s'", argv[i] );
138 return EINVAL;
139 }
140 }
141 return 0;
95259bbb 142}
143
144Int_t AliHLTTRDCalibrationComponent::InitCalibration()
145{
dc2e6604 146 //init the calibration
147 fCDB = AliCDBManager::Instance();
148 if (!fCDB)
149 {
150 HLTError("Could not get CDB instance, fCDB 0x%x", fCDB);
151 }
152 else
153 {
154 fCDB->SetRun(0); // THIS HAS TO BE RETRIEVED !!!
155 fCDB->SetDefaultStorage(fStrorageDBpath.c_str());
156 HLTDebug("fCDB 0x%x", fCDB);
157 }
158 fTRDCalibraFillHisto = AliTRDCalibraFillHisto::Instance();
159 fTRDCalibraFillHisto->SetHisto2d(); // choose to use histograms
160 fTRDCalibraFillHisto->SetCH2dOn(); // choose to calibrate the gain
161 fTRDCalibraFillHisto->SetPH2dOn(); // choose to calibrate the drift velocity
162 fTRDCalibraFillHisto->SetPRF2dOn(); // choose to look at the PRF
163 fTRDCalibraFillHisto->Init2Dhistos(); // initialise the histos
164 return 0;
95259bbb 165}
166
167Int_t AliHLTTRDCalibrationComponent::DeinitCalibration()
168{
dc2e6604 169 HLTDebug("DeinitCalibration");
170
171 // Deinitialization of the component
172
173 if (fCDB)
174 {
175 HLTDebug("destroy fCDB");
176 fCDB->Destroy();
177 fCDB = 0;
178 }
179 return 0;
95259bbb 180}
181
d679dd6c 182Int_t AliHLTTRDCalibrationComponent::ProcessCalibration(const AliHLTComponent_EventData& evtData,
dc2e6604 183 const AliHLTComponent_BlockData* blocks,
184 AliHLTComponent_TriggerData& /*trigData*/,
185 AliHLTUInt8_t* /*outputPtr*/,
186 AliHLTUInt32_t& /*size*/,
187 vector<AliHLTComponent_BlockData>& /*outputBlocks*/)
95259bbb 188{
dc2e6604 189 HLTDebug("NofBlocks %lu", evtData.fBlockCnt );
190 // Process an event
191
192 // Loop over all input blocks in the event
193 vector<AliHLTComponent_DataType> expectedDataTypes;
194 GetInputDataTypes(expectedDataTypes);
195 for ( unsigned long iBlock = 0; iBlock < evtData.fBlockCnt; iBlock++ )
196 {
197 const AliHLTComponentBlockData &block = blocks[iBlock];
198 AliHLTComponentDataType inputDataType = block.fDataType;
199 Bool_t correctDataType = kFALSE;
200
201 for(UInt_t i = 0; i < expectedDataTypes.size(); i++)
202 if( expectedDataTypes.at(i) == inputDataType)
203 correctDataType = kTRUE;
204 if (!correctDataType) {
205 HLTDebug( "Block # %i/%i; Event 0x%08LX (%Lu) Wrong received datatype: %s - Skipping",
206 iBlock, evtData.fBlockCnt,
207 evtData.fEventID, evtData.fEventID,
208 DataType2Text(inputDataType).c_str());
209 continue;
210 }
c702bc56 211 else {
dc2e6604 212 HLTDebug("We get the right data type: Block # %i/%i; Event 0x%08LX (%Lu) Received datatype: %s",
213 iBlock, evtData.fBlockCnt-1,
214 evtData.fEventID, evtData.fEventID,
215 DataType2Text(inputDataType).c_str());
c702bc56 216 }
217
dc2e6604 218 TClonesArray* tracksArray = NULL;
219 tracksArray = new TClonesArray("AliTRDtrackV1");
220 HLTDebug("BLOCK fPtr 0x%x, fOffset %i, fSize %i, fSpec 0x%x, fDataType %s", block.fPtr, block.fOffset, block.fSize, block.fSpecification, DataType2Text(block.fDataType).c_str());
221 AliHLTTRDUtils::ReadTracks(tracksArray, block.fPtr, block.fSize);
222
223 if (tracksArray) {
224 Int_t nbEntries = tracksArray->GetEntries();
225 HLTDebug(" %i TRDtracks in tracksArray", nbEntries);
226 AliTRDtrackV1* trdTrack = 0x0;
227 for (Int_t i = 0; i < nbEntries; i++){
228 HLTDebug("%i/%i: ", i+1, nbEntries);
229 trdTrack = (AliTRDtrackV1*)tracksArray->At(i);
230 trdTrack->Print();
231 fTRDCalibraFillHisto->UpdateHistogramsV1(trdTrack);
232 }
233 }
234
235
236 TObjArray *outArray = FormOutput();
237 if (outArray) {
238 PushBack(outArray, AliHLTTRDDefinitions::fgkCalibrationDataType);
239 delete outArray;
240 }
241
242 }
243 return 0;
244
95259bbb 245}
246
dc2e6604 247
d679dd6c 248/**
dc2e6604 249 * Form output array of histrograms
d679dd6c 250 */
251//============================================================================
dc2e6604 252TObjArray* AliHLTTRDCalibrationComponent::FormOutput()
d679dd6c 253{
dc2e6604 254 TObjArray *outArray=new TObjArray(3);
d679dd6c 255
dc2e6604 256 // gain histo
257 TH2I *hCH2d = fTRDCalibraFillHisto->GetCH2d();
258 outArray->Add(hCH2d);
d679dd6c 259
dc2e6604 260 // drift velocity histo
261 TProfile2D *hPH2d = fTRDCalibraFillHisto->GetPH2d();
262 outArray->Add(hPH2d);
d679dd6c 263
dc2e6604 264 // PRF histo
265 TProfile2D *hPRF2d = fTRDCalibraFillHisto->GetPRF2d();
266 outArray->Add(hPRF2d);
267
268 HLTDebug("GetCH2d = 0x%x; NEntries = %i; size = %i", hCH2d, hCH2d->GetEntries(), sizeof(hCH2d));
269 hCH2d->Print();
270 HLTDebug("GetPH2d = 0x%x; NEntries = %i; size = %i", hPH2d, hPH2d->GetEntries(), sizeof(hPH2d));
271 hPH2d->Print();
272 HLTDebug("GetPRF2d = 0x%x; NEntries = %i; size = %i", hPRF2d, hPRF2d->GetEntries(), sizeof(hPRF2d));
273 hPRF2d->Print();
274 HLTDebug("output Array: pointer = 0x%x; NEntries = %i; size = %i", outArray, outArray->GetEntries(), sizeof(outArray));
275
276
277
278 return outArray;
d679dd6c 279
d679dd6c 280}
281