// // Routines to allow retrieving and plotting histograms from // a remote server. // 12/5/2003 D. Lawrence // // // cd(system) Set "working directory" to a specific system // such as tac, hycal, veto, ps, or tagger // // ls() List histograms for current system (see cd) // // sethost(hostname) Set the hostname of the server machine // // Get(histname) Get a copy of the specified histogram from // the server // // Draw(histname) Call Get() and then draw the histogram // // GetPort(system) This is used internally to map system names // to the TCP/IP port number // char SYSTEM[64] = "bcal"; char HOST[128] = "localhost"; //----------------- // cd //----------------- cd(char *system = "tac") { strcpy(SYSTEM, system); cout<<"system is now \""<Send("ls"); TMessage *mess; int status = sock->Recv(mess); if(status < 0){ cerr<<"Oh-no! error returned from server (perhaps the server died?)"<GetClass() == TObjString::Class()) { TObjString *str = (TObjString*)mess->ReadObject(mess->GetClass()); cout<GetString().Data()<Close(); cd(system); } //----------------- // sethost //----------------- sethost(char *host) { strcpy(HOST,host); } //----------------- // Get //----------------- TMessage* Get(char *histname, char *system=SYSTEM) { TSocket *sock = new TSocket(HOST, GetPort(system)); char cmd[256]; sprintf(cmd, "get %s",histname); sock->Send(cmd); TMessage *mess; int status = sock->Recv(mess); if(status < 0){ cerr<<"Oh-no! error returned from server (perhaps the server died?)"<Close(); return NULL; } if(!mess->GetClass()){ cerr<<"Uh-oh, NULL class returned from server (did you type the histo name correctly?)"<Close(); return NULL; } // Delete any existing histogram by this name TObject *oldhist = (TObject*)gROOT->FindObject(histname); if(oldhist)delete oldhist; sock->Close(); return mess; } //----------------- // Draw //----------------- Draw(char *histname, char *opt="", char *system=SYSTEM) { TMessage *mess = Get(histname, system); if(!mess)return; TH1 *h1 = NULL; TH2 *h2 = NULL; TH3 *h3 = NULL; if(mess->GetClass()->InheritsFrom(TH1::Class()))h1 = (TH1*) mess->ReadObject(mess->GetClass()); if(mess->GetClass()->InheritsFrom(TH2::Class()))h2 = (TH1*) mess->ReadObject(mess->GetClass()); if(mess->GetClass()->InheritsFrom(TH3::Class()))h3 = (TH1*) mess->ReadObject(mess->GetClass()); if(h1)h1->Draw(); if(h2)h2->Draw(); if(h3)h3->Draw(); delete mess; } //----------------- // Loop //----------------- Loop(char *histname, int N) { for(int i=0; iUpdate(); } } //----------------- // GetPort //----------------- int GetPort(char *system) { if(!strcmp(system,"bcal" ))return 9090; return 9090; }