#define RESET "\033[0m" #define BLACK "\033[30m" /* Black */ #define RED "\033[31m" /* Red */ #define GREEN "\033[32m" /* Green */ #define YELLOW "\033[33m" /* Yellow */ #define BLUE "\033[34m" /* Blue */ #define MAGENTA "\033[35m" /* Magenta */ #define CYAN "\033[36m" /* Cyan */ #define WHITE "\033[37m" /* White */ #define BOLDBLACK "\033[1m\033[30m" /* Bold Black */ #define BOLDRED "\033[1m\033[31m" /* Bold Red */ #define BOLDGREEN "\033[1m\033[32m" /* Bold Green */ #define BOLDYELLOW "\033[1m\033[33m" /* Bold Yellow */ #define BOLDBLUE "\033[1m\033[34m" /* Bold Blue */ #define BOLDMAGENTA "\033[1m\033[35m" /* Bold Magenta */ #define BOLDCYAN "\033[1m\033[36m" /* Bold Cyan */ #define BOLDWHITE "\033[1m\033[37m" /* Bold White */ using namespace std; #include "RootHeader.h" #include "Riostream.h" #include "signal.h" #include "Bytes.h" #include "VMERemote.h" #include "TProfile.h" #include #define MAXCH 16 #define DETECTOR "ps" #define write_to_epics 1 /* * VMERemote * */ class VMERemote : public TObject { public: VMERemote(const char *pHost, int port) { host = pHost; this->port = port; // Socket = new TSocket(host, port, 32768); Socket = new TSocket(host, port, 32900); if(!Socket->IsValid()) { printf("Failed to connected to host: %s\n", pHost); } else printf("Successfully connected to host: %s\n" , pHost); /* set board type */ BoardType = 5; } /********/ Bool_t Reconnect() { if(Socket) { Socket->Close("force"); }; // Socket = Socket = new TSocket(host, port, 32768); Socket = new TSocket(host, port, 32900); return (Socket->IsValid()); } /********/ Bool_t WriteVME_SC(unsigned int addr, unsigned int val, unsigned int Status = 0, unsigned int Slot = 0) { if(!Socket->IsValid()) { printf("WriteVME_SC FAILED\n"); return kFALSE; } Cmd_Write_SC *pCmd_Write32; OutgoingMsg.Length = HTONL(REMOTE_MSG_SIZE(Cmd_Write_SC)-4); OutgoingMsg.BoardType = HTONL(BoardType); OutgoingMsg.MsgType = HTONL(REMOTE_CMD_WRITE_SC); pCmd_Write32 = (Cmd_Write_SC *)OutgoingMsg.Msg; pCmd_Write32->ID = HTONL(Slot); pCmd_Write32->Status = HTONL(Status); pCmd_Write32->Address = HTONL(addr); pCmd_Write32->Value = HTONL(val); Socket->SendRaw(&OutgoingMsg, REMOTE_MSG_SIZE(Cmd_Write_SC)); cout << " REMOTE_MSG_SIZE = " << REMOTE_MSG_SIZE(Cmd_Write_SC) << endl; cout << " Outgoing: Length = " << OutgoingMsg.Length << " " << REMOTE_MSG_SIZE(Cmd_Write_SC)-4 << " Board Type = " << OutgoingMsg.BoardType << " " << BoardType << " MsgType = " << OutgoingMsg.MsgType << " " << REMOTE_CMD_WRITE_SC << " Slot = " << pCmd_Write32->ID << " " << Slot << " Status = " << pCmd_Write32->Status << " " << Status << " Address = " << pCmd_Write32->Address << " " << addr << " Value = " << pCmd_Write32->Value << " " << val << endl; // Close(); return kTRUE; } /********/ Bool_t ReadVME32(unsigned int addr, unsigned int *val, unsigned int Status = 0) { if(!Socket->IsValid()) { printf("ReadVME32 FAILED\n"); return kFALSE; } Cmd_Read32 *pCmd_Read32; OutgoingMsg.Length = HTONL(REMOTE_MSG_SIZE(Cmd_Read32)-4); OutgoingMsg.BoardType = HTONL(BoardType); OutgoingMsg.MsgType = HTONL(REMOTE_CMD_READ32); pCmd_Read32 = (Cmd_Read32 *)OutgoingMsg.Msg; pCmd_Read32->Address = HTONL(addr); Socket->SendRaw(&OutgoingMsg, REMOTE_MSG_SIZE(Cmd_Read32)); if( (Socket->RecvRaw(&IncomingMsg.Length, 4) == 4) && (NTOHL(IncomingMsg.Length) <= sizeof(RemoteMsgStruct)) && (Socket->RecvRaw(&IncomingMsg.BoardType, NTOHL(IncomingMsg.Length)) == (int)NTOHL(IncomingMsg.Length)) ) { IncomingMsg.Length = NTOHL(IncomingMsg.Length); IncomingMsg.BoardType = NTOHL(IncomingMsg.BoardType); IncomingMsg.MsgType = NTOHL(IncomingMsg.MsgType); unsigned int *p = (unsigned int *)IncomingMsg.Msg; // if(IncomingMsg.MsgType == CMD_RSP(REMOTE_CMD_READ32)) // { *val = HTONL(*p); return kTRUE; // } } // Close(); return kFALSE; } Bool_t ReadVME_SC_ALL(unsigned int *val, unsigned int Status = 0, unsigned int sl_first = 0, unsigned int sl_last = 0 ) { if(!Socket->IsValid()) { printf("ReadVME_SC_ALL FAILED\n"); return kFALSE; } Cmd_Read_SC_ALL *pCmd_Read_SC_ALL; pCmd_Read_SC_ALL = (Cmd_Read_SC_ALL *)OutgoingMsg.Msg; OutgoingMsg.Length = HTONL(REMOTE_MSG_SIZE(Cmd_Read_SC_ALL)-4); OutgoingMsg.BoardType = HTONL(BoardType); OutgoingMsg.MsgType = HTONL(REMOTE_CMD_READ_SC_ALL); pCmd_Read_SC_ALL->IDF = HTONL(sl_first); pCmd_Read_SC_ALL->IDL = HTONL(sl_last); pCmd_Read_SC_ALL->Status = HTONL(Status); Socket->SendRaw(&OutgoingMsg, REMOTE_MSG_SIZE(Cmd_Read_SC_ALL)); cout << " ReadVME_SC_ALL SEND request. Length = " << REMOTE_MSG_SIZE(Cmd_Read_SC_ALL) << endl; if( (Socket->RecvRaw(&IncomingMsg.Length, 4) == 4) && (NTOHL(IncomingMsg.Length) <= sizeof(RemoteMsgStruct))) { Socket->RecvRaw(&IncomingMsg.BoardType, NTOHL(IncomingMsg.Length)); cout << " ReadVME_SC_ALL receive Scalers " << endl; IncomingMsg.Length = NTOHL(IncomingMsg.Length); IncomingMsg.BoardType = NTOHL(IncomingMsg.BoardType); IncomingMsg.MsgType = NTOHL(IncomingMsg.MsgType); cout << " Length = " << IncomingMsg.Length << " Board = " << IncomingMsg.BoardType << " Type = " << IncomingMsg.MsgType << endl; Cmd_Read_SC_ALL *p = (Cmd_Read_SC_ALL *)IncomingMsg.Msg; int status = 0; int slotf = NTOHL(p->IDF); int slotl = NTOHL(p->IDL); status = NTOHL(p->Status); cout << " Incoming SLOT FIRST: "<< slotf << " LAST: " << slotl << " Incoming SATUS: " << status << endl; if(status < 0) return kFALSE; for(unsigned int bd = 0; bd < 16; bd++){ int bd_slot; if(bd < 8) bd_slot = bd + 3; else bd_slot = bd + 5; cout << " FADC in slot " << bd_slot << endl; for(unsigned int ch = 0; ch < 17; ch++){ val[bd*17 + ch] = NTOHL(p->Value[bd*17 + ch]); cout << val[bd*17 + ch] << " "; } cout << endl; } return kTRUE; } return kFALSE; } Bool_t ReadVME_SC(unsigned int *val, unsigned int Status = 0, unsigned int Slot = 0 ) { if(!Socket->IsValid()) { printf("ReadVMESC FAILED\n"); return kFALSE; } // unsigned int fadc_id = 16; Cmd_Read_SC *pCmd_Read_SC; pCmd_Read_SC = (Cmd_Read_SC *)OutgoingMsg.Msg; OutgoingMsg.Length = HTONL(REMOTE_MSG_SIZE(Cmd_Read_SC)-4); OutgoingMsg.BoardType = HTONL(BoardType); OutgoingMsg.MsgType = HTONL(REMOTE_CMD_READ_SC); cout<< "SLOT :"<ID = HTONL(Slot); pCmd_Read_SC->Status = HTONL(Status); Socket->SendRaw(&OutgoingMsg, REMOTE_MSG_SIZE(Cmd_Read_SC)); cout << " ReadVME_SC SEND request. Length = " << REMOTE_MSG_SIZE(Cmd_Read_SC) << endl; if( (Socket->RecvRaw(&IncomingMsg.Length, 4) == 4) && (NTOHL(IncomingMsg.Length) <= sizeof(RemoteMsgStruct))) { // cout << " TEST = " << NTOHL(IncomingMsg.Length) << endl; Socket->RecvRaw(&IncomingMsg.BoardType, NTOHL(IncomingMsg.Length)); // cout << " TEST = " << RecvRaw(&IncomingMsg.BoardType, NTOHL(IncomingMsg.Length)) << endl; // (RecvRaw(&IncomingMsg.BoardType, NTOHL(IncomingMsg.Length)) == (int)NTOHL(IncomingMsg.Length)) ) // { cout << " ReadVME_SC receive Scalers " << endl; IncomingMsg.Length = NTOHL(IncomingMsg.Length); IncomingMsg.BoardType = NTOHL(IncomingMsg.BoardType); IncomingMsg.MsgType = NTOHL(IncomingMsg.MsgType); cout << " Length = " << IncomingMsg.Length << " Board = " << IncomingMsg.BoardType << " Type = " << IncomingMsg.MsgType << endl; Cmd_Read_SC *p = (Cmd_Read_SC *)IncomingMsg.Msg; int status =0; int fslot = NTOHL(p->ID); status = NTOHL(p->Status); cout << " Incoming SLOT: "<< fslot <<" Incoming SATUS: " << status << endl; if(status < 0) return kFALSE; for(unsigned int ch = 0; ch < 17; ch++){ val[ch] = NTOHL(p->Value[ch]); cout << val[ch] << " "; } cout << endl; return kTRUE; } // Close(); return kFALSE; } TSocket *Socket; /* socket for connection */ const char *host; int port; int BoardType; private: RemoteMsgStruct IncomingMsg; RemoteMsgStruct OutgoingMsg; }; class My_test : public TGMainFrame{ public: My_test(const TGWindow *p) : TGMainFrame(p, 1000, 700){ Pixel_t red; // pClient = new VMERemote("localhost",9090); // pClient = new VMERemote("halldtrg2.jlab.org",9090); //** pClient = new VMERemote("halldtrg3.jlab.org",9090); // pClient = new VMERemote(Host.c_str(), Port); // VMERemote *pClient; // VMERemote *pClient1; FILE *fd; char rname[255] = ""; SetCleanup(kDeepCleanup); // Check if client program is already running somewhere CHECK_CLIENT_RUNNING(DETECTOR) // Determine port number sprintf(rname,"rocps1"); sprintf(fname,"%s/%s.gui", fGUI_dir,rname); if((fd=fopen(fname,"r")) == NULL){ printf("\n Can't open config file >%s<\n\n",fname); printf("\n Try to connect using the default port 9090 \n"); Port = 9090; } else { fgets(str_tmp, 255, fd); sscanf (str_tmp, "%d\n", &Port); printf(BOLDBLUE "\n get Port = %d for %s from file >%s<\n\n" RESET,Port,rname,fname); fclose(fd); } pClient = new VMERemote("rocps1", Port); sprintf(rname,"rocps2"); sprintf(fname,"%s/%s.gui", fGUI_dir,rname); if((fd=fopen(fname,"r")) == NULL){ printf("\n Can't open config file >%s<\n\n",fname); printf("\n Try to connect using the default port 9090 \n"); Port = 9090; } else { fgets(str_tmp, 255, fd); sscanf (str_tmp, "%d\n", &Port); printf(BOLDBLUE "\n get Port = %d for %s from file >%s<\n\n" RESET,Port,rname,fname); fclose(fd); } pClient1 = new VMERemote("rocps2", Port); cout << " SSSS = " << pClient << endl; int nch = 128; Float_t x_min = 0.5, x_max = 128.5, y_min = -10, y_max = 1000000; hfadc_ps_left = new TProfile("FADC PS Lelt", "FADC PS Left", nch,x_min,x_max,y_min,y_max,""); hfadc_ps_right = new TProfile("FADC PS Right", "FADC PS Right", nch,x_min,x_max,y_min,y_max,""); hctp_ps_nleft = new TH1F("PS Coin Left", "PS Coin Left", nch,x_min,x_max); hctp_ps_nright = new TH1F("PS Coin Right", "PS Coin Right", nch,x_min,x_max); nch = 8; x_min = 0.5; x_max = 8.5; y_min = -10; y_max = 1000000; hfadc_psc_left = new TProfile("FADC PSC Left", "FADC PSC Left", nch,x_min,x_max,y_min,y_max,""); hfadc_psc_right = new TProfile("FADC PSC Right", "FADC PSC Right", nch,x_min,x_max,y_min,y_max,""); hctp_psc_nleft = new TH1F("PSC Coin Left", "PSC Coin Left", nch, x_min, x_max); hctp_psc_nright = new TH1F("PSC Coin Right", "PSC Coin Right", nch, x_min, x_max); hctp_ps = new TProfile("PS CTP rates: L Arm, R Arm, Coin)", "PS CTP rates ", 3, 0.5, 3.5,y_min,y_max,""); hctp_psc = new TProfile("PSC CTP rates: L Arm, R Arm, Coin)", "PSC CTP rates ", 3, 0.5, 3.5,y_min,y_max,""); nch = 65; x_min = 6.0; x_max = 12.5; hctp_en = new TH1F("Photon Energy", "Photon Energy", nch, x_min, x_max); hfadc_ps_left->GetYaxis()->SetTitle(" Rate (Hz) "); hfadc_ps_left->GetXaxis()->SetTitle(" Tile "); hfadc_ps_right->GetYaxis()->SetTitle(" Rate (Hz) "); hfadc_ps_right->GetXaxis()->SetTitle(" Tile "); hfadc_psc_left->GetYaxis()->SetTitle(" Rate (Hz) "); hfadc_psc_left->GetXaxis()->SetTitle(" Counter "); for(int ii = 1; ii < 9; ii++){ char tmp[10]; sprintf(tmp,"%d",ii); hfadc_psc_left->GetXaxis()->SetBinLabel(9 - ii, tmp); } hfadc_psc_right->GetYaxis()->SetTitle(" Rate (Hz) "); hfadc_psc_right->GetXaxis()->SetTitle(" Counter "); for(int ii = 1; ii < 9; ii++){ char tmp[10]; sprintf(tmp,"%d",ii); hfadc_psc_right->GetXaxis()->SetBinLabel(ii, tmp); } // hctp_ps->GetXaxis()->SetTitle("Scaler "); hctp_ps->GetYaxis()->SetTitle("Rate (Hz) "); hctp_ps->GetXaxis()->SetBinLabel(1,"Left"); hctp_ps->GetXaxis()->SetBinLabel(2,"Right"); hctp_ps->GetXaxis()->SetBinLabel(3,"Coinc"); // hctp_psc->GetXaxis()->SetTitle("Scaler "); hctp_psc->GetYaxis()->SetTitle("Rate (Hz) "); hctp_psc->GetXaxis()->SetBinLabel(1,"Left"); hctp_psc->GetXaxis()->SetBinLabel(2,"Right"); hctp_psc->GetXaxis()->SetBinLabel(3,"Coinc"); hctp_en->GetYaxis()->SetTitle("Events "); hctp_en->GetXaxis()->SetTitle("Energy "); hctp_ps_nleft->GetXaxis()->SetTitle(" Tile "); hctp_ps_nleft->GetYaxis()->SetTitle(" Events "); hctp_psc_nleft->GetXaxis()->SetTitle(" Counter "); hctp_psc_nleft->GetYaxis()->SetTitle(" Events "); gStyle->SetOptStat(0); // gStyle->SetTitleX(0.1f); // gStyle->SetTitleW(0.8f); gStyle->SetLineWidth(1.5); gStyle->SetTextSize(1.5); gStyle->SetTitleFont(30,"xy"); gStyle->SetLabelFont(30,"xy"); // gStyle->SetLabelSize(0.069,"xy"); // gStyle->SetTitleSize(0.065,"xy"); // gStyle->SetTitleOffset(1.,"xy"); // gStyle->SetTitleOffset(1.,"y"); // gStyle->SetTitleFontSize(0.08); AddFrame(pFrameTop = new TGVerticalFrame(this), new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); //| kLHintsCenterY pFrameTop->AddFrame(pFrameTimer = new TGHorizontalFrame(pFrameTop), new TGLayoutHints(kLHintsExpandX | kLHintsTop, 0, 0, 40, 40 )); pFrameTimer->AddFrame(fTStartButton = new TGTextButton(pFrameTimer, " &Exit ", 515), new TGLayoutHints( kLHintsRight | kLHintsTop, 0, 20, 0, 0)); pFrameTimer->AddFrame(pLabelTimer1 = new TGLabel(pFrameTimer, new TGString("Update Timer (sec): ")), new TGLayoutHints(kLHintsLeft, 20, 2, 2, 0)); pFrameTimer->AddFrame(pValueTimer = new TGNumberEntry(pFrameTimer, 0, 5, 500, TGNumberFormat::kNESInteger, TGNumberFormat::kNEAAnyNumber, TGNumberFormat::kNELLimitMinMax, 1, 20), new TGLayoutHints(kLHintsLeft, 0, 20, 0, 0)); pFrameTimer->AddFrame(fExitButton = new TGTextButton(pFrameTimer, " &Start ", 510), new TGLayoutHints( kLHintsLeft | kLHintsTop, 0, 20, 0, 0)); pFrameTimer->AddFrame(fTResetButton = new TGTextButton(pFrameTimer, " &Stop ", 511), new TGLayoutHints( kLHintsLeft | kLHintsTop, 0, 20, 0, 0)); pFrameTimer->AddFrame(fTStopButton = new TGTextButton(pFrameTimer, " &Reset ", 512), new TGLayoutHints( kLHintsLeft | kLHintsTop, 0, 20, 0, 0)); pValueTimer->SetIntNumber(1); pValueTimer->SetWidth(50); pFrameTop->AddFrame(fF1 = new TGCompositeFrame(pFrameTop, 100,200,kHorizontalFrame), new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 5, 5, 0, 0)); fF1->AddFrame(fEcanvas1 = new TRootEmbeddedCanvas("PS FADC L",fF1,100,200), new TGLayoutHints(kLHintsLeft | kLHintsExpandX | kLHintsExpandY , 20, 0, 0, 10)); fF1->AddFrame(fEcanvas2 = new TRootEmbeddedCanvas("PS FADC R",fF1,100,200), new TGLayoutHints(kLHintsLeft | kLHintsExpandX | kLHintsExpandY , 20, 0, 0, 10)); fF1->AddFrame(fEcanvas3 = new TRootEmbeddedCanvas("PS CTP",fF1,100,200), new TGLayoutHints(kLHintsLeft | kLHintsExpandX | kLHintsExpandY , 40, 0, 0, 10)); fF1->AddFrame(fEcanvas4 = new TRootEmbeddedCanvas("PS Coincidence",fF1,100,200), new TGLayoutHints(kLHintsLeft | kLHintsExpandX | kLHintsExpandY , 20, 20, 0, 10)); pFrameTop->AddFrame(fF2 = new TGCompositeFrame(pFrameTop, 100, 200, kHorizontalFrame), new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 5, 5, 0, 0)); fF2->AddFrame(fEcanvas11 = new TRootEmbeddedCanvas("PSC FADC L",fF2), new TGLayoutHints(kLHintsLeft | kLHintsExpandX | kLHintsExpandY , 20, 0, 0, 10)); fF2->AddFrame(fEcanvas12 = new TRootEmbeddedCanvas("PSC FADC R",fF2), new TGLayoutHints(kLHintsLeft | kLHintsExpandX | kLHintsExpandY , 20, 0, 0, 10)); fF2->AddFrame(fEcanvas13 = new TRootEmbeddedCanvas("PS CTP",fF2), new TGLayoutHints(kLHintsLeft | kLHintsExpandX | kLHintsExpandY , 40, 0, 0, 10)); fF2->AddFrame(fEcanvas14 = new TRootEmbeddedCanvas("PSC Coincidence",fF2), new TGLayoutHints(kLHintsLeft | kLHintsExpandX | kLHintsExpandY , 20, 20, 0, 10)); // ----- Print PS and PSC coincidence rates pFrameTop->AddFrame(fF3 = new TGCompositeFrame(pFrameTop, 100, 200, kHorizontalFrame), new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0)); fF3->AddFrame(pFrameRight = new TGVerticalFrame(fF3), new TGLayoutHints(kLHintsExpandX | kLHintsCenterY | kLHintsRight, 0, 0, 0, 0 )); // PS rate pFrameRight->AddFrame(pFrameLabel = new TGHorizontalFrame(pFrameRight), new TGLayoutHints(kLHintsExpandX | kLHintsCenterY | kLHintsRight, 0, 0, 0, 0 )); pFrameLabel->AddFrame(pLabelRate = new TGLabel(pFrameLabel, new TGString("Coincidence Rate PS (Hz): ")), new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 20, 30, 0, 0)); tbuf_rate = new TGTextBuffer(10); tbuf_rate->AddText(0,"0.0"); tent_rate = new TGTextEntry(pFrameLabel, tbuf_rate); tent_rate->Resize(100,tent_rate->GetDefaultHeight()); // tent_rate->Resize(100,80); pFrameLabel->AddFrame(tent_rate, new TGLayoutHints(kLHintsExpandY | kLHintsCenterY | kLHintsLeft, 10, 0, 10, 10)); // PSC rate pFrameRight->AddFrame(pFrameLabel1 = new TGHorizontalFrame(pFrameRight), new TGLayoutHints(kLHintsExpandX | kLHintsCenterY | kLHintsRight, 0, 0, 0, 0 )); pFrameLabel1->AddFrame(pLabelRate1 = new TGLabel(pFrameLabel1, new TGString("Coincidence Rate PSC (Hz): ")), new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 20, 30, 2, 0)); gClient->GetColorByName("red", red); pLabelRate1->SetTextColor(red); tbuf_rate1 = new TGTextBuffer(10); tbuf_rate1->AddText(0,"0.0"); tent_rate1 = new TGTextEntry(pFrameLabel1, tbuf_rate1); tent_rate1->Resize(100,tent_rate1->GetDefaultHeight()); pFrameLabel1->AddFrame(tent_rate1, new TGLayoutHints(kLHintsExpandY | kLHintsCenterY | kLHintsLeft, 0, 0, 10, 10)); fF3->AddFrame(fEcanvas20 = new TRootEmbeddedCanvas("PS Energy",fF3,100,30), new TGLayoutHints(kLHintsLeft | kLHintsExpandX | kLHintsExpandY , 25, 0, 10, 10)); gStyle->SetOptStat(0); gStyle->SetTitleFontSize(0.08); hfadc_ps_left->SetLabelSize(0.075,"xy"); hfadc_ps_left->SetTitleSize(0.075,"xy"); hfadc_ps_left->SetTitleOffset(1.1,"xy"); // hfadc_ps_left->SetTitleFont(22.,"xy"); hfadc_ps_right->SetLabelSize(0.075,"xy"); hfadc_ps_right->SetTitleSize(0.075,"xy"); hfadc_ps_right->SetTitleOffset(1.1,"xy"); hfadc_psc_left->SetLabelSize(0.075,"y"); hfadc_psc_left->SetLabelSize(0.12,"x"); hfadc_psc_left->SetTitleSize(0.075,"xy"); hfadc_psc_left->SetTitleOffset(1.1,"xy"); hfadc_psc_right->SetLabelSize(0.075,"y"); hfadc_psc_right->SetLabelSize(0.12,"x"); hfadc_psc_right->SetTitleSize(0.075,"xy"); hfadc_psc_right->SetTitleOffset(1.1,"xy"); hctp_ps->SetLabelSize(0.075,"y"); hctp_ps->SetLabelSize(0.12,"x"); hctp_ps->SetTitleSize(0.075,"xy"); hctp_ps->SetTitleOffset(1.1,"xy"); hctp_psc->SetLabelSize(0.075,"y"); hctp_psc->SetLabelSize(0.12,"x"); hctp_psc->SetTitleSize(0.075,"xy"); hctp_psc->SetTitleOffset(1.1,"xy"); hctp_en->SetLabelSize(0.075,"xy"); hctp_en->SetTitleSize(0.075,"xy"); hctp_en->SetTitleOffset(1.,"x"); hctp_en->SetTitleOffset(0.5,"y"); hctp_psc_nleft->SetLabelSize(0.075,"xy"); hctp_psc_nleft->SetTitleSize(0.075,"xy"); hctp_psc_nleft->SetTitleOffset(1.1,"xy"); hctp_ps_nleft->SetLabelSize(0.075,"xy"); hctp_ps_nleft->SetTitleSize(0.075,"xy"); hctp_ps_nleft->SetTitleOffset(1.1,"xy"); fCanvas1 = fEcanvas1->GetCanvas(); fCanvas1->cd(); hfadc_ps_left->Draw(); gPad->SetBottomMargin(0.16); gPad->SetLeftMargin(0.16); fCanvas2 = fEcanvas2->GetCanvas(); fCanvas2->cd(); hfadc_ps_right->Draw(); gPad->SetBottomMargin(0.16); gPad->SetLeftMargin(0.16); fCanvas3 = fEcanvas3->GetCanvas(); fCanvas3->cd(); hctp_ps->Draw(); gPad->SetBottomMargin(0.16); gPad->SetLeftMargin(0.16); fCanvas4 = fEcanvas4->GetCanvas(); fCanvas4->cd(); hctp_ps_nleft->Draw(); gPad->SetBottomMargin(0.16); gPad->SetLeftMargin(0.16); fCanvas11 = fEcanvas11->GetCanvas(); fCanvas11->cd(); hfadc_psc_left->Draw(); gPad->SetBottomMargin(0.16); gPad->SetLeftMargin(0.16); fCanvas12 = fEcanvas12->GetCanvas(); fCanvas12->cd(); hfadc_psc_right->Draw(); gPad->SetBottomMargin(0.16); gPad->SetLeftMargin(0.16); fCanvas13 = fEcanvas13->GetCanvas(); fCanvas13->cd(); hctp_psc->Draw(); gPad->SetBottomMargin(0.16); gPad->SetLeftMargin(0.16); fCanvas14 = fEcanvas14->GetCanvas(); fCanvas14->cd(); hctp_psc_nleft->Draw(); gPad->SetBottomMargin(0.16); gPad->SetLeftMargin(0.16); fCanvas20 = fEcanvas20->GetCanvas(); fCanvas20->cd(); hctp_en->Draw(); gPad->SetBottomMargin(0.15); gPad->SetLeftMargin(0.12); // MapSubwindows(); // Resize(500, 800); pValueTimer->Associate(this); fTStartButton->Associate(this); fTStopButton->Associate(this); fTResetButton->Associate(this); fExitButton->Associate(this); my_timer = new TTimer(this, 10, kTRUE); MapSubwindows(); Resize(GetDefaultSize()); Resize(1000,700); MapWindow(); }; /*******/ Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t){ cout << " I am here " << GET_MSG(msg) << endl; switch (GET_MSG(msg)) { case kC_COMMAND: { switch (GET_SUBMSG(msg)) { case kCM_BUTTON: { switch (parm1) { case 510: { cout << " Clicked Start Timer Button: Activate Timer " << " " << pValueTimer->GetIntNumber() << " s " << endl; my_timer->Stop(); // SASCHA my_timer->Start(100*pValueTimer->GetIntNumber(),kFALSE); // my_timer->Start(100*pValueTimer->GetIntNumber(),kFALSE); break; } case 511: { cout << " Clicked Stop Timer Button " << endl; my_timer->Stop(); cout << " pClient = " << pClient << endl; break; } case 512: { cout << " Clicked Reset Button. Reset Plots " << endl; hctp_ps_nleft->Reset(); hctp_ps_nright->Reset(); hctp_psc_nleft->Reset(); hctp_psc_nright->Reset(); hctp_en->Reset(); cout << " pClient = " << pClient << endl; break; } case 515: { cout << " Exit " << endl; sprintf(fname,"%s/%s_client.log", fGUI_dir, dname); if((remove(fname)) == 0) printf(" Log file deleted successfully \n\n"); else printf(" Error: unable to delete log file \n\n"); gApplication->Terminate(); break; } break; } break; } } break; } case kC_TEXTENTRY: { switch(GET_SUBMSG(msg)) { case kTE_TEXTCHANGED: { switch(parm1) { case 500: { cout << " Timer rate will be set after pressing Start button : " << pValueTimer->GetIntNumber() << endl; break; } } break; } break; } break; } } return kTRUE; }; int read_fadc_sc(VMERemote *pClient_tmp, unsigned int slot_min, unsigned int slot_max, float rate_tmp[256], int fadc_time_prev[16], int fadc_sc_prev[256]){ Float_t time = 0.; unsigned int sc_all[272]; static unsigned int aaa[272]; memset(sc_all, 0, sizeof(sc_all)); memset(rate_tmp, 0, sizeof(rate_tmp)); cout << " I am here ==== " << " Slot min = " << slot_min << " Slot_max = " << slot_max << "pClient " << pClient_tmp << endl; if( pClient_tmp->ReadVME_SC_ALL(&sc_all[0], 0, slot_min, slot_max) ){ #if 0 for(int ii = 0; ii < 16; ii++){ int time_cnt = 17*ii + 16; aaa[time_cnt] += 100; for(int ch = 0; ch < MAXCH; ch++) { int rate_ind = 17*ii + ch; aaa[rate_ind] += 10; } } for(int ii = 0; ii < 272; ii++){ sc_all[ii] = aaa[ii]; cout << " " << sc_all[ii]; } cout << endl; #endif for(int bd = 0; bd < 16; bd++){ int time_cnt = 17*bd + 16; // time = ((Float_t) sc_all[time_cnt])*2048/1.e9; /* time in sec between scalers readout (one count of scaler timer(last channel from scaler readout) is 2048ns */ time = ((Float_t) (sc_all[time_cnt] - fadc_time_prev[bd] ))*2048/1.e9; cout << " Board = " << bd << " Timer = " << time <<" sec" << endl << endl; if(time > 0) { for(int ch = 0; ch < MAXCH; ch++) { int ch_ind = 17*bd + ch; int rate_ind = 16*bd + ch; // cout << " " << sc_all[ch_ind] << " " << fadc_sc_prev[rate_ind] << endl; if( (sc_all[ch_ind] - fadc_sc_prev[rate_ind]) <= 0){ rate_tmp[rate_ind] = 0; } else { rate_tmp[rate_ind] = (sc_all[ch_ind] - fadc_sc_prev[rate_ind])/time; /*rate in Hz */ } // cout << " CH " << ch_ind << " " << sc_all[ch_ind] << " " << rate[ch] << " Hz/s "; fadc_sc_prev[rate_ind] = sc_all[ch_ind]; // cout << " " << fadc_sc_prev[rate_ind] << endl; } } else { int my_slot; if(bd < 8) my_slot = bd + 3; else my_slot = bd + 5; cout << "-->> ERROR: Slot: " << my_slot << " Timer channel(16) returns zero: Don't update Scalers rate " << endl; } fadc_time_prev[bd] = sc_all[time_cnt]; } // loop over boards return 0; } else { cout << " : Error reading scalers from server: " << (pClient_tmp->Socket->GetInetAddress()).GetHostName()<<" : "<< (pClient_tmp->Socket->GetInetAddress()).GetHostAddress()<< endl; //** need to reconnect here? if(!pClient_tmp->Reconnect()) cout << "-->> ERROR : Cannot reconnect to server: " << (pClient_tmp->Socket->GetInetAddress()).GetHostName()<<" : "<< (pClient_tmp->Socket->GetInetAddress()).GetHostAddress()<< endl; else{ cout << "**>> Connection to server restored: " << (pClient_tmp->Socket->GetInetAddress()).GetHostName()<<" : "<< (pClient_tmp->Socket->GetInetAddress()).GetHostAddress()<< endl; } } return -1; } int read_ctp_sc(VMERemote *pClient_tmp, float ctp_rate[7], unsigned long long &ctp_time_prev){ unsigned int ctp_sc[17]; unsigned long long ctp_time; int debug_ctp = 0; memset(ctp_sc,0,sizeof(ctp_sc)); if( pClient_tmp->ReadVME_SC(&ctp_sc[0], 10, 3) ) { cout << " Timestamp: " << std::hex << ctp_sc[0] << " " << ctp_sc[1] << std::dec << endl; cout << "Left Arm Counter: " << ctp_sc[2] << endl; cout << "Right Arm Counter: " << ctp_sc[3] << endl; cout << "Coinc Counter: " << ctp_sc[4] << endl; int hit_right = ctp_sc[5]; int hit_left = ctp_sc[6]; cout << "Hit channel (R) : " << hit_right << " (L) : " << hit_left << endl; ctp_time = (((uint64_t) ctp_sc[0] <<32 ) | ctp_sc[1] ); Float_t ctp_time_stamp = ((Float_t) (ctp_time - ctp_time_prev))*4./1.e9; if(debug_ctp){ cout << std::hex << " OLD TIME = " << ctp_time_prev << " NEW TIME = " << ctp_time << std::dec << endl; cout << " TIME DIFFERENCE = " << ctp_time_stamp << endl; } if( ctp_time != ctp_time_prev ){ ctp_rate[2] = ctp_sc[2] / ctp_time_stamp; ctp_rate[3] = ctp_sc[3] / ctp_time_stamp; ctp_rate[4] = ctp_sc[4] / ctp_time_stamp; ctp_rate[5] = ctp_sc[5]; ctp_rate[6] = ctp_sc[6]; } else { ctp_rate[2] = 0; ctp_rate[3] = 0; ctp_rate[4] = 0; ctp_rate[5] = 0; ctp_rate[6] = 0; } cout << " ------------------- " << endl; cout << " RATE FOR HIGH-GRAN COUNTERS = " << ctp_rate[4] << endl; cout << " ------------------- " << endl; ctp_time_prev = ctp_time; return 0; } return -1; } /*******/ virtual Bool_t HandleTimer(TTimer *t) { // Float_t fadc_rate_ps[256]; /* fadc scalers for all boards in the crate, PS */ // Float_t fadc_rate_psc[256]; /* fadc scalers for all boards in the crate, PSC */ // Float_t ctp_rate_ps[7]; // Float_t ctp_rate_psc[7]; static unsigned long long ctp_time_prev_ps; static unsigned long long ctp_time_prev_psc; static int fadc_time_prev_ps[16]; static int fadc_time_prev_psc[16]; static int fadc_sc_prev_ps[256]; static int fadc_sc_prev_psc[256]; memset(fadc_rate_ps, 0, sizeof(fadc_rate_ps)); memset(fadc_rate_psc, 0, sizeof(fadc_rate_psc)); memset(ctp_rate_ps, 0, sizeof(ctp_rate_ps)); memset(ctp_rate_psc, 0, sizeof(ctp_rate_psc)); // Read out FADC scalers read_fadc_sc(pClient, 3, 20, fadc_rate_ps, fadc_time_prev_ps, fadc_sc_prev_ps); read_fadc_sc(pClient1, 6, 6, fadc_rate_psc, fadc_time_prev_psc, fadc_sc_prev_psc); read_ctp_sc(pClient, ctp_rate_ps, ctp_time_prev_ps); read_ctp_sc(pClient1, ctp_rate_psc, ctp_time_prev_psc); UpdatePlot(); // Print rate tbuf_rate->Clear(); char buffer[20]; if(write_to_epics){ char epics_ps[100]; // ctp_rate_ps[4] = 100.4; sprintf(epics_ps, "caput PS:coinc:scaler:rate %f &", ctp_rate_ps[4]); system(epics_ps); // printf("Write PS rate to EPICS: %s\n", epics_ps); } sprintf(buffer,"%8.1f",ctp_rate_ps[4]); tbuf_rate->AddText(0, buffer); tent_rate->SetCursorPosition(tent_rate->GetCursorPosition()); tent_rate->Deselect(); fClient->NeedRedraw(tent_rate); tbuf_rate1->Clear(); char buffer1[20]; if(write_to_epics){ char epics_psc[100]; // ctp_rate_psc[4] = 100.5; sprintf(epics_psc, "caput PSC:coinc:scaler:rate %f &", ctp_rate_psc[4]); system(epics_psc); // printf("Write PS rate to EPICS: %s\n", epics_psc); } sprintf(buffer1,"%8.1f",ctp_rate_psc[4]); tbuf_rate1->AddText(0, buffer1); tent_rate1->SetCursorPosition(tent_rate1->GetCursorPosition()); tent_rate1->Deselect(); fClient->NeedRedraw(tent_rate1); #if 0 // Read Thresholds, HAS TO BE CHECKED unsigned int Thr[17]; for(int bd = 5; bd < 6; bd++){ if( pClient->ReadVME_SC(&Thr[0], 1, bd) ){ cout << "PS Thr[0] = " << Thr[0] << " Thr[1] = " << Thr[1] << endl; } if( pClient1->ReadVME_SC(&Thr[0], 1, bd) ){ cout << "PSC Thr[0] = " << Thr[0] << " Thr[1] = " << Thr[1] << endl; } } #endif cout << " Timer " << endl; return kTRUE; }; void UpdatePlot(){ hfadc_ps_left->Reset(); hfadc_ps_right->Reset(); hfadc_psc_left->Reset(); hfadc_psc_right->Reset(); hctp_ps->Reset(); hctp_psc->Reset(); // PSC 1 - 128 (left) 256 - 129 (right) for(int ch = 0; ch < 128; ch++){ hfadc_ps_left->Fill( (Float_t) ch + 1, fadc_rate_ps[ch]); hfadc_ps_right->Fill( (Float_t) ch + 1, fadc_rate_ps[255 - ch]); // cout << " " << fadc_rate_ps[255 - ch]; } cout << endl; // cout << " PSC rates = " << endl; for(int ch = 0; ch < 8; ch++){ int board_psc = 3; // Slot 6 int index = 16*board_psc; // cout << " " << fadc_rate_psc[index + 7 - ch] << " " << fadc_rate_psc[index + 8 + ch] << endl; hfadc_psc_left->Fill( (Float_t) ch + 1, fadc_rate_psc[index + 7 - ch]); hfadc_psc_right->Fill( (Float_t) ch + 1, fadc_rate_psc[index + 8 + ch]); } // FADC scalers fCanvas1->cd(); hfadc_ps_left->Draw("histo"); fCanvas1->Update(); fCanvas2->cd(); hfadc_ps_right->Draw("histo"); fCanvas2->Update(); fCanvas11->cd(); hfadc_psc_left->Draw("histo"); fCanvas11->Update(); fCanvas12->cd(); hfadc_psc_right->Draw("histo"); fCanvas12->Update(); hctp_ps->Fill( (Float_t) 1, ctp_rate_ps[2]); hctp_ps->Fill( (Float_t) 2, ctp_rate_ps[3]); hctp_ps->Fill( (Float_t) 3, ctp_rate_ps[4]); hctp_psc->Fill( (Float_t) 1, ctp_rate_psc[2]); hctp_psc->Fill( (Float_t) 2, ctp_rate_psc[3]); hctp_psc->Fill( (Float_t) 3, ctp_rate_psc[4]); fCanvas3->cd(); hctp_ps->Draw("histo"); fCanvas3->Update(); fCanvas13->cd(); hctp_psc->Draw("histo"); fCanvas13->Update(); // Don't reset here, accumulate statistics hctp_ps_nright->Fill(ctp_rate_ps[5]); hctp_ps_nleft->Fill(ctp_rate_ps[6]); hctp_psc_nright->Fill(ctp_rate_psc[5]); hctp_psc_nleft->Fill(ctp_rate_psc[6]); fCanvas4->cd(); hctp_ps_nleft->Draw("histo"); fCanvas4->Update(); fCanvas14->cd(); hctp_psc_nleft->Draw("histo"); fCanvas14->Update(); #if 1 int nleft = ctp_rate_ps[5]; int nright = ctp_rate_ps[6]; cout << " CHECK: " << ctp_rate_ps[5] << " " << ctp_rate_ps[6] << " " << nleft << " " << nright << endl; Float_t left_en = 0.; Float_t right_en = 0.; Float_t phot_en = 0.; if ( (0 < nleft) && (nleft <= 88) ) { left_en = 3.45 + 0.026*nleft; } else if ( (nleft > 88) && (nleft <= 128) ) left_en = 5.74 + 0.013*(nleft - 88); if ( (0 < nright) && (nright <= 88) ) { right_en = 3.45 + 0.026*nright; } else if ( (nright > 88) && (nright <= 128) ) right_en = 5.74 + 0.013*(nright - 88); if(nright > 0 && nleft > 0){ phot_en = left_en + right_en; hctp_en->Fill(phot_en); } else cout << " WRONG CTP HIT: Left = " << ctp_rate_ps[5] << " Right = " << ctp_rate_ps[6] << endl; fCanvas20->cd(); hctp_en->Draw("histo"); fCanvas20->Update(); #endif } private: TGVerticalFrame *pFrameTop; TGHorizontalFrame *pFrameBot; TGVerticalFrame *pFrameLeft; TGVerticalFrame *pFrameRight; TGHorizontalFrame *pFrameLabel; TGHorizontalFrame *pFrameLabel1; TGHorizontalFrame *pFrameTimer; TGLabel *pLabelHost; TGLabel *pLabelTimer1; TGLabel *pLabelRate; TGLabel *pLabelRate1; TGNumberEntry *pValueTimer; TGTextButton *fTStartButton, *fTStopButton, *fTResetButton, *fExitButton; TProfile *hfadc_ps_left, *hfadc_ps_right; TProfile *hfadc_psc_left, *hfadc_psc_right; TH1F *hctp_ps_nleft, *hctp_ps_nright; TH1F *hctp_psc_nleft, *hctp_psc_nright; TH1F *hctp_en; TProfile *hctp_ps, *hctp_psc; TProfile *hctp; TH1F *hctp_nleft, *hctp_nright; TCanvas *fCanvas1, *fCanvas2, *fCanvas3, *fCanvas4, *fCanvas11, *fCanvas12, *fCanvas13, *fCanvas14, *fCanvas20 ; TRootEmbeddedCanvas *fEcanvas1, *fEcanvas2, *fEcanvas3, *fEcanvas4, *fEcanvas11, *fEcanvas12, *fEcanvas13, *fEcanvas14, *fEcanvas20; TGCompositeFrame *fF1, *fF2, *fF3; TTimer *my_timer; TGTextBuffer *tbuf_host, *tbuf_rate, *tbuf_rate1; TGTextEntry *tent_host, *tent_rate, *tent_rate1; Float_t fadc_rate_ps[256]; /* fadc scalers for all boards in the crate, PS */ Float_t fadc_rate_psc[256]; /* fadc scalers for all boards in the crate, PSC */ Float_t ctp_rate_ps[7]; Float_t ctp_rate_psc[7]; VMERemote *pClient; VMERemote *pClient1; int Port; // Port string Host; // Host }; /***************************************************/ /***************************************************/ int main(int argc, char* argv[]) { int cargc = 1; TApplication App("Diagnostic GUI", &cargc, argv); // signal(SIGILL, SIG_DFL); // signal(SIGSEGV, SIG_DFL); // signal(SIGBUS, SIG_DFL); if (signal(SIGINT, sig_handler) == SIG_ERR) printf("\ncan't catch SIGINT\n"); if (signal(SIGTERM, sig_handler) == SIG_ERR) printf("\ncan't catch SIGTERM\n"); if(gROOT->IsBatch()) { fprintf(stderr, "%s: cannot run in batch mode\n", argv[0]); return 1; } My_test *a = new My_test(gClient->GetRoot()); /* example to set the same threshold for all channels */ // if(a->pClient->WriteVME_SC(0, 150, 5, 16)) /* send default thresholds 150mv for all channels in slot 16*/ // for(int i=0;i<16;i++) a->SetGUIThreshold(i,150); App.Run(); return 0; }