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