AlcapDAQ  1
Macros | Functions
getHist.h File Reference

Go to the source code of this file.

Macros

#define RDISP_ERR_NO_CON   1
 cannot connect to the server More...
 
#define RDISP_ERR_BAD_RESPONSE   2
 Bad response from the server. More...
 
#define RDISP_ERR_NO_RESPONSE   3
 No response from the server. More...
 
#define RDISP_ERR_NO_SOURCE   4
 No sourses open. More...
 
#define RDISP_ERR_BROKEN_PIPE   5
 Broken pipe. More...
 
#define RDISP_ERR_NO_FILE   6
 Cannot open file. More...
 
#define RDISP_ERR_NO_FOLDER   7
 Cannot load root folder from file. More...
 

Functions

TFile * openRootFile (const char *filename)
 
TSocket * openSocket (const char *hostname, const int port_nr=9090)
 
void closeSource ()
 
TObject * getObject (const char *name)
 
void clear_recv_buffer ()
 
int get_status_code ()
 
ULong_t get_run_number ()
 
void reset_error_code ()
 

Macro Definition Documentation

#define RDISP_ERR_BAD_RESPONSE   2

Bad response from the server.

Definition at line 20 of file getHist.h.

Referenced by get_status_code(), openSocket(), and TOnlineFrame::runMacro().

#define RDISP_ERR_BROKEN_PIPE   5

Broken pipe.

Definition at line 29 of file getHist.h.

Referenced by get_status_code(), and TOnlineFrame::runMacro().

#define RDISP_ERR_NO_CON   1

cannot connect to the server

Definition at line 17 of file getHist.h.

Referenced by get_run_number(), get_status_code(), getObjectFromSocket(), openSocket(), and TOnlineFrame::runMacro().

#define RDISP_ERR_NO_FILE   6

Cannot open file.

Definition at line 32 of file getHist.h.

Referenced by get_status_code(), openRootFile(), and TOnlineFrame::runMacro().

#define RDISP_ERR_NO_FOLDER   7

Cannot load root folder from file.

Definition at line 35 of file getHist.h.

Referenced by get_status_code(), openRootFile(), and TOnlineFrame::runMacro().

#define RDISP_ERR_NO_RESPONSE   3

No response from the server.

Definition at line 23 of file getHist.h.

Referenced by get_status_code(), openSocket(), and TOnlineFrame::runMacro().

#define RDISP_ERR_NO_SOURCE   4

No sourses open.

Definition at line 26 of file getHist.h.

Referenced by get_status_code(), getObject(), getObjectFromFile(), and TOnlineFrame::runMacro().

Function Documentation

void clear_recv_buffer ( )

Frees memory occupied by received objects

Definition at line 365 of file getHist.cpp.

References folder.

Referenced by closeSource(), and TOnlineFrame::runMacro().

366 {
367  if (folder) folder->Clear();
368 }
void closeSource ( )

close opened sources (socket or file )

Definition at line 178 of file getHist.cpp.

References clear_recv_buffer(), r_file, and r_socket.

Referenced by get_run_number(), getObjectFromSocket(), openRootFile(), and openSocket().

179 {
180  if (r_socket != NULL)
181  {
182  r_socket->Close();
183  delete r_socket;
184  r_socket = NULL;
185  }
186 
187  if (r_file != NULL)
188  {
189 #if 0
190  r_folder->Clear();
191  delete r_folder;
192  r_folder = NULL;
193 #endif
194  r_file->Close("R");
195  delete r_file;
196  r_file = NULL;
197  }
198 
200 }
ULong_t get_run_number ( )

Return current run number

Definition at line 426 of file getHist.cpp.

References closeSource(), getObjectFromFile(), gl_status, printf(), r_file, r_socket, RDISP_ERR_NO_CON, sprintf(), status, and timeout.

Referenced by TOnlineFrame::runMacro().

427 {
428 
429  ULong_t run_nr = 0;
430 
431  if (r_socket != NULL)
432  {
433  TMessage *m;
434  char str[256];
435 
436  sprintf(str, "GetRunNumber");
437  Int_t status = r_socket->Select(TSocket::kWrite,timeout);
438  if ( status != 1 )
439  {
440  printf("***ERROR! Broken connection to socket\n");
441  closeSource();
443  return 0;
444  }
445  r_socket->Send(str);
446 
447  status = r_socket->Select(TSocket::kRead,timeout);
448  if ( status != 1 )
449  {
450  printf("***ERROR! Broken connection to socket\n");
451  closeSource();
453  return 0;
454  }
455  Int_t n = r_socket->Recv(m);
456 
457  if ( n <= 0 )
458  {
459  printf("***ERROR! Broken pipe\n");
460  closeSource();
462  return 0;
463  }
464  m->ReadULong( run_nr );
465 
466  delete m;
467 
468  }
469  else if ( r_file != NULL)
470  {
471  TH1I *h1 = (TH1I*)getObjectFromFile( "run_number/h1_run_number" );
472  if ( h1 )
473  {
474  run_nr = h1->GetBinContent(1);
475  }
476  }
477 
478  return run_nr;
479 
480 
481 }
int get_status_code ( )

Returns error code.

