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 "AliHLTTRDTrack.h"
36 #include "AliCDBManager.h"
37 #include "AliTRDclusterizerHLT.h"
38 #include "AliRawReaderMemory.h"
39 #include "AliTRDCalibraFillHisto.h"
45 // this is a global object used for automatic component registration, do not use this
46 AliHLTTRDCalibrationComponent gAliHLTTRDCalibrationComponent;
48 ClassImp(AliHLTTRDCalibrationComponent);
50 AliHLTTRDCalibrationComponent::AliHLTTRDCalibrationComponent():
51 AliHLTCalibrationProcessor(),
52 fTRDCalibraFillHisto(NULL),
53 fUseHLTTracks(kFALSE),
54 fOutputPercentage(100), // By default we copy to the output exactly what we got as input
55 fStrorageDBpath("local://$ALICE_ROOT/OCDB"),
58 // Default constructor
61 AliHLTTRDCalibrationComponent::~AliHLTTRDCalibrationComponent()
67 const char* AliHLTTRDCalibrationComponent::GetComponentID()
69 // Return the component ID const char *
70 return "TRDCalibration"; // The ID of this component
73 void AliHLTTRDCalibrationComponent::GetInputDataTypes( vector<AliHLTComponent_DataType>& list)
75 // Get the list of input data
76 list.clear(); // We do not have any requirements for our input data type(s).
77 list.push_back( AliHLTTRDDefinitions::fgkTRDSATracksDataType );
80 AliHLTComponent_DataType AliHLTTRDCalibrationComponent::GetOutputDataType()
82 // Get the output data type
83 return AliHLTTRDDefinitions::fgkCalibrationDataType;
86 void AliHLTTRDCalibrationComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
88 // Get the output data size
90 inputMultiplier = ((double)fOutputPercentage)/100.0;
93 AliHLTComponent* AliHLTTRDCalibrationComponent::Spawn()
95 // Spawn function, return new instance of this class
96 return new AliHLTTRDCalibrationComponent;
99 Int_t AliHLTTRDCalibrationComponent::ScanArgument( int argc, const char** argv )
101 // perform initialization. We check whether our relative output size is specified in the arguments.
102 fOutputPercentage = 100;
107 HLTDebug("argv[%d] == %s", i, argv[i] );
108 if ( !strcmp( argv[i], "output_percentage" ) )
112 HLTError("Missing output_percentage parameter");
115 HLTDebug("argv[%d+1] == %s", i, argv[i+1] );
116 fOutputPercentage = strtoul( argv[i+1], &cpErr, 0 );
119 HLTError("Cannot convert output_percentage parameter '%s'", argv[i+1] );
122 HLTInfo("Output percentage set to %lu %%", fOutputPercentage );
126 else if ( strcmp( argv[i], "-cdb" ) == 0)
130 HLTError("Missing -cdb argument");
133 fStrorageDBpath = argv[i+1];
134 HLTInfo("DB storage is %s", fStrorageDBpath.c_str() );
138 else if ( strcmp( argv[i], "-useHLTTracks" ) == 0){
139 fUseHLTTracks = kTRUE;
141 HLTInfo("Expecting block of AliHLTTracks as input. Using low-level interface");
144 HLTError("Unknown option '%s'", argv[i] );
151 Int_t AliHLTTRDCalibrationComponent::InitCalibration()
153 //init the calibration
154 fCDB = AliCDBManager::Instance();
157 HLTError("Could not get CDB instance, fCDB 0x%x", fCDB);
161 fCDB->SetRun(0); // THIS HAS TO BE RETRIEVED !!!
162 fCDB->SetDefaultStorage(fStrorageDBpath.c_str());
163 HLTDebug("fCDB 0x%x", fCDB);
165 fTRDCalibraFillHisto = AliTRDCalibraFillHisto::Instance();
166 fTRDCalibraFillHisto->SetHisto2d(); // choose to use histograms
167 fTRDCalibraFillHisto->SetCH2dOn(); // choose to calibrate the gain
168 fTRDCalibraFillHisto->SetPH2dOn(); // choose to calibrate the drift velocity
169 fTRDCalibraFillHisto->SetPRF2dOn(); // choose to look at the PRF
170 fTRDCalibraFillHisto->Init2Dhistos(); // initialise the histos
174 Int_t AliHLTTRDCalibrationComponent::DeinitCalibration()
176 HLTDebug("DeinitCalibration");
178 // Deinitialization of the component
182 HLTDebug("destroy fCDB");
189 Int_t AliHLTTRDCalibrationComponent::ProcessCalibration(const AliHLTComponent_EventData& evtData,
190 const AliHLTComponent_BlockData* blocks,
191 AliHLTComponent_TriggerData& /*trigData*/,
192 AliHLTUInt8_t* /*outputPtr*/,
193 AliHLTUInt32_t& /*size*/,
194 vector<AliHLTComponent_BlockData>& /*outputBlocks*/)
197 // Logging( kHLTLogInfo, "HLT::TRDCalibration::ProcessCalibration", "Output percentage set", "Output percentage set to %lu %%", fOutputPercentage );
198 HLTDebug("NofBlocks %lu", evtData.fBlockCnt );
201 // Loop over all input blocks in the event
202 vector<AliHLTComponent_DataType> expectedDataTypes;
203 GetInputDataTypes(expectedDataTypes);
204 for ( unsigned long iBlock = 0; iBlock < evtData.fBlockCnt; iBlock++ )
206 const AliHLTComponentBlockData &block = blocks[iBlock];
207 AliHLTComponentDataType inputDataType = block.fDataType;
208 Bool_t correctDataType = kFALSE;
210 for(UInt_t i = 0; i < expectedDataTypes.size(); i++)
211 if( expectedDataTypes.at(i) == inputDataType)
212 correctDataType = kTRUE;
213 if (!correctDataType)
215 HLTDebug( "Block # %i/%i; Event 0x%08LX (%Lu) Wrong received datatype: %s - Skipping",
216 iBlock, evtData.fBlockCnt,
217 evtData.fEventID, evtData.fEventID,
218 DataType2Text(inputDataType).c_str());
222 HLTDebug("We get the right data type: Block # %i/%i; Event 0x%08LX (%Lu) Received datatype: %s",
223 iBlock, evtData.fBlockCnt-1,
224 evtData.fEventID, evtData.fEventID,
225 DataType2Text(inputDataType).c_str());
227 TClonesArray* tracksArray = NULL;
231 tracksArray = new TClonesArray("AliTRDtrackV1");
232 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());
233 ReadTracks(tracksArray, block.fPtr, block.fSize);
237 TObject *objIn = NULL;
239 objIn = (TObject *)GetFirstInputObject( AliHLTTRDDefinitions::fgkTRDSATracksDataType, "TClonesArray", ibForce);
241 objIn = (TObject *)GetNextInputObject( ibForce );
242 HLTDebug("1stBLOCK, Pointer = 0x%x", objIn);
244 tracksArray = (TClonesArray* )objIn;
250 Int_t nbEntries = tracksArray->GetEntries();
251 HLTDebug(" %i TRDtracks in tracksArray", nbEntries);
252 AliTRDtrackV1* trdTrack = 0x0;
253 for (Int_t i = 0; i < nbEntries; i++){
254 HLTDebug("%i/%i: ", i+1, nbEntries);
255 trdTrack = (AliTRDtrackV1*)tracksArray->At(i);
257 fTRDCalibraFillHisto->UpdateHistogramsV1(trdTrack);
262 TObjArray *outArray = FormOutput();
264 PushBack(outArray, AliHLTTRDDefinitions::fgkCalibrationDataType);
274 * Read track to the TClonesArray from the memory
276 //============================================================================
277 Int_t AliHLTTRDCalibrationComponent::ReadTracks(TClonesArray *outArray, void* inputPtr, AliHLTUInt32_t size)
279 AliHLTUInt8_t* iterPtr = (AliHLTUInt8_t* )inputPtr;
281 cout << "\nReading tracks from the Memory\n ============= \n";
282 AliHLTTRDTrack * hltTrack;
283 AliHLTUInt32_t trackSize = 0, curSize = 0;
286 while (curSize < size)
288 hltTrack = (AliHLTTRDTrack*) iterPtr;
289 HLTDebug("curSize %i, size %i",curSize, size);
291 trackSize = hltTrack->GetSize();
292 HLTDebug("GetSize() %i", trackSize);
294 hltTrack->ReadTrackletsFromMemory(iterPtr + sizeof(AliHLTTRDTrack));
296 AliTRDtrackV1* curTRDTrack = new((*outArray)[counter]) AliTRDtrackV1();
297 hltTrack->ExportTRDTrack(curTRDTrack);
299 curSize += trackSize;
300 iterPtr += trackSize;
304 //CheckTrackArray(outArray);
309 Int_t AliHLTTRDCalibrationComponent::ShipDataToFXS( const AliHLTComponentEventData& /*evtData*/, AliHLTComponentTriggerData& /*trigData*/)
311 // //Int_t PushToFXS(TObject* pObject, const char* pDetector, const char* pFileID, const char* pDDLNumber = "");
312 // //ireturn = PushToFXS(object, "TRD ", "TRDCalib", "1024 ");
314 TObjArray *outArray = FormOutput();
315 HLTDebug("Shipping data. Dummy. outputArray: pointer = 0x%x; NEntries = %i;", outArray, outArray->GetEntries());
316 Int_t ireturn = PushToFXS(outArray, "TRD ", "TRDCalib");
328 * Form output array of histrograms
330 //============================================================================
331 TObjArray* AliHLTTRDCalibrationComponent::FormOutput()
333 TObjArray *outArray=new TObjArray(3);
336 TH2I *hCH2d = fTRDCalibraFillHisto->GetCH2d();
337 outArray->Add(hCH2d);
339 // drift velocity histo
340 TProfile2D *hPH2d = fTRDCalibraFillHisto->GetPH2d();
341 outArray->Add(hPH2d);
344 TProfile2D *hPRF2d = fTRDCalibraFillHisto->GetPRF2d();
345 outArray->Add(hPRF2d);
347 HLTDebug("GetCH2d = 0x%x; NEntries = %i; size = %i", hCH2d, hCH2d->GetEntries(), sizeof(hCH2d));
349 HLTDebug("GetPH2d = 0x%x; NEntries = %i; size = %i", hPH2d, hPH2d->GetEntries(), sizeof(hPH2d));
351 HLTDebug("GetPRF2d = 0x%x; NEntries = %i; size = %i", hPRF2d, hPRF2d->GetEntries(), sizeof(hPRF2d));
353 HLTDebug("output Array: pointer = 0x%x; NEntries = %i; size = %i", outArray, outArray->GetEntries(), sizeof(outArray));