#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 "st" unsigned int SLOT_MIN = 3; unsigned int SLOT_MAX = 13; /* * 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_PED_ALL(unsigned int *val, unsigned int Status = 0, unsigned int sl_first = 0, unsigned int sl_last = 0 ) { unsigned int debug_read_ped = 0; if(!Socket->IsValid()) { printf("ReadVME_PED_ALL FAILED\n"); return kFALSE; } Cmd_Read_PED_ALL *pCmd_Read_PED_ALL; pCmd_Read_PED_ALL = (Cmd_Read_PED_ALL *)OutgoingMsg.Msg; OutgoingMsg.Length = HTONL(REMOTE_MSG_SIZE(Cmd_Read_PED_ALL)-4); OutgoingMsg.BoardType = HTONL(BoardType); OutgoingMsg.MsgType = HTONL(REMOTE_CMD_READ_PED_ALL); pCmd_Read_PED_ALL->IDF = HTONL(sl_first); pCmd_Read_PED_ALL->IDL = HTONL(sl_last); pCmd_Read_PED_ALL->Status = HTONL(Status); Socket->SendRaw(&OutgoingMsg, REMOTE_MSG_SIZE(Cmd_Read_PED_ALL)); cout << " ReadVME_PED_ALL SEND request. Length = " << REMOTE_MSG_SIZE(Cmd_Read_PED_ALL) << endl; if( (Socket->RecvRaw(&IncomingMsg.Length, 4) == 4) && (NTOHL(IncomingMsg.Length) <= sizeof(RemoteMsgStruct))) { Socket->RecvRaw(&IncomingMsg.BoardType, NTOHL(IncomingMsg.Length)); cout << " ReadVME_PED_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_PED_ALL *p = (Cmd_Read_PED_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++){ if(debug_read_ped){ 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 < 8; ch++){ val[bd*8 + ch] = NTOHL(p->Value[bd*8 + ch]); if(debug_read_ped){ unsigned int ped1 = val[bd*8 + ch] & 0xFFFF; unsigned int ped2 = (val[bd*8 + ch] & 0xFFFF0000) >> 16; cout << " Ch = " << 2*ch << " " << ped1 << " Ch = " << 2*ch + 1 << " ped2 " << ped2 << endl; } } 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] = "rocccal"; SetCleanup(kDeepCleanup); // gStyle->SetPalette(1); // 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 = 9; Float_t x_min = 0.5, x_max = 144.5, y_min = -10, y_max = 1000000; hfadc = new TProfile("Rate (Hz)","Rate (Hz)", nch, x_min, x_max, y_min, y_max,""); hrate = new TH2F("Rate (Hz)","Rate (Hz)", 12, -0.5, 11.5, 12, -0.5, 11.5); hped = new TProfile("Pedestals","Pedestals", nch, x_min, x_max, y_min, y_max,""); for(int ii = 0; ii < 13; ii++){ char tmp[9]; sprintf(tmp,"%d",ii); hrate->GetXaxis()->SetBinLabel(ii,tmp); hrate->GetYaxis()->SetBinLabel(ii,tmp); } // for(int ii = 1; ii < 10; ii++){ // char tmp[9]; // sprintf(tmp,"%d",ii); // hfadc->GetXaxis()->SetBinLabel(ii,tmp); // hped->GetXaxis()->SetBinLabel(ii,tmp); // } // hrate->GetXaxis()->SetBinLabel(1,"1"); hrate->GetXaxis()->SetBinLabel(2,"2"); hrate->GetXaxis()->SetBinLabel(3,"3"); // hrate->GetYaxis()->SetBinLabel(1,"1"); hrate->GetYaxis()->SetBinLabel(2,"2"); hrate->GetYaxis()->SetBinLabel(3,"3"); hfadc->GetYaxis()->SetTitle("Rate (Hz) "); hfadc->GetXaxis()->SetTitle("Channel"); hfadc->SetLabelSize(0.05,"y"); hfadc->SetLabelSize(0.09,"x"); hfadc->SetTitleSize(0.07,"xy"); hfadc->SetTitleOffset(0.9,"x"); hfadc->SetTitleOffset(1.2,"y"); hfadc->SetTitle("Scalers "); hrate->SetTitle("CCAL Scalers "); hped->SetTitle("Pedestals "); hrate->SetLabelSize(0.09,"xy"); hrate->SetTitleSize(0.07,"xy"); hrate->SetTitleOffset(1.2,"x"); hrate->SetTitleOffset(1.,"y"); hrate->GetYaxis()->SetTitle("Column "); hrate->GetXaxis()->SetTitle("Row"); hped->GetYaxis()->SetTitle(" fadc count "); hped->GetXaxis()->SetTitle(" Paddle"); hped->SetLabelSize(0.05,"y"); hped->SetLabelSize(0.09,"x"); hped->SetTitleSize(0.07,"xy"); hped->SetTitleOffset(0.9,"x"); hped->SetTitleOffset(1.2,"y"); hped->SetMaximum(120); hped->SetMinimum(80); gStyle->SetOptStat(0); gStyle->SetTitleFontSize(0.06); 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)); // fF1->AddFrame(fEcanvas[0] = new TRootEmbeddedCanvas("Rate",fF1,100,200), new TGLayoutHints(kLHintsLeft | kLHintsExpandX // | kLHintsExpandY , 20, 0, 0, 10)); fF1->AddFrame(fEcanvas[1] = new TRootEmbeddedCanvas("Rate1",fF1,100,200), new TGLayoutHints(kLHintsLeft | kLHintsExpandX | kLHintsExpandY , 20, 0, 0, 10)); // pFrameTop->AddFrame(fF2 = new TGCompositeFrame(pFrameTop, 100,200,kHorizontalFrame), new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 5, 5, 0, 0)); // fF2->AddFrame(fEcanvas[2] = new TRootEmbeddedCanvas("Rate2",fF2,100,200), new TGLayoutHints(kLHintsLeft | kLHintsExpandX // | kLHintsExpandY , 20, 0, 0, 10)); // fF2->AddFrame(fEcanvas[3] = new TRootEmbeddedCanvas("Rate3",fF2,100,200), new TGLayoutHints(kLHintsLeft | kLHintsExpandX // | kLHintsExpandY , 20, 0, 0, 10)); #if 0 fF2->AddFrame(pFrameRight = new TGVerticalFrame(fF2), 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(" Rate (Hz)")), new TGLayoutHints(kLHintsCenterX | kLHintsCenterY, 20, 30, 10, 10)); for(int row = 2; row >= 0; row--){ pFrameRight->AddFrame(pFrameLabel[row] = new TGHorizontalFrame(pFrameRight), new TGLayoutHints(kLHintsExpandX | kLHintsCenterY | kLHintsRight, 0, 0, 0, 0 )); for(int col = 0; col < 3; col++){ tbuf_rate[row][col] = new TGTextBuffer(8); tbuf_rate[row][col]->AddText(0,"0.0"); tent_rate[row][col] = new TGTextEntry(pFrameLabel[row], tbuf_rate[row][col]); tent_rate[row][col]->Resize(100,tent_rate[row][col]->GetDefaultHeight()); pFrameLabel[row]->AddFrame(tent_rate[row][col], new TGLayoutHints(kLHintsExpandY | kLHintsCenterY | kLHintsLeft, 5, 0, 5, 5)); } } #endif #if 0 fCanvas[0] = fEcanvas[0]->GetCanvas(); fCanvas[0]->cd(); hfadc->Draw(); gPad->SetBottomMargin(0.16); gPad->SetLeftMargin(0.2); #endif fCanvas[1] = fEcanvas[1]->GetCanvas(); fCanvas[1]->cd(); hrate->Draw("zcol"); gPad->SetBottomMargin(0.16); gPad->SetLeftMargin(0.2); gPad->SetRightMargin(0.15); gPad->SetLogz(); #if 0 fCanvas[2] = fEcanvas[2]->GetCanvas(); fCanvas[2]->cd(); hped->Draw("err"); gPad->SetBottomMargin(0.16); gPad->SetLeftMargin(0.2); gPad->SetRightMargin(0.15); #endif 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(600,600); 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; hped->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_fadc_ped(VMERemote *pClient_tmp, unsigned int slot_min, unsigned int slot_max, float ped_tmp[256], int crate){ unsigned int ped_all[128]; memset(ped_all, 0, sizeof(ped_all)); int debug = 0; if( pClient_tmp->ReadVME_PED_ALL(&ped_all[0], 0, slot_min, slot_max) ){ for(int bd = 0; bd < 16; bd++){ unsigned int bd_slot; if(bd < 8) bd_slot = bd + 3; else bd_slot = bd + 5; if(bd_slot >= slot_min && bd_slot <= slot_max) if(debug) cout << "read_fadc_ped: Slot = " << bd_slot << endl; for(int ch = 0; ch < 8; ch++) { int ind_ch = bd*16 + ch*2; unsigned int ped1 = ped_all[bd*8 + ch] & 0x3FFF; unsigned int ped2 = (ped_all[bd*8 + ch] & 0x3FFF0000) >> 16; ped_tmp[ind_ch] = float(ped1); ped_tmp[ind_ch+1] = float(ped2); if(bd_slot >= slot_min && bd_slot <= slot_max) if(debug) cout << " Ch = " << 2*ch << " " << ped1 << " Ch = " << 2*ch + 1 << " ped2 " << ped2 << endl; } } } else { cout << " : Error reading pedestals 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 int fadc_sc_prev[16][256]; static int fadc_time_prev_all[16][16]; memset(fadc_rate, 0, sizeof(fadc_rate)); memset(fadc_rate, 0, sizeof(fadc_ped)); read_fadc_sc(pClient, SLOT_MIN, SLOT_MAX, fadc_rate, fadc_time_prev_all, fadc_sc_prev, 0); read_fadc_ped(pClient, SLOT_MIN, SLOT_MAX, fadc_ped, 0); UpdatePlot(); cout << " Timer " << endl; return kTRUE; }; void UpdatePlot(){ hfadc->Reset(); hrate->Reset(); int my_col[144] = {1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, -1, -1, -1, -1, -2, -2, -2, -2, -2, -3, -3, -3, -3, -3, -4, -4, -4, -4, -4, -5, -5, -5, -5, -5, -1, -1, -1, -1, -2, -2, -2, -2, -2, -3, -3, -3, -3, -3, -4, -4, -4, -4, -4, -5, -5, -5, -5, -5, 1, 2, 3, 4, 5, 6, 6, 6, 6, 6, 6, 1, 2, 3, 4, 5, 6, 6, 6, 6, 6, 6, -1, -2, -3, -4, -5, -6, -6, -6, -6, -6, -6, -1, -2, -3, -4, -5, -6, -6, -6, -6, -6, -6}; int my_row[144] = {2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, -2, -3, -4, -5, -1, -2, -3, -4, -5, -1, -2, -3, -4, -5, -1, -2, -3, -4, -5, -1, -2, -3, -4, -5, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, -2, -3, -4, -5, -1, -2, -3, -4, -5, -1, -2, -3, -4, -5, -1, -2, -3, -4, -5, -1, -2, -3, -4, -5, 6, 6, 6, 6, 6, 6, 1, 2, 3, 4, 5, -6, -6, -6, -6, -6, -6, -1, -2, -3, -4, -5, 6, 6, 6, 6, 6, 6, 1, 2, 3, 4, 5, -6, -6, -6, -6, -6, -6, -1, -2, -3, -4, -5}; for(int ch = 0; ch < 144; ch++){ int col, row; if(my_col[ch] > 0) col = my_col[ch] + 5; else col = 6 + my_col[ch]; if(my_row[ch] > 0) row = my_row[ch] + 5; else row = 6 + my_row[ch]; #if 0 hfadc->Fill( (Float_t) ch - 112, fadc_rate[ch]); hped->Fill( (Float_t) ch - 112, fadc_ped[ch]/4.); int cell = ch - 112; int col = (cell % 3) + 1; int row = -10; if(cell > 0 && cell <= 3){ col = cell; row = 1; } else if(cell > 3 && cell <= 6){ col = cell - 3; row = 2; } else if(cell > 6 && cell <= 9){ col = cell - 6; row = 3; } tbuf_rate[row-1][col-1]->Clear(); char buffer[20]; sprintf(buffer,"%7.1f",fadc_rate[ch]); tbuf_rate[row-1][col-1]->AddText(0, buffer); tent_rate[row-1][col-1]->SetCursorPosition(tent_rate[row-1][col-1]->GetCursorPosition()); tent_rate[row-1][col-1]->Deselect(); fClient->NeedRedraw(tent_rate[row-1][col-1]); #endif hrate->Fill((Float_t) col, (Float_t) row, fadc_rate[ch]); } #if 0 fCanvas[0]->cd(); hfadc->Draw("histo"); fCanvas[0]->Update(); #endif fCanvas[1]->cd(); hrate->Draw("zcol"); fCanvas[1]->Update(); #if 0 fCanvas[2]->cd(); hped->Draw("err"); fCanvas[2]->Update(); #endif } private: TGVerticalFrame *pFrameTop; TGHorizontalFrame *pFrameBot; TGVerticalFrame *pFrameLeft; TGVerticalFrame *pFrameRight; TGHorizontalFrame *pFrameLabel[3]; TGHorizontalFrame *pFrameLabel1; TGHorizontalFrame *pFrameLabelGTP; TGLabel *pLabelGTP; TGHorizontalFrame *pFrameTimer; TGLabel *pLabelHost; TGLabel *pLabelTimer1; TGLabel *pLabelRate; TGLabel *pLabelRate1; TGNumberEntry *pValueTimer; TGTextButton *fTStartButton, *fTStopButton, *fTResetButton, *fExitButton; TProfile *hfadc; TProfile *hped; 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; TH2F *hrate; TCanvas *fCanvas[1]; TRootEmbeddedCanvas *fEcanvas[4]; TGCompositeFrame *fF1, *fF2; TTimer *my_timer; TGTextBuffer *tbuf_host, *tbuf_rate[3][3], *tbuf_rate1; TGTextEntry *tent_host, *tent_rate[3][3], *tent_rate1; Float_t fadc_rate[256]; /* fadc scalers for all boards in the crate */ Float_t fadc_ped[256]; /* fadc pedestals */ 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("CCAL 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; }