3 //**************************************************************************
4 //* This file is property of and copyright by the ALICE HLT Project *
5 //* ALICE Experiment at CERN, All rights reserved. *
7 //* Primary Authors: Matthias Richter <Matthias.Richter@ift.uib.no> *
8 //* for The ALICE HLT 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 AliHLTTPCRawSpacePointContainer.cxx
20 /// @author Matthias Richter, Sergey Gorbunov
22 /// @brief Helper class for handling of HLT TPC raw cluster data blocks
24 #include "AliHLTTPCRawSpacePointContainer.h"
25 #include "AliHLTErrorGuard.h"
26 #include "AliHLTTPCDefinitions.h"
27 #include "AliHLTTPCSpacePointData.h"
28 #include "AliHLTTPCRawCluster.h"
29 #include "AliHLTTPCTransform.h"
30 #include "AliHLTComponent.h"
31 #include "AliHLTTemplates.h"
32 #include "AliHLTDataDeflater.h"
43 /** ROOT macro for the implementation of ROOT specific class methods */
44 ClassImp(AliHLTTPCRawSpacePointContainer)
46 AliHLTTPCRawSpacePointContainer::AliHLTTPCRawSpacePointContainer(int mode)
47 : AliHLTSpacePointContainer()
53 , fWrittenClusterIds(NULL)
55 // see header file for class documentation
57 // refer to README to build package
59 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
60 if (fMode&kModeSingle) {
61 fSingleBlock.SetDecoder(NULL);
62 fSingleBlock.SetGrid(AllocateIndexGrid());
66 AliHLTTPCRawSpacePointContainer::AliHLTTPCRawSpacePointContainer(const AliHLTTPCRawSpacePointContainer& c)
67 : AliHLTSpacePointContainer(c)
68 , fClusters(c.fClusters.begin(), c.fClusters.end())
73 , fWrittenClusterIds(NULL)
78 AliHLTTPCRawSpacePointContainer& AliHLTTPCRawSpacePointContainer::operator=(const AliHLTTPCRawSpacePointContainer& c)
80 /// assignment operator
81 if (&c==this) return *this;
82 AliHLTSpacePointContainer::operator=(c);
83 fClusters=c.fClusters;
85 fWrittenClusterIds=NULL;
90 AliHLTTPCRawSpacePointContainer::~AliHLTTPCRawSpacePointContainer()
94 if (fSingleBlock.GetGrid()) delete fSingleBlock.GetGrid();
95 if (fWrittenClusterIds) delete fWrittenClusterIds;
98 int AliHLTTPCRawSpacePointContainer::AddInputBlock(const AliHLTComponentBlockData* pDesc)
100 // add input block to the collection
101 if (!pDesc) return -EINVAL;
104 if (pDesc->fDataType!=AliHLTTPCDefinitions::fgkRawClustersDataType) {
105 HLTWarning("ignoring data block of type %s", AliHLTComponent::DataType2Text(pDesc->fDataType).c_str());
108 if (!pDesc->fPtr) return -ENODATA;
109 if (pDesc->fSize<sizeof(AliHLTTPCRawClusterData)) return 0;
111 AliHLTTPCRawClusterData* rawClusters = (AliHLTTPCRawClusterData*)(pDesc->fPtr);
113 AliHLTUInt8_t slice = AliHLTTPCDefinitions::GetMinSliceNr( pDesc->fSpecification );
114 AliHLTUInt8_t part = AliHLTTPCDefinitions::GetMinPatchNr( pDesc->fSpecification );
116 AliHLTUInt32_t decoderIndex=AliHLTTPCSpacePointData::GetID(slice, part, 0);
118 AliHLTSpacePointPropertyGrid* pGrid=NULL;
119 if (fMode&kModeSingle) {
120 pGrid=fSingleBlock.GetGrid();
122 if (fBlocks.find(decoderIndex)!=fBlocks.end()) {
123 HLTError("data block of slice %d partition %d already added, skipping data block", slice, part);
128 if (fMode&kModeSingle && !pGrid) {
129 pGrid=AllocateIndexGrid();
135 if (fMode&kModeCreateMap) { // register immediately
137 //UInt_t nofClusters=rawClusters->fCount;
139 for( UInt_t icl=0; icl<rawClusters->fCount; icl++){
140 const AliHLTTPCRawCluster &cl = rawClusters->fClusters[icl];
141 AliHLTUInt32_t clusterID=~(AliHLTUInt32_t)0;
142 // cluster ID from slice, partition and index
143 clusterID=AliHLTTPCSpacePointData::GetID(slice, part, icl);
145 if (fClusters.find(clusterID)==fClusters.end()) {
147 fClusters[clusterID]=AliHLTTPCRawSpacePointProperties(&cl);
150 HLTError("cluster with ID 0x%08x already existing, skipping cluster %d of data block 0x%08x",
151 clusterID, icl, pDesc->fSpecification);
156 if (pGrid && (iResult=PopulateAccessGrid(pGrid, rawClusters, slice, part))<0) {
157 HLTError("failed to populate access grid for block %s 0x%09x: %d",
158 AliHLTComponent::DataType2Text(pDesc->fDataType).c_str(), pDesc->fSpecification, iResult);
162 if (fMode&kModeSingle) {
163 fSingleBlock.SetDecoder(rawClusters);
164 fSingleBlock.SetGrid(pGrid);
165 fSingleBlock.SetId(decoderIndex);
167 fBlocks[decoderIndex]=AliHLTTPCRawSpacePointBlock(decoderIndex, rawClusters, pGrid);
172 AliHLTSpacePointContainer::AliHLTSpacePointPropertyGrid* AliHLTTPCRawSpacePointContainer::AllocateIndexGrid()
174 // allocate index grid, one single point to define the dimensions
176 // max 33 padrows, step 1 padrow
177 // max 140 pads, step 2x max delta pad
178 // max 1024 time bins, step 2x max delta time
179 return new AliHLTSpacePointPropertyGrid(33, 1.0,
180 140, 2*AliHLTTPCDefinitions::GetMaxClusterDeltaPad(),
181 1024, 2*AliHLTTPCDefinitions::GetMaxClusterDeltaTime()
185 int AliHLTTPCRawSpacePointContainer::PopulateAccessGrid(AliHLTSpacePointPropertyGrid* pGrid, AliHLTUInt32_t mask) const
187 // populate an access grid
188 if (!pGrid) return -EINVAL;
192 AliHLTUInt8_t slice = AliHLTTPCDefinitions::GetMinSliceNr(mask);
193 AliHLTUInt8_t partition = AliHLTTPCDefinitions::GetMinPatchNr(mask);
194 AliHLTUInt32_t decoderIndex=AliHLTTPCSpacePointData::GetID(slice, partition, 0);
195 std::map<AliHLTUInt32_t, AliHLTTPCRawSpacePointBlock>::const_iterator block=fBlocks.find(decoderIndex);
196 if (block==fBlocks.end()) {
197 HLTError("can not find data block of id 0x%08x", mask);
200 return PopulateAccessGrid(pGrid, block->second.GetDecoder(), slice, partition);
203 int AliHLTTPCRawSpacePointContainer::PopulateAccessGrid(AliHLTSpacePointPropertyGrid* pGrid, AliHLTTPCRawClusterData* pDecoder,
204 int slice, int partition) const
206 // populate an access grid
207 if (!pDecoder) return -EINVAL;
210 for( UInt_t icl=0; icl<pDecoder->fCount; icl++){
211 const AliHLTTPCRawCluster &cl = pDecoder->fClusters[icl];
212 iResult=pGrid->CountSpacePoint(cl.GetPadRow(), cl.GetPad(), cl.GetTime());
214 HLTError("CountSpacePoint %f %f %f failed: %d", cl.GetPadRow(), cl.GetPad(), cl.GetTime(), iResult);
217 for( UInt_t icl=0; icl<pDecoder->fCount; icl++ ){
218 const AliHLTTPCRawCluster &cl = pDecoder->fClusters[icl];
219 AliHLTUInt32_t id=AliHLTTPCSpacePointData::GetID(slice, partition, icl);
220 iResult=pGrid->AddSpacePoint(AliHLTSpacePointProperties(id), cl.GetPadRow(), cl.GetPad(), cl.GetTime());
222 HLTError("AddSpacePoint 0x%08x %f %f %f failed: %d", id, cl.GetPadRow(), cl.GetPad(), cl.GetTime(), iResult);
228 const AliHLTSpacePointContainer::AliHLTSpacePointPropertyGrid* AliHLTTPCRawSpacePointContainer::GetSpacePointPropertyGrid(AliHLTUInt32_t mask) const
230 // get the access grid for a data block
231 AliHLTUInt8_t slice = AliHLTTPCDefinitions::GetMinSliceNr(mask);
232 AliHLTUInt8_t part = AliHLTTPCDefinitions::GetMinPatchNr(mask);
233 AliHLTUInt32_t decoderIndex=AliHLTTPCSpacePointData::GetID(slice, part, 0);
234 std::map<AliHLTUInt32_t, AliHLTTPCRawSpacePointBlock>::const_iterator block=fBlocks.find(decoderIndex);
235 if (block==fBlocks.end()) {
236 HLTError("can not find data block of id 0x%08x", mask);
239 return block->second.GetGrid();
242 int AliHLTTPCRawSpacePointContainer::SetSpacePointPropertyGrid(AliHLTUInt32_t mask, AliHLTSpacePointContainer::AliHLTSpacePointPropertyGrid* pGrid)
244 // set the access grid for a data block
245 AliHLTUInt8_t slice = AliHLTTPCDefinitions::GetMinSliceNr(mask);
246 AliHLTUInt8_t part = AliHLTTPCDefinitions::GetMinPatchNr(mask);
247 AliHLTUInt32_t decoderIndex=AliHLTTPCSpacePointData::GetID(slice, part, 0);
248 std::map<AliHLTUInt32_t, AliHLTTPCRawSpacePointBlock>::iterator block=fBlocks.find(decoderIndex);
249 if (block==fBlocks.end()) {
250 HLTError("can not find data block of id 0x%08x", mask);
253 if (block->second.GetGrid()!=NULL && pGrid!=NULL && block->second.GetGrid()!=pGrid) {
254 // there is trouble ahead because this will delete the index grid instance
255 // but it might be an external pointer supposed to be deleted by someone else
256 ALIHLTERRORGUARD(1, "overriding previous instance of index grid, potential memory leak or invalid deallocation ahead");
258 block->second.SetGrid(pGrid);
262 int AliHLTTPCRawSpacePointContainer::GetClusterIDs(vector<AliHLTUInt32_t>& tgt) const
264 // get array of cluster IDs
266 transform(fClusters.begin(), fClusters.end(), back_inserter(tgt), HLT::AliGetKey());
270 bool AliHLTTPCRawSpacePointContainer::Check(AliHLTUInt32_t clusterID) const
272 // check if the cluster is available
273 return fClusters.find(clusterID)!=fClusters.end();
276 const vector<AliHLTUInt32_t>* AliHLTTPCRawSpacePointContainer::GetClusterIDs(AliHLTUInt32_t mask)
278 // get array of cluster IDs filtered by mask
279 if (fSelections.find(mask)!=fSelections.end()) {
280 // return existing selection
281 return fSelections.find(mask)->second;
283 // create new collection
284 vector<AliHLTUInt32_t>* selected=new vector<AliHLTUInt32_t>;
285 if (!selected) return NULL;
286 UInt_t slice=AliHLTTPCSpacePointData::GetSlice(mask);
287 UInt_t partition=AliHLTTPCSpacePointData::GetPatch(mask);
288 //HLTInfo("creating collection 0x%08x", mask);
290 // the first cluster with number 0 has equal ID to mask unless
291 // the mask selects multiple partitions/slices
292 std::map<AliHLTUInt32_t, AliHLTTPCRawSpacePointProperties>::const_iterator cl=fClusters.find(mask);
294 if (slice>=(unsigned)AliHLTTPCTransform::GetNSlice() ||
295 partition>=(unsigned)AliHLTTPCTransform::GetNumberOfPatches()) {
296 cl=fClusters.begin();
299 for (; cl!=fClusters.end(); cl++) {
300 UInt_t s=AliHLTTPCSpacePointData::GetSlice(cl->first);
301 UInt_t p=AliHLTTPCSpacePointData::GetPatch(cl->first);
302 if ((slice>=(unsigned)AliHLTTPCTransform::GetNSlice() || s==slice) &&
303 (partition>=(unsigned)AliHLTTPCTransform::GetNumberOfPatches() || p==partition)) {
304 selected->push_back(cl->first);
306 // no need to continue, we are out of the range
310 //HLTInfo("collection 0x%08x with %d spacepoints", mask, selected->size());
311 fSelections[mask]=selected;
315 float AliHLTTPCRawSpacePointContainer::GetX(AliHLTUInt32_t clusterID) const
318 std::map<AliHLTUInt32_t, AliHLTTPCRawSpacePointProperties>::const_iterator cl=fClusters.find(clusterID);
319 if (cl==fClusters.end() ||
320 cl->second.GetCluster()==NULL) return 0.0;
321 // FIXME: understand deviation from the nominal x value
322 // there is a small deviation in the x coordinate - padrow number correlation
323 // in principle, the clusterfinder only uses the mapping to set the x parameter.
324 // now extracting the x value from the padrow no.
325 //return cl->second.Decoder()->fX;
326 return cl->second.GetCluster()->GetPadRow();
329 float AliHLTTPCRawSpacePointContainer::GetXWidth(AliHLTUInt32_t clusterID) const
331 // get error for X coordinate
332 std::map<AliHLTUInt32_t, AliHLTTPCRawSpacePointProperties>::const_iterator cl=fClusters.find(clusterID);
333 if (cl==fClusters.end() ||
334 cl->second.GetCluster()==NULL) return 0.0;
335 return 0.0; // fixed in padrow number
338 float AliHLTTPCRawSpacePointContainer::GetY(AliHLTUInt32_t clusterID) const
341 std::map<AliHLTUInt32_t, AliHLTTPCRawSpacePointProperties>::const_iterator cl=fClusters.find(clusterID);
342 if (cl==fClusters.end() ||
343 cl->second.GetCluster()==NULL) return 0.0;
344 return cl->second.GetCluster()->GetPad();
347 float AliHLTTPCRawSpacePointContainer::GetYWidth(AliHLTUInt32_t clusterID) const
349 // get error for Y coordinate
350 std::map<AliHLTUInt32_t, AliHLTTPCRawSpacePointProperties>::const_iterator cl=fClusters.find(clusterID);
351 if (cl==fClusters.end() ||
352 cl->second.GetCluster()==NULL) return 0.0;
353 return cl->second.GetCluster()->GetSigmaY2();
356 float AliHLTTPCRawSpacePointContainer::GetZ(AliHLTUInt32_t clusterID) const
359 std::map<AliHLTUInt32_t, AliHLTTPCRawSpacePointProperties>::const_iterator cl=fClusters.find(clusterID);
360 if (cl==fClusters.end() ||
361 cl->second.GetCluster()==NULL) return 0.0;
362 return cl->second.GetCluster()->GetTime();
365 float AliHLTTPCRawSpacePointContainer::GetZWidth(AliHLTUInt32_t clusterID) const
367 // get error for Z coordinate
368 std::map<AliHLTUInt32_t, AliHLTTPCRawSpacePointProperties>::const_iterator cl=fClusters.find(clusterID);
369 if (cl==fClusters.end() ||
370 cl->second.GetCluster()==NULL) return 0.0;
371 return cl->second.GetCluster()->GetSigmaZ2();
374 float AliHLTTPCRawSpacePointContainer::GetCharge(AliHLTUInt32_t clusterID) const
377 std::map<AliHLTUInt32_t, AliHLTTPCRawSpacePointProperties>::const_iterator cl=fClusters.find(clusterID);
378 if (cl==fClusters.end() ||
379 cl->second.GetCluster()==NULL) return 0.0;
380 return cl->second.GetCluster()->GetCharge();
383 float AliHLTTPCRawSpacePointContainer::GetQMax(AliHLTUInt32_t clusterID) const
386 std::map<AliHLTUInt32_t, AliHLTTPCRawSpacePointProperties>::const_iterator cl=fClusters.find(clusterID);
387 if (cl==fClusters.end() ||
388 cl->second.GetCluster()==NULL) return 0.0;
389 return cl->second.GetCluster()->GetQMax();
392 float AliHLTTPCRawSpacePointContainer::GetPhi(AliHLTUInt32_t clusterID) const
396 // phi can be derived directly from the id, no need to search
397 // for existing cluster
398 int slice=AliHLTTPCSpacePointData::GetSlice(clusterID);
399 return ( slice + 0.5 ) * TMath::Pi() / 9.0;
402 void AliHLTTPCRawSpacePointContainer::Clear(Option_t * option)
404 // clear the object and reset pointer references
407 for (std::map<AliHLTUInt32_t, vector<AliHLTUInt32_t>*>::iterator selection=fSelections.begin();
408 selection!=fSelections.end(); selection++) {
409 if (selection->second) delete selection->second;
413 for (std::map<AliHLTUInt32_t, AliHLTTPCRawSpacePointBlock>::iterator block=fBlocks.begin();
414 block!=fBlocks.end(); block++) {
415 if (block->second.GetGrid()) delete block->second.GetGrid();
419 fSingleBlock.SetDecoder(NULL);
420 if (fSingleBlock.GetGrid()) fSingleBlock.GetGrid()->Clear();
422 AliHLTSpacePointContainer::Clear(option);
425 void AliHLTTPCRawSpacePointContainer::Print(ostream& out, Option_t */*option*/) const
428 std::stringstream str;
429 str << "AliHLTTPCRawSpacePointContainer::Print" << endl;
430 str << "n clusters: " << fClusters.size() << endl;
431 for (std::map<AliHLTUInt32_t, AliHLTTPCRawSpacePointProperties>::const_iterator cl=fClusters.begin();
432 cl!=fClusters.end(); cl++) {
433 str << " 0x" << hex << setw(8) << setfill('0') << cl->first << dec << cl->second << endl;
438 AliHLTSpacePointContainer* AliHLTTPCRawSpacePointContainer::SelectByMask(AliHLTUInt32_t mask, bool /*bAlloc*/) const
440 /// create a collection of clusters for a space point mask
441 std::auto_ptr<AliHLTTPCRawSpacePointContainer> c(new AliHLTTPCRawSpacePointContainer);
442 if (!c.get()) return NULL;
444 UInt_t slice=AliHLTTPCSpacePointData::GetSlice(mask);
445 UInt_t partition=AliHLTTPCSpacePointData::GetPatch(mask);
446 for (std::map<AliHLTUInt32_t, AliHLTTPCRawSpacePointProperties>::const_iterator cl=fClusters.begin();
447 cl!=fClusters.end(); cl++) {
448 UInt_t s=AliHLTTPCSpacePointData::GetSlice(cl->first);
449 UInt_t p=AliHLTTPCSpacePointData::GetPatch(cl->first);
450 if ((slice>=(unsigned)AliHLTTPCTransform::GetNSlice() || s==slice) &&
451 (partition>=(unsigned)AliHLTTPCTransform::GetNumberOfPatches() || p==partition)) {
452 c->fClusters[cl->first]=cl->second;
458 AliHLTSpacePointContainer* AliHLTTPCRawSpacePointContainer::SelectByTrack(int trackId, bool /*bAlloc*/) const
460 /// create a collection of clusters for a specific track
461 std::auto_ptr<AliHLTTPCRawSpacePointContainer> c(new AliHLTTPCRawSpacePointContainer);
462 if (!c.get()) return NULL;
464 HLT::copy_map_if(fClusters.begin(), fClusters.end(), c->fClusters, HLT::AliHLTUnaryPredicate<AliHLTTPCRawSpacePointContainer::AliHLTTPCRawSpacePointProperties, int>(&AliHLTTPCRawSpacePointContainer::AliHLTTPCRawSpacePointProperties::GetTrackId,trackId));
468 AliHLTSpacePointContainer* AliHLTTPCRawSpacePointContainer::SelectByMC(int mcId, bool /*bAlloc*/) const
470 /// create a collection of clusters for a specific MC track
471 std::auto_ptr<AliHLTTPCRawSpacePointContainer> c(new AliHLTTPCRawSpacePointContainer);
472 if (!c.get()) return NULL;
474 HLT::copy_map_if(fClusters.begin(), fClusters.end(), c->fClusters, HLT::AliHLTUnaryPredicate<AliHLTTPCRawSpacePointContainer::AliHLTTPCRawSpacePointProperties, int>(&AliHLTTPCRawSpacePointContainer::AliHLTTPCRawSpacePointProperties::GetMCId,mcId));
478 AliHLTSpacePointContainer* AliHLTTPCRawSpacePointContainer::UsedClusters(bool /*bAlloc*/) const
480 /// create a collection of all used clusters
481 std::auto_ptr<AliHLTTPCRawSpacePointContainer> c(new AliHLTTPCRawSpacePointContainer);
482 if (!c.get()) return NULL;
484 HLT::copy_map_if(fClusters.begin(), fClusters.end(), c->fClusters, HLT::AliHLTUnaryPredicate<AliHLTTPCRawSpacePointContainer::AliHLTTPCRawSpacePointProperties, bool>(&AliHLTTPCRawSpacePointContainer::AliHLTTPCRawSpacePointProperties::IsUsed,true));
488 AliHLTSpacePointContainer* AliHLTTPCRawSpacePointContainer::UnusedClusters(bool /*bAlloc*/) const
490 /// create a collection of all unused clusters
491 std::auto_ptr<AliHLTTPCRawSpacePointContainer> c(new AliHLTTPCRawSpacePointContainer);
492 if (!c.get()) return NULL;
494 HLT::copy_map_if(fClusters.begin(), fClusters.end(), c->fClusters, HLT::AliHLTUnaryPredicate<AliHLTTPCRawSpacePointContainer::AliHLTTPCRawSpacePointProperties, bool>(&AliHLTTPCRawSpacePointContainer::AliHLTTPCRawSpacePointProperties::IsUsed,false));
498 int AliHLTTPCRawSpacePointContainer::MarkUsed(const AliHLTUInt32_t* clusterIDs, int arraySize)
500 /// mark the clusters with specified IDs as used
501 if (!clusterIDs) return -EINVAL;
503 for (int i=0; i<arraySize; i++) {
504 if (fClusters.find(clusterIDs[i])==fClusters.end()) continue;
505 fClusters[clusterIDs[i]].MarkUsed();
511 int AliHLTTPCRawSpacePointContainer::SetTrackID(int trackID, const AliHLTUInt32_t* clusterIDs, int arraySize)
513 /// set track id for specified clusters
514 if (!clusterIDs) return -EINVAL;
516 for (int i=0; i<arraySize; i++) {
517 if (fClusters.find(clusterIDs[i])==fClusters.end()) continue;
518 fClusters[clusterIDs[i]].SetTrackId(trackID);
524 int AliHLTTPCRawSpacePointContainer::GetTrackID(AliHLTUInt32_t clusterID) const
526 /// get track id for specified cluster
527 map<AliHLTUInt32_t, AliHLTTPCRawSpacePointProperties>::const_iterator element=fClusters.find(clusterID);
528 if (element==fClusters.end()) return -1;
529 return element->second.GetTrackId();
532 int AliHLTTPCRawSpacePointContainer::SetMCID(int mcID, const AliHLTUInt32_t* clusterIDs, int arraySize)
534 /// set mc id for specified clusters
535 if (!clusterIDs) return -EINVAL;
537 for (int i=0; i<arraySize; i++) {
538 if (fClusters.find(clusterIDs[i])==fClusters.end()) continue;
539 fClusters[clusterIDs[i]].SetMCId(mcID);
545 int AliHLTTPCRawSpacePointContainer::Write(AliHLTUInt8_t* outputPtr,
547 AliHLTComponentBlockDataList&
549 AliHLTDataDeflater* pDeflater,
550 const char* option) const
552 /// write blocks to HLT component output
553 AliHLTUInt32_t offset=0;
554 if (outputBlocks.size()>0) {
555 offset=outputBlocks.back().fOffset+outputBlocks.back().fSize;
557 return Write(outputPtr, size, offset, outputBlocks, pDeflater, option);
560 int AliHLTTPCRawSpacePointContainer::Write(AliHLTUInt8_t* outputPtr,
562 AliHLTUInt32_t offset,
563 AliHLTComponentBlockDataList&
565 AliHLTDataDeflater* pDeflater,
566 const char* option) const
568 /// write blocks to HLT component output
569 return WriteSorted(outputPtr, size, offset, outputBlocks, pDeflater, option);
572 int AliHLTTPCRawSpacePointContainer::WriteSorted(AliHLTUInt8_t* outputPtr,
574 AliHLTUInt32_t offset,
575 AliHLTComponentBlockDataList&
577 AliHLTDataDeflater* pDeflater,
578 const char* option) const
580 /// write blocks to HLT component output
583 if (fMode&kModeSingle) {
584 iResult=WriteSorted(outputPtr, size, offset, fSingleBlock.GetDecoder(), fSingleBlock.GetGrid(), fSingleBlock.GetId(), outputBlocks, pDeflater, option);
587 for (std::map<AliHLTUInt32_t, AliHLTTPCRawSpacePointBlock>::const_iterator block=fBlocks.begin();
588 block!=fBlocks.end(); block++) {
589 AliHLTTPCRawClusterData* pDecoder=block->second.GetDecoder();
590 AliHLTSpacePointPropertyGrid* pGrid=block->second.GetGrid();
591 AliHLTUInt32_t mask=block->first;
592 // FIXME: have to propagate the parameter which block is currently to be written
593 // for now the index grid is only set for that one
594 if (!pGrid) continue;
595 iResult=WriteSorted(outputPtr, size, offset, pDecoder, pGrid, mask, outputBlocks, pDeflater, option);
596 break; // only one is supposed to be written
598 if (iResult==-ENOENT) {
599 HLTError("could not find the index grid of the partition to be written");
605 int AliHLTTPCRawSpacePointContainer::WriteSorted(AliHLTUInt8_t* outputPtr,
607 AliHLTUInt32_t offset,
608 AliHLTTPCRawClusterData* pDecoder,
609 AliHLTSpacePointPropertyGrid* pGrid,
611 AliHLTComponentBlockDataList&
613 AliHLTDataDeflater* pDeflater,
614 const char* option) const
616 /// write blocks to HLT component output
617 if (!outputPtr || !pDecoder || !pGrid) return -EINVAL;
618 if (pDecoder->fCount==0) return 0;
620 // this is only for sending mc labels in simulation and testing
621 // no impact to real running
622 if (!fWrittenClusterIds && strcmp(option, "write-cluster-ids")==0) {
623 const_cast<AliHLTTPCRawSpacePointContainer*>(this)->fWrittenClusterIds=new vector<AliHLTUInt32_t>;
627 AliHLTUInt32_t capacity=size;
630 int slice=AliHLTTPCSpacePointData::GetSlice(mask);
631 int part=AliHLTTPCSpacePointData::GetPatch(mask);
633 // Note: the offset parameter is only for the block descriptors, output pointer and size
634 // consider already the offset
635 AliHLTTPCRawClusterData* blockout=reinterpret_cast<AliHLTTPCRawClusterData*>(outputPtr+size);
636 blockout->fVersion=0;
641 pDeflater->InitBitDataOutput(reinterpret_cast<AliHLTUInt8_t*>(blockout->fClusters), capacity-size-sizeof(AliHLTTPCRawClusterData));
642 blockout->fVersion=pDeflater->GetDeflaterVersion();
643 if (fMode&kModeDifferentialPadTime) blockout->fVersion+=2;
646 unsigned lastPadRow=0;
647 AliHLTUInt64_t lastPad64=0;
648 AliHLTUInt64_t lastTime64=0;
649 AliHLTSpacePointPropertyGrid::iterator clusterID=pGrid->begin();
650 if (clusterID!=pGrid->end()) {
651 for (; clusterID!=pGrid->end(); clusterID++) {
652 if (clusterID.Data().fTrackId>-1) {
653 // this is an assigned cluster, skip
654 // TODO: introduce selectors into AliHLTIndexGrid::begin to loop
655 // consistently over entries, e.g. this check has to be done also
656 // in the forwarding of MC labels in
657 // AliHLTTPCDataCompressionComponent::ForwardMCLabels
660 if ((unsigned)slice!=AliHLTTPCSpacePointData::GetSlice(clusterID.Data().fId) ||
661 (unsigned)part!=AliHLTTPCSpacePointData::GetPatch(clusterID.Data().fId)) {
662 HLTError("cluster index 0x%08x out of slice %d partition %d", clusterID.Data().fId, slice, part);
664 int index=AliHLTTPCSpacePointData::GetNumber(clusterID.Data().fId);
666 if( index<0 || index>= (int)pDecoder->fCount ) continue;
668 const AliHLTTPCRawCluster &input = pDecoder->fClusters[index];
670 //const AliHLTTPCRawData::iterator& input=pDecoder->find(index);
671 //if (!(input!=pDecoder->end())) continue;
672 if (fWrittenClusterIds) fWrittenClusterIds->push_back(clusterID.Data().fId);
674 int padrow=input.GetPadRow();
676 // something wrong here, padrow is stored in the cluster header
677 // word which has bit pattern 0x3 in bits bit 30 and 31 which was
679 ALIHLTERRORGUARD(1, "can not read cluster header word");
684 float pad =input.GetPad();
685 float time =input.GetTime();
686 float sigmaY2=input.GetSigmaY2();
687 float sigmaZ2=input.GetSigmaZ2();
689 AliHLTTPCRawCluster& c=blockout->fClusters[blockout->fCount];
690 padrow+=AliHLTTPCTransform::GetFirstRow(part);
692 c.SetCharge(input.GetCharge());
695 c.SetSigmaY2(sigmaY2);
696 c.SetSigmaZ2(sigmaZ2);
697 c.SetQMax(input.GetQMax());
699 AliHLTUInt64_t padrow64=input.GetPadRow();
700 if (padrow64==lastPadRow) {
701 padrow64-=lastPadRow;
702 } else if (padrow64>lastPadRow) {
703 padrow64-=lastPadRow;
704 lastPadRow+=padrow64;
706 AliFatal("padrows not ordered");
709 AliHLTUInt32_t padType=0;
710 AliHLTUInt32_t signdPad=0;
711 AliHLTUInt64_t pad64=0;
712 if ((fMode&kModeDifferentialPadTime)!=0 && sigmaY2<.00001) {
713 // single pad cluster
714 // use twice the pad position to take account for the 0.5 offset
715 // added in the AliHLTTPCRawData decoder in accordance with the
716 // offline definition. Using the factor 2, this offset is not
717 // cut off by rounding
718 pad64=(AliHLTUInt64_t)round(2*pad);
721 if (!isnan(pad)) pad64=(AliHLTUInt64_t)round(pad*AliHLTTPCDefinitions::fgkClusterParameterDefinitions[AliHLTTPCDefinitions::kPad].fScale);
723 if (fMode&kModeDifferentialPadTime && padType==0) {
724 AliHLTUInt64_t dpad64=0;
725 if (pad64<lastPad64) {
726 dpad64=lastPad64-pad64;
729 dpad64=pad64-lastPad64;
735 AliHLTUInt32_t signdTime=0;
736 AliHLTUInt64_t time64=0;
737 if (!isnan(time)) time64=(AliHLTUInt64_t)round(time*AliHLTTPCDefinitions::fgkClusterParameterDefinitions[AliHLTTPCDefinitions::kTime].fScale);
738 if (fMode&kModeDifferentialPadTime) {
739 AliHLTUInt64_t dtime64=0;
740 if (time64<lastTime64) {
741 dtime64=lastTime64-time64;
744 dtime64=time64-lastTime64;
750 AliHLTUInt64_t sigmaY264=0;
751 if (!isnan(sigmaY2)) sigmaY264=(AliHLTUInt64_t)round(sigmaY2*AliHLTTPCDefinitions::fgkClusterParameterDefinitions[AliHLTTPCDefinitions::kSigmaY2].fScale);
752 AliHLTUInt64_t sigmaZ264=0;
753 if (!isnan(sigmaZ2)) sigmaZ264=(AliHLTUInt64_t)round(sigmaZ2*AliHLTTPCDefinitions::fgkClusterParameterDefinitions[AliHLTTPCDefinitions::kSigmaZ2].fScale);
754 pDeflater->OutputParameterBits(AliHLTTPCDefinitions::kPadRow , padrow64);
755 pDeflater->OutputParameterBits(AliHLTTPCDefinitions::kPad , pad64);
756 if (fMode&kModeDifferentialPadTime) pDeflater->OutputBit(padType);
757 if (fMode&kModeDifferentialPadTime && padType==0) pDeflater->OutputBit(signdPad);
758 pDeflater->OutputParameterBits(AliHLTTPCDefinitions::kTime , time64);
759 if (fMode&kModeDifferentialPadTime) pDeflater->OutputBit(signdTime);
760 if (padType==0) pDeflater->OutputParameterBits(AliHLTTPCDefinitions::kSigmaY2, sigmaY264);
761 pDeflater->OutputParameterBits(AliHLTTPCDefinitions::kSigmaZ2, sigmaZ264);
762 pDeflater->OutputParameterBits(AliHLTTPCDefinitions::kCharge , input.GetCharge());
763 pDeflater->OutputParameterBits(AliHLTTPCDefinitions::kQMax , input.GetQMax());
768 AliHLTComponent_BlockData bd;
769 AliHLTComponent::FillBlockData(bd);
770 bd.fOffset = size+offset;
772 bd.fSize = sizeof(AliHLTTPCRawClusterData)+blockout->fCount*sizeof(AliHLTTPCRawCluster);
773 bd.fDataType = AliHLTTPCDefinitions::fgkRawClustersDataType;
775 pDeflater->Pad8Bits();
776 bd.fSize = sizeof(AliHLTTPCRawClusterData)+pDeflater->GetBitDataOutputSizeBytes();
777 pDeflater->CloseBitDataOutput();
778 bd.fDataType = AliHLTTPCDefinitions::RemainingClustersCompressedDataType();
780 bd.fSpecification = AliHLTTPCDefinitions::EncodeDataSpecification(slice, slice, part, part);
781 outputBlocks.push_back(bd);
785 if (fWrittenClusterIds && fWrittenClusterIds->size()>0) {
786 AliHLTComponent::FillBlockData(bd);
787 bd.fOffset = size+offset;
788 bd.fSize = fWrittenClusterIds->size()*sizeof(vector<AliHLTUInt32_t>::value_type);
789 if (bd.fSize+size<=capacity) {
790 memcpy(outputPtr+size, &(*fWrittenClusterIds)[0], bd.fSize);
791 bd.fDataType = AliHLTTPCDefinitions::RemainingClusterIdsDataType();
792 bd.fSpecification = AliHLTTPCDefinitions::EncodeDataSpecification(slice, slice, part, part);
793 outputBlocks.push_back(bd);
798 fWrittenClusterIds->clear();
801 if (iResult<0) return iResult;
805 AliHLTTPCRawSpacePointContainer::AliHLTTPCRawSpacePointProperties::AliHLTTPCRawSpacePointProperties()
814 AliHLTTPCRawSpacePointContainer::AliHLTTPCRawSpacePointProperties::AliHLTTPCRawSpacePointProperties(const AliHLTTPCRawCluster* pCluster)
815 : fpCluster(pCluster)
823 AliHLTTPCRawSpacePointContainer::AliHLTTPCRawSpacePointProperties::AliHLTTPCRawSpacePointProperties(const AliHLTTPCRawSpacePointProperties& src)
824 : fpCluster(src.fpCluster)
826 , fTrackId(src.fTrackId)
832 AliHLTTPCRawSpacePointContainer::AliHLTTPCRawSpacePointProperties& AliHLTTPCRawSpacePointContainer::AliHLTTPCRawSpacePointProperties::operator=(const AliHLTTPCRawSpacePointProperties& src)
834 // assignment operator
835 if (&src==this) return *this;
836 fpCluster=src.fpCluster;
838 fTrackId=src.fTrackId;
844 void AliHLTTPCRawSpacePointContainer::AliHLTTPCRawSpacePointProperties::Print(ostream& out, Option_t */*option*/) const
851 std::stringstream str;
853 str.setf(ios::fixed,ios::floatfield);
854 str << " " << setfill(' ') << setw(3) << fpCluster->GetPadRow()
855 << " " << setw(8) << setprecision(3) << fpCluster->GetPad()
856 << " " << setw(8) << setprecision(3) << fpCluster->GetTime()
857 << " " << setw(8) << setprecision(1) << fpCluster->GetSigmaY2()
858 << " " << setw(9) << setprecision(1) << fpCluster->GetSigmaZ2()
859 << " " << setw(5) << fpCluster->GetCharge()
860 << " " << setw(5) << fpCluster->GetQMax()
861 << " " << fTrackId << " " << fMCId << " " << fUsed;
865 ostream& operator<<(ostream &out, const AliHLTTPCRawSpacePointContainer::AliHLTTPCRawSpacePointProperties& p)