#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <iostream>
#include <assert.h>
#include <signal.h>
#include <TSystem.h>
#include <TROOT.h>
#include <TApplication.h>
#include <TTimer.h>
#include <TFile.h>
#include <TDirectory.h>
#include <TFolder.h>
#include <TH1D.h>
Go to the source code of this file.
Classes | |
class | MyPeriodic |
Functions | |
double | GetTimeSec () |
int | ShowMem (const char *label) |
void | help () |
void | IncrFunc () |
int | main (int argc, char *argv[]) |
Variables | |
TDirectory * | gOnlineHistDir = NULL |
TFile * | gOutputFile = NULL |
static bool | gEnableShowMem = false |
double GetTimeSec | ( | ) |
Definition at line 39 of file test_midasServer.cxx.
void help | ( | ) |
Definition at line 109 of file test_midasServer.cxx.
00110 { 00111 printf("\nUsage:\n"); 00112 00113 printf("\n./test_midasServer.exe [-h] [-PtcpPort] [-pTcpPort] [-XtmpPort] [-m]\n"); 00114 printf("\n"); 00115 printf("\t-h: print this help message\n"); 00116 printf("\t-X: Start the XML Server on specified tcp port (for use with roody)\n"); 00117 printf("\t-P: Start the TNetDirectory server on specified tcp port (for use with roody)\n"); 00118 printf("\t-p: Start the old midas histogram server on specified tcp port (for use with roody)\n"); 00119 printf("\t-m: Enable memory leak debugging\n"); 00120 printf("\n"); 00121 00122 exit(1); 00123 }
void IncrFunc | ( | ) |
Definition at line 125 of file test_midasServer.cxx.
Referenced by main().
00126 { 00127 TH1D *h; 00128 h = (TH1D*)gROOT->FindObjectAny("test1"); 00129 //printf("Histogram %p\n", h); 00130 if (h) 00131 { 00132 static int x = 0; 00133 h->Fill(x); 00134 x++; 00135 if (x>100) 00136 x = 0; 00137 } 00138 00139 h = (TH1D*)gROOT->FindObjectAny("test3"); 00140 //printf("Histogram %p\n", h); 00141 if (h) 00142 { 00143 h->Fill(33); 00144 } 00145 }
int main | ( | int | argc, | |
char * | argv[] | |||
) |
Definition at line 149 of file test_midasServer.cxx.
References TDirectory::cd(), XmlServer::Export(), gDirectory, gEnableShowMem, gManaHistosFolder, help(), IncrFunc(), TDirectory::mkdir(), NetDirectoryExport(), XmlServer::SetVerbose(), XmlServer::Start(), StartMidasServer(), and StartNetDirectoryServer().
00150 { 00151 setbuf(stdout,NULL); 00152 setbuf(stderr,NULL); 00153 00154 signal(SIGILL, SIG_DFL); 00155 signal(SIGBUS, SIG_DFL); 00156 signal(SIGSEGV, SIG_DFL); 00157 signal(SIGPIPE, SIG_DFL); 00158 00159 std::vector<std::string> args; 00160 for (int i=0; i<argc; i++) 00161 { 00162 if (strcmp(argv[i],"-h")==0) 00163 help(); // does not return 00164 args.push_back(argv[i]); 00165 } 00166 00167 TApplication *app = new TApplication("rootana", &argc, argv); 00168 00169 if(gROOT->IsBatch()) { 00170 printf("Cannot run in batch mode\n"); 00171 return 1; 00172 } 00173 00174 int oldTcpPort = 0; 00175 int tcpPort = 0; 00176 int xmlTcpPort = 0; 00177 00178 for (unsigned int i=1; i<args.size(); i++) // loop over the commandline options 00179 { 00180 const char* arg = args[i].c_str(); 00181 //printf("argv[%d] is %s\n",i,arg); 00182 00183 if (false) 00184 ; 00185 else if (strncmp(arg,"-m",2)==0) // Enable memory debugging 00186 gEnableShowMem = true; 00187 else if (strncmp(arg,"-p",2)==0) // Set the histogram server port 00188 oldTcpPort = atoi(arg+2); 00189 else if (strncmp(arg,"-P",2)==0) // Set the histogram server port 00190 tcpPort = atoi(arg+2); 00191 else if (strncmp(arg,"-X",2)==0) // Set the histogram server port 00192 xmlTcpPort = atoi(arg+2); 00193 else if (strcmp(arg,"-h")==0) 00194 help(); // does not return 00195 else if (arg[0] == '-') 00196 help(); // does not return 00197 } 00198 00199 gROOT->cd(); 00200 gOnlineHistDir = new TDirectory("rootana", "rootana online plots"); 00201 00202 #ifdef HAVE_MIDASSERVER 00203 if (oldTcpPort) 00204 StartMidasServer(oldTcpPort); 00205 #else 00206 if (oldTcpPort) 00207 fprintf(stderr,"ERROR: No support for the old midas server!\n"); 00208 #endif 00209 #ifdef HAVE_LIBNETDIRECTORY 00210 if (tcpPort) 00211 { 00212 //VerboseNetDirectoryServer(true); 00213 StartNetDirectoryServer(tcpPort, gOnlineHistDir); 00214 } 00215 #else 00216 if (tcpPort) 00217 fprintf(stderr,"ERROR: No support for the TNetDirectory server!\n"); 00218 #endif 00219 #ifdef HAVE_XMLSERVER 00220 XmlServer* xmlServer = NULL; 00221 if (xmlTcpPort) 00222 { 00223 xmlServer = new XmlServer(); 00224 xmlServer->SetVerbose(true); 00225 xmlServer->Start(xmlTcpPort); 00226 xmlServer->Export(gOnlineHistDir, gOnlineHistDir->GetName()); 00227 } 00228 #else 00229 if (xmlTcpPort) 00230 fprintf(stderr,"ERROR: No support for the XML Server!\n"); 00231 #endif 00232 00233 gOnlineHistDir->cd(); 00234 00235 //TFile *f = new TFile("/Users/olchansk/output.root", "RECREATE"); 00236 TFile *f = new TFile("output.root", "RECREATE"); 00237 f->cd(); 00238 00239 NetDirectoryExport(f, "outputFile"); 00240 00241 if (xmlServer) 00242 xmlServer->Export(f, "outputFile"); 00243 00244 TH1D* hh = new TH1D("test1", "test1", 100, 0, 100); 00245 hh->Fill(1); 00246 hh->Fill(10); 00247 hh->Fill(50); 00248 00249 TDirectory* subdir = gDirectory->mkdir("subdir with space"); 00250 subdir->cd(); 00251 00252 TH1D* hh2 = new TH1D("test2 with space", "test2", 100, 0, 100); 00253 hh2->Fill(25); 00254 00255 TFolder* subfolder = new TFolder("subfolder", "subfolder"); 00256 f->Add(subfolder); 00257 00258 TH1D* hh3 = new TH1D("test3", "test3", 100, 0, 100); 00259 hh3->Fill(33); 00260 subfolder->Add(hh3); 00261 00262 //f->Write(); 00263 //f->Close(); 00264 00265 #ifdef HAVE_MIDASSERVER 00266 if (oldTcpPort>0 && gManaHistosFolder) 00267 { 00268 NetDirectoryExport(gManaHistosFolder, "histos"); 00269 00270 TFolder *subfolder = gManaHistosFolder->AddFolder("subfolder", "Sub folder"); 00271 subfolder->Add(hh2); 00272 00273 gManaHistosFolder->Add(hh); 00274 } 00275 #endif 00276 00277 //gDirectory->cd("/"); 00278 //gDirectory->pwd(); 00279 //gROOT->cd(); 00280 00281 //NetDirectoryExport(gROOT->GetListOfFiles(), "ListOfFiles"); 00282 //NetDirectoryExport(gROOT->GetListOfGlobals(), "ListOfGlobals"); 00283 00284 if (xmlServer) { 00285 xmlServer->Export(gROOT->GetListOfFiles(), "ListOfFiles"); 00286 //xmlServer->Export(gROOT->GetListOfGlobals(), "ListOfGlobals"); 00287 } 00288 00289 new MyPeriodic(100, IncrFunc); 00290 00291 //new TBrowser(); 00292 app->Run(kTRUE); 00293 return 0; 00294 }
int ShowMem | ( | const char * | label | ) |
Definition at line 90 of file test_midasServer.cxx.
References gEnableShowMem.
00091 { 00092 if (!gEnableShowMem) 00093 return 0; 00094 00095 FILE* fp = fopen("/proc/self/statm","r"); 00096 if (!fp) 00097 return 0; 00098 00099 int mem = 0; 00100 fscanf(fp,"%d",&mem); 00101 fclose(fp); 00102 00103 if (label) 00104 printf("memory at %s is %d\n", label, mem); 00105 00106 return mem; 00107 }
bool gEnableShowMem = false [static] |
Definition at line 88 of file test_midasServer.cxx.
TDirectory* gOnlineHistDir = NULL |
Definition at line 36 of file test_midasServer.cxx.
TFile* gOutputFile = NULL |
Definition at line 37 of file test_midasServer.cxx.