]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/PHOS/OnlineDisplay/AliHLTPHOSOnlineDisplay.cxx
Fixing coding violations.
[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 #include "AliHLTPHOSRcuCellAccumulatedEnergyDataStruct.h"
41 #include "AliHLTPHOSCommonDefs.h"
42 #include <iostream>
43 #include "AliHLTPHOSOnlineDisplayEventTab.h"
44 #include "AliHLTPHOSOnlineDisplayCalibTab.h"
45
46 //#include "AliHLTPHOSFourier.h"
47
48
49 AliHLTPHOSOnlineDisplayEventTab*     AliHLTPHOSOnlineDisplay::fgEventTabPtr       = 0;
50 AliHLTPHOSOnlineDisplayFourierTab*   AliHLTPHOSOnlineDisplay::fgFourierTabPtr     = 0;
51 AliHLTPHOSOnlineDisplayCalibTab*     AliHLTPHOSOnlineDisplay::fgCalibTabPtr       = 0;
52 AliHLTPHOSOnlineDisplay*             AliHLTPHOSOnlineDisplay::fgInstancePtr       = 0;          /**<The one an only instance of PhosOnlineDisplay*/
53 HOMERReader*                         AliHLTPHOSOnlineDisplay::fgHomerReaderPtr    = 0;          /**<Homer reader that fetches events from the HLT online stream*/
54 HOMERReader*                         AliHLTPHOSOnlineDisplay::fgHomerReadersPtr[MAXHOSTS];     /**<Homer reader that fetches events from the HLT online stream*/
55 Bool_t                               AliHLTPHOSOnlineDisplay::fgAccumulate        = kFALSE ;    /**<If set to kFALSE reset fgLegoplot between event, kTRUE adds current energies to previous plot*/
56 Bool_t                               AliHLTPHOSOnlineDisplay::fgSyncronize        = kFALSE ;
57 unsigned int                         AliHLTPHOSOnlineDisplay::fgNHosts            = 0;
58 unsigned int                         AliHLTPHOSOnlineDisplay::fgNPorts            = 0;
59 char*                                AliHLTPHOSOnlineDisplay::fgHosts[MAXHOSTS];
60 short unsigned int*                  AliHLTPHOSOnlineDisplay::fgPorts             = 0; 
61 TGTab*                               AliHLTPHOSOnlineDisplay::fgTab                = 0;
62
63 using namespace std;
64
65 //gStyle->SetOptStat(false);
66
67
68 AliHLTPHOSOnlineDisplay*
69 AliHLTPHOSOnlineDisplay::Instance(int argc, char** argv) 
70 {
71   // See header file for documentation
72   if (!fgInstancePtr) fgInstancePtr = new AliHLTPHOSOnlineDisplay(argc, argv);
73   return fgInstancePtr;
74 }
75
76
77 AliHLTPHOSOnlineDisplay::AliHLTPHOSOnlineDisplay() : AliHLTPHOSBase(), fRunNumber(-1)
78 {
79   // See header file for documentation
80   cout << "ERROR ! level: FATAL, you cannot invoke the onlinedisplay without arguments" << endl;
81 }
82
83
84 AliHLTPHOSOnlineDisplay::AliHLTPHOSOnlineDisplay(int argc, char** argv) : AliHLTPHOSBase()
85 {
86   // See header file for documentation
87   gStyle->SetOptStat(false);
88   
89   ScanArguments(argc, argv);
90   char **tmp;
91   cout << "creating new PHOS Onlinedisplay" << endl;
92   fgHomerReaderPtr = new  HOMERReader(fgNHosts, (const char**)fgHosts,  fgPorts);
93   cout << "AliHLTPHOSOnlineDisplay::AliHLTPHOSOnlineDisplay: fgHomerReaderPtr =  " <<  fgHomerReaderPtr << endl;
94
95   for(int i = 0; i <fgNHosts; i++)
96     {
97       fgHomerReadersPtr[i] =      new  HOMERReader(fgHosts[i], fgPorts[i]); 
98     }
99   InitDisplay();
100 }
101
102
103 AliHLTPHOSOnlineDisplay::~AliHLTPHOSOnlineDisplay()
104 {
105   // See header file for documentation
106 }
107
108
109
110 void
111 AliHLTPHOSOnlineDisplay::InitDisplay()
112 {
113   // See header file for documentation
114   char tmpHistoName[256];
115   char tmpChDtaName[256];
116
117   gStyle->SetPalette(1);
118   fgTab = new TGTab(this, 100, 100);
119   TGLayoutHints *fL1 = new TGLayoutHints(kLHintsBottom | kLHintsExpandX |
120                                          kLHintsExpandY, 2, 2, 15, 1);
121   fgEventTabPtr =    new  AliHLTPHOSOnlineDisplayEventTab(this, fgTab, fgHomerReaderPtr, fgHomerReadersPtr, fgNHosts, fRunNumber);
122   fgFourierTabPtr =  new  AliHLTPHOSOnlineDisplayFourierTab(this, fgTab, fgHomerReaderPtr, fgHomerReadersPtr, fgNHosts); 
123   fgCalibTabPtr =    new  AliHLTPHOSOnlineDisplayCalibTab(fgTab, fgHomerReaderPtr, fgHomerReadersPtr, fgNHosts);
124   
125   //  fgEventTabPtr->SetRunNumber(fRunNumber);
126   // fgFourierTabPtr->SetRunNumber(fRunNumber);
127   // fgCalibTabPtr->SetRunNumber(fRunNumber);
128
129   AddFrame(fgTab, fL1);
130   MapSubwindows();
131   Resize();
132   SetWindowName("PHOS HLT OnlineDisplay");
133   MapWindow();
134   // MoveResize(100,100, 800,1000);
135   MoveResize(100,100, 500,700);
136
137 }
138
139
140
141 int
142 AliHLTPHOSOnlineDisplay::GetNextEvent()
143 {
144   // See header file for documentation
145   cout << "AliHLTPHOSOnlineDisplay::GetNextEvent()" << endl;
146   fgEventTabPtr->GetNextEvent();
147   fgFourierTabPtr->GetNextEvent();
148 }
149
150
151 int
152 AliHLTPHOSOnlineDisplay::GetHistogram()
153 {
154   // See header file for documentation
155   fgCalibTabPtr->GetNextEvent(); 
156 }
157
158
159
160 int
161 AliHLTPHOSOnlineDisplay::ScanArguments(int argc, char** argv)
162 {
163   // See header file for documentation
164   for(int i=0; i< MAXHOSTS; i++)
165     {
166       fgHosts[i] = new char[256];
167     }
168
169   fgPorts = new short unsigned[100];
170   Bool_t hostIsSet = kFALSE;
171   Bool_t portIsSet = kFALSE;
172   int iResult=0;
173   TString argument="";
174
175   for (int i=0; i<argc && iResult>=0; i++) 
176     {
177       argument=argv[i];
178       
179       if (argument.IsNull()) 
180         {
181           continue;
182         }
183       
184       if (argument.CompareTo("-sync")==0)
185         {
186           cout << "setting Synchronize to true" << endl;
187           fgSyncronize = kTRUE;
188         }  
189       
190       if (argument.CompareTo("-acc")==0)
191         {
192           cout << "setting Accumulate to true" << endl;
193           fgAccumulate = kTRUE;
194         }  
195       
196       if (argument.CompareTo("-run")==0) 
197         {
198           if(i+1 <= argc)
199             {
200               i++;
201               fRunNumber =  atoi(argv[i]);
202               cout << __FILE__ <<":" <<__LINE__ << ", !!!!!!!!!!!!! setting runnumber too   " <<  fRunNumber   <<endl;;
203               //              fIsSetRunNumber = true;
204             }
205
206         }
207
208
209       if (argument.CompareTo("-host")==0) 
210         {
211           if(i+1 <= argc)
212             {
213               i++;
214               sprintf(fgHosts[fgNHosts],"%s", argv[i]);
215               fgNHosts ++; 
216               cout <<"fgNHosts set to "<< fgNHosts <<endl;
217               hostIsSet = kTRUE; 
218               if(i+1 <= argc)
219                 {
220                   argument=argv[i+1];
221                   if(argument.CompareTo("-port")==0)
222                     {
223                       i++;
224                       if(i+1 <= argc)
225                         {
226                           i++;
227                           fgPorts[fgNPorts] = atoi(argv[i]);    
228                           cout << "A setting port to   " << fgPorts[fgNPorts]  <<endl; 
229                           fgNPorts ++;
230                           portIsSet = kTRUE;
231                         }
232                     }
233                   else
234                     {
235                       fgPorts[fgNPorts] =  DEFAULTEVENTPORT;    
236                       cout << "B setting port to   " << fgPorts[fgNPorts]  <<endl; 
237                       fgNPorts ++;
238                       portIsSet = kTRUE;
239                     }
240                 }
241             }
242         }
243     }
244
245   if(hostIsSet != kTRUE ||  portIsSet != kTRUE)
246     {
247       if(hostIsSet == kFALSE)
248         {
249           printf("\nERROR: no hostname is specified\n");
250         }
251       
252       if( portIsSet == kFALSE)
253         {
254           printf("ERROR: no port spcified\n");
255         }
256       printf("\nYou must specify at least one host \n\n");
257       printf("*****************************************************************\n");
258       printf("\nUsage: ./onlinedisplay  -host  <hostname>   -port  <port>");
259       printf("\n-port is optional, if not set  port 42001 will be used\n");
260       printf("*****************************************************************\n\n\n");
261       iResult = -1;
262     }
263  
264  
265   else
266     {
267       iResult = 0;
268     }
269
270   return iResult;
271 }//end ScanArguments
272
273
274
275 void 
276 AliHLTPHOSOnlineDisplay::Gain2Text(const int gain,  char *txt) const
277 {
278   // See header file for documentation
279   if(gain == LOWGAIN)
280     {
281       
282       sprintf(txt,"Low Gain");
283     }
284
285   else if(gain == HIGHGAIN)
286     {
287       sprintf(txt,"High Gain");
288     }
289
290   else
291     {
292       sprintf(txt,"Error!! invalid gain %d", gain);
293     }
294   
295 }