]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/PHOS/OnlineDisplay/AliHLTPHOSOnlineDisplay.cxx
Implemented embedded root canvas. The various diplays are contained
[u/mrichter/AliRoot.git] / HLT / PHOS / OnlineDisplay / AliHLTPHOSOnlineDisplay.cxx
1 #include  "AliHLTPHOSOnlineDisplay.h"
2 #include  "AliHLTDataTypes.h"
3 #include  "AliHLTPHOSRcuCellEnergyDataStruct.h"
4 #include  <vector>
5 #include  "stdio.h"
6 #include <string>
7 #include <sys/ipc.h>
8 #include <errno.h>
9 #include "TH2.h"
10 #include "TCanvas.h"
11 #include "AliHLTPHOSCommonDefs.h"
12
13 /**************************************************************************
14  * This file is property of and copyright by the Experimental Nuclear     *
15  * Physics Group, Dep. of Physics                                         *
16  * University of Oslo, Norway, 2007                                       *
17  *                                                                        * 
18  * Author: Per Thomas Hille <perthi@fys.uio.no> for the ALICE HLT Project.*
19  * Contributors are mentioned in the code where appropriate.              *
20  * Please report bugs to perthi@fys.uio.no                                * 
21  *                                                                        *
22  * Permission to use, copy, modify and distribute this software and its   *
23  * documentation strictly for non-commercial purposes is hereby granted   *
24  * without fee, provided that the above copyright notice appears in all   *
25  * copies and that both the copyright notice and this permission notice   *
26  * appear in the supporting documentation. The authors make no claims     *
27  * about the suitability of this software for any purpose. It is          *
28  * provided "as is" without express or implied warranty.                  *
29  **************************************************************************/
30
31 #ifndef __CINT__
32 # include <stdexcept>
33 # include <TSystem.h>
34 # include <TApplication.h>
35 # include "TStyle.h" 
36 #endif
37 #include <iostream>
38
39
40 #define MAX_BIN_VALUE 1023
41
42
43 AliHLTPHOSGetEventButton*  AliHLTPHOSOnlineDisplay::fgEventButtPtr     = 0;           /**<Button to get a new event from the HLT online stream*/
44 AliHLTPHOSOnlineDisplay*   AliHLTPHOSOnlineDisplay::fgInstancePtr      = 0;           /**<The one an only instance of PhosOnlineDisplay*/
45 HOMERReader*               AliHLTPHOSOnlineDisplay::fgHomerReaderPtr   = 0;           /**<Homer reader that fetches events from the HLT online stream*/
46 TH2S*                      AliHLTPHOSOnlineDisplay::legoPlotLGPtr      = 0;           /**<2D histogram for low gain channels*/
47 TH2S*                      AliHLTPHOSOnlineDisplay::legoPlotHGPtr      = 0;           /**<2D histogram for high gain channels*/
48 char*                      AliHLTPHOSOnlineDisplay::fgDefaultDet       = "SOHP";      /**<PHOS written backwards*/
49 char*                      AliHLTPHOSOnlineDisplay::fgDefaultDataType  = "RENELLEC";  /**<CELLENER (Celle energy) written backwards*/  
50 int                        AliHLTPHOSOnlineDisplay::fgEvntCnt          = 0;           /**<Event Counter*/
51 TCanvas*                   AliHLTPHOSOnlineDisplay::fgCanvasHGPtr      = 0;           /**<Canvas to plot legoplot for High gain channels*/ 
52 TCanvas*                   AliHLTPHOSOnlineDisplay::fgCanvasLGPtr      = 0;           /**<Canvas to plot legoplot for Low gain channels*/ 
53 Bool_t                     AliHLTPHOSOnlineDisplay::fgAccumulate       = kTRUE ;     /**<If set to kFALSE reset legoplot between event, kTRUE adds current energies to previous plot*/
54 Bool_t                     AliHLTPHOSOnlineDisplay::test[17920][2];
55 TGCompositeFrame*          AliHLTPHOSOnlineDisplay::fFrame1            = 0; 
56 TGCompositeFrame*          AliHLTPHOSOnlineDisplay::fF1                = 0;         
57 TGCompositeFrame*          AliHLTPHOSOnlineDisplay::fF2                = 0;
58 TGCompositeFrame*          AliHLTPHOSOnlineDisplay::fF3                = 0;
59 TGCompositeFrame*          AliHLTPHOSOnlineDisplay::fF4                = 0;
60 TGCompositeFrame*          AliHLTPHOSOnlineDisplay::fF5                = 0;
61 TGTab*                     AliHLTPHOSOnlineDisplay::fTab               = 0;
62 TRootEmbeddedCanvas*       AliHLTPHOSOnlineDisplay::fEc1               = 0; 
63 TRootEmbeddedCanvas*       AliHLTPHOSOnlineDisplay::fEc2               = 0; 
64 using namespace std;
65
66
67 AliHLTPHOSOnlineDisplay*
68 AliHLTPHOSOnlineDisplay::Instance(char *hostname, int port) 
69 {
70   if (!fgInstancePtr) fgInstancePtr = new AliHLTPHOSOnlineDisplay(hostname, port);
71   return fgInstancePtr;
72 }
73
74
75 AliHLTPHOSOnlineDisplay::AliHLTPHOSOnlineDisplay()
76 {
77   cout << "ERROR: You canot create Onlinedisplay without parameters" << endl;
78   cout << "Usage: AliHLTPHOSOnlineDisplay(char *hostname, int port)" << endl;
79 }
80
81 AliHLTPHOSOnlineDisplay::AliHLTPHOSOnlineDisplay(char *hostname, int port)
82 {
83   cout << "creating new PHOS Onlinedisplay" << endl;
84   legoPlotLGPtr  = 0;
85   legoPlotHGPtr  = 0;
86   fgHomerReaderPtr = new  HOMERReader(hostname, port);
87   InitDisplay();
88   int ret = 0;
89   Bool_t nextSwitch=kTRUE;
90 }
91
92
93 AliHLTPHOSOnlineDisplay::~AliHLTPHOSOnlineDisplay()
94 {
95
96 }
97
98 void
99 AliHLTPHOSOnlineDisplay::InitDisplay()
100 {
101   gStyle->SetPalette(1);
102
103   fTab = new TGTab(this, 100, 100);
104   TGCompositeFrame *tf = fTab->AddTab("Tab 1");
105   fF1 = new TGCompositeFrame(tf, 60, 20, kVerticalFrame);
106   TGLayoutHints *fL1 = new TGLayoutHints(kLHintsBottom | kLHintsExpandX |
107                                          kLHintsExpandY, 2, 2, 15, 1);
108   fEc1 = new TRootEmbeddedCanvas("ec1", fF1, 100, 100);
109   fgCanvasHGPtr = fEc1->GetCanvas();
110   fF1->AddFrame(fEc1, fL1);
111   fEc2 = new TRootEmbeddedCanvas("ec2", fF1, 100, 100);
112   fgCanvasLGPtr = fEc2->GetCanvas();
113   fF1->AddFrame(fEc2, fL1);
114   tf->AddFrame(fF1, fL1);
115
116   tf = fTab->AddTab("Tab 2");
117   fF2 = new TGCompositeFrame(tf, 60, 20, kVerticalFrame);
118   tf->AddFrame(fF2, fL1);
119
120   tf = fTab->AddTab("Tab 3");
121   fF3 = new TGCompositeFrame(tf, 60, 20, kVerticalFrame);
122   tf->AddFrame(fF3, fL1);
123
124   tf = fTab->AddTab("Tab 4");
125   fF4 = new TGCompositeFrame(tf, 60, 20, kVerticalFrame);
126   tf->AddFrame(fF4, fL1);
127
128   AddFrame(fTab, fL1);
129   fgEventButtPtr = new  AliHLTPHOSGetEventButton(fF1, "get event");
130   MapSubwindows();
131   Resize();
132   SetWindowName("online display");
133   MapWindow();
134   MoveResize(100,100,1200,1000);
135 }
136
137
138 int
139 AliHLTPHOSOnlineDisplay::GetNextEvent()
140 {
141   int whileCnt = 0;
142
143   if(fgEvntCnt == 0)
144     {
145       legoPlotHGPtr   = new TH2S("Homer","HLT:HOMER: #pi^{0} 5 - 30Gev, High gain",  N_COLUMNS_MOD* N_MODULES , 0,  N_COLUMNS_MOD* N_MODULES ,  N_ROWS_MOD, 0,  N_ROWS_MOD);
146       legoPlotHGPtr->SetMaximum( MAX_BIN_VALUE);
147       legoPlotLGPtr   = new TH2S("Homer","HLT:HOMER: #pi^{0} 5 - 30Gev, Low gain",  N_COLUMNS_MOD* N_MODULES , 0,  N_COLUMNS_MOD* N_MODULES ,  N_ROWS_MOD, 0,  N_ROWS_MOD);
148       legoPlotLGPtr->SetMaximum( MAX_BIN_VALUE);
149     }  
150
151
152   if(fgAccumulate == kFALSE)
153     {
154       cout <<"restting legoplot" << endl;
155       if(legoPlotHGPtr !=0)
156         {
157           legoPlotHGPtr->Reset(); 
158         }
159
160       if(legoPlotLGPtr !=0)
161         {
162           legoPlotLGPtr->Reset();
163         }  
164     }
165
166
167   int ret = 0;
168   unsigned long ndx;
169   const AliHLTComponentBlockData* iter = NULL;   
170   Bool_t nextSwitch=kTRUE; 
171   //  cout << "homerreader connectionstatus =" <<fgHomerReaderPtr->GetConnectionStatus() << endl;;
172
173   ret =fgHomerReaderPtr->ReadNextEvent();  
174       
175   if( ret ) 
176     {
177       int ndx = fgHomerReaderPtr->GetErrorConnectionNdx();
178       printf( "------------ TRY AGAIN --------------->Error reading event from source %d: %s (%d)\n", ndx, strerror(ret), ret );
179       return ret; 
180   }
181       
182   unsigned long blockCnt = fgHomerReaderPtr->GetBlockCnt();
183
184   for ( unsigned long i = 0; i < blockCnt; i++ ) 
185     {
186       char tmp1[9], tmp2[5];
187       memset( tmp1, 0, 9 );
188       memset( tmp2, 0, 5);
189       void *tmp11 = tmp1;
190       ULong64_t* tmp12 = (ULong64_t*)tmp11;
191       *tmp12 =fgHomerReaderPtr->GetBlockDataType( i );
192       void *tmp21 = tmp2;
193       ULong_t* tmp22 = (ULong_t*)tmp21;
194       *tmp22 =fgHomerReaderPtr->GetBlockDataOrigin( i );
195     }
196   unsigned long blk = fgHomerReaderPtr->FindBlockNdx( fgDefaultDataType, fgDefaultDet, 0xFFFFFFFF );    
197
198   
199   while ( blk != ~(unsigned long)0 ) 
200     {
201       AliHLTUInt16_t moduleID;
202       const AliHLTPHOSRcuCellEnergyDataStruct* cellEnergiesPtr = (const AliHLTPHOSRcuCellEnergyDataStruct*)fgHomerReaderPtr->GetBlockData( blk );  
203       moduleID = cellEnergiesPtr->fModuleID ;
204       int tmpCount = cellEnergiesPtr->fCnt;
205       int tmpRow;
206       int tmpCol;
207       int tmpGain;
208       Int_t tmpBin;
209
210       for(int i= 0; i<tmpCount; i++)
211         {
212           tmpRow = cellEnergiesPtr->fValidData[i].fRow;
213           tmpCol = cellEnergiesPtr->fValidData[i].fCol;
214           tmpGain =  cellEnergiesPtr->fValidData[i].fGain;
215
216           if(tmpGain == HIGH_GAIN)
217             {
218               legoPlotHGPtr->Fill(moduleID*N_COLUMNS_MOD + tmpCol +  N_COLUMNS_RCU*cellEnergiesPtr->fRcuZ,  tmpRow + N_ROWS_RCU*cellEnergiesPtr->fRcuX, cellEnergiesPtr->fValidData[i].fEnergy);
219             }
220
221           else if(tmpGain == LOW_GAIN)
222             {
223               legoPlotLGPtr->Fill(moduleID*N_COLUMNS_MOD + tmpCol +  N_COLUMNS_RCU*cellEnergiesPtr->fRcuZ, tmpRow + N_ROWS_RCU*cellEnergiesPtr->fRcuX,    cellEnergiesPtr->fValidData[i].fEnergy);
224             }
225
226         }
227
228       blk = fgHomerReaderPtr->FindBlockNdx( fgDefaultDataType, fgDefaultDet, 0xFFFFFFFF, blk+1);  
229       
230       whileCnt ++;
231
232     }
233  
234   UpdateDisplay();
235
236   fgEvntCnt ++;
237 }
238
239
240 void
241 AliHLTPHOSOnlineDisplay::UpdateDisplay()
242 {
243   fgCanvasHGPtr->cd();
244   //  fEc1->cd();
245   legoPlotHGPtr->Draw("LEGO2");
246   //  legoPlotHGPtr->Draw("COLZ");
247   legoPlotHGPtr->SetMarkerColor(4);
248   fgCanvasHGPtr->Update();
249   fgCanvasLGPtr->cd();
250   legoPlotLGPtr->Draw("LEGO2");
251
252   //  legoPlotLGPtr->Draw("COLZ");
253   fgCanvasLGPtr->Update();
254
255 }
256