3 /**************************************************************************
4 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
6 * Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
7 * Timm Steinbeck <timm@kip.uni-heidelberg.de> *
8 * for The ALICE Off-line Project. *
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 **************************************************************************/
19 /** @file AliHLTTRDCalibrationComponent.cxx
20 @author Timm Steinbeck, Matthias Richter
22 @brief A TRDCalibration processing component for the HLT. */
32 #include "AliHLTTRDCalibrationComponent.h"
33 #include "AliHLTTRDDefinitions.h"
34 #include "AliHLTTRDUtils.h"
36 #include "AliCDBManager.h"
37 #include "AliCDBStorage.h"
38 #include "AliRawReaderMemory.h"
39 #include "AliTRDCalibraFillHisto.h"
40 #include "AliTRDtrackV1.h"
46 ClassImp(AliHLTTRDCalibrationComponent);
48 AliHLTTRDCalibrationComponent::AliHLTTRDCalibrationComponent()
49 : AliHLTCalibrationProcessor(),
50 fTRDCalibraFillHisto(NULL),
56 fRecievedTimeBins(kFALSE)
58 // Default constructor
61 AliHLTTRDCalibrationComponent::~AliHLTTRDCalibrationComponent()
66 const char* AliHLTTRDCalibrationComponent::GetComponentID()
68 // Return the component ID const char *
69 return "TRDCalibration"; // The ID of this component
72 void AliHLTTRDCalibrationComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
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);
79 AliHLTComponentDataType AliHLTTRDCalibrationComponent::GetOutputDataType()
81 // Get the output data type
82 return AliHLTTRDDefinitions::fgkCalibrationDataType;
85 void AliHLTTRDCalibrationComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
87 // Get the output data size
88 constBase = fOutputSize;
92 AliHLTComponent* AliHLTTRDCalibrationComponent::Spawn()
94 // Spawn function, return new instance of this class
95 return new AliHLTTRDCalibrationComponent;
98 Int_t AliHLTTRDCalibrationComponent::ScanArgument( int argc, const char** argv )
100 // perform initialization. We check whether our relative output size is specified in the arguments.
105 HLTDebug("argv[%d] == %s", i, argv[i] );
106 if ( !strcmp( argv[i], "output_size" ) )
110 HLTError("Missing output_size parameter");
113 HLTDebug("argv[%d+1] == %s", i, argv[i+1] );
114 fOutputSize = strtoul( argv[i+1], &cpErr, 0 );
117 HLTError("Cannot convert output_size parameter '%s'", argv[i+1] );
120 HLTInfo("Output size set to %lu %%", fOutputSize );
124 if ( !strcmp( argv[i], "-everyNevent" ) )
128 HLTError("Missing everyNevent parameter");
131 HLTDebug("argv[%d+1] == %s", i, argv[i+1] );
132 fOutputSize = strtoul( argv[i+1], &cpErr, 0 );
135 HLTError("Cannot convert everyNevent parameter '%s'", argv[i+1] );
138 HLTInfo("Pushing back every %d event", feveryNevent);
144 HLTError("Unknown option '%s'", argv[i] );
151 Int_t AliHLTTRDCalibrationComponent::InitCalibration()
153 if(!AliCDBManager::Instance()->IsDefaultStorageSet()){
154 HLTError("DefaultStorage is not set in CDBManager");
157 if(AliCDBManager::Instance()->GetRun()<0){
158 HLTError("Run Number is not set in CDBManager");
161 HLTInfo("CDB default storage: %s; RunNo: %i", (AliCDBManager::Instance()->GetDefaultStorage()->GetBaseFolder()).Data(), AliCDBManager::Instance()->GetRun());
163 fTRDCalibraFillHisto = AliTRDCalibraFillHisto::Instance();
164 fTRDCalibraFillHisto->SetHisto2d(); // choose to use histograms
165 fTRDCalibraFillHisto->SetCH2dOn(); // choose to calibrate the gain
166 fTRDCalibraFillHisto->SetPH2dOn(); // choose to calibrate the drift velocity
167 fTRDCalibraFillHisto->SetPRF2dOn(); // choose to look at the PRF
168 fTRDCalibraFillHisto->SetIsHLT(); // per detector
169 //fTRDCalibraFillHisto->SetDebugLevel(1);// debug
170 fTRDCalibraFillHisto->SetFillWithZero(kTRUE);
172 fTracksArray = new TClonesArray("AliTRDtrackV1");
173 fOutArray = new TObjArray(3);
178 Int_t AliHLTTRDCalibrationComponent::DeinitCalibration()
181 // Deinitialization of the component
183 HLTDebug("DeinitCalibration");
184 fTracksArray->Delete();
186 fTRDCalibraFillHisto->Destroy();
187 //fOutArray->Delete();
193 Int_t AliHLTTRDCalibrationComponent::ProcessCalibration(const AliHLTComponent_EventData& evtData,
194 const AliHLTComponent_BlockData* blocks,
195 AliHLTComponent_TriggerData& /*trigData*/,
196 AliHLTUInt8_t* /*outputPtr*/,
197 AliHLTUInt32_t& /*size*/,
198 vector<AliHLTComponent_BlockData>& /*outputBlocks*/)
200 HLTDebug("NofBlocks %lu", evtData.fBlockCnt );
203 // Loop over all input blocks in the event
204 vector<AliHLTComponent_DataType> expectedDataTypes;
205 GetInputDataTypes(expectedDataTypes);
206 for ( unsigned long iBlock = 0; iBlock < evtData.fBlockCnt; iBlock++ )
208 const AliHLTComponentBlockData &block = blocks[iBlock];
209 AliHLTComponentDataType inputDataType = block.fDataType;
210 Bool_t correctDataType = kFALSE;
212 for(UInt_t i = 0; i < expectedDataTypes.size(); i++)
213 if( expectedDataTypes.at(i) == inputDataType)
214 correctDataType = kTRUE;
215 if (!correctDataType) {
216 HLTDebug( "Block # %i/%i; Event 0x%08LX (%Lu) Wrong received datatype: %s - Skipping",
217 iBlock, evtData.fBlockCnt,
218 evtData.fEventID, evtData.fEventID,
219 DataType2Text(inputDataType).c_str());
223 HLTDebug("We get the right data type: Block # %i/%i; Event 0x%08LX (%Lu) Received datatype: %s; Block Size: %i",
224 iBlock, evtData.fBlockCnt-1,
225 evtData.fEventID, evtData.fEventID,
226 DataType2Text(inputDataType).c_str(),
231 AliHLTTRDUtils::ReadTracks(fTracksArray, block.fPtr, block.fSize, &nTimeBins);
233 if(!fRecievedTimeBins){
234 HLTDebug("Reading number of time bins from input block. Value is: %d", nTimeBins);
235 fTRDCalibraFillHisto->Init2Dhistos(); // initialise the histos
236 fTRDCalibraFillHisto->SetNumberClusters(0); // At least 1 clusters
237 fTRDCalibraFillHisto->SetNumberClustersf(nTimeBins); // Not more than %d clusters
238 fRecievedTimeBins=kTRUE;
241 Int_t nbEntries = fTracksArray->GetEntries();
242 HLTDebug(" %i TRDtracks in tracksArray", nbEntries);
243 AliTRDtrackV1* trdTrack = 0x0;
244 for (Int_t i = 0; i < nbEntries; i++){
245 HLTDebug("%i/%i: ", i+1, nbEntries);
246 trdTrack = (AliTRDtrackV1*)fTracksArray->At(i);
248 fTRDCalibraFillHisto->UpdateHistogramsV1(trdTrack);
251 if(!fOutArray->At(0))FormOutput();
252 if (fNevent%feveryNevent==0 && fOutArray) {
253 PushBack(fOutArray, AliHLTTRDDefinitions::fgkCalibrationDataType);
256 fTracksArray->Delete();
265 * Form output array of histrograms
267 //============================================================================
268 void AliHLTTRDCalibrationComponent::FormOutput()
271 TH2I *hCH2d = fTRDCalibraFillHisto->GetCH2d();
272 fOutArray->Add(hCH2d);
274 // drift velocity histo
275 TProfile2D *hPH2d = fTRDCalibraFillHisto->GetPH2d();
276 fOutArray->Add(hPH2d);
279 TProfile2D *hPRF2d = fTRDCalibraFillHisto->GetPRF2d();
280 fOutArray->Add(hPRF2d);
282 HLTDebug("GetCH2d = 0x%x; NEntries = %i; size = %i", hCH2d, hCH2d->GetEntries(), sizeof(hCH2d));
284 HLTDebug("GetPH2d = 0x%x; NEntries = %i; size = %i", hPH2d, hPH2d->GetEntries(), sizeof(hPH2d));
286 HLTDebug("GetPRF2d = 0x%x; NEntries = %i; size = %i", hPRF2d, hPRF2d->GetEntries(), sizeof(hPRF2d));
288 HLTDebug("output Array: pointer = 0x%x; NEntries = %i; size = %i", fOutArray, fOutArray->GetEntries(), sizeof(fOutArray));
291 Int_t AliHLTTRDCalibrationComponent::ShipDataToFXS(const AliHLTComponentEventData& /*evtData*/, AliHLTComponentTriggerData& /*trigData*/)
293 //fTRDCalibraFillHisto->DestroyDebugStreamer();
294 PushToFXS((TObject*)fOutArray, "TRD", "GAINDRIFTPRF");