adding access interface for HLT TPC clusters to be used from the TPCreconstruction
[u/mrichter/AliRoot.git] / HLT / TPCLib / AliHLTTPCClusterAccessHLTOUT.cxx
CommitLineData
c54aa300 1// $Id$
2
3//**************************************************************************
4//* This file is property of and copyright by the ALICE HLT Project *
5//* ALICE Experiment at CERN, All rights reserved. *
6//* *
7//* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8//* for The ALICE HLT 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 AliHLTTPCClusterAccessHLTOUT.h
20/// @author Matthias Richter
21/// @date 2011-06-06
22/// @brief Interface to HLT TPC clusters
23///
24
25#include "AliHLTTPCClusterAccessHLTOUT.h"
26#include "AliHLTTPCDefinitions.h"
27#include "AliHLTTPCClusterDataFormat.h"
28#include "AliHLTOUT.h"
29#include "AliLog.h"
30#include "AliHLTSystem.h"
31#include "AliHLTPluginBase.h"
32#include "AliTPCclusterMI.h"
33#include "TClonesArray.h"
34
35/** ROOT macro for the implementation of ROOT specific class methods */
36ClassImp(AliHLTTPCClusterAccessHLTOUT)
37
38AliHLTTPCClusterAccessHLTOUT::AliHLTTPCClusterAccessHLTOUT()
39 : TObject()
40 , fClusters(NULL)
41{
42 // see header file for class documentation
43 // or
44 // refer to README to build package
45 // or
46 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
47}
48
49AliHLTTPCClusterAccessHLTOUT::~AliHLTTPCClusterAccessHLTOUT()
50{
51 // destructor
52 if (fClusters) {
53 fClusters->Clear();
54 delete fClusters;
55 fClusters=NULL;
56 }
57}
58
59void AliHLTTPCClusterAccessHLTOUT::Execute(const char *method, const char */*params*/, Int_t *error)
60{
61 /// inherited from TObject: abstract command interface
62 if (strcmp(method, "read")==0) {
63 int iResult=ProcessClusters();
64 if (error) *error=iResult;
65 return;
66 }
67}
68
69TObject* AliHLTTPCClusterAccessHLTOUT::FindObject(const char *name) const
70{
71 /// inherited from TObject: return the cluster array if name id "clusterarray"
72 if (strcmp(name, "clusterarray")==0) return fClusters;
73 return TObject::FindObject(name);
74}
75
76void AliHLTTPCClusterAccessHLTOUT::Clear(Option_t * /*option*/)
77{
78 /// inherited from TObject: cleanup
79 if (fClusters) fClusters->Clear();
80}
81
82void AliHLTTPCClusterAccessHLTOUT::Print(Option_t */*option*/) const
83{
84 /// inherited from TObject
85 if (!fClusters) return;
86 for (int i=0; i<fClusters->GetEntriesFast(); i++) {
87 if (!fClusters->At(i)) continue;
88 AliTPCclusterMI* pCluster=dynamic_cast<AliTPCclusterMI*>(fClusters->At(i));
89 if (!pCluster) break;
90 cout << "AliTPCclusterMI:"
91 << " row=" << pCluster->GetRow()
92 << " pad=" << pCluster->GetPad()
93 << " time=" << pCluster->GetTimeBin()
94 << " charge=" << pCluster->GetQ()
95 << " maxq=" << pCluster->GetMax()
96 << endl;
97 }
98}
99
100int AliHLTTPCClusterAccessHLTOUT::ProcessClusters()
101{
102 /// process the cluster data from HLTOUT and fill array
103 /// the cluster data can be in many different formats, e.g.
104 /// raw or compressed
105 int iResult=0;
106 if (!fClusters) {
107 fClusters=new TClonesArray("AliTPCclusterMI");
108 }
109 if (!fClusters) return -ENOMEM;
110
111 AliHLTSystem* pSystem=AliHLTPluginBase::GetInstance();
112 if (!pSystem) {
113 AliError("can not access HLT system");
114 return -ENODEV;
115 }
116 AliHLTOUT* pHLTOUT=pSystem->RequestHLTOUT();
117 if (!pHLTOUT) {
118 AliError("can not access HLTOUT");
119 return -ENODEV;
120 }
121
122 if (pHLTOUT->SelectFirstDataBlock(AliHLTTPCDefinitions::fgkClustersDataType)>=0) {
123 iResult=ReadAliHLTTPCClusterData(pHLTOUT, fClusters);
124 }
125
126 pSystem->ReleaseHLTOUT(pHLTOUT);
127 return iResult;
128}
129
130int AliHLTTPCClusterAccessHLTOUT::ReadAliHLTTPCClusterData(AliHLTOUT* pHLTOUT, TClonesArray* pClusters) const
131{
132 // read cluster data from AliHLTTPCClusterData
133 int iResult=0;
134 if (!pHLTOUT || !pClusters) return -EINVAL;
135 do {
136 const AliHLTUInt8_t* pBuffer=NULL;
137 AliHLTUInt32_t size=0;
138 if ((iResult=pHLTOUT->GetDataBuffer(pBuffer, size))<0) {
139 continue;
140 }
141 if (pBuffer==NULL || size<4) {
142 AliError("invalid cluster data block");
143 continue;
144 }
145 const AliHLTTPCClusterData* clusterData = reinterpret_cast<const AliHLTTPCClusterData*>(pBuffer);
146 Int_t nSpacepoints = (Int_t) clusterData->fSpacePointCnt;
147 if (nSpacepoints*sizeof(AliHLTTPCSpacePointData) + sizeof(AliHLTTPCClusterData) != size) {
148 AliError("inconsistent cluster data block size, skipping block");
149 continue;
150 }
151 const AliHLTTPCSpacePointData *clusters = clusterData->fSpacePoints;
152 int offset=fClusters->GetEntries();
153 fClusters->ExpandCreate(offset+nSpacepoints);
154 for (int i=0; i<nSpacepoints; i++) {
155 if (!fClusters->At(offset+i)) continue;
156 AliTPCclusterMI* pCluster=dynamic_cast<AliTPCclusterMI*>(fClusters->At(offset+i));
157 if (!pCluster) {
158 AliError("invalid object type, expecting AliTPCclusterMI");
159 break; // this is a problem of all objects
160 }
161 pCluster->SetRow(clusters[i].fPadRow);
162 pCluster->SetTimeBin(clusters[i].fZ);
163 pCluster->SetPad(clusters[i].fX);
164 pCluster->SetQ(clusters[i].fCharge);
165 pCluster->SetMax(clusters[i].fQMax);
166 }
167 AliInfo(Form("converted %d cluster(s)", nSpacepoints));
168 } while (pHLTOUT->SelectNextDataBlock()>=0);
169 return iResult;
170}