- Timestamp:
- 06/08/09 14:30:46 (16 years ago)
- Location:
- drsdaq
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
drsdaq/DAQReadout.cc
r51 r55 11 11 #include "DAQReadout.h" 12 12 #include "SlowData.h" 13 14 #define TMPNAME "/tmp/__tmp__drsdaq__" 13 15 14 16 static const char* daq_state_str[] = {"active", "stopped"}; … … 64 66 65 67 // Initialize status structure 66 daq_state = stopped; 67 daq_runtype = data; 68 Socket = -1; 69 Exit = false; 70 CalibrationRead = false; 71 NumEvents = 0; 72 NumEventsRequested = 100; 73 NumBoards = 0; 74 FirstBoard = 0; 75 LastBoard = -1; 76 68 daq_state = stopped; 69 daq_runtype = data; 70 Socket = -1; 71 Exit = false; 72 CalibrationRead = false; 73 NumEvents = 0; 74 NumEventsRequested = 100; 75 NumBoards = 0; 76 FirstBoard = 0; 77 LastBoard = -1; 78 CmdFromSocket = false; 79 77 80 // Read configuration file 78 81 FILE *File; … … 83 86 printf("Reading drsdaq configuration file %s\n", Configfile); 84 87 ReadCard("LogFile", fLogFile, 's', File); 88 ReadCard("MaxLogLines", &fMaxLogLines, 'U', File); 85 89 ReadCard("RawDataPath", fRawDataPath, 's', File); 86 90 ReadCard("RotateWave", &fRotateWave, 'I', File); … … 100 104 fLastSample = kNumberOfBins; 101 105 } 102 103 // Open log file and print configuration 104 if ((Logfile = fopen(fLogFile, "a")) == NULL) 105 fprintf(stderr,"Warning: Could not open log file '%s'\n", fLogFile); 106 else PrintMessage(MsgToLog,"********** Logging started **********\n"); 106 107 // Truncate log file to given number of lines 108 char ShellCmd[MAX_COM_SIZE]; 109 snprintf(ShellCmd, sizeof(ShellCmd), "tail --lines=%u %s >%s; cp %s %s; rm %s", fMaxLogLines, fLogFile, TMPNAME, TMPNAME, fLogFile, TMPNAME); 110 if (system(ShellCmd) != 0) printf("Warning: Could not truncate log file '%s' to %u lines\n", fLogFile, fMaxLogLines); 111 112 // Open log file 113 if ((Logfile = fopen(fLogFile, "a")) == NULL) printf("Warning: Could not open log file '%s'\n", fLogFile); 114 PrintMessage(MsgToLog,"********** Logging started **********\n"); 115 116 // Print configuration 107 117 cmd_config(); 108 118 … … 165 175 // -------------------------------- 166 176 167 int DAQReadout::CommandControl(char *Command, bool FromSocket) { 168 169 if (strlen(Command) < 2 ) return 0; // Ignore commands with only '/n' 170 if (Command[strlen(Command)-1]=='\n') Command[strlen(Command)-1]='\0'; // Remove '/n' 171 177 void DAQReadout::CommandControl(char *Command) { 178 179 if (strlen(Command)==0) return; // Ignore empty commands 180 172 181 if(Command[0]=='.') { // Shell command 173 182 system(&(Command[1])); 174 return 0;183 return; 175 184 } 176 185 177 186 for(int i=0; i<MAX_NUM_TOKEN; i++) Param[i] = ""; // All pointers point initially to empty string 178 187 NParam = ParseInput(Command, Param); 179 180 CmdFromSocket = FromSocket; 188 181 189 for(CmdNumber=0; CmdNumber<sizeof(CommandList)/sizeof(CL_Struct); CmdNumber++) 182 190 if (Match(Param[0], CommandList[CmdNumber].Name)) { … … 184 192 else if(CommandList[CmdNumber].NeedNotBusy && NumBoards==0) PrintMessage("No mezzanine boards available\n"); 185 193 else (this->*CommandList[CmdNumber].CommandPointer)(); 186 return 0;187 } 188 PrintMessage("Unknown command : %s\n",Param[0]);189 return 0;194 return; 195 } 196 PrintMessage("Unknown command '%s'\n",Param[0]); 197 return; 190 198 } 191 199 … … 194 202 time_t ActualT; 195 203 time (&ActualT); 196 PrintMessage( CmdFromSocket ? MsgToSocket:MsgToConsole,"%d:%02d:%02d\n", (int) difftime(ActualT, StartTime)/3600, ((int) difftime(ActualT, StartTime)/60)%60, (int) difftime(ActualT, StartTime)%60);204 PrintMessage("%d:%02d:%02d\n", (int) difftime(ActualT, StartTime)/3600, ((int) difftime(ActualT, StartTime)/60)%60, (int) difftime(ActualT, StartTime)%60); 197 205 } 198 206 199 207 // Print disk space 200 208 void DAQReadout::cmd_disk() { 201 PrintMessage( CmdFromSocket ? MsgToSocket:MsgToConsole,"Free disk space (%s) [MB]: %lu\n", fRawDataPath, CheckDisk(fRawDataPath));209 PrintMessage("Free disk space (%s) [MB]: %lu\n", fRawDataPath, CheckDisk(fRawDataPath)); 202 210 } 203 211 … … 210 218 // Print DAQ configuration 211 219 void DAQReadout::cmd_config() { 212 PrintMessage("LogFile: %s\t RawDataPath: %s\n"220 PrintMessage("LogFile: %s\tMaxLogLines: %u\tRawDataPath: %s\n" 213 221 "RotateWave: %d\t\tFirstSample: %d\t\tLastSample: %d\n" 214 222 "MinDiskSpaceMB: %u\tMaxFileSizeMB: %d\tCCPort: %d\n" 215 "FirstVMESlot: %d\t\tLastVMESlot: %d\n" 216 "HVFeedbackConfig: \t%s\n", 217 fLogFile,fRawDataPath,fRotateWave,fFirstSample,fLastSample,fMinDiskSpaceMB, 223 "FirstVMESlot: %d\t\tLastVMESlot: %d\t\tHVFeedbackConfig: %s\n", 224 fLogFile,fMaxLogLines,fRawDataPath,fRotateWave,fFirstSample,fLastSample,fMinDiskSpaceMB, 218 225 fMaxFileSizeMB,fCCPort,fFirstVMESlot,fLastVMESlot,fHVFeedbackConfig); 219 226 } … … 278 285 // Create DAQ thread 279 286 if ((pthread_create(&thread_DAQ, NULL, (void * (*)(void *)) DAQ,(void *) this)) != 0) 280 perror("pthread_create failed with DAQ thread");287 PrintMessage("pthread_create failed with DAQ thread (%s)\n",strerror(errno)); 281 288 else { 282 289 daq_state = active; … … 552 559 LastBoard = drs->GetNumberOfBoards()-1; 553 560 } 554 else if (NParam==2 && atoi(Param[1]) >= 0 && atoi(Param[1]) <NumBoards) {561 else if (NParam==2 && atoi(Param[1])>=0 && atoi(Param[1])<NumBoards) { 555 562 FirstBoard = atoi(Param[1]); 556 563 LastBoard = FirstBoard; … … 565 572 } 566 573 567 // Print help 574 // Print help (only to console or socket, not to log file) 568 575 void DAQReadout::cmd_help() { 569 576 char Buffer[MAX_COM_SIZE]; … … 978 985 979 986 EHeader->EventNumber = NumEvents; 980 EHeader->TriggerType = 0x0;987 EHeader->TriggerType = (daq_runtype == data) ? 1 : 0; 981 988 EHeader->Second = Time.tv_sec; 982 989 EHeader->Microsecond = Time.tv_usec; … … 1003 1010 } 1004 1011 1005 // Print message to screen, log file and socket1012 // Print message to log file, and screen or socket (depending on command origin) 1006 1013 void DAQReadout::PrintMessage(const char *Format, ...) { 1007 1014 va_list ArgumentPointer; 1008 va_start(ArgumentPointer, Format); 1009 PrintMessage(MsgToConsole|MsgToLog|MsgToSocket, Format, ArgumentPointer); 1015 va_start(ArgumentPointer, Format); 1016 if(CmdFromSocket) PrintMessage(MsgToSocket|MsgToLog, Format, ArgumentPointer); 1017 else PrintMessage(MsgToConsole|MsgToLog, Format, ArgumentPointer); 1010 1018 va_end(ArgumentPointer); 1011 1019 } … … 1069 1077 while(!isspace(*Command) && *Command!='\0') Command++; 1070 1078 } 1071 *Command++ = '\0';1079 if(*Command != '\0') *Command++ = '\0'; 1072 1080 Count++; 1073 } ;1081 } 1074 1082 return Count; 1075 1083 } 1076 1084 1077 // ReadCard function by F. Goebel 1078 int ReadCard(const char *card_flag, void *store, char type, FILE *fptr) { 1079 1080 char *card_name, *card_val, line[160]; 1081 1082 rewind(fptr); 1083 1084 while (fgets(line, 160, fptr) != NULL) { // Read line by line 1085 card_name = strtok(line," \t\n"); 1086 card_val = strtok(NULL," \t\n"); 1085 // ReadCard function (original version by F. Goebel) 1086 // Data is read into an array if MaxNum is larger than 1 1087 bool ReadCard(const char *card_flag, void *store, char Type, FILE *File, unsigned int MaxNum) { 1088 1089 char *card_name, *card_val, Buffer[MAX_COM_SIZE]; 1090 unsigned int Count=0; 1091 1092 rewind(File); 1093 1094 while (fgets(Buffer, sizeof(Buffer), File) != NULL) { // Read line by line 1095 card_name = strtok(Buffer," \t\n"); 1087 1096 1088 if ( card_name != NULL && card_val != NULL // Comment or empty line? 1089 && card_name[0] != '*' && card_name[0] != '#') { 1090 1091 if (strcmp(card_name, card_flag)!=0) { // Is this the card name we are looking for? 1092 continue; 1097 // Ignore empty lines, comments, and skip if card name does not match 1098 if (card_name==NULL || card_name[0]=='#' || strcmp(card_name, card_flag)!=0) continue; 1099 1100 // Read numbers of given type (if MaxNum>1 read array) 1101 while ((card_val=strtok(NULL," \t\n")) != NULL && Count++<MaxNum) { 1102 switch (Type) { 1103 case 'I': *(((int *&) store)++) = (int) strtol(card_val, NULL, 10); 1104 break; 1105 case 'i': *(((short *&) store)++) = (short) strtol(card_val, NULL, 10); 1106 break; 1107 case 'U': *(((unsigned int *&) store)++) = (unsigned int) strtoul(card_val, NULL, 10); 1108 break; 1109 case 'u': *(((unsigned short *&) store)++) = (unsigned short) strtoul(card_val, NULL, 10); 1110 break; 1111 case 'f': *(((float *&) store)++) = atof(card_val); 1112 break; 1113 case 'd': *(((double *&) store)++) = atof(card_val); 1114 break; 1115 case 's': sprintf((char *) store, "%s", card_val); 1116 break; 1117 case 'c': *((char *) store) = card_val[0]; 1118 break; 1119 default: fprintf(stderr,"Warning: Unknown type '%c' for reading of configuration file\n", Type); 1120 return false; 1093 1121 } 1094 1095 switch (type) { 1096 case 'I': *((int *) store) = (int) strtol(card_val, (char**)NULL, 10); 1097 break; 1098 case 'i': *((short *) store) = (short) strtol(card_val, (char**)NULL, 10); 1099 break; 1100 case 'U': *((unsigned int *) store) = (unsigned int) strtoul(card_val, (char**)NULL, 10); 1101 break; 1102 case 'u': *((unsigned short *) store) = (unsigned short) strtoul(card_val, (char**)NULL, 10); 1103 break; 1104 case 'f': *((float *) store) = atof(card_val); 1105 break; 1106 case 'd': *((double *) store) = atof(card_val); 1107 break; 1108 case 's': sprintf((char *) store,"%s",card_val); 1109 break; 1110 case 'c': *((char *) store) = card_val[0]; 1111 break; 1112 default: fprintf(stderr,"WARNING: ReadCard: unknown type: %c\n", type); 1113 return -2; 1114 } 1115 return 0; // Found card name 1116 } 1117 } 1118 fprintf(stderr,"WARNING: ReadCard: card: %s not found\n", card_flag); 1119 return -1; 1122 } 1123 return true; // Finished reading data for card name 1124 1125 } 1126 fprintf(stderr,"Warning: Configuration value %s not found\n", card_flag); 1127 return false; 1120 1128 } 1121 1129 -
drsdaq/DAQReadout.h
r51 r55 36 36 unsigned int CmdNumber; 37 37 FILE *Logfile; 38 bool CmdFromSocket; // Current command issued via socket39 38 void PrintUsage(); 40 39 bool CalibrationRead; … … 52 51 // Configuration data 53 52 char fLogFile[MAX_PATH]; 53 unsigned int fMaxLogLines; 54 54 char fRawDataPath[MAX_PATH]; 55 55 int fMinDiskSpaceMB; // Minimum required disk space in MBytes … … 64 64 65 65 // Status variables 66 int NParam; // Number of parameters66 int NParam; // Number of command parameters 67 67 const char *Param[MAX_NUM_TOKEN]; // Pointers to parameters 68 bool CmdFromSocket; // Current command issued via socket 68 69 int NumBoards; 69 70 int FirstBoard; … … 104 105 void cmd_fresponse(); void cmd_fconfig(); 105 106 106 int CommandControl(char*, bool);107 void CommandControl(char*); 107 108 void StartDRS(); 108 109 void StopDRS(); … … 133 134 int ParseInput(char*, const char *Param[]); 134 135 int CheckDisk(char*); 135 int ReadCard(const char *, void *, char, FILE *);136 bool ReadCard(const char *, void *, char, FILE *, unsigned int=1); 136 137 137 138 #endif -
drsdaq/HVFeedback.cc
r49 r55 31 31 snprintf(Filename,sizeof(Filename),"%s/SlowData/", m->fRawDataPath); 32 32 SlowDataClass = new SlowData(m, "HVFB", Filename); 33 34 // Initialise with zero content 35 Average = new float [m->NumBoards][kNumberOfChips][kNumberOfChannels](); 36 Sigma = new float [m->NumBoards][kNumberOfChips][kNumberOfChannels](); 37 Response = new float [m->NumBoards][kNumberOfChips][kNumberOfChannels](); 38 Target = new float [m->NumBoards][kNumberOfChips][kNumberOfChannels](); 39 Buffer = new float [m->NumBoards][kNumberOfChips][kNumberOfChannels](); 33 40 34 41 // Read configuration file … … 51 58 ReadCard("HVControlPort", &fHVControlPort, 'I', File); 52 59 ReadCard("MaxCmdAckDelay", &fMaxCmdAckDelay, 'I', File); 60 ReadCard("DefaultResponse", Response, 'f', File, m->NumBoards*kNumberOfChips*kNumberOfChannels); 53 61 fclose(File); 54 62 } 55 63 PrintConfig(); 56 57 // Initialise with zero content 58 Average = new float [m->NumBoards][kNumberOfChips][kNumberOfChannels](); 59 Sigma = new float [m->NumBoards][kNumberOfChips][kNumberOfChannels](); 60 Response = new float [m->NumBoards][kNumberOfChips][kNumberOfChannels](); 61 Target = new float [m->NumBoards][kNumberOfChips][kNumberOfChannels](); 62 Buffer = new float [m->NumBoards][kNumberOfChips][kNumberOfChannels](); 63 64 65 // Initial state 64 66 Gain = 1; 65 67 SetFBMode(FB_Off); -
drsdaq/History.txt
r51 r55 9 9 26/3/2009 Added PixelMap translation to communication with HV control. 10 10 30/3/2009 Added feedback gain. Checked into repository. 11 1/4/2009 Change smany 'char *' to 'const char *' to honour compiler warning11 1/4/2009 Changed many 'char *' to 'const char *' to honour compiler warning 12 12 on ihp-pc26 (newer version of g++ than on eth-vme02) 13 2/4/2009 Int oduced check for magic number in RawDataCTX.cc13 2/4/2009 Introduced check for magic number in RawDataCTX.cc 14 14 3/4/2009 Added frequency and scale factor transmission to socket protocol 15 15 6/4/2009 Allowed reading of data via read command also while DAQ is active. … … 30 30 28/5/2009 Replaced NCMCBoards by NBoards for clarity. Added line editing 31 31 capability with the readline library. 32 29/5/2009 Number of lines in log file limited to configurable number. 33 4/6/2009 Config file can contain array of numbers. Reading of config file now 34 safe for buffer overflow. RawDataCTX class take the possibility of 35 varying event data size into account. -
drsdaq/RawDataCTX.cc
r49 r55 105 105 fprintf(fptr, "*** Board %d ***\n", i); 106 106 fprintf(fptr, "Serial number: %d\n", BStruct[i].SerialNo); 107 fprintf(fptr, "Sampling frequency [GHz]: %.3f\n", BStruct[i].NomFreq);108 fprintf(fptr, "Temperature [C]: %.3f\n", BStruct[i].BoardTemp);107 fprintf(fptr, "Sampling frequency: %.3f GHz\n", BStruct[i].NomFreq); 108 fprintf(fptr, "Temperature: %.3f deg C\n", BStruct[i].BoardTemp); 109 109 fprintf(fptr, "Scale factor: %.3f\n", BStruct[i].ScaleFactor); 110 110 } … … 138 138 } 139 139 140 /* // Move file pointer to desired event header (if zero read next event) 141 if(EventNo!=0 && fseek(Rawfile, RHeader->RunHeaderSize+RHeader->BoardStructureSize*RHeader->NBoards+(EventNo-1)*(RHeader->EventHeaderSize+RHeader->NBoards*RHeader->NChips* 142 RHeader->NChannels*RHeader->Samples*sizeof(short)), SEEK_SET)!=0) { 140 // Move file pointer to desired event header (if zero read next event) 141 bool SEEK_OK=true; 142 if (EventNo!=0 && fseek(Rawfile, RHeader->RunHeaderSize+RHeader->BoardStructureSize*RHeader->NBoards, SEEK_SET) != 0) SEEK_OK=false; 143 while(SEEK_OK) { 144 if (fread(EHeader, RHeader->EventHeaderSize, 1, Rawfile) != 1) { 145 if (feof(Rawfile)==0) { 146 if (!Silent) printf("Error: Could not read event header\n"); 147 return CTX_EHEADER; 148 } 149 else return CTX_EOF; 150 } 151 else { 152 if (EHeader->EventNumber==EventNo || EventNo==0) break; 153 if (fseek(Rawfile, EHeader->EventSize, SEEK_CUR) != 0) SEEK_OK = false; 154 } 155 } 156 if(!SEEK_OK) { 143 157 if(!Silent) printf("Error: Could not move to requested event\n"); 144 158 return CTX_SEEK; 145 159 } 146 */147 160 148 // Move file pointer to desired event header (if zero read next event) 149 if (EventNo != 0) { 150 bool SEEK_OK=true; 151 if (fseek(Rawfile, RHeader->RunHeaderSize+RHeader->BoardStructureSize*RHeader->NBoards, SEEK_SET) != 0) SEEK_OK=false; 152 while(SEEK_OK) { 153 if (fread(EHeader, RHeader->EventHeaderSize, 1, Rawfile) != 0) SEEK_OK = false; 154 else { 155 if (EHeader->EventNumber==EventNo) break; 156 if (fseek(Rawfile, EHeader->EventSize, SEEK_CUR) != 0) SEEK_OK = false; 157 } 158 } 159 if(!SEEK_OK) { 160 if(!Silent) printf("Error: Could not move to requested event\n"); 161 return CTX_SEEK; 162 } 163 } 164 // Read event header 165 else if (fread(EHeader, RHeader->EventHeaderSize, 1, Rawfile) != 1) { 166 if (feof(Rawfile)==0) { 167 if (!Silent) printf("Error: Could not read event header\n"); 168 return CTX_EHEADER; 169 } 170 else return CTX_EOF; 171 } 161 // Read event data 172 162 if(fread(Data, 1, EHeader->EventSize, Rawfile) != EHeader->EventSize) { 173 163 if(!Silent) printf("Error: Could not read (all) event data\n"); … … 191 181 return FileOpen; 192 182 } 193 -
drsdaq/drsdaq.cpp
r51 r55 142 142 143 143 strftime(Buf,MAX_COM_SIZE, "%d/%m/%y %X", localtime(&(Time=time(NULL)))); 144 m->PrintMessage(MsgToLog, "CONSOLE(%s)> %s", Buf, Command); 145 144 m->PrintMessage(MsgToLog, "CONSOLE(%s)> %s\n", Buf, Command); 145 146 // Process command 146 147 pthread_mutex_lock(&m->control_mutex); 147 m->CommandControl(Command , false);148 m->CommandControl(Command); 148 149 pthread_mutex_unlock(&m->control_mutex); 149 150 … … 224 225 break; 225 226 } 227 if (Command[strlen(Command)-1]=='\n') Command[strlen(Command)-1]='\0'; // Remove trailing newline 226 228 227 strftime(Buf,MAX_COM_SIZE,"%d/%m/%y %X", localtime(&(Time=time(NULL)))); 228 m->PrintMessage(MsgToLog,"SOCKET(%s)> %s%s",Buf, Command, Command[strlen(Command)-1]=='\n' ? "":"\n"); 229 m->PrintMessage(MsgToConsole,"SOCKET> %s%s",Command, Command[strlen(Command)-1]=='\n' ? "":"\n"); 230 231 pthread_mutex_lock(&m->control_mutex); 232 m->CommandControl(Command, true); // Process CC command 229 strftime(Buf, MAX_COM_SIZE, "%d/%m/%y %X", localtime(&(Time=time(NULL)))); 230 m->PrintMessage(MsgToConsole|MsgToLog, "SOCKET(%s)> %s\n", Buf, Command); 231 232 // Process command 233 pthread_mutex_lock(&m->control_mutex); 234 m->CmdFromSocket = true; 235 m->CommandControl(Command); 236 m->CmdFromSocket = false; 233 237 pthread_mutex_unlock(&m->control_mutex); 234 238 }
Note:
See TracChangeset
for help on using the changeset viewer.