Changeset 10101
- Timestamp:
- 01/13/11 11:56:40 (14 years ago)
- Location:
- fact/FADctrl
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
fact/FADctrl/FAD.cc
r10100 r10101 32 32 {"address", &FAD::cmd_address, true, 2, "<range> <value>", "Set addresses in range to value"}, 33 33 {"send", &FAD::cmd_send, true, 1, "<value>", "Set arbitrary data to board"}, 34 {"acalib", &FAD::cmd_acalib, true, 0, "[n ]", "Amplitude calibration (n events)"},34 {"acalib", &FAD::cmd_acalib, true, 0, "[n|invalidate|file]", "Perform or read amplitude calibration (n events)"}, 35 35 //{"wmode", &FAD::cmd_wmode, 0, "<run|stop>", "Domino wave running or stopped during read out"}, 36 36 //{"rmode", &FAD::cmd_rmode, 0, "<first|stop>", "Readout start at first bin or stop position (DRS4)"}, … … 61 61 // DIM console service used in PrintMessage() 62 62 ConsoleOut = new DimService(SERVER_NAME"/ConsoleOut", (char *) ""); 63 64 // Get configuration data (static needed for c_str() pointers to remain valid after constructor finished)65 //static string _CalibDataPath = GetConfig("CalibDataPath");66 //fCalibDataPath = _CalibDataPath.c_str();67 68 //snprintf(CalibInfoFilename,sizeof(CalibInfoFilename), "%s/CalibInfo", fCalibDataPath);69 63 70 64 // Construct boards … … 164 158 // Check if idle mode required 165 159 if (CommandList[i].NeedIdle && Mode != idle) { 166 PrintMessage("Current mode is not idle ('cancel' will stop current operation) ");160 PrintMessage("Current mode is not idle ('cancel' will stop current operation)\n"); 167 161 return; 168 162 } … … 449 443 450 444 pthread_t Thread; 451 int Code; 445 int Code, Count; 446 FILE *File; 447 vector<string> Items; 452 448 453 449 // Invalidate calibration? … … 456 452 return; 457 453 } 458 454 455 // Read calibration data from file? 456 if (Parameter.size() == 2 && !ConvertToInt(Parameter[1], &NumCalibEvents)) { 457 // Open file 458 if ((File = fopen(Parameter[1].c_str(), "r")) == NULL) { 459 PrintMessage("Error opening file '%s'\n", Parameter[1].c_str()); 460 return; 461 } 462 PrintMessage("Reading amplitude calibration information from file '%s'\n", Parameter[1].c_str()); 463 464 // Read file into buffer and close file 465 string Buffer; 466 while (feof(File)==0 && ferror(File)==0) Buffer.push_back((char) fgetc(File)); 467 if (Buffer.size() > 0) Buffer = Buffer.substr(0, Buffer.size()-1); 468 if (fclose(File) != 0) PrintMessage("Could not close file '%s'\n", Parameter[1].c_str()); 469 470 // Search for calibration data for boards 471 vector<string> Result = Tokenize(Buffer, "\n"); 472 473 for (unsigned int Brd=0; Brd<Boards.size(); Brd++) { 474 for (unsigned int Line=0; Line<Result.size(); Line++) { 475 if (Result[Line].find(Boards[Brd]->Name) == string::npos) continue; 476 477 PrintMessage("Found calibration data for board '%s'\n", Boards[Brd]->Name); 478 Items = Tokenize(Result[Line]); 479 480 // Check if correct number of items 481 if (Items.size() != NChips*NChannels*NBins*2 + 3) { 482 PrintMessage("Error, data format invalid\n", Parameter[1].c_str()); 483 return; 484 } 485 486 // Extract data 487 Boards[Brd]->ACalibTemp = atof(Items[1].c_str()); 488 Boards[Brd]->ACalibTime = atoi(Items[2].c_str()); 489 490 Count = 3; 491 for (unsigned int i=0; i<NChips; i++) { 492 for (unsigned int j=0; j<NChannels; j++) { 493 for (unsigned int k=0; k<NBins; k++) { 494 Boards[Brd]->Baseline[i][j][k] = atoi(Items[Count++].c_str()); 495 Boards[Brd]->Gain[i][j][k] = atof(Items[Count++].c_str()); 496 } 497 } 498 } 499 } 500 } // Loop over boards 501 502 return; 503 } // Reading calibration from file 504 459 505 // Set number of events required for calibration 460 506 if (Parameter.size()==1 || !ConvertToInt(Parameter[1], &NumCalibEvents) || NumCalibEvents<=0) { … … 518 564 struct FADBoard::BoardStatus S = Boards[i]->GetStatus(); 519 565 520 PrintMessage("Board #%d (%sactive) Communication %s\n", i, Boards[i]->Active ? "":"in", Boards[i]->CommError ? "ERROR":"OK");566 PrintMessage("Board #%d - %s (%sactive) Communication %s\n", i, Boards[i]->Name, Boards[i]->Active ? "":"in", Boards[i]->CommError ? "ERROR":"OK"); 521 567 PrintMessage("DAC %d %d %d %d %d %d %d %d\n", S.DAC[0], S.DAC[1], S.DAC[2], S.DAC[3], S.DAC[4], S.DAC[5], S.DAC[6], S.DAC[7] ); 522 568 PrintMessage("Temperature %.2f %.2f %.2f %.2f", S.Temp[0], S.Temp[1], S.Temp[2], S.Temp[3]); … … 654 700 /* Procedure 655 701 656 1. Register sampling frequency from FTM!657 ...658 702 5. Issue single trigger and verify settings 659 703 ... … … 682 726 Boards[Brd]->Send(&ROICmd[0], ROICmd.size()*sizeof(unsigned short)); 683 727 684 // Set DAC firstvalue728 // Set first DAC value 685 729 DACCmd[1] = htons(0); 686 730 DACCmd[3] = htons(0); … … 688 732 Boards[Brd]->Send(DACCmd, sizeof(DACCmd)); 689 733 690 691 734 // Switch off SCLK 735 //Boards[Brd]->Send(CMD_SCLK_OFF); 692 736 693 737 // Start accumulation 694 738 Boards[Brd]->AccumulateSum(NumCalibEvents); 695 //Boards[Brd]->Send(CMD_Trigger_C);696 739 } 697 740 … … 723 766 Boards[Brd]->Send(DACCmd, sizeof(DACCmd)); 724 767 725 726 768 // Switch off SCLK 769 //Boards[Brd]->Send(CMD_SCLK_OFF); 727 770 728 771 // Start accumulation … … 739 782 } 740 783 } 741 for (unsigned int Brd=0; Brd<Boards.size(); Brd++) {742 // Switch on SCLK743 Boards[Brd]->Send(CMD_SCLK_ON);744 }745 784 746 785 // Stop triggering, write back original ROI and DAC settings 747 786 for (unsigned int Brd=0; Brd<Boards.size(); Brd++) { 748 //Boards[Brd]->Send(CMD_Trigger_S); 787 // Switch on SCLK 788 Boards[Brd]->Send(CMD_SCLK_ON); 749 789 750 790 // Determine gain … … 773 813 } 774 814 815 Mode = idle; 816 817 if (Cancel) { 818 PrintMessage("Amplitude calibration cancelled\n"); 819 return; 820 } 821 775 822 PrintMessage("Amplitude calibration of all active boards finished, original ROI and DAC set\n"); 776 Mode = idle; 777 778 // Write short calibration information 779 /*time_t Time = time(NULL); 780 FILE *InfoFile = fopen(CalibInfoFilename, "w"); 781 if (InfoFile != NULL) { 782 fprintf(InfoFile, "# Calibration information as of %s\n", ctime(&Time)); 783 for (int i=0; i<GetNumberOfBoards(); i++) { 784 fprintf(InfoFile, "%d %d %.1f %d %.2f\n", GetBoard(i)->GetBoardSerialNumber(), ACalib[i], ACalibTemp[i], TCalib[i], DRSFreq[i]); 785 } 786 fclose(InfoFile); 787 } 788 else PrintMessage("Could not write calibration information to file '%s'\n", CalibInfoFilename); 789 */ 823 824 // Write calibration data to file 825 time_t Time = time(NULL); 826 struct tm *TimeInfo; 827 char Buffer[200]; 828 829 // Generate filename 830 TimeInfo = localtime(&Time); 831 if (strftime(Buffer, sizeof(Buffer), "/FADcalib_%y-%m-%jT%X.txt", TimeInfo) == 0) { 832 PrintMessage("Could not generate calibration data file name, strftime() failed\n"); 833 return; 834 } 835 string Filename = string(getenv("HOME"))+Buffer; 836 837 FILE *File = fopen(Filename.c_str(), "w"); 838 if (File == NULL) { 839 PrintMessage("Could not open calibration data file '%s'\n", Filename.c_str()); 840 return; 841 } 842 843 // Fix: Should actually contain serial number! 844 for (unsigned int Brd=0; Brd<Boards.size(); Brd++) { 845 fprintf(File, "\n%s: %f %d ", Boards[Brd]->Name, Boards[Brd]->ACalibTemp, (int) Boards[Brd]->ACalibTime); 846 for (unsigned int i=0; i<NChips; i++) { 847 for (unsigned int j=0; j<NChannels; j++) { 848 for (unsigned int k=0; k<NBins; k++) { 849 fprintf(File, "%d %lf ", Boards[Brd]->Baseline[i][j][k], Boards[Brd]->Gain[i][j][k]); 850 } 851 } 852 } 853 } 854 855 // Close file 856 if (fclose(File) != 0) { 857 PrintMessage("Could not close calibration file '%s'\n", Filename.c_str()); 858 } 859 860 PrintMessage("Wrote amplitude calibration information to file '%s'\n", Filename.c_str()); 790 861 } 791 862 … … 896 967 if (Boards[Brd]->ACalibTime == -1) Data[Count++] = Boards[Brd]->Data[Chip][Chan][i]; 897 968 else { 898 //Data[Count++] = (Boards[Brd]->Data[Chip][Chan][i] - Boards[Brd]->Baseline[Chip][Chan][(i+S.TriggerCell[Chip])%NBins]) * Boards[Brd]->Gain[Chip][Chan][(i+S.TriggerCell[Chip])%NBins];899 969 Temp = (Boards[Brd]->Data[Chip][Chan][i] - Boards[Brd]->Baseline[Chip][Chan][(i+S.TriggerCell[Chip])%NBins]); 900 970 Temp *= Boards[Brd]->Gain[Chip][Chan][0]/Boards[Brd]->Gain[Chip][Chan][(i+S.TriggerCell[Chip])%NBins]; … … 926 996 } 927 997 998 928 999 /* 929 // Read calibration data930 bool FAD::ReadCalibration() {931 932 static char Buffer[MAX_COM_SIZE];933 int Serial, Calib;934 float Temp, Freq;935 936 for (int i=FirstBoard; i<=LastBoard; i++) {937 if (GetBoard(i)->GetDRSType() == 4) {938 if (ACalib[i] == false) {939 // Check calibration info file if EEPROM data on DRS board still valild940 FILE *CalibInfo = fopen(CalibInfoFilename, "r");941 if (CalibInfo == NULL) return false;942 fgets(Buffer, sizeof(Buffer), CalibInfo); // skip first two lines943 fgets(Buffer, sizeof(Buffer), CalibInfo);944 945 while (fgets(Buffer, sizeof(Buffer), CalibInfo) != NULL) {946 if (sscanf(Buffer, "%d %d %f %*d %f", &Serial, &Calib, &Temp, &Freq) != 4) {947 fclose(CalibInfo);948 return false;949 }950 951 if (Serial==GetBoard(i)->GetBoardSerialNumber() && int(Freq*100)==int(DRSFreq[i]*100) && Calib==1) {952 ACalib[i] = true;953 ACalibTemp[i] = Temp;954 break;955 }956 }957 fclose(CalibInfo);958 }959 }960 else {961 if (!ACalib[i]) {962 GetBoard(i)->SetCalibrationDirectory(fCalibDataPath);963 PrintMessage("Reading response calibration file for board %d from: \"%s\"\n", i, fCalibDataPath);964 for (int Chip=0; Chip<GetBoard(i)->GetNumberOfChips(); Chip++) {965 if (GetBoard(i)->GetResponseCalibration()->ReadCalibration(Chip) == false) return false;966 }967 ACalib[i] = true;968 }969 }970 if (fabs(ACalibTemp[i]-GetBoard(i)->GetTemperature())>2) PrintMessage("Warning: Large difference to calibration temperature for board %d\n", i);971 } // Loop over boards972 return true;973 }974 975 1000 // Set DOMINO mode 976 1001 void FAD::SetDOMINOMode(int mode) { -
fact/FADctrl/FAD.h
r10100 r10101 21 21 22 22 const int DEFAULT_NUM_CALIB_EVENTS = 100; 23 const char CALIB_DIRECTORY[] = "~/"; 23 24 24 25 enum ModeType {idle, acalib, tcalib}; … … 44 45 45 46 int NumCalibEvents; 46 //const char *fCalibDataPath;47 //char CalibInfoFilename[MAX_PATH];48 47 49 48 std::vector<std::string> BoardList; -
fact/FADctrl/FADBoard.cc
r10099 r10101 220 220 // Check if buffer starts with start_package_flag, remove data if not 221 221 Temp = 0; 222 while (ntohs(Header->start_package_flag) != 0xfb01 && Pos > 0) { 223 memmove(Buffer, Buffer+1, Pos-1); 224 Pos--; 225 Temp++; 226 } 222 while (ntohs(*((unsigned short *) (Buffer+Temp))) != 0xfb01 && Temp<Pos) Temp++; 227 223 if (Temp != 0) { 228 printf("Removed %d bytes because of start_package_flag not found\n", Temp); 224 memmove(Buffer, Buffer+Temp, Pos-Temp); 225 Pos -= Temp; 226 m->PrintMessage("Removed %d bytes because of start_package_flag not found\n", Temp); 229 227 continue; 230 228 } -
fact/FADctrl/FADBoard.h
r10080 r10101 25 25 class FAD *m; 26 26 int Socket; 27 char *Name;28 27 pthread_t Thread; 29 28 pthread_mutex_t Mutex; … … 69 68 void Unlock(); 70 69 70 char *Name; 71 71 bool InitOK; 72 72 bool CommError; -
fact/FADctrl/FADctrl.cc
r10099 r10101 5 5 #include <stdio.h> 6 6 #include <readline/history.h> 7 #include <string> 7 8 8 9 #include "FAD.h" 9 10 10 const char READLINE_HIST_FILE[] = "/tmp/.history.FADctrl";11 using namespace std; 11 12 13 const string READLINE_HIST_FILE = string(getenv("HOME"))+"/.history_FADctrl"; 12 14 void OpenOtherSockets(); 13 15 … … 22 24 23 25 // Load history buffer 24 read_history(READLINE_HIST_FILE );26 read_history(READLINE_HIST_FILE.c_str()); 25 27 26 28 system("clear"); … … 73 75 DimClient::sendCommand(SERVER_NAME"/Command", "dwrite on"); 74 76 DimClient::sendCommand(SERVER_NAME"/Command", "roi all 1024"); 75 sleep (1);76 77 77 //EmptySockets(SocketDescriptor, 8, 750000L);78 78 M.PrintMessage("Finished initalizing all boards\n"); 79 79 … … 100 100 101 101 // Save history buffer 102 int Ret = write_history(READLINE_HIST_FILE );103 if (Ret != 0 ) printf("Error writing history file to '%s' (%s)\n", READLINE_HIST_FILE , strerror(Ret));102 int Ret = write_history(READLINE_HIST_FILE.c_str()); 103 if (Ret != 0 ) printf("Error writing history file to '%s' (%s)\n", READLINE_HIST_FILE.c_str(), strerror(Ret)); 104 104 105 105 // Terminate thread for other sockets -
fact/FADctrl/History.txt
r10083 r10101 3 3 22/10/2010 First check-in of FADctrl. Initial version derived from drsdaq revision 10007. 4 4 5/1/2011 First version of amplitude calibration (no secondary calibration, yet). New 'socketmode' command. 5 13/1/2011 Amplitude calibration data is written to text file.
Note:
See TracChangeset
for help on using the changeset viewer.