#include //------------------------------------------------------------------------- TH1 *h1; //------------------------------------------------------------------------- int hist_client1(char* rem_host, char* hist_name, TCanvas *canvas ); int STREQ1(const char*s1,const char*s2) { if (strncmp(s1,s2,strlen(s2))) return 0; else return 1; } //------------------------------------------------------------------------- void f125() { //hist=(TH1*)hbk[ifil]->Get(hname); //gROOT->ls(); //TThread::Lock(); int event = gPad->GetEvent(); //printf(" Enter to f125.C event=%d ------>>>>>>>>> \n",event); //if (event != 11) return; //may be comment this line //if (event != 53 || event !== 11) return; //may be comment this line TObject *select = gPad->GetSelected(); if(!select) return; printf(" f250.C:: Event=%d object = %s \n",event,select->GetName()); if (!select->InheritsFrom(TProfile::Class()) && !select->InheritsFrom(TH1::Class())) { gPad->SetUniqueID(0); return;} gPad->GetCanvas()->FeedbackMode(kTRUE); //erase old position and draw a line at current position int pyold = gPad->GetUniqueID(); int px = gPad->GetEventX(); int py = gPad->GetEventY(); float uxmin = gPad->GetUxmin(); float uxmax = gPad->GetUxmax(); int pxmin = gPad->XtoAbsPixel(uxmin); int pxmax = gPad->XtoAbsPixel(uxmax); //if(pyold) gVirtualX->DrawLine(pxmin,pyold,pxmax,pyold); //gVirtualX->DrawLine(pxmin,py,pxmax,py); gPad->SetUniqueID(py); Float_t upy = gPad->AbsPixeltoY(py); Float_t y = gPad->PadtoY(upy); Float_t upx = gPad->AbsPixeltoX(px); Float_t x = gPad->PadtoX(upx); //draw slice corresponding to mouse position //TH2 *h = (TH2*)select; TProfile *h = (TProfile*)select; Int_t binx = h->GetXaxis()->FindBin(x)-1; Int_t biny = h->GetYaxis()->FindBin(y)-1; int slot=binx/72; int chan=binx-slot*72; printf("F125:: slot=%d Chan=%d\n",slot,chan); //TH1D *hp = h->ProjectionX("",biny,biny); /* float xlc = 0.01; float ylc = 0.01; label = new TPaveLabel(xlc, ylc, xlc+0.8, ylc+0.1,"This is a PaveLabel"); label->SetFillColor(24); label->Draw(); */ if (event != 11 && event != 12) return; //may be comment this line //create or set the new canvas c2 TVirtualPad *padsav = gPad; TCanvas *c2 = (TCanvas*)gROOT->GetListOfCanvases()->FindObject("c2"); if(c2) {} // printf(" c2 exists... \n");// delete c2->GetPrimitive("Projection"); else c2 = new TCanvas("c2"); c2->cd(); char title[80]; //slot*MAXCHAN+chan char host_name[80]; char* pos; sprintf(host_name,"%s",select->GetName()); if ((pos=strstr(host_name,":"))) { pos[0]=0; printf("host_name=%s\n",host_name); } //sprintf(title,"%s:F125_tdc:%02d:%02d",host_name,slot,chan); sprintf(title,"%s:F125_adc:%02d:%02d",host_name,slot,chan); printf("search hist= :%s:\n",title); //sprintf(title,"ADC-4-%d-%d",biny,binx); TH1 *hist_adc=NULL; //hist_adc = (TH1*)gROOT->Get(title); //hist_adc = (TH1*)gROOT->Get("roctof1:F125_adc:04:04"); //printf(" -------- Position of mouse: hist_adc=%p binx=%d biny=%d ------->>>>>>>>>> \n",hist_adc,binx,biny); if (event==11) { hist_client1(host_name,title,c2); } else { //hp->SetName("Projection"); //hp->SetTitle(title); //hp->Fit("gaus","ql"); h->Draw(); //hist_adc->Fit("gaus","ql"); } //TThread::Lock(); c2->Update(); padsav->cd(); //TThread::UnLock(); } /*=====================================================================*/ /* */ /*=====================================================================*/ int hist_client1(char* rem_host, char* hist_name, TCanvas *canvas ) { // Open connection to server // TSocket *sock = new TSocket("localhost",32765); // SRV_PARAM *s_param = (SRV_PARAM*) arg; // char* rem_host = s_param->REM_HOST; // TCanvas *canvas = s_param->canvas; // int ipad=s_param->pad; // int myTAB=s_param->tab; // char* myName=s_param->thread_name; //TSocket *sock = new TSocket(rem_host,32765); TSocket sock(rem_host,32765); printf(" thread:: hist_client() connected to %s\n",rem_host); // Wait till we get the start message char str[64]; sock.Recv(str, 64); int idx = 0; // server tells us who we are if (STREQ1(str,"go")) { idx = !strcmp(str, "go 1") ? 1 : 0; printf("Server:: %s \n",str); } else { printf("Server:: %s \n",str); return 0; } Float_t messlen = 0; Float_t cmesslen = 0; if (idx == 1) sock.SetCompressionLevel(1); int i=0; const int LNhist=256; char histname[LNhist]; i++; char sss[64]; // sprintf(sss,"Update = %d\n",i); //-- update all hist // sock.Send(sss); // tell server we are finished // sock.Send("Update"); // tell server we are finished sprintf(sss,"Hist:%s",hist_name); //-- update only one hist sock.Send(sss); // req. update printf("%s\n",sss); TMessage *mess2; while (1) { //-- objects loop -- printf("wait next message... "); sock.Recv(mess2); //printf("recv message. \n"); if (mess2->What() == kMESS_STRING) { mess2->ReadString(str, 64); printf("Client cmd: %s\n", str); if ( STREQ1(str,"END")) { //sleep(1); //printf("===> Close Sock 1\n"); //sock.Close(); break; //sock.Send(sss); // req. update } } else if (mess2->What() == kMESS_OBJECT) { TThread::Lock(); //printf("got object of class:%s:\n", mess2->GetClass()->GetName()); if (STREQ1(mess2->GetClass()->GetName(),"TH1")) { //==================== 1D === h1 = (TH1 *)mess2->ReadObject(mess2->GetClass()); printf("1D hist name=:%s:\n", h1->GetName()); //h1->Print(); strncpy(histname,h1->GetName(),LNhist); if (STREQ1(hist_name,histname)) { printf("Found!! Draw:: name=:%s:\n", h1->GetName()); canvas->cd(); h1->SetStats(1); gStyle->SetOptStat(1111); h1->DrawCopy(); //canvas->Update(); } delete h1; // delete histogram } else if (STREQ1(mess2->GetClass()->GetName(),"TH2F")) { //============ 2D === TH2F *h2 = (TH2F *)mess2->ReadObject(mess2->GetClass()); printf("2D hist name=:%s:\n", h2->GetName()); h2->Print(); strncpy(histname,h2->GetName(),LNhist); if (STREQ1(hist_name,histname)) { canvas->cd(); //gStyle->SetOptStat(0); // -no statistic gStyle->SetPadRightMargin(0.3); // increase for colz plots!! gPad->SetLogz(); h2->DrawCopy("colz"); //canvas->Update(); } delete h2; // delete histogram } TThread::UnLock(); } //--- if Object delete mess2; } //-- recv hist loop sock.Send("Finished"); // tell server we are finished if (cmesslen > 0) printf("Average compression ratio: %g\n", messlen/cmesslen); printf("===> Close Sock 2\n"); sock.Close(); return 0; } /*=====================================================================*/ /* TIter next(gDirectory->GetList()); TObject *obj; while ((obj=next())) { if (obj->InheritsFrom("TH1")) { TH1 *h1 = (TH1*)obj; //h->GetXaxis()->SetTitle("E [keV]"); printf("Next Object:: --------------------------------\n"); h1->Print(); } } */