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