]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/TPCLib/HWCFemulator/AliHLTTPCHWCFProcessorUnit.cxx
debug output added
[u/mrichter/AliRoot.git] / HLT / TPCLib / HWCFemulator / AliHLTTPCHWCFProcessorUnit.cxx
1 //****************************************************************************
2 //* This file is property of and copyright by the ALICE HLT Project          * 
3 //* ALICE Experiment at CERN, All rights reserved.                           *
4 //*                                                                          *
5 //* Primary Authors: Sergey Gorbunov, Torsten Alt                            *
6 //* Developers:      Sergey Gorbunov <sergey.gorbunov@fias.uni-frankfurt.de> *
7 //*                  Torsten Alt <talt@cern.ch>                              *
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   AliHLTTPCHWCFProcessorUnit.cxx
20 //  @author Sergey Gorbunov <sergey.gorbunov@fias.uni-frankfurt.de>
21 //  @author Torsten Alt <talt@cern.ch> 
22 //  @date   
23 //  @brief  Channel Processor unit of FPGA ClusterFinder Emulator for TPC
24 //  @brief  ( see AliHLTTPCHWCFEmulator class )
25 //  @note 
26
27 #include "AliHLTTPCHWCFProcessorUnit.h"
28 #include <iostream>
29
30
31 AliHLTTPCHWCFProcessorUnit::AliHLTTPCHWCFProcessorUnit()
32   :
33   fOutput(),
34   fkBunch(0),
35   fBunchIndex(0),
36   fDeconvolute(0),
37   fSingleSeqLimit(0),
38   fDebug(0)
39 {
40   //constructor 
41   Init();
42 }
43
44
45 AliHLTTPCHWCFProcessorUnit::~AliHLTTPCHWCFProcessorUnit()
46 {   
47   //destructor 
48 }
49
50 AliHLTTPCHWCFProcessorUnit::AliHLTTPCHWCFProcessorUnit(const AliHLTTPCHWCFProcessorUnit&)
51   :
52   fOutput(),
53   fkBunch(0),
54   fBunchIndex(0),
55   fDeconvolute(0),
56   fSingleSeqLimit(0),
57   fDebug(0)
58 {
59   // dummy
60   Init();
61 }
62
63 AliHLTTPCHWCFProcessorUnit& AliHLTTPCHWCFProcessorUnit::operator=(const AliHLTTPCHWCFProcessorUnit&)
64 {
65   // dummy  
66   return *this;
67 }
68
69 int AliHLTTPCHWCFProcessorUnit::Init()
70 {
71   // initialise  
72
73   fkBunch = 0;
74   return 0;
75 }
76
77 int AliHLTTPCHWCFProcessorUnit::InputStream( const AliHLTTPCHWCFBunch *bunch )
78 {
79   // input stream of data 
80   
81   if( bunch && fDebug ){
82     printf("\nHWCF Processor: input bunch F %1d R %3d P %3d T %3d NS %2ld:\n",
83            bunch->fFlag, bunch->fRow, bunch->fPad, bunch->fTime, bunch->fData.size());
84     for( unsigned int i=0; i<bunch->fData.size(); i++ ){
85       printf("   %2d ", bunch->fData[i]);
86       if( i*3+2<bunch->fMC.size() ){
87         printf("(");
88         for( int j=0; j<3; j++ ) printf(" {%d,%2.0f}",bunch->fMC[i*3+j].fMCID, bunch->fMC[i*3+j].fWeight );
89         printf(" )\n");
90       }
91     }
92   }
93
94   fkBunch = bunch;
95   fBunchIndex = 0;
96   return 0;
97 }
98
99 const AliHLTTPCHWCFClusterFragment *AliHLTTPCHWCFProcessorUnit::OutputStream()
100
101   // output stream of data 
102
103   if( !fkBunch ) return 0;
104   
105   fOutput.fFlag = fkBunch->fFlag;
106   fOutput.fRow = fkBunch->fRow;
107   fOutput.fPad = fkBunch->fPad;
108   fOutput.fBranch = fkBunch->fBranch;
109   fOutput.fBorder = fkBunch->fBorder;  
110   fOutput.fQ = 0;
111   fOutput.fT = 0;
112   fOutput.fT2 = 0;
113   fOutput.fP = 0;
114   fOutput.fP2 = 0;
115   fOutput.fTMean =  fkBunch->fTime;
116
117   fOutput.fMC.clear();
118   
119   if( fkBunch->fFlag==2 && fkBunch->fData.size()==1 ){ // rcu trailer word, forward it 
120     fOutput.fRow = fkBunch->fData[0];
121   }     
122   
123   if( fkBunch->fFlag >1 ){
124     fkBunch = 0;
125     fBunchIndex = 0;
126     return &fOutput;
127   }
128
129   if( fkBunch->fFlag < 1 ) return 0;
130
131
132   if( fBunchIndex >= fkBunch->fData.size() || fkBunch->fTime < fBunchIndex ) return 0;  
133
134   AliHLTInt32_t bunchTime0 = fkBunch->fTime - fBunchIndex;
135   AliHLTInt32_t bunchTime = bunchTime0;
136
137   AliHLTUInt64_t qLast = 0;
138   bool slope = 0;
139   AliHLTUInt32_t length = 0;
140   for( ; fBunchIndex<fkBunch->fData.size() && bunchTime>=0; fBunchIndex++, bunchTime--, length++ ){
141     AliHLTUInt64_t q = fkBunch->fData[fBunchIndex]*fkBunch->fGain;
142     if( fDeconvolute && slope && q>qLast ){
143       //cout<<"deconvolution time!!!"<<endl;
144       if( length==1 && fOutput.fQ<fSingleSeqLimit ){
145         fOutput.fQ = 0;
146         fOutput.fT = 0;
147         fOutput.fT2 = 0;
148         fOutput.fP = 0;
149         fOutput.fP2 = 0;
150         bunchTime0 = fkBunch->fTime - fBunchIndex;
151         qLast = 0;
152         slope = 0;
153         length = 0;
154       } else {      
155         break;
156       }
157     }
158     if( q<qLast ) slope = 1;
159     qLast = q;
160     fOutput.fQ += q;
161     fOutput.fT += q*bunchTime;
162     fOutput.fT2+= q*bunchTime*bunchTime;
163     fOutput.fP += q*fkBunch->fPad;
164     fOutput.fP2+= q*fkBunch->fPad*fkBunch->fPad;
165     fOutput.fMC.insert(fOutput.fMC.end(),fkBunch->fMC.begin(), fkBunch->fMC.end() );
166   }
167   
168   fOutput.fTMean = (AliHLTUInt64_t)( (bunchTime0 + bunchTime + 1)/2 );
169
170   if( length==1 && fOutput.fQ < fSingleSeqLimit ) return 0;
171
172   return &fOutput;
173 }