]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TRD/AliHLTTRDCalibrationComponent.cxx
fix warnings
[u/mrichter/AliRoot.git] / HLT / TRD / AliHLTTRDCalibrationComponent.cxx
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
21     @date
22     @brief  A TRDCalibration processing component for the HLT. */
23
24 #if __GNUC__ >= 3
25     using namespace std;
26 #endif
27
28 #include "TTree.h"
29 #include "TFile.h"
30 #include "TBranch.h"
31
32 #include "AliHLTTRDCalibrationComponent.h"
33 #include "AliHLTTRDDefinitions.h"
34 #include "AliHLTTRDUtils.h"
35
36 #include "AliCDBManager.h"
37 #include "AliRawReaderMemory.h"
38 #include "AliTRDCalibraFillHisto.h"
39 #include "AliTRDtrackV1.h"
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
46 AliHLTTRDCalibrationComponent gAliHLTTRDCalibrationComponent;
47
48 ClassImp(AliHLTTRDCalibrationComponent);
49
50 AliHLTTRDCalibrationComponent::AliHLTTRDCalibrationComponent():
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)
56 {
57     // Default constructor
58 }
59
60 AliHLTTRDCalibrationComponent::~AliHLTTRDCalibrationComponent()
61 {
62     // Destructor
63     ;
64 }
65
66 const char* AliHLTTRDCalibrationComponent::GetComponentID()
67 {
68     // Return the component ID const char *
69     return "TRDCalibration"; // The ID of this component
70 }
71
72 void AliHLTTRDCalibrationComponent::GetInputDataTypes( vector<AliHLTComponent_DataType>& list)
73 {
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 );
77 }
78
79 AliHLTComponent_DataType AliHLTTRDCalibrationComponent::GetOutputDataType()
80 {
81     // Get the output data type
82     return AliHLTTRDDefinitions::fgkCalibrationDataType;
83 }
84
85 void AliHLTTRDCalibrationComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
86 {
87     // Get the output data size
88     constBase = 0;
89     inputMultiplier = ((double)fOutputPercentage)/100.0;
90 }
91
92 AliHLTComponent* AliHLTTRDCalibrationComponent::Spawn()
93 {
94     // Spawn function, return new instance of this class
95     return new AliHLTTRDCalibrationComponent;
96 };
97
98 Int_t AliHLTTRDCalibrationComponent::ScanArgument( int argc, const char** argv )
99 {
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;
142 }
143
144 Int_t AliHLTTRDCalibrationComponent::InitCalibration()
145 {
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;
165 }
166
167 Int_t AliHLTTRDCalibrationComponent::DeinitCalibration()
168 {
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;
180 }
181
182 Int_t AliHLTTRDCalibrationComponent::ProcessCalibration(const AliHLTComponent_EventData& evtData,
183                                                         const AliHLTComponent_BlockData* blocks,
184                                                         AliHLTComponent_TriggerData& /*trigData*/,
185                                                         AliHLTUInt8_t* /*outputPtr*/,
186                                                         AliHLTUInt32_t& /*size*/,
187                                                         vector<AliHLTComponent_BlockData>& /*outputBlocks*/)
188 {
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             }
211             else {
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());
216             }
217             
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
245 }
246
247
248 /**
249  * Form output array of histrograms
250  */
251 //============================================================================
252 TObjArray* AliHLTTRDCalibrationComponent::FormOutput()
253 {
254     TObjArray *outArray=new TObjArray(3);
255
256     // gain histo
257     TH2I *hCH2d = fTRDCalibraFillHisto->GetCH2d();
258     outArray->Add(hCH2d);
259
260     // drift velocity histo
261     TProfile2D *hPH2d = fTRDCalibraFillHisto->GetPH2d();
262     outArray->Add(hPH2d);
263
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;
279
280 }
281