Changeset 10212 for fact/FADctrl
- Timestamp:
- 03/02/11 13:35:50 (14 years ago)
- Location:
- fact/FADctrl
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
fact/FADctrl/FAD.cc
r10187 r10212 70 70 // Initialise configuration information (later non-blocking access in commandHandler()) 71 71 GetConfig("CalibTempDiffWarn", "0"); 72 GetConfig("CalibFreqDiffWarn", "0"); 72 73 73 74 // Construct boards … … 492 493 493 494 // Check conditions for run of all active boards 494 float MaxDiff = atof(GetConfig("CalibTempDiffWarn").c_str()); 495 float MaxTempDiff = atof(GetConfig("CalibTempDiffWarn").c_str()); 496 float MaxFreqDiff = atof(GetConfig("CalibFreqDiffWarn").c_str()); 495 497 496 498 for (unsigned int i=0; i<Boards.size(); i++) { 497 499 if (!Boards[i]->Active) continue; 498 500 499 if (Boards[i]->ACalib Time == -1) PrintMessage("Warning: Amplitude calibration missing for board %d\n", i);501 if (Boards[i]->ACalib.Time == -1) PrintMessage("Warning: Amplitude calibration missing for board %d\n", i); 500 502 else { 501 503 Temp = 0; 502 504 for (unsigned int j=0; j<NTemp; j++) Temp += Boards[i]->GetStatus().Temp[j] / NTemp; 503 if (fabs(Boards[i]->ACalibTemp-Temp) > MaxDiff) PrintMessage("Warning: Amplitude calibration to current temperature difference larger than %.1f K for board %d\n", MaxDiff, i); 505 if (fabs(Boards[i]->ACalib.Temp-Temp) > MaxTempDiff) PrintMessage("Warning: Calibration to current temperature difference larger than %.1f K for board %d\n", MaxTempDiff, i); 506 if (fabs(Boards[i]->ACalib.Frequency-Boards[i]->GetStatus().Frequency) > MaxFreqDiff) PrintMessage("Warning: Calibration to current frequency difference larger than %.1f GHz for board %d\n", MaxFreqDiff, i); 504 507 } 505 508 } … … 515 518 void FAD::cmd_acalib() { 516 519 517 int Count;518 FILE *File;519 vector<string> Items;520 521 520 // Invalidate calibration? 522 521 if (Parameter.size() == 2 && Match(Parameter[1], "invalidate")) { 523 for (unsigned int i=0; i<Boards.size(); i++) Boards[i]->ACalib Time = -1;522 for (unsigned int i=0; i<Boards.size(); i++) Boards[i]->ACalib.Time = -1; 524 523 return; 525 524 } … … 527 526 // Read calibration data from file? 528 527 if (Parameter.size() == 2 && !ConvertToInt(Parameter[1], &NumEventsRequested)) { 528 FILE *File; 529 struct FADBoard::CalibData Data; 530 529 531 // Open file 530 532 if ((File = fopen(Parameter[1].c_str(), "r")) == NULL) { … … 532 534 return; 533 535 } 534 PrintMessage("Reading amplitude calibration information from file '%s'\n", Parameter[1].c_str()); 535 536 // Read file into buffer and close file 537 string Buffer; 538 while (feof(File)==0 && ferror(File)==0) Buffer.push_back((char) fgetc(File)); 539 if (Buffer.size() > 0) Buffer = Buffer.substr(0, Buffer.size()-1); 536 // Read data and check if it applies to any board 537 while (fread(&Data, sizeof(Data), 1, File) == 1) { 538 for (unsigned int i=0; i<Boards.size(); i++) if (Data.DNA == Boards[i]->GetStatus().DNA) { 539 PrintMessage("Found calibration data for board %d (%s)\n", i, ctime(&Data.Time)); 540 Boards[i]->ACalib = Data; 541 } 542 } 543 //Close file 540 544 if (fclose(File) != 0) PrintMessage("Could not close file '%s'\n", Parameter[1].c_str()); 541 542 // Search for calibration data for boards543 vector<string> Result = Tokenize(Buffer, "\n");544 545 for (unsigned int Brd=0; Brd<Boards.size(); Brd++) {546 for (unsigned int Line=0; Line<Result.size(); Line++) {547 if (Result[Line].find(Boards[Brd]->Name) == string::npos) continue;548 549 PrintMessage("Found calibration data for board '%s'\n", Boards[Brd]->Name);550 Items = Tokenize(Result[Line]);551 552 // Check if correct number of items553 if (Items.size() != NChips*NChannels*NBins*3 + 3) {554 PrintMessage("Error, data format invalid\n", Parameter[1].c_str());555 return;556 }557 558 // Extract data559 Boards[Brd]->ACalibTemp = atof(Items[1].c_str());560 Boards[Brd]->ACalibTime = atoi(Items[2].c_str());561 562 Count = 3;563 for (unsigned int i=0; i<NChips; i++) {564 for (unsigned int j=0; j<NChannels; j++) {565 for (unsigned int k=0; k<NBins; k++) {566 Boards[Brd]->Baseline[i][j][k] = atoi(Items[Count++].c_str());567 Boards[Brd]->Gain[i][j][k] = atof(Items[Count++].c_str());568 Boards[Brd]->SecondaryBaseline[i][j][k] = atof(Items[Count++].c_str());569 }570 }571 }572 }573 } // Loop over boards574 575 545 return; 576 546 } // Reading calibration from file … … 602 572 } 603 573 604 PrintMessage("\rTotal boards: %d (%d communication errors) Active boards: %d\n", Boards.size(), Error, Count);574 PrintMessage("\rTotal boards: %d (%d communication errors)\n", Boards.size(), Error); 605 575 606 576 // Print list of active boards 607 if (Count != 0) { 608 PrintMessage("Active are "); 609 for (unsigned int i=0; i<Boards.size(); i++) if (Boards[i]->Active) PrintMessage(" %d", i); 610 PrintMessage("\n"); 611 } 577 PrintMessage("Active are %d boards(s) ", Count); 578 for (unsigned int i=0; i<Boards.size(); i++) { 579 if (Boards[i]->Active) PrintMessage(" %d", i); 580 if (!Boards[i]->Active) PrintMessage("!"); 581 } 582 PrintMessage("\n"); 612 583 613 584 // Current mode … … 633 604 634 605 // Calibration information 635 if (Boards[i]->ACalib Time == -1) PrintMessage("No amplitude calibration available\n");636 else PrintMessage("Calibration temperature %.1f Calibration time %s" , Boards[i]->ACalibTemp, ctime(&Boards[i]->ACalibTime));606 if (Boards[i]->ACalib.Time == -1) PrintMessage("No amplitude calibration available\n"); 607 else PrintMessage("Calibration data: Temperature %.1f Frequency %.2f Time %s" , Boards[i]->ACalib.Temp, Boards[i]->ACalib.Frequency, ctime(&Boards[i]->ACalib.Time)); 637 608 638 609 // Status information … … 645 616 PrintMessage("Last event received %s", ctime(&S.Update.tv_sec)); 646 617 647 PrintMessage("Board ID %d Firmware revision %d\n", S.BoardID, S.FirmwareRevision); 618 // Board identification 619 PrintMessage("Board ID %d Firmware revision %d Serial %llx\n", S.BoardID, S.FirmwareRevision, S.DNA); 620 PrintMessage("Board time %d Event counter %d\n", S.BoardTime, S.EventCounter); 621 622 // Slow data 623 PrintMessage("Frequency %.2f GHz Phase shift %d PLL lock %d %d %d %d\n", S.Frequency, S.PhaseShift, S.Lock[0], S.Lock[1], S.Lock[2], S.Lock[3]); 648 624 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] ); 649 625 PrintMessage("Temperature %.2f %.2f %.2f %.2f", S.Temp[0], S.Temp[1], S.Temp[2], S.Temp[3]); … … 654 630 } 655 631 PrintMessage("\n"); 656 /*PrintMessage("Serial %d, firmware %d\n" 657 GetBoard(i)->GetBoardSerialNumber(), 658 632 /* 659 633 if (GetBoard(i)->GetStatusReg() & BIT_RUNNING) 660 634 PrintMessage(" Domino wave running\n"); … … 799 773 // 800 774 // Exit programm 801 // SIGTERM sets ExitRequest flag, and also makes 802 // readline() return (in case command came over network) 775 // SIGTERM makes readline() return (in case command came over network) 803 776 // 804 777 void FAD::cmd_exit() { … … 806 779 if (Mode != idle) cmd_stop(); 807 780 781 ExitRequest = true; 782 783 // Wait to allow console input to arrive at readline() 784 usleep(10000); 808 785 pthread_kill(MainThread, SIGTERM); 809 786 } … … 830 807 PrintMessage("Amplitude calibration of all active boards finished, original ROI and DAC set\n"); 831 808 832 // Write calibration data to file 833 time_t Time = time(NULL); 834 struct tm *TimeInfo; 835 char Buffer[200]; 836 837 // Generate filename 838 TimeInfo = localtime(&Time); 839 if (strftime(Buffer, sizeof(Buffer), "/FADcalib_%y-%m-%dT%X.txt", TimeInfo) == 0) { 840 PrintMessage("Could not generate calibration data file name, strftime() failed\n"); 841 return; 842 } 843 string Filename = string(getenv("HOME"))+Buffer; 844 845 FILE *File = fopen(Filename.c_str(), "w"); 809 // Open calibration data file 810 string Filename = string(getenv("HOME"))+"/FAD_ACal"; 811 FILE *File = fopen(Filename.c_str(), "ab"); 812 846 813 if (File == NULL) { 847 814 PrintMessage("Could not open calibration data file '%s'\n", Filename.c_str()); … … 849 816 } 850 817 851 // Fix: Should actually contain serial number! 852 for (unsigned int Brd=0; Brd<Boards.size(); Brd++) { 853 fprintf(File, "\n%s: %f %d ", Boards[Brd]->Name, Boards[Brd]->ACalibTemp, (int) Boards[Brd]->ACalibTime); 854 for (unsigned int i=0; i<NChips; i++) { 855 for (unsigned int j=0; j<NChannels; j++) { 856 for (unsigned int k=0; k<NBins; k++) { 857 fprintf(File, "%d %lf %lf ", Boards[Brd]->Baseline[i][j][k], Boards[Brd]->Gain[i][j][k], Boards[Brd]->SecondaryBaseline[i][j][k]); 858 } 859 } 818 // Write calibration information 819 for (unsigned int i=0; i<Boards.size(); i++) { 820 if (fwrite(&Boards[i]->ACalib, sizeof(Boards[i]->ACalib), 1, File) != 1) { 821 PrintMessage("Could not write to calibration file '%s'\n", Filename.c_str()); 822 break; 860 823 } 861 824 } 862 825 863 826 // Close file 864 if (fclose(File) != 0) { 865 PrintMessage("Could not close calibration file '%s'\n", Filename.c_str()); 866 } 867 868 PrintMessage("Wrote amplitude calibration information to file '%s'\n", Filename.c_str()); 827 if (fclose(File) != 0) PrintMessage("Could not close calibration file '%s'\n", Filename.c_str()); 828 829 PrintMessage("Appended amplitude calibration information to file '%s'\n", Filename.c_str()); 869 830 } 870 831 … … 1002 963 S = Boards[Brd]->GetStatus(); 1003 964 BStruct[Brd]->SerialNo = S.BoardID; 1004 BStruct[Brd]->NomFreq = 2;965 BStruct[Brd]->NomFreq = S.Frequency; 1005 966 BStruct[Brd]->BoardTemp = 0; 1006 967 for (unsigned int i=0; i<NTemp; i++) BStruct[Brd]->BoardTemp += S.Temp[i]/NTemp; … … 1024 985 for (unsigned int Chip=0; Chip<NChips; Chip++) for (unsigned int Chan=0; Chan<NChannels; Chan++) { 1025 986 for (int i=0; i<S.ROI[Chip][Chan]; i++) { 1026 if (Boards[Brd]->ACalib Time == -1) Data[Count++] = Boards[Brd]->Data[Chip][Chan][i];987 if (Boards[Brd]->ACalib.Time == -1) Data[Count++] = Boards[Brd]->Data[Chip][Chan][i]; 1027 988 else { 1028 Temp = (Boards[Brd]->Data[Chip][Chan][i] - Boards[Brd]-> Baseline[Chip][Chan][(i+S.TriggerCell[Chip])%NBins]);1029 Temp *= Boards[Brd]-> Gain[Chip][Chan][0]/Boards[Brd]->Gain[Chip][Chan][(i+S.TriggerCell[Chip])%NBins];1030 //Temp -= Boards[Brd]-> SecondaryBaseline[Chip][Chan][i];989 Temp = (Boards[Brd]->Data[Chip][Chan][i] - Boards[Brd]->ACalib.Baseline[Chip][Chan][(i+S.TriggerCell[Chip])%NBins]); 990 Temp *= Boards[Brd]->ACalib.Gain[Chip][Chan][0]/Boards[Brd]->ACalib.Gain[Chip][Chan][(i+S.TriggerCell[Chip])%NBins]; 991 //Temp -= Boards[Brd]->ACalib.Secondary[Chip][Chan][i]; 1031 992 Data[Count++] = (short) Temp; 1032 993 } -
fact/FADctrl/FAD.h
r10187 r10212 20 20 21 21 #include "FADBoard.h" 22 #include "../drsdaq/RawDataCTX.h" 22 23 23 24 const unsigned int PORT = 5000; -
fact/FADctrl/FADBoard.cc
r10187 r10212 20 20 Continue = true; 21 21 CommOK = false; 22 ACalib Time = -1;22 ACalib.Time = -1; 23 23 Status.Update.tv_sec = -1; 24 24 Port = ServerPort; … … 166 166 case init: 167 167 // Invalidate current calibration 168 ACalib Time = -1;168 ACalib.Time = -1; 169 169 170 170 // Save initial board status, set all ROIs to 1024 and set DAC values … … 203 203 for (unsigned int j=0; j<NChannels; j++) { 204 204 for (unsigned int k=0; k<NBins; k++) { 205 Baseline[i][j][k] = Sum[i][j][k] / m->NumEventsRequested;205 ACalib.Baseline[i][j][k] = Sum[i][j][k] / m->NumEventsRequested; 206 206 } 207 207 } … … 237 237 for (unsigned int j=0; j<NChannels; j++) { 238 238 for (unsigned int k=0; k<NBins; k++) { 239 Gain[i][j][k] = (Sum[i][j][k] / m->NumEventsRequested) -Baseline[i][j][k];239 ACalib.Gain[i][j][k] = (Sum[i][j][k] / m->NumEventsRequested) - ACalib.Baseline[i][j][k]; 240 240 } 241 241 } … … 260 260 for (unsigned int Chan=0; Chan<NChannels; Chan++) { 261 261 for (int i=0; i<Status.ROI[Chip][Chan]; i++) { 262 Sum[Chip][Chan][i] = Data[Chip][Chan][i] - Baseline[Chip][Chan][(i-Status.TriggerCell[Chip]) % NBins];262 Sum[Chip][Chan][i] = Data[Chip][Chan][i] - ACalib.Baseline[Chip][Chan][(i-Status.TriggerCell[Chip]) % NBins]; 263 263 } 264 264 } … … 271 271 for (unsigned int j=0; j<NChannels; j++) { 272 272 for (unsigned int k=0; k<NBins; k++) { 273 SecondaryBaseline[i][j][k] = Sum[i][j][k] / (double) m->NumEventsRequested;273 ACalib.Secondary[i][j][k] = Sum[i][j][k] / (double) m->NumEventsRequested; 274 274 } 275 275 } … … 290 290 291 291 // Store calibration time and temperature 292 ACalibTime = time(NULL); 293 ACalibTemp = 0; 294 for (unsigned int i=0; i<NTemp; i++) ACalibTemp += Status.Temp[i] / NTemp; 292 ACalib.DNA = Status.DNA; 293 ACalib.Frequency = Status.Frequency; 294 ACalib.Time = time(NULL); 295 ACalib.Temp = 0; 296 for (unsigned int i=0; i<NTemp; i++) ACalib.Temp += Status.Temp[i] / NTemp; 295 297 296 298 // Inform event thread that calibration is finished … … 415 417 gettimeofday(&Status.Update, NULL); 416 418 417 // Extract ID and typeinformation418 Status.BoardID = ntohl(Header->board_id); 419 // Extract board and trigger information 420 Status.BoardID = ntohl(Header->board_id); 419 421 Status.FirmwareRevision = ntohl(Header->version_no); 422 Status.BoardTime = ntohl(Header->time); 423 Status.EventCounter = ntohl(Header->fad_evt_counter); 420 424 Status.TriggerID = ntohl(Header->trigger_id); 421 425 Status.TriggerType = ntohs(Header->trigger_type); 426 Status.TriggerCRC = ntohs(Header->trigger_crc); 427 Status.DNA = Header->DNA; 428 429 // Extract frequency related information 430 Status.Frequency = ntohl(Header->REFCLK_frequency)/1.0e6; 431 Status.PhaseShift = ntohs(Header->adc_clock_phase_shift); 432 for (unsigned int i=0; i<NChips; i++) { 433 if ((Header->PLLLCK & (1<<i)) != 0) Status.Lock[i] = true; 434 else Status.Lock[i] = false; 435 } 422 436 423 437 // Extract temperatures (MSB indicates if temperature is positive or negative) -
fact/FADctrl/FADBoard.h
r10164 r10212 38 38 39 39 struct BoardStatus { 40 unsigned short BoardID; 41 unsigned short FirmwareRevision; 42 unsigned long TriggerID; 43 unsigned char TriggerType; 44 unsigned short TriggerCell[NChips]; 45 unsigned short ROI[NChips][NChannels]; 46 unsigned short DAC[NDAC]; 40 uint16_t BoardID; 41 uint64_t DNA; 42 uint16_t FirmwareRevision; 43 uint32_t BoardTime; 44 uint32_t EventCounter; 45 uint32_t TriggerID; 46 uint16_t TriggerType; 47 uint16_t TriggerCRC; 48 uint16_t TriggerCell[NChips]; 49 float Frequency; 50 bool Lock[NChips]; 51 uint16_t PhaseShift; 52 uint16_t ROI[NChips][NChannels]; 53 uint16_t DAC[NDAC]; 47 54 float Temp[NTemp]; 48 55 struct timeval Update; … … 51 58 short Data[NChips][NChannels][NBins]; 52 59 long int Sum[NChips][NChannels][NBins]; 53 short Baseline[NChips][NChannels][NBins];54 double Gain[NChips][NChannels][NBins];55 double SecondaryBaseline[NChips][NChannels][NBins];56 float ACalibTemp;57 time_t ACalibTime;58 60 61 struct CalibData { 62 uint64_t DNA; 63 short Baseline[NChips][NChannels][NBins]; 64 double Gain[NChips][NChannels][NBins]; 65 double Secondary[NChips][NChannels][NBins]; 66 float Temp; 67 float Frequency; 68 time_t Time; 69 } ACalib; 59 70 60 71 void Send(const void *, size_t); -
fact/FADctrl/FADFormat.h
r10187 r10212 2 2 #define FADFORMAT_H_SEEN 3 3 4 #include "../drsdaq/RawDataCTX.h"4 #include <stdint.h> 5 5 6 6 // … … 30 30 #define CMD_Write 0x0500 // write to Config-RAM 31 31 32 #define CMD_TRIGGERS_ON 0x1800 // enables the trigger line -- incoming triggers can now be accepted33 #define CMD_TRIGGERS_OFF 0x1900 // disables the trigger line -- no trigger will be accepted32 #define CMD_TRIGGERS_ON 0x1800 // enables the trigger line 33 #define CMD_TRIGGERS_OFF 0x1900 // disables the trigger line 34 34 35 35 // 36 36 // Other definitions 37 37 // 38 #define MAX_ADDR 0xFF 39 #define BADDR_ROI 0x00 40 #define BADDR_DAC 0x24 38 #define MAX_ADDR 0xFF // highest address in Config-RAM 39 #define BADDR_ROI 0x00 // Baseaddress ROI-Values 40 #define BADDR_DAC 0x24 // Baseaddress DAC-Values 41 41 #define MAX_VAL 65535 42 42 #define MAX_ROIVAL 1024 … … 53 53 // 54 54 typedef struct { 55 // ------------------------------ 56 uint16_t start_package_flag;57 uint16_t package_length;58 uint16_t version_no;59 uint16_t PLLLCK;60 // ------------------------------ 61 uint16_t trigger_crc;62 uint16_t trigger_type;63 uint32_t trigger_id;64 // ------------------------------ 65 uint32_t fad_evt_counter;66 uint32_t REFCLK_frequency;67 // ------------------------------ 68 uint16_t board_id;69 uint16_t adc_clock_phase_shift;70 uint16_t number_of_triggers_to_generate;71 uint16_t trigger_generator_prescaler;72 // ------------------------------ 73 uint8_t DNA[8]; // Xilinx DNA 74 // ------------------------------ 75 uint32_t time;76 uint32_t fad_status;77 // ------------------------------ 78 int16_t drs_temperature[NTemp];79 // ------------------------------ 80 uint16_t dac[NDAC];81 // ------------------------------ 55 56 uint16_t start_package_flag; 57 uint16_t package_length; 58 uint16_t version_no; 59 uint16_t PLLLCK; 60 61 uint16_t trigger_crc; 62 uint16_t trigger_type; 63 uint32_t trigger_id; 64 65 uint32_t fad_evt_counter; 66 uint32_t REFCLK_frequency; 67 68 uint16_t board_id; 69 uint16_t adc_clock_phase_shift; 70 uint16_t number_of_triggers_to_generate; 71 uint16_t trigger_generator_prescaler; 72 73 uint64_t DNA; 74 75 uint32_t time; 76 uint32_t fad_status; 77 78 int16_t drs_temperature[NTemp]; 79 80 uint16_t dac[NDAC]; 81 82 82 } __attribute__((__packed__)) PEVNT_HEADER; 83 83 84 typedef struct { 84 85 uint16_t id; -
fact/FADctrl/History.txt
r10186 r10212 16 16 28/2/2011 Removed 'static' keywords in FADBoard::ReadLoop() 17 17 1/3/2011 Board list can be passed via command line 18 2/3/2011 Implemented new FAD data format
Note:
See TracChangeset
for help on using the changeset viewer.