Calibration component - beta implementation of AliHLTCalibrationProcessor for TRD...
[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
21 @date
22 @brief A TRDCalibration processing component for the HLT. */
23
24#if __GNUC__ >= 3
25using 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
35#include "AliCDBManager.h"
36#include "AliTRDclusterizerHLT.h"
37#include "AliRawReaderMemory.h"
38
39#include <cstdlib>
40#include <cerrno>
41#include <string>
42
43// this is a global object used for automatic component registration, do not use this
44AliHLTTRDCalibrationComponent gAliHLTTRDCalibrationComponent;
45
46ClassImp(AliHLTTRDCalibrationComponent);
47
48AliHLTTRDCalibrationComponent::AliHLTTRDCalibrationComponent()
49 : AliHLTCalibrationProcessor()
50 , fOutputPercentage(100) // By default we copy to the output exactly what we got as input
51 , fStrorageDBpath("local://$ALICE_ROOT")
52 , fCDB(NULL)
53{
54 // Default constructor
55}
56
57AliHLTTRDCalibrationComponent::~AliHLTTRDCalibrationComponent()
58{
59 // Destructor
60 ;
61}
62
63const char* AliHLTTRDCalibrationComponent::GetComponentID()
64{
65 // Return the component ID const char *
66 return "TRDCalibration"; // The ID of this component
67}
68
69void AliHLTTRDCalibrationComponent::GetInputDataTypes( vector<AliHLTComponent_DataType>& list)
70{
71 // Get the list of input data
72 list.clear(); // We do not have any requirements for our input data type(s).
73 list.push_back( AliHLTTRDDefinitions::fgkTRDSATracksDataType );
74}
75
76AliHLTComponent_DataType AliHLTTRDCalibrationComponent::GetOutputDataType()
77{
78 // Get the output data type
79 return AliHLTTRDDefinitions::fgkCalibrationDataType;
80}
81
82void AliHLTTRDCalibrationComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier )
83{
84 // Get the output data size
85 constBase = 0;
86 inputMultiplier = ((double)fOutputPercentage)/100.0;
87}
88
89AliHLTComponent* AliHLTTRDCalibrationComponent::Spawn()
90{
91 // Spawn function, return new instance of this class
92 return new AliHLTTRDCalibrationComponent;
93};
94
95Int_t AliHLTTRDCalibrationComponent::ScanArgument( int argc, const char** argv )
96{
97 // perform initialization. We check whether our relative output size is specified in the arguments.
98 fOutputPercentage = 100;
99 int i = 0;
100 char* cpErr;
101 while ( i < argc )
102 {
103 Logging( kHLTLogDebug, "HLT::TRDCalibration::ScanArgument", "Arguments", "argv[%d] == %s", i, argv[i] );
104 if ( !strcmp( argv[i], "output_percentage" ) )
105 {
106 if ( i+1>=argc )
107 {
108 Logging(kHLTLogError, "HLT::TRDCalibration::ScanArgument", "Missing Argument", "Missing output_percentage parameter");
109 return ENOTSUP;
110 }
111 Logging( kHLTLogDebug, "HLT::TRDCalibration::ScanArgument", "Arguments", "argv[%d+1] == %s", i, argv[i+1] );
112 fOutputPercentage = strtoul( argv[i+1], &cpErr, 0 );
113 if ( *cpErr )
114 {
115 Logging(kHLTLogError, "HLT::TRDCalibration::ScanArgument", "Wrong Argument", "Cannot convert output_percentage parameter '%s'", argv[i+1] );
116 return EINVAL;
117 }
118 Logging( kHLTLogInfo, "HLT::TRDCalibration::ScanArgument", "Output percentage set", "Output percentage set to %lu %%", fOutputPercentage );
119 i += 2;
120 continue;
121 }
122
123 if ( strcmp( argv[i], "-cdb" ) == 0)
124 {
125 if ( i+1 >= argc )
126 {
127 Logging(kHLTLogError, "HLT::TRDCalibration::ScanArgument", "Missing Argument", "Missing -cdb argument");
128 return ENOTSUP;
129 }
130 fStrorageDBpath = argv[i+1];
131 Logging( kHLTLogInfo, "HLT::TRDCalibration::ScanArgument", "DB storage set", "DB storage is %s", fStrorageDBpath.c_str() );
132 i += 2;
133 continue;
134 }
135
136 Logging(kHLTLogError, "HLT::TRDCalibration::ScanArgument", "Unknown Option", "Unknown option '%s'", argv[i] );
137 return EINVAL;
138 }
139 return 0;
140}
141
142Int_t AliHLTTRDCalibrationComponent::InitCalibration()
143{
144 //init the calibration
145 fCDB = AliCDBManager::Instance();
146 if (!fCDB)
147 {
148 Logging(kHLTLogError, "HLT::TRDCalibration::InitCalibration", "Could not get CDB instance", "fCDB 0x%x", fCDB);
149 }
150 else
151 {
152 fCDB->SetRun(0); // THIS HAS TO BE RETRIEVED !!!
153 fCDB->SetDefaultStorage(fStrorageDBpath.c_str());
154 Logging(kHLTLogDebug, "HLT::TRDCalibration::InitCalibration", "CDB instance", "fCDB 0x%x", fCDB);
155 }
156
157}
158
159Int_t AliHLTTRDCalibrationComponent::DeinitCalibration()
160{
161 // Deinitialization of the component
162 if (fCDB)
163 {
164 Logging( kHLTLogDebug, "HLT::TRDCalibration::DeinitCalibration", "destroy", "fCDB");
165 fCDB->Destroy();
166 fCDB = 0;
167 }
168}
169
170Int_t AliHLTTRDCalibrationComponent::ProcessCalibration( const AliHLTComponentEventData& evtData, AliHLTComponentTriggerData& trigData)
171{
172 // Process an event
173// Logging( kHLTLogInfo, "HLT::TRDCalibration::ProcessCalibration", "Output percentage set", "Output percentage set to %lu %%", fOutputPercentage );
174 Logging( kHLTLogDebug, "HLT::TRDCalibration::ProcessCalibration", "BLOCKS", "NofBlocks %lu", evtData.fBlockCnt );
175 // Process an event
176 unsigned long totalSize = 0;
177
178 //implement a usage of the following
179// AliHLTUInt32_t triggerDataStructSize = trigData.fStructSize;
180// AliHLTUInt32_t triggerDataSize = trigData.fDataSize;
181// void *triggerData = trigData.fData;
182 Logging( kHLTLogDebug, "HLT::TRDCalibration::ProcessCalibration", "Trigger data received",
183 "Struct size %d Data size %d Data location 0x%x", trigData.fStructSize, trigData.fDataSize, (UInt_t*)trigData.fData);
184
185 // Loop over all input blocks in the event
186 int ibForce = 0;
187 TObject *tobjin = (TObject *)GetFirstInputObject( AliHLTTRDDefinitions::fgkTRDSATracksDataType, "AliTRDtrack", ibForce);
188 Logging( kHLTLogInfo, "HLT::TRDCalibration::ProcessCalibration", "1stBLOCK", "Pointer = 0x%x", tobjin);
189 while (tobjin)
190 {
191 tobjin = (TObject *)GetNextInputObject( ibForce );
192 Logging( kHLTLogInfo, "HLT::TRDCalibration::ProcessCalibration", "nextBLOCK", "Pointer = 0x%x", tobjin);
193 }
194
195 return 0;
196}
197
198Int_t AliHLTTRDCalibrationComponent::ShipDataToFXS( const AliHLTComponentEventData& evtData, AliHLTComponentTriggerData& trigData)
199{
200 //Int_t PushToFXS(TObject* pObject, const char* pDetector, const char* pFileID, const char* pDDLNumber = "");
201 //ireturn = PushToFXS(object, "TRD ", "TRDCalib", "1024 ");
202 Logging( kHLTLogDebug, "HLT::TRDCalibration::ProcessCalibration", "Shipping data",
203 "Nothing serious");
204 Int_t ireturn = 0;
205 return ireturn;
206}