Changeset 254 for drsdaq/DAQReadout.cc
- Timestamp:
- 07/20/10 13:20:47 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
drsdaq/DAQReadout.cc
r230 r254 57 57 58 58 // Global pointer for thread entry routines 59 class DAQReadout *This ;59 class DAQReadout *ThisClass; 60 60 61 61 // ----------------------------------------------- … … 67 67 68 68 // Initialization 69 This = this;70 MainThread = getpid();69 ThisClass = this; 70 MainThread = pthread_self(); 71 71 ConsoleText = NULL; 72 72 time(&StartTime); … … 74 74 // DIM console service used in PrintMessage() 75 75 ConsoleOut = new DimService(SERVER_NAME"/ConsoleOut", (char *) ""); 76 77 // Initialize mutex for thread synchronisation78 if (pthread_mutex_init(&Mutex, NULL) != 0) {79 Message(FATAL, "pthread_mutex_init() failed");80 }81 76 82 77 // Initialize status structure … … 169 164 delete ConsoleOut; 170 165 free(ConsoleText); 171 172 if (pthread_mutex_destroy(&Mutex) != 0) Message(ERROR, "pthread_mutex_destroy() failed");173 166 } 174 167 … … 202 195 else if(CommandList[Count].NeedNotBusy && NumBoards==0) PrintMessage("No boards available\n"); 203 196 else { 204 int Ret;205 206 // Lock (Execute() runs in thread spawned by commandHandler())207 if ((Ret = pthread_mutex_lock(&Mutex)) != 0) {208 Message(FATAL, "pthread_mutex_lock() failed (%s)", strerror(Ret));209 }210 // Run command211 197 CmdNumber = Count; 212 198 (this->*CommandList[CmdNumber].CommandPointer)(); 213 // Unlock214 if ((Ret = pthread_mutex_unlock(&Mutex)) != 0) {215 Message(FATAL, "pthread_mutex_unlock() failed (%s)", strerror(Ret));216 }217 199 } 218 200 } … … 238 220 // Print DAQ configuration 239 221 void DAQReadout::cmd_config() { 240 PrintConfig( MsgToConsole);222 PrintConfig(); 241 223 } 242 224 … … 411 393 } 412 394 413 PrintMessage( MsgToConsole,"==START== %d %.2f %.2f ",kNumberOfBins+2,DRSFreq[Board],GetBoard(Board)->GetPrecision());395 PrintMessage("==START== %d %.2f %.2f ",kNumberOfBins+2,DRSFreq[Board],GetBoard(Board)->GetPrecision()); 414 396 for (int k=0; k<kNumberOfBins; k++) { 415 PrintMessage( MsgToConsole,"%.1f ", (float) WaveForm[Board][Chip][Channel][k]);416 } 417 PrintMessage( MsgToConsole,"==END==");418 PrintMessage( MsgToConsole,"\n");419 PrintMessage( MsgToConsole,"Trigger cell: %d\n", TriggerCell[Board][Chip]);397 PrintMessage("%.1f ", (float) WaveForm[Board][Chip][Channel][k]); 398 } 399 PrintMessage("==END=="); 400 PrintMessage("\n"); 401 PrintMessage("Trigger cell: %d\n", TriggerCell[Board][Chip]); 420 402 } 421 403 … … 757 739 for(unsigned int i=0; i<sizeof(CommandList)/sizeof(CL_Struct); i++) { 758 740 snprintf(Buffer, sizeof(Buffer), "%s %s", CommandList[i].Name, CommandList[i].Parameters); 759 PrintMessage( MsgToConsole,"%-28s%s\n", Buffer, CommandList[i].Help);741 PrintMessage("%-28s%s\n", Buffer, CommandList[i].Help); 760 742 } 761 PrintMessage( MsgToConsole,".<command> Execute shell command\n\n"743 PrintMessage(".<command> Execute shell command\n\n" 762 744 "Items in <> are mandatory, in [] optional, | indicates mutual exclusive or.\n" 763 745 "Test data can also be written if no DRS boards are available.\n" … … 770 752 771 753 if (daq_state == active) PrintMessage("Issue 'stop' first to stop daq\n"); 772 else kill(MainThread, SIGTERM);754 else pthread_kill(MainThread, SIGTERM); 773 755 } 774 756 … … 777 759 778 760 if(Match(Param[1],"off")) HVFB->SetFBMode(FB_Off); 779 if(Match(Param[1],"active")) HVFB->SetFBMode(FB_Active);780 if(Match(Param[1],"targets")) HVFB->SetFBMode(FB_Targets);781 HVFB->GetFBMode();761 else if(Match(Param[1],"active")) HVFB->SetFBMode(FB_Active); 762 else if(Match(Param[1],"targets")) HVFB->SetFBMode(FB_Targets); 763 else HVFB->GetFBMode(); 782 764 } 783 765 … … 823 805 void DAQReadout::cmd_fconfig() { 824 806 825 HVFB->PrintConfig( MsgToConsole);807 HVFB->PrintConfig(); 826 808 } 827 809 … … 1175 1157 1176 1158 // Print configuration to target 1177 void DAQReadout::PrintConfig( int Target) {1178 PrintMessage( Target,"RawDataPath: %s\n"1159 void DAQReadout::PrintConfig() { 1160 PrintMessage("RawDataPath: %s\n" 1179 1161 "DefaultFrequency: %.2f\tFirstSample: %d\tSamples: %u\n" 1180 1162 "MinDiskSpaceMB: %u\tMaxFileSizeMB: %d\n" … … 1191 1173 // Print progress (used in DRS class) 1192 1174 void DAQReadout::Progress(int Progress) { 1193 PrintMessage( MsgToConsole,"\rProgress: %d%% ", Progress);1175 PrintMessage("\rProgress: %d%% ", Progress); 1194 1176 fflush(stdout); 1195 1177 }; 1196 1197 // Print message to selected target1198 void DAQReadout::PrintMessage(int Target, const char *Format, ...) {1199 1200 va_list ArgumentPointer;1201 va_start(ArgumentPointer, Format);1202 DoPrintMessage(Format, ArgumentPointer, Target);1203 va_end(ArgumentPointer);1204 }1205 1178 1206 1179 // Print message to console only 1207 1180 void DAQReadout::PrintMessage(const char *Format, ...) { 1181 1182 static char Error[] = "vasprintf() failed in PrintMessage()"; 1183 char *Text; 1184 1185 // Evaluate arguments 1208 1186 va_list ArgumentPointer; 1209 1187 va_start(ArgumentPointer, Format); 1210 DoPrintMessage(Format, ArgumentPointer, MsgToConsole);1188 if (vasprintf(&Text, Format, ArgumentPointer) == -1) Text = Error; 1211 1189 va_end(ArgumentPointer); 1212 }1213 1214 // Function doing the actual printing work1215 // Note: Be careful when overloading variadic functions. va_list is1216 // in gcc an int, which can be interpreted as char *...1217 void DAQReadout::DoPrintMessage(const char *Format, va_list ArgumentPointer, int Target) {1218 1219 static char Error[] = "vasprintf() failed in DoPrintMessage()";1220 char *Text;1221 1222 // Evaluate arguments1223 if (vasprintf(&Text, Format, ArgumentPointer) == -1) Text = Error;1224 1190 1225 1191 // Print to console 1226 if(Target & MsgToConsole) { 1227 if(strlen(Text)>0 && Text[strlen(Text)-1]=='\n') printf("\r%s%s", Text, Prompt); // New prompt 1228 else printf("%s", Text); 1229 fflush(stdout); 1230 } 1231 1232 // Send to DIM console service and to log if requested 1233 ConsoleOut->updateService(Text); 1234 if(Target & MsgToLog) SendToLog("%s %s", SERVER_NAME, Text); 1192 if(strlen(Text)>0 && Text[strlen(Text)-1]=='\n') printf("\r%s%s", Text, Prompt); // New prompt 1193 else printf("%s", Text); 1194 fflush(stdout); 1195 1196 // Send to DIM text service 1197 ConsoleOut->updateService(Text); 1235 1198 1236 1199 // Free old text … … 1246 1209 *((char *) getCommand()->getData()+getCommand()->getSize()-1) != '\0' || 1247 1210 strlen(getCommand()->getString()) == 0) return; 1248 1249 // Log command reception1250 SendToLog("Command '%s' from %s (ID %d)", getCommand()->getString(), getClientName(), getClientId());1251 1211 1252 1212 // Copy command to new buffer (will be freed by global Execute() function) … … 1263 1223 PrintMessage("pthread_create() failed in DRSReadout::commandHandler() (%s)\n", strerror(Code)); 1264 1224 } 1265 else { 1266 if ((Code = pthread_detach(Thread)) != 0) { 1267 PrintMessage("pthread_detach() failed in DRSReadout::commandHandler() (%s)\n", strerror(Code)); 1268 } 1225 else if ((Code = pthread_detach(Thread)) != 0) { 1226 PrintMessage("pthread_detach() failed in DRSReadout::commandHandler() (%s)\n", strerror(Code)); 1269 1227 } 1270 1228 } … … 1459 1417 void Execute(char *Command) { 1460 1418 1461 This->Execute(Command); 1462 free(Command); 1463 } 1419 ThisClass->Lock(); 1420 ThisClass->Execute(Command); 1421 free(Command); 1422 ThisClass->Unlock(); 1423 }
Note:
See TracChangeset
for help on using the changeset viewer.