Changeset 92 for drsdaq/DAQReadout.cc
- Timestamp:
- 07/28/09 09:13:41 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
drsdaq/DAQReadout.cc
r89 r92 12 12 #include "SlowData.h" 13 13 14 #define TMPNAME "/tmp/__tmp__drsdaq__" 14 #define TMPNAME "/tmp/__tmp__drsdaq__" // ..for log file truncation 15 15 16 16 static const char* daq_state_str[] = {"active", "stopped"}; … … 26 26 {"status", &DAQReadout::cmd_status, false, "[daq|drs]", "Show DAQ/DRS status information"}, 27 27 {"freq", &DAQReadout::cmd_freq, true, "<GHz> [reg]", "Set DRS sampling frequency (regulated)"}, 28 {"calib", &DAQReadout::cmd_calib, true, "<t_f> <c_f> [dir]", "Response calibration"},28 {"calib", &DAQReadout::cmd_calib, true, "<t_f> <c_f>", "Response calibration"}, 29 29 {"trigger", &DAQReadout::cmd_trigger, true, "<on|off>", "Hardware trigger on or off"}, 30 30 {"delayed", &DAQReadout::cmd_delayed, true, "<on|off>", "Switch delayed start on or off"}, … … 76 76 LastBoard = -1; 77 77 CmdFromSocket = false; 78 79 // Read configuration file 78 ConfigOK = true; 79 80 // Read configuration file (if any item missing, program will be terminated in main() routine) 80 81 FILE *File; 81 82 if ((File = fopen(Configfile,"r")) == NULL) { 82 83 printf("Error: Could not open drsdaq configuration file '%s'\n", Configfile); 84 ConfigOK = false; 85 return; 83 86 } 84 87 else { 85 88 printf("Reading drsdaq configuration file %s\n", Configfile); 86 ReadCard("LogFile", fLogFile, 's', File); 87 ReadCard("MaxLogLines", &fMaxLogLines, 'U', File); 88 ReadCard("RawDataPath", fRawDataPath, 's', File); 89 ReadCard("FirstSample", &fFirstSample, 'I', File); 90 ReadCard("Samples", &fSamples, 'U', File); 91 ReadCard("MinDiskSpaceMB", &fMinDiskSpaceMB, 'U', File); 92 ReadCard("MaxFileSizeMB", &fMaxFileSizeMB, 'I', File); 93 ReadCard("CCPort", &fCCPort, 'I', File); 94 ReadCard("FirstVMESlot", &fFirstVMESlot, 'I', File); 95 ReadCard("LastVMESlot", &fLastVMESlot, 'I', File); 96 ReadCard("HVFeedbackConfig", fHVFeedbackConfig, 's', File); 89 ConfigOK &= ReadCard("LogFile", fLogFile, 's', File); 90 ConfigOK &= ReadCard("SlowDataPath", fSlowDataPath, 's', File); 91 ConfigOK &= ReadCard("MaxLogLines", &fMaxLogLines, 'U', File); 92 ConfigOK &= ReadCard("RawDataPath", fRawDataPath, 's', File); 93 ConfigOK &= ReadCard("FirstSample", &fFirstSample, 'I', File); 94 ConfigOK &= ReadCard("Samples", &fSamples, 'U', File); 95 ConfigOK &= ReadCard("MinDiskSpaceMB", &fMinDiskSpaceMB, 'U', File); 96 ConfigOK &= ReadCard("MaxFileSizeMB", &fMaxFileSizeMB, 'I', File); 97 ConfigOK &= ReadCard("CCPort", &fCCPort, 'I', File); 98 ConfigOK &= ReadCard("FirstVMESlot", &fFirstVMESlot, 'I', File); 99 ConfigOK &= ReadCard("LastVMESlot", &fLastVMESlot, 'I', File); 100 ConfigOK &= ReadCard("HVFeedbackConfig", fHVFeedbackConfig, 's', File); 101 ConfigOK &= ReadCard("DefaultFrequency", &fDefaultFrequency , 'd', File); 97 102 fclose(File); 103 if (!ConfigOK) return; 98 104 } 99 105 if (fFirstSample < 0 || fFirstSample > kNumberOfBins || fSamples > kNumberOfBins) { … … 108 114 if (system(ShellCmd) != 0) printf("Warning: Could not truncate log file '%s' to %u lines\n", fLogFile, fMaxLogLines); 109 115 110 // Open log file 116 // Open log file and log configuration 111 117 if ((Logfile = fopen(fLogFile, "a")) == NULL) printf("Warning: Could not open log file '%s'\n", fLogFile); 112 118 PrintMessage(MsgToLog,"********** Logging started **********\n"); 113 114 // Print configuration 115 cmd_config(); 119 PrintConfig(MsgToLog); 116 120 117 121 // Create DRS instance and perform initial scan … … 151 155 152 156 // Create instance of slow data class for DAQ 153 char Filename[MAX_PATH]; 154 snprintf(Filename,sizeof(Filename),"%s/SlowData/", fRawDataPath); 155 SlowDataClass = new SlowData("DAQ", Filename); 157 SlowDataClass = new SlowData("DAQ", fSlowDataPath); 156 158 if(SlowDataClass->ErrorCode != 0) { 157 159 PrintMessage("Warning: Could not open DAQ slowdata file (%s)\n", strerror(SlowDataClass->ErrorCode)); 158 160 } 161 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 "); 159 162 } 160 163 … … 170 173 delete[] WaveForm; delete[] TriggerCell; 171 174 172 PrintMessage(MsgToLog,"********** Logging ended **********\n\n");173 175 if(Logfile) { 174 176 if(!fclose(Logfile)) printf("Closing logfile\n"); … … 224 226 // Print DAQ configuration 225 227 void DAQReadout::cmd_config() { 226 PrintMessage("LogFile: %s\tMaxLogLines: %u\tRawDataPath: %s\n" 227 "FirstSample: %d\tSamples: %u\n" 228 "MinDiskSpaceMB: %u\tMaxFileSizeMB: %d\tCCPort: %d\n" 229 "FirstVMESlot: %d\t\tLastVMESlot: %d\n" 230 "HVFeedbackConfig: %s\n", 231 fLogFile,fMaxLogLines,fRawDataPath,fFirstSample,fSamples,fMinDiskSpaceMB, 232 fMaxFileSizeMB,fCCPort,fFirstVMESlot,fLastVMESlot,fHVFeedbackConfig); 228 PrintConfig(CmdFromSocket ? MsgToSocket : MsgToConsole); 233 229 } 234 230 … … 241 237 return; 242 238 } 243 if (!IsDRSFreqSet()) return; 239 if (!IsDRSFreqSet()) { 240 PrintMessage("Setting default frequency\n"); 241 SetDRSFrequency(fDefaultFrequency, false); 242 CalibrationRead = false; 243 } 244 244 245 if (!CalibrationRead && !ReadCalibration()) { 245 246 PrintMessage("Cannot start run if response calibration not read.\n"); … … 445 446 // Do internal calibration 446 447 void DAQReadout::cmd_calib() { 447 if (NParam==4 && atof(Param[1]) && atof(Param[2])) 448 CalibrateDRS((char *) Param[3],atof(Param[1]),atof(Param[2])); 449 else if (NParam==3 && atof(Param[1]) && atof(Param[2])) 450 CalibrateDRS(NULL,atof(Param[1]),atof(Param[2])); 451 else PrintUsage(); 448 char str[MAX_COM_SIZE]; 449 450 if (NParam!=3 || !atof(Param[1]) || !atof(Param[2])) { 451 PrintUsage(); 452 return; 453 } 454 455 getcwd(str, sizeof(str)); 456 strcat(str,"/calib"); 457 PrintMessage("Writing calibration data to directory '%s'\n",str); 458 459 for (int i=FirstBoard; i<=LastBoard; i++) { 460 drs->GetBoard(i)->Init(); 461 drs->GetBoard(i)->SetFrequency(atof(Param[2])); 462 drs->GetBoard(i)->SoftTrigger(); 463 464 PrintMessage("Creating calibration of board %d (%d)\n", i, drs->GetBoard(i)->GetCMCSerialNumber()); 465 466 drs->GetBoard(i)->EnableTcal(1); 467 PrintMessage("Tcal enabled\n"); 468 469 if (drs->GetBoard(i)->GetChipVersion() == 3) drs->GetBoard(i)->GetResponseCalibration()->SetCalibrationParameters(1,21,0,20,0,0,0,0,0); 470 else drs->GetBoard(i)->GetResponseCalibration()->SetCalibrationParameters(1,36,110,20,19,40,15,atof(Param[1]),0); 471 drs->GetBoard(i)->SetCalibrationDirectory(str); 472 473 for (int j=0; j<2; j++) { 474 drs->GetBoard(i)->GetResponseCalibration()->ResetCalibration(); 475 PrintMessage("Calibration reset done.\n"); 476 477 while (!drs->GetBoard(i)->GetResponseCalibration()->RecordCalibrationPoints(j)) {} 478 PrintMessage("Record calibration points done.\n"); 479 while (!drs->GetBoard(i)->GetResponseCalibration()->FitCalibrationPoints(j)) {} 480 PrintMessage("Calibration points fitted.\n"); 481 while (!drs->GetBoard(i)->GetResponseCalibration()->OffsetCalibration(j)) {} 482 PrintMessage("Offset calibration done.\n"); 483 484 if (!drs->GetBoard(i)->GetResponseCalibration()->WriteCalibration(j)) break; 485 } 486 drs->GetBoard(i)->Init(); // Reset linear range -0.2 ... 0.8 V 487 } // Loop over boards 452 488 } 453 489 … … 650 686 // Print feedback configuration 651 687 void DAQReadout::cmd_fconfig() { 652 HVFB->PrintConfig( );688 HVFB->PrintConfig(CmdFromSocket ? MsgToSocket : MsgToConsole); 653 689 } 654 690 … … 799 835 } 800 836 801 // Do internal calibration802 void DAQReadout::CalibrateDRS(char *dir, double trigfreq, double calibfreq) {803 804 int i,j;805 char str[MAX_COM_SIZE];806 DIR *pdir;807 808 if (NumBoards) {809 if(dir!=NULL) {810 if ((pdir=opendir(str))==0){811 PrintMessage("Error: target directory \"%s\" does not exist!\n",str);812 return;813 }814 closedir(pdir);815 snprintf(str,sizeof(str),"%s",dir);816 PrintMessage("Target: \"%s\"\n",str);817 }818 else {819 getcwd(str, sizeof(str));820 strcat(str,"/calib");821 PrintMessage("Taking default target: \"%s/\"\n",str);822 }823 824 for (i=FirstBoard; i<=LastBoard; i++) {825 drs->GetBoard(i)->Init();826 drs->GetBoard(i)->SetFrequency(calibfreq);827 drs->GetBoard(i)->SoftTrigger();828 829 PrintMessage("Creating calibration of board %d\n", drs->GetBoard(i)->GetCMCSerialNumber());830 831 drs->GetBoard(i)->EnableTcal(1);832 PrintMessage("Tcal enabled");833 834 if (drs->GetBoard(i)->GetChipVersion() == 3)835 drs->GetBoard(i)->GetResponseCalibration()->SetCalibrationParameters(1,21,0,20,0,0,0,0,0);836 else837 drs->GetBoard(i)->GetResponseCalibration()->SetCalibrationParameters(1,36,110,20,19,40,15,trigfreq,0);838 839 drs->GetBoard(i)->SetCalibrationDirectory(str);840 PrintMessage("Storage directory \"%s\"\n",str);841 842 for (j=0;j<2;j++) {843 drs->GetBoard(i)->GetResponseCalibration()->ResetCalibration();844 PrintMessage("Calibration reset done.\n");845 846 while (!drs->GetBoard(i)->GetResponseCalibration()->RecordCalibrationPoints(j)) {}847 PrintMessage("Record calibration points done.\n");848 while (!drs->GetBoard(i)->GetResponseCalibration()->FitCalibrationPoints(j)) {}849 PrintMessage("Calibration points fitted.\n");850 while (!drs->GetBoard(i)->GetResponseCalibration()->OffsetCalibration(j)) {}851 PrintMessage("Offset calibration done.\n");852 853 if (!drs->GetBoard(i)->GetResponseCalibration()->WriteCalibration(j))854 break;855 }856 drs->GetBoard(i)->Init(); // Reset linear range -0.2 ... 0.8 V857 } // Loop over boards858 }859 else PrintMessage("No DRS boards available\n");860 }861 862 837 // Check if DRS is sampling 863 838 bool DAQReadout::IsDRSBusy() { … … 871 846 bool DAQReadout::IsDRSFreqSet() { 872 847 873 for (int i=FirstBoard; i<=LastBoard;i++)848 for (int i=FirstBoard; i<=LastBoard; i++) 874 849 if (DRSFreq[i]==0) { 875 850 PrintMessage("DRS sampling frequency of board %d not set!\n",i); … … 992 967 } 993 968 994 // Write event header 995 bool DAQReadout::WriteEventHeader() { 996 969 // Write event 970 bool DAQReadout::WriteEvent() { 971 972 // Event header 997 973 struct timeval Time; 998 974 … … 1000 976 1001 977 EHeader->EventNumber = NumEvents; 1002 EHeader->TriggerType = (daq_runtype == data) ? 1 : 0;978 EHeader->TriggerType = daq_runtype==data ? 0 : 1; 1003 979 EHeader->Second = Time.tv_sec; 1004 980 EHeader->Microsecond = Time.tv_usec; … … 1010 986 return false; 1011 987 } 1012 return true; 1013 } 1014 1015 // Write event data (It is required that at least three chunks can be written with writev(), therefore 1016 // IOV_MAX>=3 is checked at startup 1017 bool DAQReadout::WriteEventData() { 1018 988 989 // Event data (It is required that at least three chunks can be written with writev(), therefore 990 // IOV_MAX>=3 is checked at startup 991 1019 992 unsigned int Start, Count = 0; 1020 993 ssize_t WriteResult, Size = 0; … … 1022 995 1023 996 // First chunk: trigger cells 1024 DataPart[Count].iov_base = TriggerCell + FirstBoard*kNumberOfChips;997 DataPart[Count].iov_base = (char *) TriggerCell + FirstBoard*kNumberOfChips*sizeof(int); // TriggerCell is without cast a pointer to an 8-byte unit (two ints) ! 1025 998 DataPart[Count++].iov_len = RHeader->NBoards * kNumberOfChips * sizeof(int); 1026 999 Size += DataPart[Count-1].iov_len; … … 1054 1027 } // Chips 1055 1028 } // Boards 1029 1056 1030 return true; 1031 } 1032 1033 // Print configuration to target 1034 void DAQReadout::PrintConfig(int Target) { 1035 PrintMessage(Target, "LogFile: %s\tMaxLogLines: %u\tRawDataPath: %s\n" 1036 "DefaultFrequency: %.2f\tFirstSample: %d\tSamples: %u\n" 1037 "MinDiskSpaceMB: %u\tMaxFileSizeMB: %d\tCCPort: %d\n" 1038 "FirstVMESlot: %d\t\tLastVMESlot: %d\n" 1039 "SlowDataPath: %s\tHVFeedbackConfig: %s\n", 1040 fLogFile,fMaxLogLines,fRawDataPath,fDefaultFrequency,fFirstSample,fSamples,fMinDiskSpaceMB, 1041 fMaxFileSizeMB,fCCPort,fFirstVMESlot,fLastVMESlot,fSlowDataPath,fHVFeedbackConfig); 1057 1042 } 1058 1043 … … 1238 1223 else if (m->daq_runtype == pedestal) m->StopDRS(); // ..or for software trigger 1239 1224 1240 EventsInFile++; m->NumEvents++;1241 WriteError |= !m->WriteEventHeader();1242 1243 1225 // Read event data via VME or generate test data (for one board if no boards available) 1244 1226 if (m->daq_runtype != test) { … … 1252 1234 } 1253 1235 1254 // Write data to disk and update file size 1255 WriteError |= !m->WriteEventData(); 1236 // Write event to disk and update file size 1237 EventsInFile++; m->NumEvents++; 1238 WriteError |= !m->WriteEvent(); 1256 1239 1257 1240 if((FileSize = lseek(m->Rawfile, 0, SEEK_CUR)) == -1) { … … 1273 1256 } while((m->NumEvents<m->NumEventsRequested || m->NumEventsRequested==0) && !m->Stop && !WriteError); 1274 1257 1275 // Print run summary to slow data file and to screen1276 1258 m->StopDRS(); 1277 if(!WriteError) { 1278 m->PrintMessage("\rRun #%d (%s) %s, %d events\n",m->RunNumber,daq_runtype_str[m->daq_runtype],(m->NumEvents == m->NumEventsRequested) ? "completed":"stopped",m->NumEvents); 1279 m->SlowDataClass->NewEntry("Runinfo"); 1280 m->SlowDataClass->AddToEntry("%d %s %s %d %d", m->RunNumber, daq_runtype_str[m->daq_runtype], m->RHeader->Description, m->NumEvents, m->FileNumber); 1281 if(m->SlowDataClass->ErrorCode != 0) { 1282 m->PrintMessage("Error, could not write DAQ data to file (%s), file closed\n", strerror(m->SlowDataClass->ErrorCode)); 1283 } 1284 1285 } 1259 1260 // Print run summary to screen 1261 if(!WriteError) m->PrintMessage("\rRun #%d (%s) %s, %d events\n",m->RunNumber,daq_runtype_str[m->daq_runtype],(m->NumEvents == m->NumEventsRequested) ? "completed":"stopped",m->NumEvents); 1286 1262 else m->PrintMessage("\rRun #%d (%s) aborted due to error after %d events\n",m->RunNumber,daq_runtype_str[m->daq_runtype],m->NumEvents); 1263 1264 // Write run summary to slow data file 1265 m->SlowDataClass->NewEntry("Runinfo"); 1266 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); 1267 if(m->SlowDataClass->ErrorCode != 0) { 1268 m->PrintMessage("Error, could not write DAQ data to file (%s), file closed\n", strerror(m->SlowDataClass->ErrorCode)); 1269 } 1287 1270 1288 1271 // Print run statistics
Note:
See TracChangeset
for help on using the changeset viewer.