Returns
0 if no error

Definition at line 377 of file getHist.cpp.

References gl_status, printf(), RDISP_ERR_BAD_RESPONSE, RDISP_ERR_BROKEN_PIPE, RDISP_ERR_NO_CON, RDISP_ERR_NO_FILE, RDISP_ERR_NO_FOLDER, RDISP_ERR_NO_RESPONSE, and RDISP_ERR_NO_SOURCE.

Referenced by TOnlineFrame::runMacro().

378 {
379  switch ( gl_status )
380  {
381  case 0:
382  // no error
383  break;
384  case RDISP_ERR_NO_CON:
385  printf("No connection to remote server\n");
386  break;
388  printf("Bad response from the server\n");
389  break;
391  printf("No response from the server\n");
392  break;
393  case RDISP_ERR_NO_SOURCE:
394  printf("No sources opened\n");
395  break;
397  printf("Broken pipe\n");
398  break;
399  case RDISP_ERR_NO_FILE:
400  printf("Cannot open ROOT file\n");
401  break;
402  case RDISP_ERR_NO_FOLDER:
403  printf("Cannot load root folder from the ROOT file\n");
404  break;
405  default:
406  printf("Unknown error\n");
407  break;
408  }
409 
410  return gl_status;
411 }
TObject* getObject ( const char *  name)

no sources available

Definition at line 202 of file getHist.cpp.

References getObjectFromFile(), getObjectFromSocket(), gl_status, printf(), r_file, r_socket, and RDISP_ERR_NO_SOURCE.

Referenced by G__Dictionary__0_1300().

203 {
204  if (r_socket != NULL)
205  {
206  return getObjectFromSocket( name );
207  }
208  else if (r_file != NULL)
209  {
210  return getObjectFromFile( name );
211  }
212 
214  if ( gl_status == 0 )
215  {
216  printf("No connection\n");
218  }
219  return NULL;
220 }
TFile* openRootFile ( const char *  filename)

Opens ROOT file on disk

Parameters
filename
Returns
pointer to opened file

Definition at line 75 of file getHist.cpp.

References closeSource(), gl_status, printf(), r_file, RDISP_ERR_NO_FILE, and RDISP_ERR_NO_FOLDER.

Referenced by TOnlineFrame::OpenRootFile().

76 {
77  closeSource();
78 
79  r_file = new TFile(filename);
80  if ( r_file->IsZombie() )
81  {
82  printf("***ERROR! Cannot open ROOT file [%s]\n",filename);
83  delete r_file;
84  r_file = NULL;
85 #if 0
86  r_folder = NULL;
87 #endif
89  }
90 #if 0
91  else
92  {
93  // *** get top folder ***
94  r_file->GetObject("histos",r_folder);
95  if ( !r_folder )
96  {
97  printf("**ERROR! Cannot load folder 'histos' from file [%filename]\n",filename);
98  delete r_file;
99  r_file = NULL;
100  r_folder = NULL;
102  }
103  else
104  {
105  r_folder->SetOwner( kTRUE );
106  }
107  }
108 #endif
109 
110  printf("Connected to source file :[%s]\n",filename);
111 
112  return r_file;
113 }
TSocket* openSocket ( const char *  hostname,
const int  port_nr 
)

Connects to ROOT server (MIDAS analyzer)

Parameters
hostname
port_nr
Returns
opened socket or zero

Definition at line 124 of file getHist.cpp.

References closeSource(), gl_status, printf(), r_socket, RDISP_ERR_BAD_RESPONSE, RDISP_ERR_NO_CON, RDISP_ERR_NO_RESPONSE, sprintf(), status, and timeout.

Referenced by TOnlineFrame::ConnectToServer().

125 {
126  Int_t status;
127 
128  closeSource();
129 
130  r_socket = new TSocket(hostname, port_nr);
131 
132  if ( ! r_socket->IsValid() )
133  {
134  delete r_socket;
135  r_socket = NULL;
137  return r_socket;
138  }
139 
140  char str[64];
141  sprintf(str,"ERROR");
142  status = r_socket->Select(TSocket::kRead,timeout);
143  if ( status == 1 )
144  {
145  r_socket->Recv(str, sizeof(str));
146  if ( strncmp(str, "RMSERV", 6) != 0 )
147  {
148  // *** incorrect responce from the server ***
149  printf("***ERROR! Unexpected response from the server [%s] on port %i: [%s]",hostname,port_nr,str);
150  r_socket->Close();
151  delete r_socket;
152  r_socket = NULL;
154  return r_socket;
155  }
156  }
157  else
158  {
159  // *** no response from the server ***
160  printf("***ERROR! No response from the server [%s] on port %i\n",hostname, port_nr);
161  r_socket->Close();
162  delete r_socket;
163  r_socket = NULL;
165  return r_socket;
166  }
167 
168  printf("Successfully connected to server on host [%s] port %i\n",hostname,port_nr);
169  gl_status = 0;
170 
171  return r_socket;
172 }
void reset_error_code ( )

Clears error flag. All operations will be blocked untill ther error is cleared.

Definition at line 418 of file getHist.cpp.

References gl_status.

419 {
420  gl_status = 0;
421 }