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