]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/PHOS/AliHLTPHOSRcuDAComponent.cxx
2f7bd24a29aa5d5c61f4a2d6db066b5ebc192019
[u/mrichter/AliRoot.git] / HLT / PHOS / AliHLTPHOSRcuDAComponent.cxx
1 // $Id$
2
3 /**************************************************************************
4  * This file is property of and copyright by the ALICE HLT Project        * 
5  * All rights reserved.                                                   *
6  *                                                                        *
7  * Primary Authors: Oystein Djuvsland                                     *
8  *                                                                        *
9  * Permission to use, copy, modify and distribute this software and its   *
10  * documentation strictly for non-commercial purposes is hereby granted   *
11  * without fee, provided that the above copyright notice appears in all   *
12  * copies and that both the copyright notice and this permission notice   *
13  * appear in the supporting documentation. The authors make no claims     *
14  * about the suitability of this software for any purpose. It is          * 
15  * provided "as is" without express or implied warranty.                  *
16  **************************************************************************/
17
18
19 #include "AliPHOSRcuDA1.h"
20 #include "AliHLTPHOSSharedMemoryInterface.h"
21 #include "AliHLTPHOSRcuDAComponent.h"
22 #include "AliHLTPHOSDefinitions.h"
23 #include "AliHLTPHOSConstants.h"
24 #include "AliHLTPHOSRcuCellEnergyDataStruct.h"
25 #include "TObjArray.h"
26
27 //#include <iostream>
28
29 /** @file   AliHLTPHOSRcuDAComponent.cxx
30     @author Oystein Djuvsland
31     @date   
32     @brief  A module calibration component for PHOS HLT, using the PHOS DA's
33 */
34
35 // see header file for class documentation
36 // or
37 // refer to README to build package
38 // or
39 // visit http://web.ift.uib.no/~kjeks/doc/alice-hlt
40
41 using namespace PhosHLTConst;
42
43 AliHLTPHOSRcuDAComponent gAliHLTPHOSRcuDAComponent;
44
45 AliHLTPHOSRcuDAComponent::AliHLTPHOSRcuDAComponent() : AliHLTPHOSRcuProperties(),
46                                                        AliHLTCalibrationProcessor(),
47                                                        fPhosEventCount(0),
48                                                        fPHOSDAPtr(0),
49                                                        fShmPtr(0) 
50                                                        //    fTest(-2)
51 {
52   fShmPtr = new AliHLTPHOSSharedMemoryInterface();
53 }
54
55
56
57 AliHLTPHOSRcuDAComponent::~AliHLTPHOSRcuDAComponent() 
58 {
59   if(fShmPtr)
60     {
61       delete fShmPtr;
62       fShmPtr = 0;
63     }
64   if(fPHOSDAPtr)
65     {
66       delete fPHOSDAPtr;
67       fPHOSDAPtr = 0;
68     }
69 }
70
71
72 void AliHLTPHOSRcuDAComponent::GetInputDataTypes(vector<AliHLTComponentDataType>& list)
73 {
74   list.clear();
75   list.push_back(AliHLTPHOSDefinitions::fgkCellEnergyDataType);
76 }
77
78
79 AliHLTComponentDataType AliHLTPHOSRcuDAComponent::GetOutputDataType()
80 {
81   return AliHLTPHOSDefinitions::fgkEmcCalibDataType;
82 }
83   
84                                    
85 void AliHLTPHOSRcuDAComponent::GetOutputDataSize(unsigned long& constBase, double& inputMultiplier)
86 {
87   constBase = 0;
88   inputMultiplier = 2;
89 }
90
91
92 AliHLTComponent* 
93 AliHLTPHOSRcuDAComponent::Spawn()
94 {
95   return new AliHLTPHOSRcuDAComponent();
96 }
97
98 const char* 
99 AliHLTPHOSRcuDAComponent::GetComponentID()
100 {
101   return "PhosRcuDAProcessor";  
102 }
103
104
105 Int_t
106 AliHLTPHOSRcuDAComponent::ScanArgument( Int_t argc, const char** argv)
107 {
108   ScanArguments(argc, argv);
109   return 0;
110 }
111
112
113 Int_t AliHLTPHOSRcuDAComponent::InitCalibration()
114 {  
115   //CRAP PT just to get something working by 5 May 2008
116   const int tmpModule = 2;
117   fPHOSDAPtr = new AliPHOSRcuDA1(tmpModule ,GetRCUID()); 
118   return 0;
119 }
120
121
122 Int_t AliHLTPHOSRcuDAComponent::DeinitCalibration()
123 {
124   AliHLTComponentEventData dummyEvtData;
125   AliHLTComponentTriggerData dummyTrgData;
126   ShipDataToFXS(dummyEvtData, dummyTrgData); 
127
128
129   if(fShmPtr)
130     {
131       delete fShmPtr;
132       fShmPtr = 0;
133     }
134   if(fPHOSDAPtr)
135     {
136       delete fPHOSDAPtr;
137       fPHOSDAPtr = 0;
138     }
139   return 0;
140 }
141
142
143
144 Int_t AliHLTPHOSRcuDAComponent::ProcessCalibration(const AliHLTComponentEventData& evtData, AliHLTComponentTriggerData& trigData)
145 {
146   fPhosEventCount ++;
147   const  AliHLTComponentEventData eDta  = evtData;
148   AliHLTComponentTriggerData  tDta =  trigData;
149
150   UInt_t specification = 0;
151   const AliHLTComponentBlockData* iter = 0;
152   iter = GetFirstInputBlock( AliHLTPHOSDefinitions::fgkCellEnergyDataType | kAliHLTDataOriginPHOS);
153
154   AliHLTPHOSRcuCellEnergyDataStruct* cellDataPtr = 0;
155   AliHLTPHOSValidCellDataStruct *currentChannel =0;
156   Int_t xOffset = 0;
157   Int_t zOffset = 0;
158   Int_t module = -1;
159
160   Float_t energyArray[N_XCOLUMNS_MOD][N_ZROWS_MOD][N_GAINS];
161   Float_t timeArray[N_XCOLUMNS_MOD][N_ZROWS_MOD][N_GAINS];
162   ResetArrays(energyArray, timeArray);
163
164   while(iter != 0)
165     {
166       specification = specification|iter->fSpecification;
167       cellDataPtr = (AliHLTPHOSRcuCellEnergyDataStruct*)( iter->fPtr);
168       module = cellDataPtr->fModuleID;
169       xOffset = cellDataPtr->fRcuX*N_XCOLUMNS_RCU;
170       zOffset = cellDataPtr->fRcuZ*N_ZROWS_RCU;
171
172       while(currentChannel != 0)
173         {
174           Int_t tmpZ =  currentChannel->fZ;
175           Int_t tmpX =  currentChannel->fX;
176           Int_t tmpGain =  currentChannel->fGain;
177           
178           energyArray[tmpX+xOffset][tmpZ+zOffset][tmpGain] = currentChannel->fEnergy;
179           timeArray[tmpX+xOffset][tmpZ+zOffset][tmpGain] = currentChannel->fTime;
180         }
181
182 //       for(Int_t x = 0; x < N_XCOLUMNS_RCU; x++)
183 //      {
184 //        for(Int_t z = 0; z < N_ZROWS_RCU; z++)
185 //          {
186 //            for(Int_t gain = 0; gain < N_GAINS; gain++)
187 //              {
188 //                energyArray[x+xOffset][z+zOffset][gain] = cellDataPtr->fValidData[x][z][gain].fEnergy;
189 //                timeArray[x+xOffset][z+zOffset][gain] = cellDataPtr->fValidData[x][z][gain].fTime;
190 //              }
191 //          }
192 //      }
193       iter = GetNextInputBlock(); 
194     }
195   
196   fPHOSDAPtr->FillHistograms(energyArray, timeArray);
197
198   ResetArrays(energyArray, timeArray);
199
200   return 0; 
201 }
202
203   
204 Int_t 
205 AliHLTPHOSRcuDAComponent::ShipDataToFXS( const AliHLTComponentEventData& /*evtData*/, AliHLTComponentTriggerData& /*trigData*/ ) 
206 {
207   Char_t filename[200];
208
209   for(int i=0; i < 200; i++)
210     {
211       filename[i] = 0;
212     }
213   const TObjArray *calibPtr = fPHOSDAPtr->GetHistoContainer();
214   sprintf(filename, "/home/perthi/hlt/rundir/test/outdata/%s.root", fPHOSDAPtr->GetName() );
215   TFile *outFile =  new TFile(filename, "recreate");
216   calibPtr->Write(); 
217   outFile->Close();
218   PushToFXS( (TObject*)fPHOSDAPtr->GetHistoContainer(), "PHOS",  filename);
219   cout << "Finnished pushing data to HLT FXS" << endl;
220   return 0;
221 }  
222
223
224 void
225 AliHLTPHOSRcuDAComponent::ResetArrays(Float_t e[N_XCOLUMNS_MOD][N_ZROWS_MOD][N_GAINS], Float_t t[N_XCOLUMNS_MOD][N_ZROWS_MOD][N_GAINS])
226 {
227   for(Int_t x = 0; x < N_XCOLUMNS_RCU; x++)
228     {
229       for(Int_t z = 0; z < N_ZROWS_RCU; z++)
230         {
231           for(Int_t gain = 0; gain < N_GAINS; gain++)
232             {
233               e[x][z][gain] = 0;
234               t[x][z][gain] = 0;
235             }
236         }
237     }
238 }