#include "daqMainFrame.hh" #include #include "rs_cmsg.h" #include "rs_info.h" #include "daqmon1.hh" #include #include #include //#include "hist_lib.hh" // GLOBALS rs_cmsg *RS_CMSG = NULL; rs_info *RS_INFO = NULL; pthread_rwlock_t *ROOT_MUTEX = NULL; string ROOTSPY_UDL = "cMsg://127.0.0.1/cMsg/rootspy"; string CMSG_NAME = ""; //------------------------- //--- monitor GLobals --- //------------------------- struct timeval tvA[10], tvB[10]; daqMainFrame *dmf; TCanvas *c1,*c2,*c3,*c4; int HIST_UPDATED=0; int SHOW_TAB=0; extern int button_EXIT,button_PAUSE; int button_EXIT=0,button_PAUSE=0; vector hids; daqTab *tab; vector tabs; //vector > *tabs; //--------------------- root client test ------------------------------ extern int CurrentTAB; int CurrentTAB=0; char REM_HOST[] = "roctof2"; TList *ALL_1D_HIST; TList *ALL_2D_HIST; //--------------------------------------------------------------------- // //--------------------------------------------------------------------- void FindHistos(string system, string pattern, vector &hids) { RS_INFO->Lock(); // Make list of all histograms from all servers map::iterator server_info_iter = RS_INFO->servers.begin(); for(; server_info_iter!=RS_INFO->servers.end(); server_info_iter++){//iterates over servers const string &server = server_info_iter->first; const vector &hnamepaths = server_info_iter->second.hnamepaths; for(unsigned int j=0; jhids.clear(); for(unsigned int j=0; jpattern.size(); j++) { printf("Next pattern = %s \n",tabs[ID]->pattern[j].c_str()); FindHistos(tabs[ID]->system[0],tabs[ID]->pattern[j],tabs[ID]->hids); } gettimeofday(&tvB[1], NULL); int idiff=tvB[1].tv_usec - tvA[1].tv_usec + 1000000 * (tvB[1].tv_sec - tvA[1].tv_sec); printf("update_Tab:: hists found =%d, time=%d us \n",tabs[ID]->hids.size(),idiff); //sleep(1); time_t t1=time(NULL); while (1) { time_t t2=time(NULL); if ((t2-t1)>TIME) break; if (button_EXIT) break; usleep(10); } if (button_EXIT) break; } } //--------------------------------------------------------------------- // //--------------------------------------------------------------------- void *list_update(void* arg) { int TIME=10; //-- sec -- TThread::Printf(" New TThread :: list_update <--"); //TThread::Lock(); //TThread::UnLock(); // Get list of active hnamepaths on active servers // We get a copy of the hinfo_t objects so we don't // have to hold a mutex lock to prevent them from // changing on us while we're working with them. // GetAllHistos(hids); // Ping server occasionally to make sure our histogram list is up-to-date // Loop over servers while (1) { //---------------------------------------------------------------------- // update list of hist //---------------------------------------------------------------------- printf("------------> update list of hist (Lock) <------------------\n"); gettimeofday(&tvA[2], NULL); RS_INFO->Lock(); map::iterator iter = RS_INFO->servers.begin(); for(; iter!=RS_INFO->servers.end(); iter++){ string servername = iter->first; if(servername!=""){ RS_CMSG->RequestHists(servername); //RS_CMSG->RequestMacroList(servername); } } RS_INFO->Unlock(); gettimeofday(&tvB[2], NULL); int idiff=tvB[2].tv_usec - tvA[2].tv_usec + 1000000 * (tvB[2].tv_sec - tvA[2].tv_sec); printf("------------> update list of hist DONE (Unlock) time=%d us <------------------\n",idiff); //TThread::Printf(" ***> list_update done, time=%d us, sleep=%d sec<--",idiff,TIME); //sleep(10); time_t t1=time(NULL); while (1) { time_t t2=time(NULL); if ((t2-t1)>TIME) break; if (button_EXIT) break; usleep(10); } if (button_EXIT) break; } } //============================================================================== // //============================================================================== void *hist_update(void* arg) { int TIME=2*1000000; //-- sec -- vector hids; TThread::Printf(" New TThread :: hist_update <--"); //TThread::Lock(); //TThread::UnLock(); while (1) { HIST_UPDATED=0; usleep(10); gettimeofday(&tvA[3], NULL); hids.clear(); //---------------------------------------------------------------------- // RS_INFO->Lock(); printf("------------> Make list of all histograms from all servers <------------------\n"); // Make list of all histograms from all servers map::iterator server_info_iter = RS_INFO->servers.begin(); for(; server_info_iter!=RS_INFO->servers.end(); server_info_iter++){//iterates over servers const string &server = server_info_iter->first; const vector &hnamepaths = server_info_iter->second.hnamepaths; printf("SS:: Server=%s hnamepaths.size()=%d \n", server.c_str(),hnamepaths.size() ); printf("------------> LOOP over HIST <------------------\n"); for(unsigned int j=0; jRequestHistogram(server, hnamepaths[j]); hids.push_back(hid_t(server, hnamepaths[j])); } } gettimeofday(&tvB[3], NULL); int idiff=tvB[3].tv_usec - tvA[3].tv_usec + 1000000 * (tvB[3].tv_sec - tvA[3].tv_sec); printf("------------> End Make list of all histograms from all servers, time=%d us<------------------\n",idiff); // RS_INFO->Unlock(); //---------------------------------------------------------------------- HIST_UPDATED=1; // Refill TGListTree if needed // if(hists_changed)UpdateListTree(hids); TThread::Printf(" ***> hist_update done, sleep 5 sec<--"); //sleep(5); gettimeofday(&tvA[0], NULL); //time_t t1=time(NULL); while (1) { //time_t t2=time(NULL); //if ((t2-t1)>TIME && HIST_UPDATED!=1) break; gettimeofday(&tvB[0], NULL); idiff=tvB[0].tv_usec - tvA[0].tv_usec + 1000000 * (tvB[0].tv_sec - tvA[0].tv_sec); if (idiff>TIME && HIST_UPDATED!=1) break; if (button_EXIT) break; //putchar('.'); usleep(10); } if (button_EXIT) break; } } //============================================================================== // //============================================================================== int main() { TThread *thr_list_update=NULL; TThread *thr_hist_update=NULL; TThread *thr_update_Tab=NULL; TThread *thr_hist_clnt=NULL; //--- Create rs_info object --- RS_INFO = new rs_info(); TApplication theApp("App", NULL, NULL); //DRootSpy* RS = new DRootSpy(); //---- Makes a Mutex to lock / unlock Root Global --- ROOT_MUTEX = new pthread_rwlock_t; pthread_rwlock_init(ROOT_MUTEX, NULL); printf("old::ROOTSPY_UDL=%s\n",ROOTSPY_UDL.c_str()); const char *ptr = getenv("ROOTSPY_UDL"); if(ptr)ROOTSPY_UDL = ptr; printf("new::ROOTSPY_UDL=%s\n",ROOTSPY_UDL.c_str()); //--- Create cMsg object --- char hostname[256]; gethostname(hostname, 256); char str[512]; sprintf(str, "RootSpy GUI %s-%d", hostname, getpid()); CMSG_NAME = string(str); cout << "Full UDL is " << ROOTSPY_UDL << endl; RS_CMSG = new rs_cmsg(ROOTSPY_UDL, CMSG_NAME); //--- Create Main Frame --- dmf = new daqMainFrame(gClient->GetRoot(), 900, 700); //------------------------------------------------------------------------ //--- Create Tabs --- //------------------------------------------------------------------------ //---- Profile --- tab=new daqTab(dmf,"Prof",3,3); tabs.push_back(tab); tab->system.push_back("roc"); //char pat[] = { }; tab->pattern.push_back("prof"); printf("Created TAB id=%d, total=%d \n",tab->ID,dmf->get_n_tabs()); //---- TRIGGER --- tab=new daqTab(dmf,"Trigger",5,4); tabs.push_back(tab); tab->system.push_back("roctrig"); tab->pattern.push_back("prof"); printf("Created TAB id=%d, total=%d \n",tab->ID,dmf->get_n_tabs()); //---- F250 PED --- tab=new daqTab(dmf,"F250",4,4); tabs.push_back(tab); tab->system.push_back("roc"); tab->pattern.push_back("FADC"); printf("Created TAB id=%d, total=%d \n",tab->ID,dmf->get_n_tabs()); //---- F125 PED --- tab=new daqTab(dmf,"F125",5,4); tabs.push_back(tab); tab->system.push_back("roccdc"); tab->pattern.push_back("F125"); printf("Created TAB id=%d, total=%d \n",tab->ID,dmf->get_n_tabs()); //---- F1TDC --- tab=new daqTab(dmf,"F1TDC",5,4); tabs.push_back(tab); tab->system.push_back("rocbcal"); tab->pattern.push_back("F1TDC"); printf("Created TAB id=%d, total=%d \n",tab->ID,dmf->get_n_tabs()); //---- CAEN TDC --- tab=new daqTab(dmf,"CAENTDC",5,4); tabs.push_back(tab); tab->system.push_back("roctof"); tab->pattern.push_back("CAENTDC"); printf("Created TAB id=%d, total=%d \n",tab->ID,dmf->get_n_tabs()); //---- TOF Profile --- tab=new daqTab(dmf,"TOFp",3,3); tabs.push_back(tab); tab->system.push_back("roctof"); tab->pattern.push_back("roctof1_ped_prof"); tab->pattern.push_back("roctof2_ped_prof"); tab->pattern.push_back("roctof3_ped_prof"); tab->pattern.push_back("roctof1_Slot_03_FADC_09"); tab->pattern.push_back("roctof1_Slot_05_FADC_13"); tab->pattern.push_back("roctof1_Slot_05_FADC_16"); printf("Created TAB id=%d, total=%d \n",tab->ID,dmf->get_n_tabs()); //---- BCAL rates --- tab=new daqTab(dmf,"BCALr",3,3); tabs.push_back(tab); tab->system.push_back("rocbcal"); tab->pattern.push_back("Scalers"); printf("Created TAB id=%d, total=%d \n",tab->ID,dmf->get_n_tabs()); //---- FCAL rates --- tab=new daqTab(dmf,"FCALr",4,3); tabs.push_back(tab); tab->system.push_back("rocfcal"); tab->pattern.push_back("Scalers"); printf("Created TAB id=%d, total=%d \n",tab->ID,dmf->get_n_tabs()); //---- TOF RATES --- tab=new daqTab(dmf,"TOFr",2,2); tabs.push_back(tab); tab->system.push_back("roctof"); tab->pattern.push_back("Scalers"); printf("Created TAB id=%d, total=%d \n",tab->ID,dmf->get_n_tabs()); //------------------------------------------------------------------------ printf("Numb Tabs = %d \n",dmf->get_n_tabs()); printf("Current Tab = %d \n",dmf->fTab->GetCurrent()); printf("Size of tabs = %d \n",tabs.size()); //------------------------------------------------------------------------ //--- Start threads --- //------------------------------------------------------------------------ thr_list_update = new TThread("list_update", list_update, NULL); thr_list_update->Run(); thr_hist_update = new TThread("hist_update", hist_update, NULL); thr_hist_update->Run(); thr_update_Tab = new TThread("update_Tab", update_Tab, NULL); thr_update_Tab->Run(); //thr_hist_clnt = new TThread("hist_client_thread", hist_client, (void*)REM_HOST); //thr_hist_clnt->Run(); TThread::Ps(); printf("------------> all THREADS are STARTED <------------------\n"); //------------------------------------------------------------------------------- // Main Loop //------------------------------------------------------------------------------- while(1) { int j=0; //-------------------------------------------------------- //while (HIST_UPDATED!=1) { // gSystem->ProcessEvents(); //putchar('.'); // if (dmf->v_EXIT) { button_EXIT=1; break; } // usleep(10); //} int ID=dmf->CurrentTAB; printf("update_Tab:: current tab =%d \n",ID); tabs[ID]->hids.clear(); for(unsigned int j=0; jpattern.size(); j++) { printf("Next pattern = %s \n",tabs[ID]->pattern[j].c_str()); FindHistos(tabs[ID]->system[0],tabs[ID]->pattern[j],tabs[ID]->hids); } printf("update_Tab:: hists found = =%d \n",tabs[ID]->hids.size()); //-------------------------------------------------------- printf("----------> New hids: size of hids=%d \n",hids.size()); hids=tabs[dmf->CurrentTAB]->hids; printf("----------> New PLOT LOOP size of hids=%d \n",hids.size()); // now load the histograms that we want to display for( vector::const_iterator hid_it = hids.begin(); hid_it != hids.end(); hid_it++ ) { j++; if (j>tabs[dmf->CurrentTAB]->max_hist) break; //RS_CMSG->RequestHistogram(hid_it->serverName, hid_it->hnamepath); map::iterator hdef_iter0 = RS_INFO->histdefs.find(hid_it->hnamepath); if(hdef_iter0==RS_INFO->histdefs.end()) continue; //hdef_iter->second.active = true; // allow a wildcard "*" to select all servers if(hid_it->serverName != "*") { hdef_iter0->second.servers[hid_it->serverName] = true; } RS_INFO->current = hid_t(hid_it->serverName, hid_it->hnamepath); printf("current=%s \n",RS_INFO->current.hnamepath.c_str()); // add this hinfo_t object to the list map::iterator hdef_iter = RS_INFO->histdefs.find(RS_INFO->current.hnamepath); //map::iterator hdef_iter = RS_INFO->histdefs.find(hnamepaths[j]); printf("second.hists.size=%d \n",hdef_iter->second.hists.size()); printf("second.sum_hist=%p \n",hdef_iter->second.sum_hist); if(!hdef_iter->second.sum_hist) continue; tabs[dmf->CurrentTAB]->canvas->cd(j); if (!hdef_iter->second.sum_hist_modified) { printf("Skip hist=%s MOD FLAG=%d\n",hid_it->hnamepath.c_str(),hdef_iter->second.sum_hist_modified); continue; } //DrawHist(tabs[dmf->CurrentTAB]->canvas, hdef_iter->second.sum_hist, hdef_iter->second.hnamepath, hdef_iter->second.type, hdef_iter->second.display_info); hdef_t::histdimension_t hdim = hdef_iter->second.type; if(hdim == hdef_t::oneD) { TH1* h1=(TH1D*)hdef_iter->second.sum_hist; gStyle->SetOptStat("nemruo"); h1->Draw(); } else if(hdim == hdef_t::twoD) { TH1* h2=(TH1D*)hdef_iter->second.sum_hist; gStyle->SetOptStat(0); // -no statistic gStyle->SetPadRightMargin(0.3); // increase for colz plots!! gPad->SetLogz(); h2->Draw("COLZ"); } else { gStyle->SetOptStat("nemruo"); TH1* h=(TH1D*)hdef_iter->second.sum_hist; h->Draw(); } hdef_iter->second.sum_hist_modified = false; // set flag indicating we've drawn current version } printf(" main:: plot done , update canvas... \n"); HIST_UPDATED=2; tabs[dmf->CurrentTAB]->canvas->Modified(); tabs[dmf->CurrentTAB]->canvas->Update(); printf(" main:: plot done , update canvas done, usleep/process \n"); //----- sleep ----- time_t t1=time(NULL); while (1) { time_t t2=time(NULL); if ((((t2-t1)>1) || (dmf->CurrentTAB != ID)) && (HIST_UPDATED==1)) break; gSystem->ProcessEvents(); //putchar('.'); if (dmf->v_EXIT) { button_EXIT=1; break; } usleep(1); } if (button_EXIT) break; } // Hand control to the ROOT "event" loop //theApp.SetReturnFromRun(true); //theApp.Run(); if (thr_update_Tab) { thr_update_Tab->Join(); printf(" Join thr_update_Tab pass\n"); } if (thr_hist_update) { thr_hist_update->Join(); printf(" Join thr_hist_update pass\n"); } if (thr_list_update) { thr_list_update->Join(); printf(" Join thr_list_update pass\n"); } //return 0; exit(0); }