]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/PHOS/AliHLTPHOSRawAnalyzerComponentv2.cxx
setting keyword substitution
[u/mrichter/AliRoot.git] / HLT / PHOS / AliHLTPHOSRawAnalyzerComponentv2.cxx
1 // $Id$
2
3
4 /**************************************************************************
5  * This file is property of and copyright by the ALICE HLT Project        * 
6  * All rights reserved.                                                   *
7  *                                                                        *
8  * Primary Authors: Per Thomas Hille, Oystein Djuvsland                   *
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 #include "AliHLTPHOSRawAnalyzer.h"
20 #include "AliHLTPHOSRawAnalyzerComponentv2.h"
21 #include "AliHLTPHOSChannelDataHeaderStruct.h"
22 #include "AliHLTPHOSChannelDataStruct.h"
23 #include "AliHLTPHOSMapper.h"
24 #include "AliHLTPHOSSanityInspector.h"
25 #include "AliHLTPHOSBaseline.h"
26 #include  "AliAltroDecoder.h"
27 #include  "AliAltroData.h"   
28 #include  "AliAltroBunch.h"  
29
30
31 AliHLTPHOSRawAnalyzerComponentv2::AliHLTPHOSRawAnalyzerComponentv2():
32   AliHLTPHOSRcuProcessor(), 
33   fAnalyzerPtr(0), 
34   fMapperPtr(0), 
35   fSanityInspectorPtr(0),
36   fDecoderPtr(0),  
37   fAltroDataPtr(0),
38   fAltroBunchPtr(0),
39   fAlgorithm(0),
40   fOffset(0),
41   fBunchSizeCut(5),
42   fMinPeakPosition(0),
43   fMaxPeakPosition(100)
44 {
45   //comment
46   fMapperPtr = new AliHLTPHOSMapper();
47   fAltroDataPtr = new AliAltroData();
48   fAltroBunchPtr = new AliAltroBunch();
49   fDecoderPtr = new AliAltroDecoder();
50   fSanityInspectorPtr = new AliHLTPHOSSanityInspector();
51 }
52
53
54 AliHLTPHOSRawAnalyzerComponentv2::~AliHLTPHOSRawAnalyzerComponentv2()
55 {
56   //comment
57   Deinit();
58 }
59
60
61
62 int 
63 AliHLTPHOSRawAnalyzerComponentv2::Deinit()
64 {
65   //comment
66   if(fAnalyzerPtr)
67     {
68       delete fAnalyzerPtr;
69       fAnalyzerPtr = 0;
70     }
71   if(fMapperPtr)
72     {
73       delete  fMapperPtr;
74       fMapperPtr = 0;
75     }
76   if(fAltroDataPtr)
77     {
78       delete fAltroDataPtr;
79       fAltroDataPtr = 0;
80     }
81   if(fAltroBunchPtr)
82     {
83       delete fAltroBunchPtr;
84       fAltroBunchPtr = 0;
85     }
86   if(fDecoderPtr)
87     {
88       delete fDecoderPtr;
89       fDecoderPtr = 0;
90     }
91   return 0;
92 }
93
94 const char* 
95 AliHLTPHOSRawAnalyzerComponentv2::GetComponentID()
96 {
97   //comment
98   return "PhosRawAnalyzerv2";
99 }
100
101
102 void
103 AliHLTPHOSRawAnalyzerComponentv2::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
104 {
105   //comment
106   list.clear();
107   list.push_back( AliHLTPHOSDefinitions::fgkDDLPackedRawDataType | kAliHLTDataOriginPHOS);
108 }
109
110 AliHLTComponentDataType 
111 AliHLTPHOSRawAnalyzerComponentv2::GetOutputDataType()
112 {
113   //comment
114   return AliHLTPHOSDefinitions::fgkChannelDataType;
115 }
116
117 void
118 AliHLTPHOSRawAnalyzerComponentv2::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier )
119 {
120   //comment
121   constBase = sizeof(AliHLTPHOSChannelDataHeaderStruct);
122   inputMultiplier = 0.5;
123 }
124
125 int 
126 AliHLTPHOSRawAnalyzerComponentv2::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks, AliHLTComponentTriggerData& /*trigData*/, 
127                                          AliHLTUInt8_t* outputPtr, AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& outputBlocks )
128 {
129   //comment
130   Int_t blockSize          = 0;
131   UInt_t totSize           = 0;
132
133   const AliHLTComponentBlockData* iter = NULL; 
134   unsigned long ndx;
135
136   for( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
137     {
138       iter = blocks+ndx;
139       if ( iter->fDataType != AliHLTPHOSDefinitions::fgkDDLPackedRawDataType  )
140         {
141           HLTDebug("Data block is not of type fgkDDLPackedRawDataType");
142           continue; 
143         }
144
145       blockSize = DoIt(iter, outputPtr, size, totSize); // Processing the block
146       if(blockSize == -1) // If the processing returns -1 we are out of buffer and return an error msg.
147         {
148           return -ENOBUFS;
149         }
150
151       totSize += blockSize; //Keeping track of the used size
152       // HLTDebug("Output data size: %d - Input data size: %d", totSize, iter->fSize);
153
154       AliHLTComponentBlockData bdChannelData;
155       FillBlockData( bdChannelData );
156       bdChannelData.fOffset = 0; //CRAP
157       bdChannelData.fSize = blockSize;
158       bdChannelData.fDataType = AliHLTPHOSDefinitions::fgkChannelDataType;
159       bdChannelData.fSpecification = iter->fSpecification;
160       outputBlocks.push_back(bdChannelData);
161
162       outputPtr += blockSize; //Updating position of the output buffer
163     }
164
165   fPhosEventCount++; 
166   size = totSize; //telling the framework how much buffer space we have used.
167   
168   return 0;
169 }//end DoEvent
170
171 Int_t
172 AliHLTPHOSRawAnalyzerComponentv2::DoIt(const AliHLTComponentBlockData* iter, AliHLTUInt8_t* outputPtr, const AliHLTUInt32_t size, UInt_t& totSize)
173 {
174  
175
176   Int_t crazyness          = 0;
177   Int_t nSamples           = 0;
178   Short_t channelCount     = 0;
179
180   // Firs we want to write a header to the output
181   AliHLTPHOSChannelDataHeaderStruct *channelDataHeaderPtr = reinterpret_cast<AliHLTPHOSChannelDataHeaderStruct*>(outputPtr); 
182
183   // Then comes the channel data
184   AliHLTPHOSChannelDataStruct *channelDataPtr = reinterpret_cast<AliHLTPHOSChannelDataStruct*>(outputPtr+sizeof(AliHLTPHOSChannelDataHeaderStruct)); 
185
186   Short_t channelSize = sizeof(AliHLTPHOSChannelDataStruct);
187  
188   totSize += sizeof(AliHLTPHOSChannelDataHeaderStruct);
189  
190   fDecoderPtr->SetMemory(reinterpret_cast<UChar_t*>( iter->fPtr ), iter->fSize);
191   fDecoderPtr->Decode();
192       
193   while(fDecoderPtr->NextChannel(fAltroDataPtr) == true )
194     {          
195       if(fAltroDataPtr->GetDataSize() != 0 )
196         {
197           
198           while(fAltroDataPtr->NextBunch(fAltroBunchPtr) == true) {}
199           
200           if(fAltroBunchPtr->GetBunchSize() >  fBunchSizeCut)
201             {
202               totSize += channelSize;
203               if(totSize > size)
204                 {
205                   HLTError("Buffer overflow: Trying to write data of size: %d bytes. Output buffer available: %d bytes.", totSize, size);
206                   return -1;
207                 }
208               
209               nSamples = fAltroBunchPtr->GetBunchSize();
210               
211               //crazyness = fSanityInspectorPtr->CheckInsanity(static_cast<const UInt_t*>(fAltroBunchPtr->GetData()), static_cast<const Int_t>(fAltroBunchPtr->GetBunchSize()));
212               
213               fAnalyzerPtr->SetData(fAltroBunchPtr->GetData(), fAltroBunchPtr->GetBunchSize());   
214               fAnalyzerPtr->Evaluate(0, fAltroBunchPtr->GetBunchSize());  
215               
216               if(fAnalyzerPtr->GetTiming() > fMinPeakPosition && fAnalyzerPtr->GetTiming() < fMaxPeakPosition && fAltroBunchPtr->GetBunchSize() > fBunchSizeCut)
217                 {
218                   // Writing to the output buffer
219                   channelDataPtr->fChannelID = fMapperPtr->GetChannelID(iter->fSpecification, fAltroDataPtr->GetHadd());
220                   //channelDataPtr->fChannelID = fMapperPtr->GetChannelID(1, fAltroDataPtr->GetHadd());
221                   channelDataPtr->fEnergy = static_cast<Float_t>(fAnalyzerPtr->GetEnergy()) - fOffset;
222                   channelDataPtr->fTime = static_cast<Float_t>(fAnalyzerPtr->GetTiming());
223                   channelDataPtr->fCrazyness = static_cast<Short_t>(crazyness);
224                   channelCount++;
225                   channelDataPtr++; // Updating position of the free output.
226                 }
227             }
228         }
229     }
230
231   channelDataHeaderPtr->fNChannels  = channelCount;
232   channelDataHeaderPtr->fAlgorithm  = fAlgorithm;
233   channelDataHeaderPtr->fInfo       = 0;
234   channelDataHeaderPtr->fHasRawData = false;
235
236   HLTDebug("Number of channels: %d", channelCount);
237
238   return channelSize*channelCount + sizeof(AliHLTPHOSChannelDataHeaderStruct);
239 }
240
241 int
242 AliHLTPHOSRawAnalyzerComponentv2::DoInit( int argc, const char** argv )
243
244
245   //See base class for documentation
246   fPrintInfo = kFALSE;
247   int iResult=0;
248   fMapperPtr = new AliHLTPHOSMapper();
249
250   for(int i = 0; i < argc; i++)
251     {
252       if(!strcmp("-offset", argv[i]))
253         {
254           fOffset = atoi(argv[i+1]);
255         }
256       if(!strcmp("-bunchsizecut", argv[i]))
257         {
258           fBunchSizeCut = atoi(argv[i+1]);
259         }
260       if(!strcmp("-minpeakposition", argv[i]))
261         {
262           fMinPeakPosition = atoi(argv[i+1]);
263         }
264       if(!strcmp("-maxpeakposition", argv[i]))
265         {
266           fMaxPeakPosition = atoi(argv[i+1]);
267         }  
268     }
269  
270   if(fMapperPtr->GetIsInitializedMapping() == false)
271     {
272       Logging(kHLTLogFatal, __FILE__ , IntToChar(  __LINE__ ) , "AliHLTPHOSMapper::Could not initial mapping from file %s, aborting", fMapperPtr->GetFilePath());
273       return -4;
274     }
275
276   return iResult;
277 }