update by Gaute:
[u/mrichter/AliRoot.git] / HLT / ITS / AliHLTITSClusterFinderSPDComponent.cxx
CommitLineData
6e34b293 1// $Id$
5f2721d5 2//**************************************************************************
3//* This file is property of and copyright by the ALICE HLT Project *
4//* ALICE Experiment at CERN, All rights reserved. *
5//* *
6//* Primary Authors: Gaute Øvrebekk <st05886@alf.uib.no> *
7//* for The ALICE HLT Project. *
8//* *
9//* Permission to use, copy, modify and distribute this software and its *
10//* documentation strictly for non-commercial purposes is hereby granted *
11//* without fee, provided that the above copyright notice appears in all *
12//* copies and that both the copyright notice and this permission notice *
13//* appear in the supporting documentation. The authors make no claims *
14//* about the suitability of this software for any purpose. It is *
15//* provided "as is" without express or implied warranty. *
16//**************************************************************************
17
18/** @file AliHLTITSClusterFinderSPDComponent.cxx
19 @author Gaute Øvrebekk <st05886@alf.uib.no>
20 @date
21 @brief Component to run offline clusterfinder for SPD
22*/
23
24#if __GNUC__>= 3
25using namespace std;
26#endif
27
28#include "AliHLTITSClusterFinderSPDComponent.h"
29
30#include "AliCDBEntry.h"
31#include "AliCDBManager.h"
32#include "AliHLTDataTypes.h"
33#include "AliITSgeomTGeo.h"
34#include "AliITSRecPoint.h"
c0b68f8e 35#include "AliHLTITSSpacePointData.h"
36#include "AliHLTITSClusterDataFormat.h"
5f2721d5 37
38#include <cstdlib>
39#include <cerrno>
40#include "TString.h"
41#include "TObjString.h"
42#include <sys/time.h>
43
44/** ROOT macro for the implementation of ROOT specific class methods */
45ClassImp(AliHLTITSClusterFinderSPDComponent);
46
47AliHLTITSClusterFinderSPDComponent::AliHLTITSClusterFinderSPDComponent()
48 :
6e34b293 49 fNModules(240/*AliITSDetTypeRec::fgkDefaultNModulesSPD*/),
5f2721d5 50 fClusterFinder(NULL),
51 fRawReader(NULL),
52 fDettype(NULL),
53 fClusters(NULL),
5f2721d5 54 fgeom(NULL),
6e34b293 55 fgeomInit(NULL),
56 fSeg(NULL)
57{
5f2721d5 58 // see header file for class documentation
59 // or
60 // refer to README to build package
61 // or
62 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
6e34b293 63
64 // AliITSDetTypeRec::fgkDefaultNModulesSPD private for the moment
65// if (AliITSDetTypeRec::fgkDefaultNModulesSPD!=240) {
66// HLTWarning("Number of modules has changed (AliITSDetTypeRec::fgkDefaultNModulesSPD)");
67// }
5f2721d5 68}
69
70AliHLTITSClusterFinderSPDComponent::~AliHLTITSClusterFinderSPDComponent() {
71 // see header file for class documentation
72}
73
74// Public functions to implement AliHLTComponent's interface.
75// These functions are required for the registration process
76
77const char* AliHLTITSClusterFinderSPDComponent::GetComponentID()
78{
79 // see header file for class documentation
80
81 return "ITSClusterFinderSPD";
82}
83
84void AliHLTITSClusterFinderSPDComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list) {
85 // see header file for class documentation
86 list.clear();
87 list.push_back( kAliHLTDataTypeDDLRaw | kAliHLTDataOriginITSSPD );
88
89}
90
91AliHLTComponentDataType AliHLTITSClusterFinderSPDComponent::GetOutputDataType() {
92 // see header file for class documentation
c0b68f8e 93 return kAliHLTDataTypeClusters|kAliHLTDataOriginITSSSD;
5f2721d5 94}
95
96void AliHLTITSClusterFinderSPDComponent::GetOutputDataSize( unsigned long& constBase, double& inputMultiplier ) {
97 // see header file for class documentation
98
99 constBase = 0;
c0b68f8e 100 inputMultiplier = 1;
5f2721d5 101}
102
103AliHLTComponent* AliHLTITSClusterFinderSPDComponent::Spawn() {
104 // see header file for class documentation
105 return new AliHLTITSClusterFinderSPDComponent();
106}
107
108Int_t AliHLTITSClusterFinderSPDComponent::DoInit( int /*argc*/, const char** /*argv*/ ) {
109 // see header file for class documentation
110
111 if ( fClusterFinder )
112 return EINPROGRESS;
113
114 fClusters = new TClonesArray*[fNModules];
115 for (Int_t iModule = 0; iModule < fNModules; iModule++) {
116 fClusters[iModule] = NULL;
117 }
118
5f2721d5 119 //fgeomInit = new AliITSInitGeometry(kvSPD02,2);
120 fgeomInit = new AliITSInitGeometry(kvPPRasymmFMD,2);
121 fgeom = fgeomInit->CreateAliITSgeom();
122
123 //set dettype
124 fDettype = new AliITSDetTypeRec();
125 fDettype->SetITSgeom(fgeom);
6e34b293 126 fDettype->SetReconstructionModel(0,fClusterFinder);
127 fDettype->SetDefaultClusterFindersV2(kTRUE);
128 fDettype->GetCalibration();
129 fSeg = new AliITSsegmentationSSD();
130 fDettype->SetSegmentationModel(0,fSeg);
5f2721d5 131
132 fClusterFinder = new AliITSClusterFinderV2SPD(fDettype);
6e34b293 133 fClusterFinder->InitGeometry();
5f2721d5 134
135 if ( fRawReader )
136 return EINPROGRESS;
137
138 fRawReader = new AliRawReaderMemory();
139
140 return 0;
141}
142
143Int_t AliHLTITSClusterFinderSPDComponent::DoDeinit() {
144 // see header file for class documentation
145
146 if ( fRawReader )
147 delete fRawReader;
148 fRawReader = NULL;
149
150 if ( fClusterFinder )
151 delete fClusterFinder;
152 fClusterFinder = NULL;
153
6e34b293 154 if ( fDettype )
155 delete fDettype;
156 fDettype = NULL;
157
158 for (Int_t iModule = 0; iModule < fNModules; iModule++) {
159 if (fClusters[iModule]) delete fClusters[iModule];
160 fClusters[iModule] = NULL;
161 }
162
163 if ( fgeomInit )
164 delete fgeomInit;
165 fgeomInit = NULL;
166
5f2721d5 167 return 0;
168}
169
170Int_t AliHLTITSClusterFinderSPDComponent::DoEvent( const AliHLTComponentEventData& evtData, AliHLTComponentTriggerData& /*trigData*/)
171{ // see header file for class documentation
172
173 // -- Iterator over Data Blocks --
174 const AliHLTComponentBlockData* iter = NULL;
175
176 if(GetFirstInputBlock( kAliHLTDataTypeSOR ) || GetFirstInputBlock( kAliHLTDataTypeEOR )){
177 return 0;
178 }
179
180 if (!IsDataEvent()) return 0;
181
182 if ( evtData.fBlockCnt<=0 )
183 {
184 Logging( kHLTLogWarning, "HLT::ITSClusterFinderSPD::DoEvent", "DoEvent", "no blocks in event" );
185 return 0;
186 }
187
188 // -- Loop over blocks
189 for ( iter = GetFirstInputBlock(kAliHLTDataTypeDDLRaw | kAliHLTDataOriginITSSPD); iter != NULL; iter = GetNextInputBlock() ) {
190
191 // -- Debug output of datatype --
192 HLTDebug("Event 0x%08LX (%Lu) received datatype: %s - required datatype: %s",
193 evtData.fEventID, evtData.fEventID,
194 DataType2Text(iter->fDataType).c_str(),
195 DataType2Text(kAliHLTDataTypeDDLRaw | kAliHLTDataOriginITSSPD).c_str());
196
197 // -- Check for the correct data type
6e34b293 198 if ( iter->fDataType != (kAliHLTDataTypeDDLRaw | kAliHLTDataOriginITSSPD) )
5f2721d5 199 continue;
200
5f2721d5 201 // -- Get equipment ID out of specification
202 AliHLTUInt32_t spec = iter->fSpecification;
203
204 if(spec>0x00040000){
205 HLTDebug("The Spec is to high for ITS SPD");
206 }
207
208 Int_t id = 0;
6e34b293 209 for ( Int_t ii = 0; ii < 20 ; ii++ ) { //number of ddl's
5f2721d5 210 if ( spec & 0x00000001 ) {
211 id += ii;
212 break;
213 }
214 spec = spec >> 1 ;
215 }
216
217 // -- Set equipment ID to the raw reader
6e34b293 218
5f2721d5 219 if(!fRawReader->AddBuffer((UChar_t*) iter->fPtr, iter->fSize, id)){
220 HLTWarning("Could not add buffer");
221 }
222
223 fClusterFinder->RawdataToClusters(fRawReader,fClusters);
c0b68f8e 224
225 UInt_t nClusters=0;
5f2721d5 226 for(int i=0;i<fNModules;i++){
227 if(fClusters[i] != NULL){
c0b68f8e 228 nClusters += fClusters[i]->GetEntries();
5f2721d5 229 }
230 }
c0b68f8e 231
232 UInt_t bufferSize = nClusters * sizeof(AliHLTITSSpacePointData) + sizeof(AliHLTITSClusterData);
233 AliHLTUInt8_t *buffer = new AliHLTUInt8_t[bufferSize];
234 AliHLTITSClusterData *outputClusters = reinterpret_cast<AliHLTITSClusterData*>(buffer);
235 outputClusters->fSpacePointCnt=nClusters;
6e34b293 236
c0b68f8e 237 int clustIdx=0;
5f2721d5 238 for(int i=0;i<fNModules;i++){
239 if(fClusters[i] != NULL){
c0b68f8e 240 for(int j=0;j<fClusters[i]->GetEntries();j++){
241 AliITSRecPoint *recpoint = (AliITSRecPoint*) fClusters[i]->At(j);
242 outputClusters->fSpacePoints[clustIdx].fY=recpoint->GetY();
243 outputClusters->fSpacePoints[clustIdx].fZ=recpoint->GetZ();
244 outputClusters->fSpacePoints[clustIdx].fSigmaY2=recpoint->GetSigmaY2();
245 outputClusters->fSpacePoints[clustIdx].fSigmaZ2=recpoint->GetSigmaZ2();
246 outputClusters->fSpacePoints[clustIdx].fSigmaYZ=recpoint->GetSigmaYZ();
247 outputClusters->fSpacePoints[clustIdx].fQ=recpoint->GetQ();
248 outputClusters->fSpacePoints[clustIdx].fNy=recpoint->GetNy();
249 outputClusters->fSpacePoints[clustIdx].fNz=recpoint->GetNz();
250 outputClusters->fSpacePoints[clustIdx].fLayer=recpoint->GetLayer();
251 outputClusters->fSpacePoints[clustIdx].fIndex=recpoint->GetDetectorIndex();// | recpoint->GetPindex() | recpoint->GetNindex();
252 outputClusters->fSpacePoints[clustIdx].fTracks[0]=recpoint->GetLabel(0);
253 outputClusters->fSpacePoints[clustIdx].fTracks[1]=recpoint->GetLabel(1);
254 outputClusters->fSpacePoints[clustIdx].fTracks[2]=recpoint->GetLabel(2);
255
256 clustIdx++;
5f2721d5 257 }
6e34b293 258 }
259 }
5f2721d5 260
c0b68f8e 261 PushBack(buffer,bufferSize,kAliHLTDataTypeClusters|kAliHLTDataOriginITSSSD,iter->fSpecification);
262
6e34b293 263 for (Int_t iModule = 0; iModule < fNModules; iModule++) {
264 if(fClusters[iModule]){delete fClusters[iModule];}
5f2721d5 265 fClusters[iModule] = NULL;
266 }
6e34b293 267
5f2721d5 268 fRawReader->ClearBuffers();
269
270 } // for ( ndx = 0; ndx < evtData.fBlockCnt; ndx++ ) {
271
5f2721d5 272 return 0;
273}
c0b68f8e 274