- Timestamp:
- 03/12/10 15:53:20 (15 years ago)
- Location:
- drsdaq
- Files:
-
- 2 deleted
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
drsdaq/DAQReadout.cc
r176 r182 10 10 11 11 #include "DAQReadout.h" 12 #include "SlowData.h"13 14 #define TMPNAME "/tmp/__tmp__drsdaq__" // ..for log file truncation15 12 16 13 static const char* daq_state_str[] = {"active", "stopped"}; … … 63 60 // 64 61 65 DAQReadout::DAQReadout( const char *Configfile) {62 DAQReadout::DAQReadout() :EvidenceServer(SERVER_NAME) { 66 63 67 64 time(&StartTime); // Start time of DAQ … … 78 75 LastBoard = -1; 79 76 CmdFromSocket = false; 80 ConfigOK = true; 81 82 // Read configuration file (if any item missing, program will be terminated in main() routine) 83 FILE *File; 84 if ((File = fopen(Configfile,"r")) == NULL) { 85 printf("Error: Could not open drsdaq configuration file '%s'\n", Configfile); 86 ConfigOK = false; 87 return; 88 } 89 else { 90 printf("Reading drsdaq configuration file %s\n", Configfile); 91 ConfigOK &= ReadCard("LogFile", fLogFile, 's', File); 92 ConfigOK &= ReadCard("SlowDataPath", fSlowDataPath, 's', File); 93 ConfigOK &= ReadCard("MaxLogLines", &fMaxLogLines, 'U', File); 94 ConfigOK &= ReadCard("RawDataPath", fRawDataPath, 's', File); 95 ConfigOK &= ReadCard("CalibDataPath", fCalibDataPath, 's', File); 96 ConfigOK &= ReadCard("FirstSample", &fFirstSample, 'I', File); 97 ConfigOK &= ReadCard("Samples", &fSamples, 'U', File); 98 ConfigOK &= ReadCard("MinDiskSpaceMB", &fMinDiskSpaceMB, 'U', File); 99 ConfigOK &= ReadCard("MaxFileSizeMB", &fMaxFileSizeMB, 'I', File); 100 ConfigOK &= ReadCard("CCPort", &fCCPort, 'I', File); 101 ConfigOK &= ReadCard("HVFeedbackConfig", fHVFeedbackConfig, 's', File); 102 ConfigOK &= ReadCard("DefaultFrequency", &fDefaultFrequency , 'd', File); 103 fclose(File); 104 if (!ConfigOK) return; 105 } 77 78 // Get configuration data 79 fRawDataPath = GetConfig("RawDataPath"); 80 fCalibDataPath = GetConfig("CalibDataPath"); 81 fFirstSample = atoi(GetConfig("FirstSample")); 82 fSamples = atoi(GetConfig("Samples")); 83 fMinDiskSpaceMB = atoi(GetConfig("MinDiskSpaceMB")); 84 fMaxFileSizeMB = atoi(GetConfig("MaxFileSizeMB")); 85 fCCPort = atoi(GetConfig("CCPort")); 86 fDefaultFrequency = atof(GetConfig("DefaultFrequency")); 87 106 88 if (fFirstSample < 0 || fFirstSample > kNumberOfBins || fSamples > kNumberOfBins) { 107 89 PrintMessage("Warning: Sample range in configuration beyond limits, setting to full range\n"); … … 109 91 fSamples = kNumberOfBins; 110 92 } 111 112 // Open log file and log configuration 113 if ((Logfile = fopen(fLogFile, "a")) == NULL) printf("Warning: Could not open log file '%s'\n", fLogFile); 114 PrintMessage(MsgToLog,"********** Logging started **********\n"); 115 PrintConfig(MsgToLog); 116 93 snprintf(CalibInfoFilename,sizeof(CalibInfoFilename), "%s/CalibInfo", fCalibDataPath); 94 117 95 // Allocate headers and initialise to zero 118 96 RHeader = new RunHeader; … … 120 98 EHeader = new EventHeader; 121 99 memset(EHeader, 0, sizeof(EventHeader)); 122 100 123 101 // Scan for DRS boards 124 DRSFreq = new float [GetNumberOfBoards()];125 ACalib = new bool [GetNumberOfBoards()];126 ACalib Temp = new double [GetNumberOfBoards()];127 TCalib = new bool [GetNumberOfBoards()];128 129 if (GetNumberOfBoards() == 0) PrintMessage("No DRS boards found - check VME crate and configuration file!\n"); 130 131 for (int i=0; i<GetNumberOfBoards(); i++) { 132 NumBoards++;102 NumBoards = GetNumberOfBoards(); 103 DRSFreq = new float [NumBoards]; 104 ACalib = new bool [NumBoards]; 105 ACalibTemp = new double [NumBoards]; 106 TCalib = new bool [NumBoards]; 107 108 if (NumBoards == 0) PrintMessage("No DRS boards found - check VME crate and configuration file!\n"); 109 110 for (int i=0; i<NumBoards; i++) { 133 111 LastBoard++; 134 112 GetBoard(i)->Init(); … … 138 116 TCalib[i] = false; 139 117 } 140 BStruct = new BoardStructure [NumBoards == 0 ? 1: GetNumberOfBoards()];141 memset(BStruct, 0, sizeof(BoardStructure)*(NumBoards == 0 ? 1: GetNumberOfBoards()));118 BStruct = new BoardStructure [NumBoards == 0 ? 1:NumBoards]; 119 memset(BStruct, 0, sizeof(BoardStructure)*(NumBoards == 0 ? 1:NumBoards)); 142 120 143 121 WaveForm = new short [NumBoards == 0 ? 1:NumBoards][kNumberOfChipsMax][kNumberOfChannelsMax][kNumberOfBins]; … … 145 123 146 124 // Create instance of HV feedback (must be called after CMC board detection) 147 HVFB = new HVFeedback(this, fHVFeedbackConfig); 148 149 // Create instance of slow data class for DAQ 150 SlowDataClass = new SlowData("DAQ", fSlowDataPath); 151 if(SlowDataClass->ErrorCode != 0) { 152 PrintMessage("Warning: Could not open DAQ slowdata file (%s)\n", strerror(SlowDataClass->ErrorCode)); 153 } 154 SlowDataClass->NewEntry("Runinfo-Info", "Run information written after completion or termination of run (Status can be OK or Error): Runnumber Status Runtype Events Files Description "); 125 HVFB = new HVFeedback(this); 155 126 } 156 127 … … 160 131 161 132 DAQReadout::~DAQReadout() { 162 delete SlowDataClass; 133 163 134 delete RHeader; delete EHeader; 164 135 delete HVFB; delete[] ACalibTemp; … … 166 137 delete[] DRSFreq; delete[] BStruct; 167 138 delete[] WaveForm; delete[] TriggerCell; 168 169 if(Logfile) {170 if(!fclose(Logfile)) printf("Closing logfile\n");171 else perror("Error closing logfile");172 }173 139 } 174 140 … … 514 480 } 515 481 516 PrintMessage("Creating amplitude calibration of board %d (serial #%04d)\n ", i, GetBoard(i)->GetBoardSerialNumber());517 482 PrintMessage("Creating amplitude calibration of board %d (serial #%04d)\n Note: No input signals should be connected\n", i, GetBoard(i)->GetBoardSerialNumber()); 483 518 484 GetBoard(i)->EnableTcal(0); 519 485 GetBoard(i)->SelectClockSource(0); … … 545 511 ACalib[i] = true; 546 512 ACalibTemp[i] = GetBoard(i)->GetTemperature(); 513 547 514 } // Loop over boards 548 515 PrintMessage("Amplitude calibration finished\n"); 516 517 // Write short calibration information 518 time_t Time = time(NULL); 519 FILE *InfoFile = fopen(CalibInfoFilename, "w"); 520 if (InfoFile != NULL) { 521 fprintf(InfoFile, "# Calibration information as of %s\n", ctime(&Time)); 522 for (int i=0; i<GetNumberOfBoards(); i++) { 523 fprintf(InfoFile, "%d %d %.1f %d %.2f\n", GetBoard(i)->GetBoardSerialNumber(), ACalib[i], ACalibTemp[i], TCalib[i], DRSFreq[i]); 524 } 525 fclose(InfoFile); 526 } 527 else PrintMessage("Could not write calibration information to file '%s'\n", CalibInfoFilename); 528 549 529 } 550 530 … … 554 534 if (!IsDRSFreqSet()) { 555 535 PrintMessage("Set sampling frequency for all boards first\n"); 536 return; 537 } 538 if (!ReadCalibration()) { 539 PrintMessage("Amplitude calibration has to be done first\n"); 556 540 return; 557 541 } … … 562 546 continue; 563 547 } 564 if (!ACalib[i]) { 565 PrintMessage("Amplitude calibration of board %d has to be done first, skipping this board\n", i); 566 continue; 567 } 568 PrintMessage("Creating time calibration of board %d (serial #%04d)\n", i, GetBoard(i)->GetBoardSerialNumber()); 548 PrintMessage("Creating time calibration of board %d (serial #%04d)\n Note: No input signals should be connected\n", i, GetBoard(i)->GetBoardSerialNumber()); 569 549 570 550 GetBoard(i)->SetFrequency(DRSFreq[i], true); … … 586 566 GetBoard(i)->GetTime(Chip, Time[Chip], true, false); 587 567 } 588 589 if (asprintf(&Filename, "TCalib_%d_%.2fGHz.txt", GetBoard(i)->GetBoardSerialNumber(), DRSFreq[i]) == -1) { 568 569 // Write calibration data to file 570 if (asprintf(&Filename, "%s/TCalib_%d_%.2fGHz.txt", fCalibDataPath, GetBoard(i)->GetBoardSerialNumber(), DRSFreq[i]) == -1) { 590 571 PrintMessage("Error: asprintf() failed, cannot generate filename (%s)\n", strerror(errno)); 591 572 return; … … 827 808 GetBoard(i)->TransferWaves(GetBoard(i)->GetNumberOfChannels()*GetBoard(i)->GetNumberOfChips()); 828 809 829 for (int j=0; j<GetBoard(i)->GetNumberOfChannels(); j++) { 830 for (int k=0; k<GetBoard(i)->GetNumberOfChips(); k++) { 831 GetBoard(i)->GetWave(k, j, WaveForm[i][k][j], true, GetBoard(i)->GetTriggerCell(k)); 832 TriggerCell[i][k] = GetBoard(i)->GetTriggerCell(k); 810 for (int k=0; k<GetBoard(i)->GetNumberOfChips(); k++) { 811 TriggerCell[i][k] = GetBoard(i)->GetTriggerCell(k); 812 813 for (int j=0; j<GetBoard(i)->GetNumberOfChannels(); j++) { 814 GetBoard(i)->GetWave(k, j, WaveForm[i][k][j], true, TriggerCell[i][k]); 833 815 } 834 816 } … … 836 818 } 837 819 838 // Read calibration file820 // Read calibration data 839 821 bool DAQReadout::ReadCalibration() { 840 822 823 static char Buffer[MAX_COM_SIZE]; 824 int Serial, Calib; 825 float Temp, Freq; 826 841 827 for (int i=FirstBoard; i<=LastBoard; i++) { 842 if (!TCalib[i]) PrintMessage("Warning: No time calibration for board %d\n", i);843 844 828 if (GetBoard(i)->GetDRSType() == 4) { 845 if (ACalib[i] == false) return false; 829 if (ACalib[i] == false) { 830 // Check calibration info file if EEPROM data on DRS board still valild 831 FILE *CalibInfo = fopen(CalibInfoFilename, "r"); 832 if (CalibInfo == NULL) return false; 833 fgets(Buffer, sizeof(Buffer), CalibInfo); // skip first two lines 834 fgets(Buffer, sizeof(Buffer), CalibInfo); 835 836 while (fgets(Buffer, sizeof(Buffer), CalibInfo) != NULL) { 837 if (sscanf(Buffer, "%d %d %f %*d %f", &Serial, &Calib, &Temp, &Freq) != 4) { 838 fclose(CalibInfo); 839 return false; 840 } 841 842 if (Serial==GetBoard(i)->GetBoardSerialNumber() && int(Freq*100)==int(DRSFreq[i]*100) && Calib==1) { 843 ACalib[i] = true; 844 ACalibTemp[i] = Temp; 845 break; 846 } 847 } 848 fclose(CalibInfo); 849 } 846 850 } 847 851 else { … … 855 859 } 856 860 } 861 if (fabs(ACalibTemp[i]-GetBoard(i)->GetTemperature())>2) PrintMessage("Warning: Large difference to calibration temperature for board %d\n", i); 857 862 } // Loop over boards 858 863 return true; … … 1127 1132 // Print configuration to target 1128 1133 void DAQReadout::PrintConfig(int Target) { 1129 PrintMessage(Target, " LogFile: %s\tMaxLogLines: %u\tRawDataPath: %s\n"1134 PrintMessage(Target, "RawDataPath: %s\n" 1130 1135 "DefaultFrequency: %.2f\tFirstSample: %d\tSamples: %u\n" 1131 1136 "MinDiskSpaceMB: %u\tMaxFileSizeMB: %d\tCCPort: %d\n" 1132 "CalibDataPath: %s\n" 1133 "SlowDataPath: %s\tHVFeedbackConfig: %s\n", 1134 fLogFile,fMaxLogLines,fRawDataPath,fDefaultFrequency,fFirstSample,fSamples,fMinDiskSpaceMB, 1135 fMaxFileSizeMB,fCCPort,fCalibDataPath,fSlowDataPath,fHVFeedbackConfig); 1137 "CalibDataPath: %s\n", 1138 fRawDataPath,fDefaultFrequency,fFirstSample,fSamples,fMinDiskSpaceMB, 1139 fMaxFileSizeMB,fCCPort,fCalibDataPath); 1136 1140 } 1137 1141 … … 1160 1164 va_list ArgumentPointer; 1161 1165 va_start(ArgumentPointer, Format); 1162 if(CmdFromSocket) DoPrintMessage(Format, ArgumentPointer, MsgToSocket |MsgToLog);1163 else DoPrintMessage(Format, ArgumentPointer, MsgToConsole |MsgToLog);1166 if(CmdFromSocket) DoPrintMessage(Format, ArgumentPointer, MsgToSocket); 1167 else DoPrintMessage(Format, ArgumentPointer, MsgToConsole); 1164 1168 va_end(ArgumentPointer); 1165 1169 } … … 1179 1183 if(strlen(Textbuffer)>0 && Textbuffer[strlen(Textbuffer)-1]=='\n') { 1180 1184 printf("\r%s%s", Textbuffer, Prompt); // New prompt 1181 fflush(stdout);1182 1185 } 1183 1186 else printf("%s", Textbuffer); 1184 } 1185 // Print to log file 1186 if((Target & MsgToLog) && Logfile!=NULL) { 1187 time_t Time; 1188 strftime(Textbuffer+strlen(Textbuffer)+1,MAX_COM_SIZE-strlen(Textbuffer)-1, "%d/%m/%y %X", localtime(&(Time=time(NULL)))); 1189 fprintf(Logfile, "%s: %s", Textbuffer+strlen(Textbuffer)+1, Textbuffer); 1190 fflush(Logfile); 1187 fflush(stdout); 1188 } 1189 // Send to log 1190 if(Target & MsgToLog) { 1191 char *Buf; 1192 if (asprintf(&Buf, "%s %s", SERVER_NAME, Textbuffer) != -1) { 1193 DimClient::sendCommandNB("DColl/Log", Buf); 1194 free(Buf); 1195 } 1196 else DimClient::sendCommandNB("DColl/Log", SERVER_NAME" asprintf() failed"); 1191 1197 } 1192 1198 // Print to socket … … 1233 1239 } 1234 1240 1235 // ReadCard function (original version by F. Goebel)1236 // Data is read into an array if MaxNum is larger than 11237 bool ReadCard(const char *card_flag, void *store, char Type, FILE *File, unsigned int MaxNum) {1238 1239 char *card_name, *card_val, Buffer[MAX_COM_SIZE];1240 unsigned int Count=0;1241 1242 rewind(File);1243 1244 while (fgets(Buffer, sizeof(Buffer), File) != NULL) { // Read line by line1245 card_name = strtok(Buffer," \t\n");1246 1247 // Ignore empty lines, comments, and skip if card name does not match1248 if (card_name==NULL || card_name[0]=='#' || strcmp(card_name, card_flag)!=0) continue;1249 1250 // Read numbers of given type (if MaxNum>1 read array)1251 while ((card_val=strtok(NULL," \t\n")) != NULL && Count++<MaxNum) {1252 switch (Type) {1253 case 'I': *(((int *&) store)++) = (int) strtol(card_val, NULL, 10);1254 break;1255 case 'i': *(((short *&) store)++) = (short) strtol(card_val, NULL, 10);1256 break;1257 case 'U': *(((unsigned int *&) store)++) = (unsigned int) strtoul(card_val, NULL, 10);1258 break;1259 case 'u': *(((unsigned short *&) store)++) = (unsigned short) strtoul(card_val, NULL, 10);1260 break;1261 case 'f': *(((float *&) store)++) = atof(card_val);1262 break;1263 case 'd': *(((double *&) store)++) = atof(card_val);1264 break;1265 case 's': sprintf((char *) store, "%s", card_val);1266 break;1267 case 'c': *((char *) store) = card_val[0];1268 break;1269 default: fprintf(stderr,"Warning: Unknown type '%c' for reading of configuration file\n", Type);1270 return false;1271 }1272 }1273 return true; // Finished reading data for card name1274 1275 }1276 fprintf(stderr,"Warning: Configuration value %s not found\n", card_flag);1277 return false;1278 }1279 1280 1241 1281 1242 /********************************************************************\ … … 1368 1329 1369 1330 // Write run summary to slow data file 1370 m->SlowDataClass->NewEntry("Runinfo"); 1371 m->SlowDataClass->AddToEntry("%d %s %s %d %d %s", m->RunNumber, WriteError?"Error":"OK", daq_runtype_str[m->daq_runtype], m->NumEvents, m->FileNumber, m->RHeader->Description); 1372 if(m->SlowDataClass->ErrorCode != 0) { 1373 m->PrintMessage("Error: Could not write DAQ slow data to file (%s), file closed\n", strerror(m->SlowDataClass->ErrorCode)); 1374 } 1331 //m->SlowDataClass->NewEntry("Runinfo"); 1332 //m->SlowDataClass->AddToEntry("%d %s %s %d %d %s", m->RunNumber, WriteError?"Error":"OK", daq_runtype_str[m->daq_runtype], m->NumEvents, m->FileNumber, m->RHeader->Description); 1375 1333 1376 1334 // Print run statistics -
drsdaq/DAQReadout.h
r176 r182 14 14 #include <sys/vfs.h> 15 15 #include <signal.h> 16 #include <sys/time.h> 16 17 17 18 #include "RawDataCTX.h" … … 32 33 enum runtype_enum {data, pedestal, reserved, test}; 33 34 34 class DAQReadout : public DRS, public DRSCallback {35 class DAQReadout : public DRS, public DRSCallback, public EvidenceServer { 35 36 time_t StartTime; 36 37 … … 39 40 40 41 unsigned int CmdNumber; 41 FILE *Logfile;42 42 void PrintUsage(); 43 43 … … 52 52 int Rawfile; 53 53 class HVFeedback* HVFB; 54 class SlowData *SlowDataClass;55 54 56 55 // Configuration data 57 char fLogFile[MAX_PATH]; 58 char fSlowDataPath[MAX_PATH]; 59 char fCalibDataPath[MAX_PATH]; 60 unsigned int fMaxLogLines; 61 char fRawDataPath[MAX_PATH]; 56 char *fCalibDataPath; 57 char *fRawDataPath; 62 58 int fMinDiskSpaceMB; // Minimum required disk space in MBytes 63 59 int fMaxFileSizeMB; // Maximum File size in Bytes … … 65 61 unsigned int fSamples; 66 62 int fCCPort; 67 char fHVFeedbackConfig[MAX_PATH];68 63 double fDefaultFrequency; 69 64 … … 92 87 char FileName[MAX_PATH]; 93 88 char Prompt[MAX_COM_SIZE]; 94 bool ConfigOK;89 char CalibInfoFilename[MAX_PATH]; 95 90 96 91 // Public functions 97 DAQReadout( const char*);92 DAQReadout(); 98 93 ~DAQReadout(); 99 94 … … 149 144 int ParseInput(char*, const char *Param[]); 150 145 int CheckDisk(char*); 151 bool ReadCard(const char *, void *, char, FILE *, unsigned int=1);152 146 153 147 #endif -
drsdaq/DRS/DRS.cc
r176 r182 183 183 #endif 184 184 /* check all VME slave slots */ 185 for (index = 2; index <= 10; index++) {185 for (index = 2; index <= 9; index++) { 186 186 #ifdef CT_VME 187 187 MasterMap.vmebus_address = GEVPC_BASE_ADDR + index * GEVPC_WINSIZE; // VME board base address 188 MasterMapVME(&MasterMapping[index]);188 if (MasterMapVME(&MasterMapping[index]) != VME_SUCCESS) continue; 189 189 #endif 190 190 … … 4857 4857 4858 4858 // use following lines to save calibration into an ASCII file 4859 #if 14859 #if 0 4860 4860 FILE *fh; 4861 4861 … … 6907 6907 if ((ErrorCode = VME_Open()) != VME_SUCCESS) { 6908 6908 VME_ErrorString(ErrorCode,ErrorString); 6909 printf(" Error:%s\n",ErrorString);6909 printf("VME_Open() %s\n",ErrorString); 6910 6910 } 6911 6911 return ErrorCode; … … 6917 6917 if (ErrorCode = VME_MasterMap(&MasterMap, MMap)) { 6918 6918 VME_ErrorString(ErrorCode,ErrorString); 6919 printf(" Error:%s\n",ErrorString);6919 printf("VME_MasterMap() %s\n",ErrorString); 6920 6920 } 6921 6921 return(ErrorCode); … … 6927 6927 if (ErrorCode = VME_MasterUnmap(MMap)) { 6928 6928 VME_ErrorString(ErrorCode,ErrorString); 6929 printf(" Error:%s\n",ErrorString);6929 printf("VME_MasterUnmap() %s\n",ErrorString); 6930 6930 } 6931 6931 return(ErrorCode); … … 6937 6937 if ((ErrorCode = VME_Close()) != VME_SUCCESS) { 6938 6938 VME_ErrorString(ErrorCode,ErrorString); 6939 printf(" Error:%s\n",ErrorString);6939 printf("VME_Close() %s\n",ErrorString); 6940 6940 } 6941 6941 return ErrorCode; … … 6947 6947 if ((ErrorCode = CMEM_Open()) != CMEM_RCC_SUCCESS) { 6948 6948 VME_ErrorString(ErrorCode,ErrorString); 6949 printf(" Error:%s\n",ErrorString);6949 printf("CMEM_Open() %s\n",ErrorString); 6950 6950 } 6951 6951 return ErrorCode; … … 6957 6957 if ((ErrorCode = CMEM_Close()) != CMEM_RCC_SUCCESS) { 6958 6958 VME_ErrorString(ErrorCode,ErrorString); 6959 printf(" Error:%s\n",ErrorString);6959 printf("CMEM_Close %s\n",ErrorString); 6960 6960 } 6961 6961 return ErrorCode; … … 6966 6966 if ((ErrorCode = CMEM_SegmentAllocate(SegSize, "DMA_BUFFER", CMEM_SegIdentifier)) != CMEM_RCC_SUCCESS) { 6967 6967 VME_ErrorString(ErrorCode,ErrorString); 6968 printf(" Error:%s\n",ErrorString);6968 printf("CMEM_SegmentAllocate() %s\n",ErrorString); 6969 6969 } 6970 6970 return ErrorCode; … … 6976 6976 if ((ErrorCode = CMEM_SegmentPhysicalAddress(CMEM_SegIdentifier, PCIAddress)) != CMEM_RCC_SUCCESS) { 6977 6977 VME_ErrorString(ErrorCode,ErrorString); 6978 printf(" Error:%s\n",ErrorString);6978 printf("CMEM_SegmentPhysicalAddress() %s\n",ErrorString); 6979 6979 } 6980 6980 return ErrorCode; … … 6986 6986 if ((ErrorCode = CMEM_SegmentVirtualAddress(CMEM_SegIdentifier, VirtualAddress)) != CMEM_RCC_SUCCESS) { 6987 6987 VME_ErrorString(ErrorCode,ErrorString); 6988 printf(" Error:%s\n",ErrorString);6988 printf("CMEM_SegmentVirtualAddress() %s\n",ErrorString); 6989 6989 } 6990 6990 return ErrorCode; … … 6996 6996 if ((ErrorCode = CMEM_SegmentFree(CMEM_SegIdentifier)) != CMEM_RCC_SUCCESS) { 6997 6997 VME_ErrorString(ErrorCode,ErrorString); 6998 printf(" Error:%s\n",ErrorString);6998 printf("CMEM_SegmentFree() %s\n",ErrorString); 6999 6999 } 7000 7000 return ErrorCode; -
drsdaq/HVFeedback.cc
r176 r182 25 25 // Constructor: Initialise feedback 26 26 // 27 HVFeedback::HVFeedback(DAQReadout* DAQClass , char* Configfile):28 EvidenceServer(SERVER_NAME){27 HVFeedback::HVFeedback(DAQReadout* DAQClass){//: 28 //EvidenceServer(SERVER_NAME){ 29 29 30 30 m = DAQClass; 31 31 32 fNumberOfChannels = m-> fNumberOfChannels;33 fNumberOfChips = m-> fNumberOfChips;32 fNumberOfChannels = m->GetBoard(0)->GetNumberOfChannels(); 33 fNumberOfChips = m->GetBoard(0)->GetNumberOfChips(); 34 34 35 35 PixMap = new PixelMap(PIXMAP_LOCATION, false); … … 45 45 DIMSigma = new float [m->NumBoards][kNumberOfChipsMax][kNumberOfChannelsMax](); 46 46 47 // Read configuration file 48 FILE *File; 49 if ((File = fopen(Configfile,"r")) == NULL) { 50 printf("Error: Could not open feedback configuration file '%s'\n", Configfile); 51 } 52 else { 53 printf("Reading feedback configuration file %s\n", Configfile); 54 ReadCard("TrigBoard", &fLedTrigBoard, 'I', File); 55 ReadCard("TrigChannel", &fLedTrigChannel, 'I', File); 56 ReadCard("TrigChip", &fLedTrigChip, 'I', File); 57 ReadCard("TrigSample", &fLedTrigSample, 'I', File); 58 ReadCard("TrigThreshold", &fLedTrigThreshold, 'f', File); 59 ReadCard("SignalSample", &fLedSignalSample, 'I', File); 60 ReadCard("BaselineSample", &fLedBaselineSample, 'I', File); 61 ReadCard("IntHalfWidth", &fIntHalfWidth, 'U', File); 62 ReadCard("DefaultNumAverage", &fDefaultNumAverage, 'I', File); 63 ReadCard("DefaultResponse", Response, 'f', File, m->NumBoards*fNumberOfChips*fNumberOfChannels); 64 ReadCard("DefaultTarget", Target, 'f', File, m->NumBoards*fNumberOfChips*fNumberOfChannels); 65 // Add also initial gain to configuration parameters 66 fclose(File); 67 } 47 // Get configuration data 48 fLedTrigBoard = atoi(m->GetConfig("TrigBoard")); 49 fLedTrigChannel = atoi(m->GetConfig("TrigChannel")); 50 fLedTrigChip = atoi(m->GetConfig("TrigChip")); 51 fLedTrigSample = atoi(m->GetConfig("TrigSample")); 52 fLedTrigThreshold = atoi(m->GetConfig("TrigThreshold")); 53 fLedSignalSample = atoi(m->GetConfig("SignalSample")); 54 fLedBaselineSample = atoi(m->GetConfig("BaselineSample")); 55 fIntHalfWidth = atoi(m->GetConfig("IntHalfWidth")); 56 fDefaultNumAverage = atoi(m->GetConfig("DefaultNumAverage")); 57 58 char *Token = strtok(m->GetConfig("DefaultResponse"), " \t"); 59 for (int i=0; i<m->NumBoards*fNumberOfChips*fNumberOfChannels; i++) { 60 if (Token == NULL) break; 61 *(&Response[0][0][0]+i) = (float) atof(Token); 62 Token = strtok(NULL, " \t"); 63 } 64 Token = strtok(m->GetConfig("DefaultTarget"), " \t"); 65 for (int i=0; i<m->NumBoards*fNumberOfChips*fNumberOfChannels; i++) { 66 if (Token == NULL) break; 67 *(&Target[0][0][0]+i) = (float) atof(Token); 68 Token = strtok(NULL, " \t"); 69 } 70 68 71 PrintConfig(MsgToLog); 69 72 … … 76 79 77 80 // Initial state 78 Gain = 0.2;81 Gain = atoi(m->GetConfig("DefaultGain")); 79 82 SetFBMode(FB_Off); 80 83 SetNumAverages(fDefaultNumAverage); … … 94 97 95 98 delete[] Average; delete[] Response; 99 delete[] DIMAverage; delete[] DIMSigma; 100 delete[] Sigma; 96 101 delete[] Target; delete[] Buffer; 97 102 delete PixMap; … … 256 261 else { 257 262 FBMode = Mode; 258 if (Mode != FB_ResponseFirst) State(INFO, "%s", FBState_Description[FBMode]);259 else State(INFO, "%s (voltage difference %.3f)", FBState_Description[FBMode], DiffVoltage);263 if (Mode != FB_ResponseFirst) m->State(m->INFO, "%s", FBState_Description[FBMode]); 264 else m->State(m->INFO, "%s (voltage difference %.3f)", FBState_Description[FBMode], DiffVoltage); 260 265 ClearAverages(); 261 266 } -
drsdaq/HVFeedback.h
r175 r182 13 13 #include "DAQReadout.h" 14 14 15 #define kNumberOfChipsMax 216 #define kNumberOfChannelsMax 1017 18 15 enum FBState {FB_Off, FB_Active, FB_Targets, FB_ResponseFirst, FB_ResponseSecond}; 19 16 20 class HVFeedback: public EvidenceServer {17 class HVFeedback: public DimServer {//EvidenceServer { 21 18 22 19 class DAQReadout *m; … … 60 57 61 58 public: 62 HVFeedback(class DAQReadout* , char*);59 HVFeedback(class DAQReadout*); 63 60 ~HVFeedback(); 64 61 -
drsdaq/History.txt
r176 r182 59 59 9/3/2010 Feedback now depended on DIM for communication with bias server. 60 60 Started migration to DRS4 (last tested revision as daqct3 for DRS2 is 161). DRS class will not run anymore with DRS2 FPGA firmware. 61 61 11/3/2010 Removed SlowData class. 62 12/3/2010 Removed local configuration and logging. -
drsdaq/Makefile
r175 r182 10 10 CC = g++ # Compiler to use 11 11 12 SOURCES = HVFeedback.cc DAQReadout.cc RawDataCTX.cc SlowData.cc../pixelmap/Pixel.cc ../pixelmap/PixelMap.cc DRS/DRS.cc DRS/mxml.c DRS/strlcpy.c drsdaq.cpp ../Evidence/Evidence.cc12 SOURCES = HVFeedback.cc DAQReadout.cc RawDataCTX.cc ../pixelmap/Pixel.cc ../pixelmap/PixelMap.cc DRS/DRS.cc DRS/mxml.c DRS/strlcpy.c drsdaq.cpp ../Evidence/Evidence.cc 13 13 OBJECTS = $(addsuffix .o, $(basename $(SOURCES))) 14 14 INCDIRS = -I. -IDRS -I../pixelmap -I../Evidence -I$(DIMDIR)/dim -
drsdaq/drsdaq.cpp
r110 r182 30 30 void SignalHandler(int); 31 31 void CrashHandler(int); 32 void ExitFunction(); 32 33 33 34 // ================ … … 84 85 signal(SIGINT, &CrashHandler); 85 86 signal(SIGHUP, &CrashHandler); 86 87 atexit(&ExitFunction); 88 87 89 // Construct main instance and create mutex for thread synchronization 88 DAQReadout dreadout (argc==3 ? argv[2] : DEFAULT_CONFIG);90 DAQReadout dreadout; 89 91 if (pthread_mutex_init(&dreadout.control_mutex, NULL) != 0) { 90 92 perror("pthread_mutex_init failed"); … … 92 94 } 93 95 94 if (dreadout.ConfigOK) { // Normal program execution only if configuration was complete 95 // Create threads 96 if (pthread_mutex_init(&dreadout.control_mutex, NULL) != 0) { 97 perror("pthread_mutex_init failed"); 98 throw; 99 } 100 if ((pthread_create(&thread_ConsoleCommand, NULL, (void * (*)(void *)) ConsoleCommand,(void *) &dreadout)) != 0) { 101 perror("pthread_create failed with console thread"); 102 throw; 103 } 104 if ((pthread_create(&thread_CCCommand, NULL, (void * (*)(void *)) CCCommand,(void *) &dreadout)) != 0) { 105 perror("pthread_create failed with socket thread"); 106 dreadout.SocketThread = NULL; 107 } 108 else dreadout.SocketThread = &thread_CCCommand; // Thread should be accessible for sending signals 109 110 // Wait for threads to quit 111 pthread_join(thread_ConsoleCommand, NULL); 112 if(dreadout.SocketThread != NULL) pthread_join(thread_CCCommand, NULL); 113 } 114 else printf("Error: Configuration parameter missing in %s, terminating.\n", argc==3 ? argv[2] : DEFAULT_CONFIG); 96 // Create threads 97 if (pthread_mutex_init(&dreadout.control_mutex, NULL) != 0) { 98 perror("pthread_mutex_init failed"); 99 throw; 100 } 101 if ((pthread_create(&thread_ConsoleCommand, NULL, (void * (*)(void *)) ConsoleCommand,(void *) &dreadout)) != 0) { 102 perror("pthread_create failed with console thread"); 103 throw; 104 } 105 if ((pthread_create(&thread_CCCommand, NULL, (void * (*)(void *)) CCCommand,(void *) &dreadout)) != 0) { 106 perror("pthread_create failed with socket thread"); 107 dreadout.SocketThread = NULL; 108 } 109 else dreadout.SocketThread = &thread_CCCommand; // Thread should be accessible for sending signals 110 111 // Wait for threads to quit 112 pthread_join(thread_ConsoleCommand, NULL); 113 if(dreadout.SocketThread != NULL) pthread_join(thread_CCCommand, NULL); 115 114 116 115 // Destruct mutex and main instance … … 282 281 return; 283 282 } 283 284 // This function will be implicitly called by exit() 285 void ExitFunction() { 286 remove(LOCKFILE); 287 return; 288 }
Note:
See TracChangeset
for help on using the changeset viewer.