#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 */ #include "RootHeader.h" #include "Riostream.h" #include "signal.h" #include "Bytes.h" #include "VMERemote.h" #include "TProfile.h" #include #define MAXCH 16 #define DETECTOR "trig" #define write_to_epics 1 using namespace std; /* * 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_TS(unsigned int *val, unsigned int Status = 0 ) { if(!Socket->IsValid()) { printf("ReadVME_TS FAILED\n"); return kFALSE; } Cmd_Read_TS *pCmd_Read_TS; pCmd_Read_TS = (Cmd_Read_TS *)OutgoingMsg.Msg; OutgoingMsg.Length = HTONL(REMOTE_MSG_SIZE(Cmd_Read_TS)-4); OutgoingMsg.BoardType = HTONL(BoardType); OutgoingMsg.MsgType = HTONL(REMOTE_CMD_READ_TS); pCmd_Read_TS->Status = HTONL(Status); Socket->SendRaw(&OutgoingMsg, REMOTE_MSG_SIZE(Cmd_Read_TS)); cout << " ReadVME_TS SEND request. Length = " << REMOTE_MSG_SIZE(Cmd_Read_TS) << endl; if( (Socket->RecvRaw(&IncomingMsg.Length, 4) == 4) && (NTOHL(IncomingMsg.Length) <= sizeof(RemoteMsgStruct))) { Socket->RecvRaw(&IncomingMsg.BoardType, NTOHL(IncomingMsg.Length)); cout << " ReadVME_TS 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_TS *p = (Cmd_Read_TS *)IncomingMsg.Msg; int status = 0; status = NTOHL(p->Status); cout << " Incoming SATUS: " << status << endl; if(status < 0) return kFALSE; for(unsigned int sc = 0; sc < 66; sc++){ val[sc] = NTOHL(p->Value[sc]); cout << val[sc] << " "; } cout << endl; return kTRUE; } 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, 900, 450){ FILE *fd; char rname[20] = "roctrig1"; SetCleanup(kDeepCleanup); // Check if client program is already running somewhere CHECK_CLIENT_RUNNING(DETECTOR) // Determine port number sprintf(fname,"%s/%s.gui", fGUI_dir, rname); if((fd = fopen(fname,"r")) == NULL){ printf(BOLDRED "\n Can't open config file >%s<\n\n" RESET, 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(rname, Port); int nch = 16; Float_t x_min = -0.5, x_max = 15.5, y_min = -10, y_max = 10000000; hfadc[0] = new TProfile("TS GTP", "TS GTP", nch, x_min, x_max, y_min, y_max,""); hfadc[0]->GetXaxis()->SetTitle(" GTP input"); hfadc[0]->GetYaxis()->SetTitle(" Rate (Hz) "); hfadc[0]->SetLabelSize(0.075,"xy"); hfadc[0]->SetTitleSize(0.075,"xy"); hfadc[0]->SetTitleOffset(1.1,"xy"); nch = 16; x_min = 0.5, x_max = 16.5, y_min = -10, y_max = 10000000; hfadc[1] = new TProfile("TS FP", "TS FP", nch, x_min, x_max, y_min, y_max,""); hfadc[1]->GetXaxis()->SetTitle(" FP input"); hfadc[1]->GetYaxis()->SetTitle(" Rate (Hz) "); hfadc[1]->SetLabelSize(0.075,"xy"); hfadc[1]->SetTitleSize(0.075,"xy"); hfadc[1]->SetTitleOffset(1.1,"xy"); gStyle->SetOptStat(0); gStyle->SetLineWidth(1.5); gStyle->SetTextSize(1.5); gStyle->SetTitleFont(30,"xy"); gStyle->SetLabelFont(30,"xy"); 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)); for(int frame = 0; frame < 2; frame++){ char tmp[20]; sprintf(tmp,"TS_%d",frame + 1); fF1->AddFrame(fEcanvas[frame] = new TRootEmbeddedCanvas("tmp",fF1,100,200), new TGLayoutHints(kLHintsLeft | kLHintsExpandX | kLHintsExpandY , 20, 0, 0, 10)); } fF1->AddFrame(pFrameRight = new TGVerticalFrame(fF1), new TGLayoutHints(kLHintsExpandX | kLHintsCenterY | kLHintsRight, 0, 0, 0, 0 )); pFrameRight->AddFrame(pFrameLabelGTP = new TGHorizontalFrame(pFrameRight), new TGLayoutHints(kLHintsExpandX | kLHintsCenterY | kLHintsRight, 0, 0, 0, 0 )); pFrameLabelGTP->AddFrame(pLabelGTP = new TGLabel(pFrameLabelGTP, new TGString(" GTP Rate (Hz)")), new TGLayoutHints(kLHintsCenterX | kLHintsCenterY, 20, 30, 10, 10)); for(int label = 0; label < 4; label++){ char tmp[20]; sprintf(tmp," Lane %d ", label); pFrameRight->AddFrame(pFrameLabel[label] = new TGHorizontalFrame(pFrameRight), new TGLayoutHints(kLHintsExpandX | kLHintsCenterY | kLHintsRight, 0, 0, 0, 0 )); pFrameLabel[label]->AddFrame(pLabelRate = new TGLabel(pFrameLabel[label], new TGString(tmp)), new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 20, 30, 0, 0)); tbuf_rate[label] = new TGTextBuffer(10); tbuf_rate[label]->AddText(0,"0.0"); tent_rate[label] = new TGTextEntry(pFrameLabel[label], tbuf_rate[label]); tent_rate[label]->Resize(100,tent_rate[label]->GetDefaultHeight()); pFrameLabel[label]->AddFrame(tent_rate[label], new TGLayoutHints(kLHintsExpandY | kLHintsCenterY | kLHintsLeft, 10, 0, 10, 10)); } pFrameRight->AddFrame(pFrameLabelTS = new TGHorizontalFrame(pFrameRight), new TGLayoutHints(kLHintsExpandX | kLHintsCenterY | kLHintsRight, 0, 0, 0, 0 )); pFrameLabelTS->AddFrame(pLabelTS = new TGLabel(pFrameLabelTS, new TGString(" TS livetime ( % )")), new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 20, 30, 0, 0)); tbuf_rate_lt = new TGTextBuffer(10); tbuf_rate_lt->AddText(0,"0.0"); tent_rate_lt = new TGTextEntry(pFrameLabelTS, tbuf_rate_lt); tent_rate_lt->Resize(100,tent_rate_lt->GetDefaultHeight()); pFrameLabelTS->AddFrame(tent_rate_lt, new TGLayoutHints(kLHintsExpandY | kLHintsCenterY | kLHintsLeft, 10, 0, 10, 10)); // gStyle->SetOptStat(0); gStyle->SetTitleFontSize(0.08); for(int frame = 0; frame < 2; frame++){ fCanvas[frame] = fEcanvas[frame]->GetCanvas(); fCanvas[frame]->cd(); hfadc[frame]->GetXaxis()->SetNdivisions(508,-1); hfadc[frame]->Draw(); gPad->SetBottomMargin(0.16); gPad->SetLeftMargin(0.16); } 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(900,350); 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(1000*pValueTimer->GetIntNumber(),kFALSE); // my_timer->Start(100*pValueTimer->GetIntNumber(),kFALSE); break; } case 511: { cout << " Clicked Stop Timer Button " << endl; my_timer->Stop(); 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(); 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_ts_sc(VMERemote *pClient_tmp, float ts_tmp[66], unsigned int ts_sc_prev[66]){ unsigned int ts_sc_all[66]; unsigned int live_time; unsigned int busy_time; unsigned int status = 0; memset(ts_sc_all, 0, sizeof(ts_sc_all)); if( pClient_tmp->ReadVME_TS(&ts_sc_all[0], status) ){ live_time = ts_sc_all[64]; busy_time = ts_sc_all[65]; if( (ts_sc_prev[64] > live_time) || (ts_sc_prev[65] > busy_time) ){ ts_sc_prev[64] = ts_sc_prev[65] = 0; } ts_tmp[64] = 0.; ts_tmp[65] = 0.; for(int sc = 0; sc < 64; sc++){ ts_tmp[sc] = 0.; if(ts_sc_prev[sc] > ts_sc_all[sc]) ts_sc_prev[sc] = 0; } float tot_time = (live_time - ts_sc_prev[64] + busy_time - ts_sc_prev[65])*7.68e-6; if(tot_time > 0){ for(int sc = 0; sc < 64; sc++){ ts_tmp[sc] = (float) (ts_sc_all[sc] - ts_sc_prev[sc])/ tot_time; ts_sc_prev[sc] = ts_sc_all[sc]; } ts_tmp[64] = (float) (live_time - ts_sc_prev[64])*7.68e-6/ tot_time; } ts_sc_prev[64] = live_time; ts_sc_prev[65] = busy_time; } 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 0; } int read_fadc_sc(VMERemote *pClient_tmp, unsigned int slot_min, unsigned int slot_max, float rate_tmp[256], int fadc_time_prev[16][16], int fadc_sc_prev[16][256], int crate){ Float_t time = 0.; int fadc_time; unsigned int sc_all[272]; memset(sc_all, 0, sizeof(sc_all)); // 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) ){ for(int bd = 0; bd < 16; bd++){ int time_cnt = 17*bd + 16; fadc_time = sc_all[time_cnt]; time = ((Float_t) (fadc_time - fadc_time_prev[crate][bd]))*2048/1.e9; // 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 */ // cout << " Board = " << bd << " FADC time prev = " << fadc_time_prev[crate][bd] << " FADC time = " << fadc_time << endl; // 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; if( (sc_all[ch_ind] - fadc_sc_prev[crate][rate_ind]) <= 0){ rate_tmp[rate_ind] = 0; } else rate_tmp[rate_ind] = (sc_all[ch_ind] - fadc_sc_prev[crate][rate_ind]) /time; /*rate in Hz */ // cout << " CH " << ch_ind << " " << sc_all[ch_ind] << " " << rate[ch] << " Hz/s "; fadc_sc_prev[crate][rate_ind] = sc_all[ch_ind]; } } 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; } // time fadc_time_prev[crate][bd] = fadc_time; } // loop over boards } 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 0; } 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; } /*******/ virtual Bool_t HandleTimer(TTimer *t) { // static unsigned long long ctp_time_prev_ps; // static unsigned long long ctp_time_prev_psc; static unsigned int ts_sc_prev[66]; memset(ts_rate, 0, sizeof(ts_rate)); read_ts_sc(pClient, ts_rate, ts_sc_prev); cout << " ===== Print Scalers ==== " << endl; for(int ii = 0; ii < 32; ii++){ cout << " " << ts_rate[ii]; } cout << endl; for(int ii = 32; ii < 65; ii++){ cout << " " << ts_rate[ii]; } cout << endl; UpdatePlot(); // Print ratecd for(int lane = 0; lane < 4; lane++){ tbuf_rate[lane]->Clear(); char buffer[20]; sprintf(buffer,"%7.1f",ts_rate[lane]); tbuf_rate[lane]->AddText(0, buffer); tent_rate[lane]->SetCursorPosition(tent_rate[lane]->GetCursorPosition()); tent_rate[lane]->Deselect(); fClient->NeedRedraw(tent_rate[lane]); } if(write_to_epics){ char epics_ts_main[100]; sprintf(epics_ts_main, "caput HD:trig:rate:main %f &", ts_rate[0]); system(epics_ts_main); printf("Write TS FCAL & BCAL trigger rate to EPICS: %s\n", epics_ts_main); char epics_ts_bcal[100]; sprintf(epics_ts_bcal, "caput HD:trig:rate:bcal %f &", ts_rate[2]); system(epics_ts_bcal); printf("Write TS BCAL rate to EPICS: %s\n", epics_ts_bcal); char epics_ts_ps[100]; sprintf(epics_ts_ps, "caput HD:trig:rate:ps %f &", ts_rate[3]); system(epics_ts_ps); printf("Write TS PS rate to EPICS: %s\n", epics_ts_ps); } tbuf_rate_lt->Clear(); char buffer[20]; sprintf(buffer,"%7.1f",ts_rate[64]*100.); tbuf_rate_lt->AddText(0, buffer); tent_rate_lt->SetCursorPosition(tent_rate_lt->GetCursorPosition()); tent_rate_lt->Deselect(); fClient->NeedRedraw(tent_rate_lt); cout << " Timer " << endl; return kTRUE; }; void UpdatePlot(){ hfadc[0]->Reset(); hfadc[1]->Reset(); for(int ch = 0; ch < 32; ch++){ hfadc[0]->Fill( (Float_t) ch, ts_rate[ch]); cout << " " << ts_rate[ch]; } cout << endl; for(int ch = 32; ch < 64; ch++){ hfadc[1]->Fill( (Float_t) ch - 31, ts_rate[ch]); cout << " " << ts_rate[ch]; } cout << endl; for(int plot = 0; plot < 2; plot++){ fCanvas[plot]->cd(); hfadc[plot]->Draw("histo"); fCanvas[plot]->Update(); } } private: TGVerticalFrame *pFrameTop; TGHorizontalFrame *pFrameBot; TGVerticalFrame *pFrameLeft; TGVerticalFrame *pFrameRight; TGHorizontalFrame *pFrameLabelGTP; TGHorizontalFrame *pFrameLabelTS; TGHorizontalFrame *pFrameLabel[4]; TGHorizontalFrame *pFrameTimer; TGLabel *pLabelHost; TGLabel *pLabelTimer1; TGLabel *pLabelRate; TGLabel *pLabelGTP; TGLabel *pLabelTS; TGNumberEntry *pValueTimer; TGTextButton *fTStartButton, *fTStopButton, *fTResetButton, *fExitButton; TProfile *hfadc[4]; 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 *fCanvas[2]; TRootEmbeddedCanvas *fEcanvas[2]; TGCompositeFrame *fF1; TTimer *my_timer; TGTextBuffer *tbuf_host, *tbuf_rate[4], *tbuf_rate1, *tbuf_rate_lt; TGTextEntry *tent_host, *tent_rate[4], *tent_rate1, *tent_rate_lt; Float_t ts_rate[66]; /* Rate of TS scalers */ Float_t ctp_rate_ps[7]; Float_t ctp_rate_psc[7]; VMERemote *pClient; 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()); a->SetWindowName("BCAL FADC scalers"); /* 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; }