]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/PHOS/OnlineDisplay/AliHLTPHOSOnlineDisplay.cxx
Debug msg
[u/mrichter/AliRoot.git] / HLT / PHOS / OnlineDisplay / AliHLTPHOSOnlineDisplay.cxx
1 // $Id$
2
3 /**************************************************************************
4  * This file is property of and copyright by the Experimental Nuclear     *
5  * Physics Group, Dep. of Physics                                         *
6  * University of Oslo, Norway, 2007                                       *
7  *                                                                        * 
8  * Author: Per Thomas Hille <perthi@fys.uio.no> for the ALICE HLT Project.*
9  * Contributors are mentioned in the code where appropriate.              *
10  * Please report bugs to perthi@fys.uio.no                                * 
11  *                                                                        *
12  * Permission to use, copy, modify and distribute this software and its   *
13  * documentation strictly for non-commercial purposes is hereby granted   *
14  * without fee, provided that the above copyright notice appears in all   *
15  * copies and that both the copyright notice and this permission notice   *
16  * appear in the supporting documentation. The authors make no claims     *
17  * about the suitability of this software for any purpose. It is          *
18  * provided "as is" without express or implied warranty.                  *
19  **************************************************************************/
20
21 #ifndef __CINT__
22 # include <stdexcept>
23 # include <TSystem.h>
24 # include <TApplication.h>
25 # include "TStyle.h" 
26 #endif
27
28
29
30 #include  "AliHLTPHOSOnlineDisplay.h"
31 #include  "AliHLTDataTypes.h"
32 //#include  "AliHLTPHOSRcuCellEnergyDataStruct.h"
33 #include  <vector>
34 #include  "stdio.h"
35 #include <string>
36 #include <sys/ipc.h>
37 #include <errno.h>
38 #include "TH2.h"
39 #include "TCanvas.h"
40
41 //#include "AliHLTPHOSRcuCellAccumulatedEnergyDataStruct.h"
42 #include "AliHLTCaloRcuCellAccumulatedEnergyDataStruct.h"
43
44 #include "AliHLTPHOSCommonDefs.h"
45 #include <iostream>
46 #include "AliHLTPHOSOnlineDisplayEventTab.h"
47 #include "AliHLTPHOSOnlineDisplayCalibTab.h"
48 #include "AliHLTPHOSOnlineDisplayFourierTab.h"
49
50 //#include "AliHLTPHOSFourier.h"
51
52
53 AliHLTPHOSOnlineDisplayEventTab*     AliHLTPHOSOnlineDisplay::fgEventTabPtr       = 0;
54 AliHLTPHOSOnlineDisplayFourierTab*   AliHLTPHOSOnlineDisplay::fgFourierTabPtr     = 0;
55 AliHLTPHOSOnlineDisplayCalibTab*     AliHLTPHOSOnlineDisplay::fgCalibTabPtr       = 0;
56 AliHLTPHOSOnlineDisplay*             AliHLTPHOSOnlineDisplay::fgInstancePtr       = 0;          /**<The one an only instance of PhosOnlineDisplay*/
57 HOMERReader*                         AliHLTPHOSOnlineDisplay::fgHomerReaderPtr    = 0;          /**<Homer reader that fetches events from the HLT online stream*/
58 HOMERReader*                         AliHLTPHOSOnlineDisplay::fgHomerReadersPtr[MAXHOSTS];     /**<Homer reader that fetches events from the HLT online stream*/
59 Bool_t                               AliHLTPHOSOnlineDisplay::fgAccumulate        = kFALSE ;    /**<If set to kFALSE reset fgLegoplot between event, kTRUE adds current energies to previous plot*/
60 Bool_t                               AliHLTPHOSOnlineDisplay::fgSyncronize        = kFALSE ;
61 unsigned int                         AliHLTPHOSOnlineDisplay::fgNHosts            = 0;
62 unsigned int                         AliHLTPHOSOnlineDisplay::fgNPorts            = 0;
63 char*                                AliHLTPHOSOnlineDisplay::fgHosts[MAXHOSTS];
64 short unsigned int*                  AliHLTPHOSOnlineDisplay::fgPorts             = 0; 
65 TGTab*                               AliHLTPHOSOnlineDisplay::fgTab                = 0;
66
67 using namespace std;
68
69 //gStyle->SetOptStat(false);
70
71
72 AliHLTPHOSOnlineDisplay*
73 AliHLTPHOSOnlineDisplay::Instance(int argc, char** argv) 
74 {
75   // See header file for documentation
76   if (!fgInstancePtr) fgInstancePtr = new AliHLTPHOSOnlineDisplay(argc, argv);
77   return fgInstancePtr;
78 }
79
80
81 //AliHLTPHOSOnlineDisplay::AliHLTPHOSOnlineDisplay() : AliHLTPHOSBase(), fRunNumber(-1)
82 AliHLTPHOSOnlineDisplay::AliHLTPHOSOnlineDisplay() : fRunNumber(-1)
83
84 {
85   // See header file for documentation
86   cout << "ERROR ! level: FATAL, you cannot invoke the onlinedisplay without arguments" << endl;
87 }
88
89
90 //AliHLTPHOSOnlineDisplay::AliHLTPHOSOnlineDisplay(int argc, char** argv) : AliHLTPHOSBase()
91 AliHLTPHOSOnlineDisplay::AliHLTPHOSOnlineDisplay(int argc, char** argv) 
92 {
93   // See header file for documentation
94   gStyle->SetOptStat(false);
95   
96   ScanArguments(argc, argv);
97   char **tmp;
98   cout << "creating new PHOS Onlinedisplay" << endl;
99   fgHomerReaderPtr = new  HOMERReader(fgNHosts, (const char**)fgHosts,  fgPorts);
100   cout << "AliHLTPHOSOnlineDisplay::AliHLTPHOSOnlineDisplay: fgHomerReaderPtr =  " <<  fgHomerReaderPtr << endl;
101
102   for(int i = 0; i <fgNHosts; i++)
103     {
104       fgHomerReadersPtr[i] =      new  HOMERReader(fgHosts[i], fgPorts[i]); 
105     }
106   InitDisplay();
107 }
108
109
110 AliHLTPHOSOnlineDisplay::~AliHLTPHOSOnlineDisplay()
111 {
112   // See header file for documentation
113 }
114
115
116
117 void
118 AliHLTPHOSOnlineDisplay::InitDisplay()
119 {
120   // See header file for documentation
121   char tmpHistoName[256];
122   char tmpChDtaName[256];
123
124   gStyle->SetPalette(1);
125   fgTab = new TGTab(this, 100, 100);
126   TGLayoutHints *fL1 = new TGLayoutHints(kLHintsBottom | kLHintsExpandX |
127                                          kLHintsExpandY, 2, 2, 15, 1);
128   fgEventTabPtr =    new  AliHLTPHOSOnlineDisplayEventTab(this, fgTab, fgHomerReaderPtr, fgHomerReadersPtr, fgNHosts, fRunNumber);
129   fgFourierTabPtr =  new  AliHLTPHOSOnlineDisplayFourierTab(this, fgTab, fgHomerReaderPtr, fgHomerReadersPtr, fgNHosts); 
130   fgCalibTabPtr =    new  AliHLTPHOSOnlineDisplayCalibTab(fgTab, fgHomerReaderPtr, fgHomerReadersPtr, fgNHosts);
131   
132   //  fgEventTabPtr->SetRunNumber(fRunNumber);
133   // fgFourierTabPtr->SetRunNumber(fRunNumber);
134   // fgCalibTabPtr->SetRunNumber(fRunNumber);
135
136   AddFrame(fgTab, fL1);
137   MapSubwindows();
138   Resize();
139   SetWindowName("PHOS HLT OnlineDisplay");
140   MapWindow();
141   // MoveResize(100,100, 800,1000);
142   MoveResize(100,100, 500,700);
143
144 }
145
146
147
148 int
149 AliHLTPHOSOnlineDisplay::GetNextEvent()
150 {
151   // See header file for documentation
152   cout << "AliHLTPHOSOnlineDisplay::GetNextEvent()" << endl;
153   fgEventTabPtr->GetNextEvent();
154   fgFourierTabPtr->GetNextEvent();
155 }
156
157
158 int
159 AliHLTPHOSOnlineDisplay::GetHistogram()
160 {
161   // See header file for documentation
162   fgCalibTabPtr->GetNextEvent(); 
163 }
164
165
166
167 int
168 AliHLTPHOSOnlineDisplay::ScanArguments(int argc, char** argv)
169 {
170   // See header file for documentation
171   for(int i=0; i< MAXHOSTS; i++)
172     {
173       fgHosts[i] = new char[256];
174     }
175
176   fgPorts = new short unsigned[100];
177   Bool_t hostIsSet = kFALSE;
178   Bool_t portIsSet = kFALSE;
179   int iResult=0;
180   TString argument="";
181
182   for (int i=0; i<argc && iResult>=0; i++) 
183     {
184       argument=argv[i];
185       
186       if (argument.IsNull()) 
187         {
188           continue;
189         }
190       
191       if (argument.CompareTo("-sync")==0)
192         {
193           cout << "setting Synchronize to true" << endl;
194           fgSyncronize = kTRUE;
195         }  
196       
197       if (argument.CompareTo("-acc")==0)
198         {
199           cout << "setting Accumulate to true" << endl;
200           fgAccumulate = kTRUE;
201         }  
202       
203       if (argument.CompareTo("-run")==0) 
204         {
205           if(i+1 <= argc)
206             {
207               i++;
208               fRunNumber =  atoi(argv[i]);
209               cout << __FILE__ <<":" <<__LINE__ << ", !!!!!!!!!!!!! setting runnumber too   " <<  fRunNumber   <<endl;;
210               //              fIsSetRunNumber = true;
211             }
212
213         }
214
215
216       if (argument.CompareTo("-host")==0) 
217         {
218           if(i+1 <= argc)
219             {
220               i++;
221               sprintf(fgHosts[fgNHosts],"%s", argv[i]);
222               fgNHosts ++; 
223               cout <<"fgNHosts set to "<< fgNHosts <<endl;
224               hostIsSet = kTRUE; 
225               if(i+1 <= argc)
226                 {
227                   argument=argv[i+1];
228                   if(argument.CompareTo("-port")==0)
229                     {
230                       i++;
231                       if(i+1 <= argc)
232                         {
233                           i++;
234                           fgPorts[fgNPorts] = atoi(argv[i]);    
235                           cout << "A setting port to   " << fgPorts[fgNPorts]  <<endl; 
236                           fgNPorts ++;
237                           portIsSet = kTRUE;
238                         }
239                     }
240                   else
241                     {
242                       fgPorts[fgNPorts] =  DEFAULTEVENTPORT;    
243                       cout << "B setting port to   " << fgPorts[fgNPorts]  <<endl; 
244                       fgNPorts ++;
245                       portIsSet = kTRUE;
246                     }
247                 }
248             }
249         }
250     }
251
252   if(hostIsSet != kTRUE ||  portIsSet != kTRUE)
253     {
254       if(hostIsSet == kFALSE)
255         {
256           printf("\nERROR: no hostname is specified\n");
257         }
258       
259       if( portIsSet == kFALSE)
260         {
261           printf("ERROR: no port spcified\n");
262         }
263       printf("\nYou must specify at least one host \n\n");
264       printf("*****************************************************************\n");
265       printf("\nUsage: ./onlinedisplay  -host  <hostname>   -port  <port>");
266       printf("\n-port is optional, if not set  port 42001 will be used\n");
267       printf("*****************************************************************\n\n\n");
268       iResult = -1;
269     }
270  
271  
272   else
273     {
274       iResult = 0;
275     }
276
277   return iResult;
278 }//end ScanArguments
279
280
281
282 void 
283 AliHLTPHOSOnlineDisplay::Gain2Text(const int gain,  char *txt) const
284 {
285   // See header file for documentation
286   if(gain == LOWGAIN)
287     {
288       
289       sprintf(txt,"Low Gain");
290     }
291
292   else if(gain == HIGHGAIN)
293     {
294       sprintf(txt,"High Gain");
295     }
296
297   else
298     {
299       sprintf(txt,"Error!! invalid gain %d", gain);
300     }
301   
302 }