AlcapDAQ  1
mainWindow.cpp
Go to the documentation of this file.
1 #include <iostream>
2 #include <iomanip>
3 #include <sstream>
4 #include <fstream>
5 #include <vector>
6 #include <time.h>
7 #include <stdlib.h>
8 #include <libgen.h>
9 // test
10 #include "TApplication.h"
11 #include "TGButton.h"
12 #include "TRootEmbeddedCanvas.h"
13 #include "TGStatusBar.h"
14 #include "TCanvas.h"
15 #include "TROOT.h"
16 #include "TGTextEntry.h"
17 #include "TGLabel.h"
18 #include "TG3DLine.h"
19 #include "TGFileDialog.h"
20 #include "TSocket.h"
21 #include "TMessage.h"
22 #include "TH1D.h"
23 #include "TH1.h"
24 #include "TObjArray.h"
25 #include "TObjString.h"
26 
27 #include "getHist.h"
28 #include "TOnlineFrame.h"
29 
30 std::vector<screen_info>screens;
31 
32 int width = 800;
33 int height = 600;
34 
35 /*
36  void cycleThread(void *v)
37  {
38  TOnlineFrame *onlineFrame = (TOnlineFrame *) v;
39 
40  printf("Entering cycleThread\n");
41  while(1)
42  {
43  TThread::Sleep(20,0);
44  onlineFrame->ConsiderCycling();
45  }
46  }
47  */
48 
49 void HelpMessage();
50 
51 int main(int argc, char **argv)
52 {
53  int c;
54  std::string server_name = "localhost";
55  int server_port = 9090;
56  std::string root_file_name = "";
57  std::string module_file_name = "";
58 
59  while ((c = getopt(argc, argv, "hH:p:i:M:")) != -1)
60  {
61  switch (c)
62  {
63  case 'h':
64  HelpMessage();
65  return 0;
66  case 'H':
67  server_name = optarg;
68  break;
69  case 'p':
70  server_port = atoi(optarg);
71  break;
72  case 'i':
73  root_file_name = optarg;
74  break;
75  case 'M':
76  module_file_name = optarg;
77  break;
78  default:
79  break;
80  }
81  }
82 
83  int fake_argc = 1;
84  char fake_arg_str[256];
85  sprintf(fake_arg_str,"./online-display");
86  char *fake_argv[] = {fake_arg_str};
87 
88  TApplication theApp("RMidas", &fake_argc, fake_argv);
89 
90  if (gROOT->IsBatch()) {
91  printf("%s: cannot run in batch mode\n", argv[0]);
92  return 1;
93  }
94 
95  std::cout<<module_file_name<<std::endl;
96  TOnlineFrame *onlineFrame = new TOnlineFrame(gClient->GetRoot(),module_file_name);
97 
98  if (root_file_name.length() != 0)
99  onlineFrame->OpenRootFile(root_file_name.c_str());
100  else
101  {
102  onlineFrame->setServerName(server_name.c_str());
103  onlineFrame->setServerPort(server_port);
104  onlineFrame->ConnectToServer();
105  onlineFrame->Print();
106 
107 #if 0
108  // Get list of all histograms, then copy them to the current directory
109  std::vector<TString> vHistTitles = onlineFrame->GetHistTitles();
110  for (unsigned int i = 0; i < vHistTitles.size(); ++i)
111  {
112  //printf("%d: %s\n", i, vHistTitles.at(i).Data());
113  TH1 *hist = onlineFrame->GetHist(vHistTitles.at(i).Data());
114  if(hist)
115  {
116  //hist->Draw();
117  hist->Clone(vHistTitles.at(i).Data());
118  }
119  }
120 #endif
121  }
122 
123  //onlineFrame->runMacro("modules/common/root_init.C");
124 
125  /*
126  TThread *ct = new TThread(cycleThread, onlineFrame);
127  ct->Run();
128  */
129 
130  //theApp.SetIdleTimer(1,".q");
131 
132  onlineFrame->UpdateDisplay();
133  theApp.Run(1);
134 #if 0
135  time_t lastCycleTime = 0;//time(NULL);
136  while(true)
137  {
138  theApp.Run(1);
139  if(time(NULL) > lastCycleTime + onlineFrame->getAutoUpdateTime())
140  {
141  //printf("Considering cycling\n");
142  onlineFrame->ConsiderCycling();
143  onlineFrame->ConsiderAutoupdate();
144  lastCycleTime = time(NULL);
145  }
146  else
147  {
148  usleep(10000);
149  }
150  }
151 #endif
152 
153  return 0;
154 }
155 
157 {
158  printf("Default connection is to localhost:9090.\n");
159  printf("To specify another host, use: \n");
160  printf("\t ./online-display -H hostname -p port\n");
161  printf("Or, to open a ROOT file:\n");
162  printf("\t ./online-display -i filename\n");
163 }