#include "root_inc.hh" #include "rootspy_hist.hh" #include "daqMainFrame.hh" #include "daqmon.hh" #include "hist_lib.hh" #include extern int button_EXIT,button_PAUSE; extern int CurrentTAB; extern vector tabs; /*=====================================================================*/ /* */ /*=====================================================================*/ int STREQ(const char*s1,const char*s2) { if (strncasecmp(s1,s2,strlen(s2))) return 0; else return 1; } /*=====================================================================*/ /* */ /*=====================================================================*/ void* hist_find(char *name, TList* histptr) { int id,nf=0; TObject *obj, *hist; printf("hist_find():: jist name=%s\n",name); TIter next1(histptr); while ((obj = next1())) { obj->Print(); //--printf("hist_find():: search 1D nf=%d name=:%s: :%s:\n", nf,name,obj->GetName()); if (STREQ(obj->GetName(),name)) { hist=obj; nf++; } } if (nf==1) return (void*)hist; return NULL; } /*=====================================================================*/ /* */ /*=====================================================================*/ daqPad* pad_find(const char *name, daqTab* tab) { int id,nf=0; daqPad *pad; //printf("pad_find():: search hname=%s\n",name); for ( int ipad=0; ipadpads.size(); ipad++ ) { pad=tab->pads[ipad]; //printf("pad_find():: pad=%d search hist=%s current name=:%s: \n",ipad, name,pad->hname); if (STREQ(pad->Hname,name)) { nf++; //-- printf("pad_find(): FOUND!! ipad=%d name=%s \n",ipad,name); break; } } if (nf==1) return pad; return NULL; } /*=====================================================================*/ /* */ /*=====================================================================*/ daqPad* pad_find_id(int id, daqTab* tab) { int nf=0; daqPad *pad; //printf("pad_find():: search hname=%s\n",name); for ( int ipad=0; ipadpads.size(); ipad++ ) { pad=tab->pads[ipad]; //printf("pad_find():: pad=%d search hist=%s current name=:%s: \n",ipad, name,pad->hname); if (pad->Pad==id) { nf++; //-- printf("pad_find_id(): FOUND!! ipad=%d id=%d, name=%s \n",ipad,id,pad->Hname); break; } } if (nf==1) return pad; return NULL; } /*=====================================================================*/ /* */ /*=====================================================================*/ void* hist_client(void * arg) { // 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); 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 (STREQ(str,"go")) { idx = !strcmp(str, "go 1") ? 1 : 0; printf("Server:: %s \n",str); } else { printf("Server:: %s \n",str); return NULL; } 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); sock->Send(sss); // tell server we are finished // sock->Send("Update"); // tell server we are finished printf("%s\n",sss); TMessage *mess2; while (button_EXIT==0) { //-- objects loop -- printf("wait next message... \n"); sock->Recv(mess2); //printf("recv message. \n"); if (mess2->What() == kMESS_STRING) { mess2->ReadString(str, 64); printf("Client cmd: %s\n", str); if ( STREQ(str,"END")) { sleep(1); // break; while(myTAB!=CurrentTAB && button_EXIT==0) { printf("Sleep 1 sec....... %s myTAB=%d CurrentTAB=%d\n",myName,myTAB,CurrentTAB); //canvas->Modified(); //canvas->Update(); sleep(1); // 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 (STREQ(mess2->GetClass()->GetName(),"TH1")) { TH1 *h = (TH1 *)mess2->ReadObject(mess2->GetClass()); printf("1D hist name=:%s:\n", h->GetName()); h->Print(); /* strncpy(histname,h->GetName(),LNhist); TH1F *hp = (TH1F *) hist_find(histname); if (hp) { printf(" Histogram FOUND !!! %s \n",hp->GetName()); // TThread::Lock(); hp->Reset(); hp->Add(h,1.); // TThread::UnLock(); } */ delete h; // delete histogram } else if (STREQ(mess2->GetClass()->GetName(),"TH2F")) { TH2F *h = (TH2F *)mess2->ReadObject(mess2->GetClass()); printf("2D hist name=:%s:\n", h->GetName()); h->Print(); canvas->cd(ipad); //gStyle->SetOptStat(0); // -no statistic gStyle->SetPadRightMargin(0.3); // increase for colz plots!! gPad->SetLogz(); h->DrawCopy("colz"); strncpy(histname,h->GetName(),LNhist); /* TH2F *hp = (TH2F *) hist_find(histname); if (hp) { printf(" Histogram FOUND !!! %s \n",hp->GetName()); // TThread::Lock(); hp->Reset(); hp->Add(h,1.); // TThread::UnLock(); } */ delete h; // 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); sock->Close(); return NULL; } /*=====================================================================*/ /* */ /*=====================================================================*/ void* hist_client2(void * arg) { int Debug=0; 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; TH1 **hruninfo=&s_param->RunInfo; TSocket *sock = NULL; printf(" thread:: hist_client2() started host= %s\n",rem_host); while (button_EXIT==0) { //-- connection loop -- sock = new TSocket(rem_host,32765); printf(" thread:: hist_client2() connected to %s\n",rem_host); // Wait till we get the start message char str[256]; sock->Recv(str, 256); int idx = 0; // server tells us who we are if (STREQ(str,"go")) { idx = !strcmp(str, "go 1") ? 1 : 0; printf("Server:: %s \n",str); } else { printf("Server:: %s \n",str); return NULL; } 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[256]; sprintf(sss,"Update = %d\n",i); sock->Send(sss); // tell server we are finished // sock->Send("Update"); // tell server we are finished printf("%s\n",sss); int REQ_SENT=1; //gStyle->SetTitleSize(0.09f,"t"); //-- size as "fraction of the pad" --- TMessage *mess2 = NULL; int retry =10; while (button_EXIT==0) { //-- objects loop -- if (Debug>1) printf("hist_client2(%s):: wait next message... \n",rem_host); sock->Recv(mess2); if (!mess2) { printf("%s: error mess2=%p , resend , retry=%d\\n",rem_host,mess2,retry); sock->Send("Update = 2 "); usleep(1000000); retry--; if (retry<1) break; continue; } if (mess2->What() == kMESS_STRING) { mess2->ReadString(str, 256); if (Debug>0) printf("hist_client2(%s):: Client cmd: %s\n",rem_host, str); if ( STREQ(str,"END")) { if (--REQ_SENT) continue; //-- wait for all histograms //printf("hist_client2():: Sleep %d sec.\n",tabs[CurrentTAB]->update_time); sleep(tabs[CurrentTAB]->update_time); // break; while(button_EXIT==0 && button_PAUSE==1) { //printf("hist_client2():: Sleep 1 sec....... %s nPads=%d CurrentTAB=%d,Pause=%d\n" // ,rem_host,tabs[CurrentTAB]->pads.size(),CurrentTAB,button_PAUSE); sleep(1); // break; } //while (tabs[CurrentTAB]->pads.size()>0) //---------------------------- while(true) { gStyle->SetTitleSize(0.03+0.01*sqrt((double)tabs[CurrentTAB]->pads.size()),"t"); //-- TITLE size as "fraction of the pad" --- for ( int ipad=0; ipad < tabs[CurrentTAB]->pads.size(); ipad++ ) { char *hname=tabs[CurrentTAB]->pads[ipad]->Hname; if (Debug>2) printf(" Pad=%d Hname=%s \n",ipad,hname); char *hh, *substr1, *substr2, hhost[256]; substr1=hname; if ((substr2=strstr(hname,":"))) { int Lhost=(substr2-substr1); strncpy(hhost,substr1,Lhost); hhost[Lhost]=0; hh=&substr2[1]; if (Debug>2) printf("found /:/ host=|%s|, Lhost=%d rem_host=%s hist=%s\n",hhost,Lhost,rem_host,hh); if (strncmp(hhost,rem_host,Lhost)) continue; if (Debug>0) printf("===> MyHOST! host=|%s|, Lhost=%d rem_host=%s hist=%s\n",hhost,Lhost,rem_host,hh); sprintf(sss,"Hist:%s",hname); sock->Send(sss); // req. update REQ_SENT++; } sprintf(sss,"Hist:%s:RunInfo",rem_host); //-- always update RunInfo, sock->Send(sss); // req. update REQ_SENT++; if (Debug>0) printf("Sent host=|%s|, str=%s REQ=%d\n",hhost,sss,REQ_SENT); } if (REQ_SENT) { usleep(100); break; } else sleep(1); sprintf(sss,"Hist:%s:RunInfo",rem_host); //-- always update RunInfo, every 1 sec. sock->Send(sss); // req. update REQ_SENT++; if (Debug>0) printf("Sent SLOW host=|%s|, str=%s REQ=%d\n",rem_host,sss,REQ_SENT); } //---------------------------- //sock->Send(sss); // req. update } } else if (mess2->What() == kMESS_OBJECT) { if (Debug>0) printf("hist_client2(%s):: got object of class:%s:\n",rem_host, mess2->GetClass()->GetName()); //TThread::Lock(); if (STREQ(mess2->GetClass()->GetName(),"TH1")) { //------ 1D hist ----- TH1 *h = (TH1 *)mess2->ReadObject(mess2->GetClass()); //printf("1D hist name=:%s:\n", h->GetName()); //h->Print(); daqPad* pad = pad_find(h->GetName(),tabs[CurrentTAB]); if (pad) { pad->hist1=h; gettimeofday(&(pad->Time), NULL); TThread::Lock(); tabs[CurrentTAB]->canvas->cd(pad->Pad); //printf("1D hist name=:%s: stat=%d\n", h->GetName(),pad->Stat); h->SetStats(pad->Stat); // -no statistic gStyle->SetOptStat(pad->Hopt); //if (pad->RightMargin>0) gStyle->SetPadRightMargin(pad->RightMargin); // increase for colz plots!! //h->GetZaxis()->SetLabelOffset(0.01); if (pad->LogY>0) gPad->SetLogy(); if (pad->Marker>0) h->SetMarkerStyle(pad->Marker); if (pad->MSize>0) h->SetMarkerSize(pad->MSize); if (pad->MColor>0) h->SetMarkerColor(pad->MColor); //printf("hist=%s TSize=%f\n",h->GetName(),pad->TSize); if (pad->TSize>0) { //int npads=tabs[CurrentTAB]->pads.size() h->SetTitleSize(pad->TSize,"t"); } if (pad->LSize>0) { pad->XSize=pad->LSize; pad->YSize=pad->LSize; } if (pad->XSize>0) h->GetXaxis()->SetLabelSize(pad->XSize); else if (pad->TSize>0) h->GetXaxis()->SetLabelSize(pad->TSize); if (pad->YSize>0) h->GetYaxis()->SetLabelSize(pad->YSize); else if (pad->TSize>0) h->GetYaxis()->SetLabelSize(pad->TSize); h->DrawCopy(pad->Dopt); //gPad->Modified(); gPad->Update(); /* if (pad->TSize>0) { TPaveText *pt = (TPaveText*)(gPad->GetPrimitive("title")); pt->SetTextSize(pad->TSize); gPad->Modified(); } */ TThread::UnLock(); tabs[CurrentTAB]->modified++; } //------------------------------ get hruninfo ------------------------------- strncpy(histname,h->GetName(),LNhist); sprintf(sss,"%s:RunInfo",rem_host); if (!strncmp(sss,histname,strlen(sss))) { //printf("sss=%d %s hn=%d %s h=%p hri=%p \n",strlen(sss),sss,strlen(histname),histname,h,*hruninfo); TThread::Lock(); if (*hruninfo) delete *hruninfo; *hruninfo=h; //s_param->RunInfo=h; TThread::UnLock(); h=NULL; //printf("----> h=%p hri=%p %s\n",h,*hruninfo,rem_host); } else { delete h; // delete histogram } //--------------------------------------------------------------------------- } else if (STREQ(mess2->GetClass()->GetName(),"TH2")) { //------ 2D hist ----- TH2F *h = (TH2F *)mess2->ReadObject(mess2->GetClass()); //printf("2D hist name=:%s:\n", h->GetName()); //h->Print(); daqPad* pad = pad_find(h->GetName(),tabs[CurrentTAB]); if (pad) { TThread::Lock(); tabs[CurrentTAB]->canvas->cd(pad->Pad); h->SetStats(pad->Stat); // -no statistic gStyle->SetOptStat(pad->Hopt); //if (pad->RightMargin>0) gStyle->SetPadRightMargin(pad->RightMargin); // increase for colz plots!! //h->GetZaxis()->SetLabelOffset(0.01); if (pad->LogZ>0) gPad->SetLogz(); if (pad->TSize>0) { h->SetTitleSize(pad->TSize,"t"); h->SetTitleSize(pad->TSize*0.5,"x"); h->SetTitleSize(pad->TSize*0.5,"y"); } if (pad->LSize>0) { pad->XSize=pad->LSize; pad->YSize=pad->LSize; pad->ZSize=pad->LSize; } if (pad->XSize>0) h->GetXaxis()->SetLabelSize(pad->XSize); else if (pad->TSize>0) h->GetXaxis()->SetLabelSize(pad->TSize); if (pad->YSize>0) h->GetYaxis()->SetLabelSize(pad->YSize); else if (pad->TSize>0) h->GetYaxis()->SetLabelSize(pad->TSize); if (pad->ZSize>0) { h->GetZaxis()->SetLabelSize(pad->ZSize); gPad->SetRightMargin(0.13); } else if (pad->TSize>0) { h->GetZaxis()->SetLabelSize(pad->TSize); gPad->SetRightMargin(0.13); } h->DrawCopy(pad->Dopt); gPad->Update(); tabs[CurrentTAB]->modified=1; TObject* X3 = gPad->GetPrimitive(h->GetName()); pad->hist2=(TH2*) X3; printf("2D hist addr=%p name=:%s: cont=%f ptr=%p \n",h, h->GetName(),h->GetBinContent(5,6),pad->hist2); gettimeofday(&(pad->Time), NULL); delete h; TThread::UnLock(); } else delete h; // delete histogram //---------------------------------------------------------------------------------- } else if (STREQ(mess2->GetClass()->GetName(),"TProfile")) { //------ Profile hist ----- TProfile *h = (TProfile *)mess2->ReadObject(mess2->GetClass()); //printf("TProfile hist name=:%s:\n", h->GetName()); //h->Print(); daqPad* pad = pad_find(h->GetName(),tabs[CurrentTAB]); if (pad) { pad->prof=h; gettimeofday(&(pad->Time), NULL); TThread::Lock(); tabs[CurrentTAB]->canvas->cd(pad->Pad); h->SetStats(pad->Stat); // -no statistic //if (pad->RightMargin>0) gStyle->SetPadRightMargin(pad->RightMargin); // increase for colz plots!! //h->GetZaxis()->SetLabelOffset(0.01); if (pad->LogZ>0) gPad->SetLogz(); if (pad->Marker>0) h->SetMarkerStyle(pad->Marker); if (pad->MSize>0) h->SetMarkerSize(pad->MSize); if (pad->MColor>0) h->SetMarkerColor(pad->MColor); if (pad->TSize>0) h->SetTitleSize(pad->TSize,"t"); if (pad->LSize>0) { pad->XSize=pad->LSize; pad->YSize=pad->LSize; } if (pad->XSize>0) h->GetXaxis()->SetLabelSize(pad->XSize); else if (pad->TSize>0) h->GetXaxis()->SetLabelSize(pad->TSize); if (pad->YSize>0) h->GetYaxis()->SetLabelSize(pad->YSize); else if (pad->TSize>0) h->GetYaxis()->SetLabelSize(pad->TSize); h->DrawCopy(pad->Dopt); gPad->Update(); /* if (pad->TSize>0) { TPaveText *pt = (TPaveText*)(gPad->GetPrimitive("title")); pt->SetTextSize(pad->TSize); gPad->Modified(); } */ TThread::UnLock(); tabs[CurrentTAB]->modified=1; } delete h; // 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); sock->Close(); delete sock; sleep(5); } //--- connection loop return NULL; } /*=====================================================================*/