11 #include "TApplication.h"
13 #include "TRootEmbeddedCanvas.h"
14 #include "TGStatusBar.h"
17 #include "TGTextEntry.h"
20 #include "TGFileDialog.h"
21 #include "TObjString.h"
43 const char *env_name =
"DAQdir";
44 std::string env_value =
"";
46 if ( getenv(env_name) )
48 if (module_file_name.empty() ) module_file_name=
"MODULES";
49 env_value = getenv(env_name);
50 is_name = env_value +
"/online-display/"+module_file_name;
54 std::cerr <<
"***ERROR! shell variable " << env_name <<
" is not set. The program will not be able to find display modules." << std::endl;
58 std::cout <<
"Reading modules from file [" << is_name <<
"]" << std::endl;
59 ifstream *is =
new ifstream( is_name.c_str() );
65 is->getline(buf,1024);
66 if ( buf[0] ==
'#' )
continue;
67 if ( is->gcount() < 2 )
break;
68 std::istringstream iss (buf,std::istringstream::in);
76 std::cout << buf << std::endl;
82 std::string macro_path =
gROOT->GetMacroPath();
83 macro_path += std::string(
":")+std::string(env_value)+std::string(
"/online-display/modules");
84 gROOT->SetMacroPath( macro_path.c_str() );
88 fTopFrame =
new TGHorizontalFrame(
this,
width - 10, 30, kChildFrame);
89 AddFrame(
fTopFrame,
new TGLayoutHints(kLHintsExpandX) );
101 TGLabel *label =
new TGLabel(
fTopFrame,
"every");
102 fTopFrame->AddFrame(label,
new TGLayoutHints(kLHintsLeft|kLHintsCenterY,0,2,2,2));
110 fTopFrame->AddFrame(label,
new TGLayoutHints(kLHintsLeft|kLHintsCenterY,1,2,2,2));
119 TGVertical3DLine *vline =
new TGVertical3DLine(
fTopFrame);
120 fTopFrame->AddFrame(vline,
new TGLayoutHints(kLHintsLeft|kLHintsExpandY,1,2,2,2));
124 fTopFrame->AddFrame(label,
new TGLayoutHints(kLHintsLeft|kLHintsCenterY,2,1,2,2));
133 fTopFrame->AddFrame(label,
new TGLayoutHints(kLHintsLeft|kLHintsCenterY,2,2,2,2));
147 fTopFrame->AddFrame(vline,
new TGLayoutHints(kLHintsLeft|kLHintsExpandY,1,2,2,2));
151 fTopFrame->AddFrame(label,
new TGLayoutHints(kLHintsLeft|kLHintsCenterY,2,2,2,2));
158 fTopFrame->AddFrame(
fFileName,
new TGLayoutHints(kLHintsLeft|kLHintsCenterY,2,2,2,2));
168 fTopFrame->AddFrame(vline,
new TGLayoutHints(kLHintsLeft|kLHintsExpandY,1,2,2,2));
180 TGHorizontalFrame *frame_aux =
new TGHorizontalFrame(
this, 50, 80);
181 AddFrame(frame_aux,
new TGLayoutHints(kLHintsExpandY|kLHintsExpandX,1,1,1,1) );
185 TGVerticalFrame *frame_user =
new TGVerticalFrame(frame_aux, 10, 30);
186 frame_aux->AddFrame(frame_user,
new TGLayoutHints(kLHintsExpandY,1,1,1,1) );
193 for (
unsigned int i = 0;
i <
screens.size();
i++)
195 TGTextButton *b =
new TGTextButton(frame_user,
screens[
i].visibleName,
199 frame_user->AddFrame(b,
new TGLayoutHints(kLHintsLeft|kFitWidth));
205 new TRootEmbeddedCanvas(
"Canvas", frame_aux,
width - 10,
height - 32,kSunkenFrame|kDoubleBorder|kFitWidth|kFitHeight);
207 frame_aux->AddFrame(
fEmbeddedCanvas,
new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 1, 1, 1, 1));
210 AddFrame(
fStatusBar,
new TGLayoutHints(kLHintsExpandX, 1, 1, 1, 1));
211 int parts[] = {70,10,20};
214 SetWindowName(
"MIDAS Online Display");
216 Resize(GetDefaultSize());
221 gROOT->LoadMacro(
"modules/common/get_histogram.C");
222 gROOT->LoadMacro(
"modules/common/get_histogram_2d.C");
237 switch (GET_MSG(msg))
240 switch (GET_SUBMSG(msg))
245 ULong_t ucolor_black;
246 gClient->GetColorByName(
"#000000",ucolor_black);
256 unsigned long int t =
time(NULL);
261 sprintf(text,
"Canvas printed to file [%s]",name);
274 const char *file_types[] = {
"hist files",
"h*.root",
276 fi.fFileTypes = file_types;
277 fi.fMultipleSelection = kFALSE;
278 fi.SetMultipleSelection( kFALSE );
291 printf(
"Unknown command received\n");
296 switch (GET_SUBMSG(msg))
318 cout<<
"Loaded macro: "<<current_display.
macroName<<endl;
321 int last_slash=current_display.
macroName.rfind(
"/")+1;
322 std::string command=current_display.
macroName.substr(last_slash);
323 int extension_start=command.find(
".");
324 command=command.substr(0,extension_start);
325 if(!current_display.
hasArgs) command+=
"()";
327 cout<<
"Processing Line: "<<command<<endl;
328 gROOT->ProcessLine(command.c_str());
330 cout<<
"about to set color"<<endl;
332 gClient->GetColorByName(
"#FF0000",ucolor_red);
340 gApplication->Terminate(0);
409 ULong_t ucolor_white;
410 gClient->GetColorByName(
"#ffffff",ucolor_white);
413 if ( (s =
openSocket(hostname,port_nr)) == 0 )
415 sprintf(msg,
"Cannot connect to port %d on host [%s]",port_nr,hostname);
423 sprintf(msg,
"Connected to remote server %s:%d",hostname,port_nr);
425 sprintf(msg,
"%s:%d",hostname,port_nr);
428 ULong_t ucolor_green;
429 gClient->GetColorByName(
"#A0F5A0",ucolor_green);
433 fFileName->ChangeBackground(ucolor_white);
447 ULong_t ucolor_white;
448 gClient->GetColorByName(
"#ffffff",ucolor_white);
453 sprintf(msg,
"Cannot open ROOT file [%s]",filename);
463 sprintf(msg,
"Connected to ROOT file %s",filename);
469 ULong_t ucolor_green;
470 gClient->GetColorByName(
"#A0FfA0",ucolor_green);
471 fFileName->ChangeBackground(ucolor_green);
474 if ( update_filename )
491 sprintf(txt,
"Executing macro [%s]",macro);
504 const char *
msg =
"";
508 msg =
"No connection to remote server";
511 msg =
"Bad response from the server";
514 msg =
"No response from the server";
517 msg =
"No sources opened";
523 msg =
"Cannot open ROOT file";
526 msg =
"Cannot load root folder from the ROOT file";
529 msg =
"Unknown error";
563 sprintf(req,
"GET %s", histname);
568 TH1 *hist = (TH1*) msg->ReadObject(msg->GetClass());
578 std::vector<TString> v;
585 TObjArray *objArray = (TObjArray *)msg->ReadObject(msg->GetClass());
586 for (
int i = 0;
i < objArray->GetEntries(); ++
i)
588 TObjString *
title = (TObjString *)objArray->At(
i);
589 v.push_back((TString)title->GetString());