]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/PHOS/AliHLTPHOSRcuHistogramProducerComponent.cxx
Removing obsolete code + refactoring
[u/mrichter/AliRoot.git] / HLT / PHOS / AliHLTPHOSRcuHistogramProducerComponent.cxx
1 // $Id$
2
3 /**************************************************************************
4  * Copyright(c) 2006, ALICE Experiment at CERN, All rights reserved.      *
5  *                                                                        *
6  * Authors: Boris Polichtchouk & Per Thomas Hille for the ALICE           *
7  * offline/HLT Project. Contributors are mentioned in the code where      *
8  * appropriate.                                                           *
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 "AliHLTPHOSRcuCellEnergyDataStruct.h"
20 #include "AliHLTPHOSRcuHistogramProducer.h"
21 #include "AliHLTPHOSRcuHistogramProducerComponent.h"
22 #include "AliHLTPHOSRcuCellAccumulatedEnergyDataStruct.h"
23 #include "AliHLTPHOSSharedMemoryInterface.h"
24 #include "AliHLTPHOSValidCellDataStruct.h" 
25
26 AliHLTPHOSRcuHistogramProducerComponent gAliHLTPHOSRcuHistogramProducerComponent;
27 /*************************************************************************
28 * Class AliHLTPHOSRcuHistogramProducerComponent accumulating histograms  *
29 * with amplitudes per PHOS channel                                       *
30 * It is intended to run at the HLT farm                                  *
31 * and it fills the histograms with amplitudes per channel.               * 
32 * Usage example see in PHOS/macros/Shuttle/AliPHOSCalibHistoProducer.C   *
33 **************************************************************************/
34 AliHLTPHOSRcuHistogramProducerComponent:: AliHLTPHOSRcuHistogramProducerComponent() : AliHLTPHOSRcuProcessor(), 
35                                                                                       fHistoWriteFrequency(100), 
36                                                                                       fRcuHistoProducerPtr(0), 
37                                                                                       fOutPtr(0),
38                                                                                       fShmPtr(0)
39 {
40   fShmPtr = new AliHLTPHOSSharedMemoryInterface();
41  //Default constructor
42
43
44
45 AliHLTPHOSRcuHistogramProducerComponent::~ AliHLTPHOSRcuHistogramProducerComponent()
46 {
47   //Destructor
48 }
49
50
51 int 
52 AliHLTPHOSRcuHistogramProducerComponent::Deinit()
53 {
54   //See html documentation of base class
55   cout << "AliHLTPHOSRcuHistogramProducerComponent::Deinit()" << endl;
56   char* arg = new char[9];
57   sprintf(arg, "recreate");
58   fRcuHistoProducerPtr->WriteAllHistograms(arg);
59   return 0;
60 }
61
62
63 const char* 
64 AliHLTPHOSRcuHistogramProducerComponent::GetComponentID()
65 {
66   //See html documentation of base class
67   return "RcuHistogramProducer";
68 }
69
70
71 void
72 AliHLTPHOSRcuHistogramProducerComponent::GetInputDataTypes( vector<AliHLTComponentDataType>& list)
73 {
74   //See html documentation of base class
75   const AliHLTComponentDataType* pType=fgkInputDataTypes;
76   while (pType->fID!=0) 
77     {
78       list.push_back(*pType);
79       pType++;
80     }
81 }
82
83
84 AliHLTComponentDataType 
85 AliHLTPHOSRcuHistogramProducerComponent::GetOutputDataType()
86 {
87   //See html documentation of base class  
88   return AliHLTPHOSDefinitions::fgkCellEnergyDataType;
89 }
90
91
92 void
93 AliHLTPHOSRcuHistogramProducerComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier )
94 {
95   //See html documentation of base class
96   constBase = 30;
97   inputMultiplier = 1;
98 }
99
100
101
102 int  AliHLTPHOSRcuHistogramProducerComponent::DoEvent( const AliHLTComponentEventData& evtData, const AliHLTComponentBlockData* blocks, 
103                                               AliHLTComponentTriggerData& trigData, AliHLTUInt8_t* outputPtr, 
104                                               AliHLTUInt32_t& size, vector<AliHLTComponentBlockData>& outputBlocks )
105 {
106   
107   cout <<  "  AliHLTPHOSRcuHistogramProducerComponent::Doevent, entering event loop" << endl;
108
109  //See html documentation of base class
110  
111   // trigData++;
112   // trigData--; //shutting up the compiler, we dont use trigData now but will do in near future
113
114   AliHLTComponentTriggerData &trDta = trigData;  
115   trDta.fDataSize++;
116   trDta.fDataSize--; //shutting up the compiler, we dont use trigData now but will do in near future
117
118   AliHLTPHOSValidCellDataStruct *currentChannel =0;
119   unsigned long ndx       = 0;
120   UInt_t offset           = 0; 
121   UInt_t mysize           = 0;
122   UInt_t tSize            = 0;
123   const AliHLTComponentBlockData* iter = NULL;   
124   AliHLTPHOSRcuCellEnergyDataStruct *cellDataPtr;
125   AliHLTUInt8_t* outBPtr;
126
127   for( ndx = 0; ndx < evtData.fBlockCnt; ndx++ )
128     {
129       cout <<  "  AliHLTPHOSRcuHistogramProducerComponent::DoEvent, recieved block" << endl;
130       iter = blocks+ndx;
131       if(iter->fDataType != AliHLTPHOSDefinitions::fgkCellEnergyDataType)
132         {
133           cout <<  "  AliHLTPHOSRcuHistogramProducerComponent::DoEvent, recieved block of wrong type" << endl;
134           cout << "evtData.fSize ="  << evtData.fStructSize  <<  "evtData.fBlockCnt =" << evtData.fBlockCnt   <<endl ;
135
136           continue;
137         }
138       
139       cellDataPtr = (AliHLTPHOSRcuCellEnergyDataStruct*)( iter->fPtr);
140       fShmPtr->SetMemory(cellDataPtr);
141       currentChannel = fShmPtr->NextChannel();
142       
143       Int_t* tmpDataPtr = 0;
144       Int_t nSamples = 0;
145       if(cellDataPtr->fHasRawData == true)
146         {
147           while(currentChannel != 0)
148             {
149               tmpDataPtr = fShmPtr->GetRawData(nSamples);
150               fRcuHistoProducerPtr->FillEnergy(currentChannel->fX, currentChannel->fZ, currentChannel->fGain, currentChannel->fEnergy);
151               fRcuHistoProducerPtr->FillLiveChannels(tmpDataPtr, nSamples, currentChannel->fX, currentChannel->fZ,currentChannel->fGain);
152               currentChannel = fShmPtr->NextChannel();
153             }
154         }
155       else
156         {
157           
158           Logging(kHLTLogFatal, __FILE__ , IntToChar(  __LINE__ ) , "AliHLTPHOSRcuHistogramProducerComponent::We are not pushing raw data, aborting");
159           return -1;
160         }
161     }
162
163   outBPtr = outputPtr;
164   fOutPtr =  (AliHLTPHOSRcuCellAccumulatedEnergyDataStruct*)outBPtr;
165   const AliHLTPHOSRcuCellAccumulatedEnergyDataStruct  &innPtr = fRcuHistoProducerPtr->GetCellAccumulatedEnergies();
166   fOutPtr->fModuleID = fModuleID;
167   fOutPtr->fRcuX     = fRcuX;
168   fOutPtr->fRcuZ     = fRcuZ;
169
170   for(int x=0; x < NXCOLUMNSRCU; x ++)
171     {
172       for(int z=0; z < NZROWSRCU; z ++)
173         {
174           for(int gain =0;  gain < NGAINS; gain ++)
175             {
176               fOutPtr->fAccumulatedEnergies[x][z][gain] = innPtr.fAccumulatedEnergies[x][z][gain];
177               fOutPtr->fHits[x][z][gain] = innPtr.fHits[x][z][gain];
178               fOutPtr->fDeadChannelMap[x][z][gain] = innPtr.fDeadChannelMap[x][z][gain];
179             }
180         }
181     }
182
183   mysize += sizeof(AliHLTPHOSRcuCellAccumulatedEnergyDataStruct);
184   AliHLTComponentBlockData bd;
185   FillBlockData( bd );
186   bd.fOffset = offset;
187   bd.fSize = mysize;
188   bd.fDataType = AliHLTPHOSDefinitions::fgkCellAccumulatedEnergyDataType;
189   bd.fSpecification = 0xFFFFFFFF;
190   outputBlocks.push_back( bd );
191   tSize += mysize;
192   outBPtr += mysize;
193
194   if( tSize > size )
195     {
196       Logging( kHLTLogFatal, "HLT::AliHLTRcuHistogramProducerComponent::DoEvent", "Too much data",
197                "Data written over allowed buffer. Amount written: %lu, allowed amount: %lu."
198                , tSize, size );
199       return EMSGSIZE;
200     }
201
202   fPhosEventCount++; 
203
204   if( (fPhosEventCount%fHistoWriteFrequency == 0) &&  ( fPhosEventCount != 0))
205     {
206       char* arg = new char[9];
207       sprintf(arg, "recreate");
208       fRcuHistoProducerPtr->WriteAllHistograms(arg);
209     }
210   return 0;
211 }//end DoEvent
212
213
214 int
215 AliHLTPHOSRcuHistogramProducerComponent::DoInit( int argc, const char** argv )
216 {
217   //See html documentation of base class
218   fPrintInfo = kFALSE;
219   int iResult=0;
220   TString argument="";
221   iResult = ScanArguments(argc, argv);
222   if(fIsSetEquippmentID == kFALSE)
223     {
224       Logging( kHLTLogFatal, "HLT::AliHLTPHOSRcuHistogramProducerComponent::DoInt( int argc, const char** argv )", "Missing argument",
225                "The argument equippmentID is not set: set it with a component argumet like this: -equippmentID  <number>");
226       iResult = -2; 
227     }
228   fRcuHistoProducerPtr = new AliHLTPHOSRcuHistogramProducer( fModuleID, fRcuX, fRcuZ);
229   return iResult; 
230   
231 }
232
233
234 AliHLTComponent*
235 AliHLTPHOSRcuHistogramProducerComponent::Spawn()
236 {
237   //See html documentation of base class
238   return new AliHLTPHOSRcuHistogramProducerComponent;
239 }
240
241
242