Changeset 254
- Timestamp:
- 07/20/10 13:20:47 (14 years ago)
- Location:
- drsdaq
- Files:
-
- 6 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 } -
drsdaq/DAQReadout.h
r229 r254 12 12 #include <unistd.h> 13 13 #include <sys/socket.h> 14 #include <pthread.h>15 14 #include <fcntl.h> 16 15 #include <dirent.h> 17 16 #include <sys/vfs.h> 18 #include <signal.h>19 17 #include <sys/time.h> 20 18 … … 26 24 #define MAX_COM_SIZE 10000 27 25 #define MAX_NUM_TOKEN 10 28 29 #define MsgToConsole 130 #define MsgToLog 231 26 32 27 enum state_enum {active, stopped}; … … 47 42 void commandHandler(); 48 43 49 pthread_mutex_t Mutex;50 44 int Rawfile; 51 45 class HVFeedback* HVFB; … … 127 121 bool ReadCalibration(); 128 122 void ReadCalibratedDRSData(); 129 void PrintConfig(int); 130 void PrintMessage(int, const char*, ...); 123 void PrintConfig(); 131 124 void PrintMessage(const char*, ...); 132 void DoPrintMessage(const char*, va_list, int);133 125 bool OpenRawFile(); 134 126 bool WriteRunHeader(); -
drsdaq/HVFeedback.cc
r229 r254 30 30 31 31 m = DAQClass; 32 33 32 fNumberOfChannels = m->GetBoard(0)->GetNumberOfChannels(); 34 33 fNumberOfChips = m->GetBoard(0)->GetNumberOfChips(); … … 77 76 } 78 77 79 PrintConfig(MsgToLog);80 81 78 // Provide DIM services 82 FeedbackAverage = new DimService (SERVER_NAME"/Average", "F", DIMAverage, m->NumBoards*kNumberOfChipsMax*kNumberOfChannelsMax*sizeof(float)); 83 FeedbackSigma = new DimService (SERVER_NAME"/Sigma", "F", DIMSigma, m->NumBoards*kNumberOfChipsMax*kNumberOfChannelsMax*sizeof(float)); 84 FeedbackResponse = new DimService (SERVER_NAME"/Response", "F", Response, m->NumBoards*kNumberOfChipsMax*kNumberOfChannelsMax*sizeof(float)); 85 FeedbackTarget = new DimService (SERVER_NAME"/Target", "F", Target, m->NumBoards*kNumberOfChipsMax*kNumberOfChannelsMax*sizeof(float)); 86 CountService = new DimService (SERVER_NAME"/Count", Count); 79 FeedbackAverage = new DimService ("Feedback/Average", "F", DIMAverage, m->NumBoards*kNumberOfChipsMax*kNumberOfChannelsMax*sizeof(float)); 80 FeedbackSigma = new DimService ("Feedback/Sigma", "F", DIMSigma, m->NumBoards*kNumberOfChipsMax*kNumberOfChannelsMax*sizeof(float)); 81 FeedbackResponse = new DimService ("Feedback/Response", "F", Response, m->NumBoards*kNumberOfChipsMax*kNumberOfChannelsMax*sizeof(float)); 82 FeedbackTarget = new DimService ("Feedback/Target", "F", Target, m->NumBoards*kNumberOfChipsMax*kNumberOfChannelsMax*sizeof(float)); 83 CountService = new DimService ("Feedback/Count", Count); 84 FeedbackState = new DimService ("Feedback/State", "I:1;C", NULL, 0); 87 85 88 86 // Initial state … … 98 96 HVFeedback::~HVFeedback() { 99 97 98 delete FeedbackState; 100 99 delete CountService; 101 100 delete FeedbackAverage; … … 105 104 106 105 delete[] Average; delete[] Response; 107 delete[] DIMAverage; 106 delete[] DIMAverage; delete[] DIMSigma; 108 107 delete[] Sigma; 109 108 delete[] Target; delete[] Buffer; … … 159 158 160 159 switch (FBMode) { 161 case FB_Active: // Determine correction from response maxtrix and change voltages 160 case FB_Active: 161 // Determine correction from response maxtrix and change voltages 162 162 Correction = -(Target[i][j][k] - Average[i][j][k])*Response[i][j][k]*Gain; 163 if (fabs(Correction) > 0.1) Correction = fabs(Correction)/Correction*0.1; // Limit changes to 100 mV 163 // Limit voltage steps 164 if (fabs(Correction) > 0.1) Correction = fabs(Correction)/Correction*0.1; // Limit changes to 100 mV 165 // Check if voltage change command possible 164 166 if(Correction==0 || Target[i][j][k]==0 || PixMap->DRS_to_Pixel(i,j,k).empty()) break; 165 printf("Average of board %d, chip %d, channel %d is %.2f +/- %.2f Correction %.3f\n",i,j,k,Average[i][j][k],Sigma[i][j][k],Correction); 166 167 if(fabs(Average[i][j][k]) < 2*Sigma[i][j][k]) printf("Too noisy!\n"); 168 else { 167 // Add voltage change command if not too noisy 168 if(fabs(Average[i][j][k]) > 2*Sigma[i][j][k]) { 169 169 Cmd << PixMap->DRS_to_Pixel(i,j,k)+" " << std::showpos << Correction << " "; 170 170 } … … 184 184 case FB_ResponseSecond: // Determine response from signal variation 185 185 if(Buffer[i][j][k] == Average[i][j][k]) { 186 m->PrintMessage("HV Feedback: Warning, response singular for board %d, chip %d, channel %d .\n",i,j,k);186 m->PrintMessage("HV Feedback: Warning, response singular for board %d, chip %d, channel %d\n",i,j,k); 187 187 Response[i][j][k] = 0; 188 188 } … … 211 211 case FB_Targets: 212 212 FeedbackTarget->updateService(); 213 m->PrintMessage("HV Feedback: New targets set, switching off .\n");213 m->PrintMessage("HV Feedback: New targets set, switching off\n"); 214 214 SetFBMode(FB_Off, true); 215 215 break; 216 216 case FB_ResponseFirst: 217 217 SetFBMode(FB_ResponseSecond, true); 218 m->PrintMessage("HV Feedback: Increasing voltages by %f for response measurement, acquiring data .\n", DiffVoltage);218 m->PrintMessage("HV Feedback: Increasing voltages by %f for response measurement, acquiring data\n", DiffVoltage); 219 219 break; 220 220 case FB_ResponseSecond: 221 221 FeedbackResponse->updateService(); 222 m->PrintMessage("HV Feedback: Response measurements finished, original voltages set, switching off .\n");222 m->PrintMessage("HV Feedback: Response measurements finished, original voltages set, switching off\n"); 223 223 SetFBMode(FB_Off, true); 224 224 break; … … 277 277 void HVFeedback::SetFBMode(FBState Mode, bool Internal) { 278 278 if((Mode==FB_ResponseFirst || Mode==FB_ResponseFirst) && !Internal) 279 m->PrintMessage("Start reponse measurement by calling MeasureResponse() .\n");279 m->PrintMessage("Start reponse measurement by calling MeasureResponse()\n"); 280 280 else { 281 281 FBMode = Mode; 282 if (Mode != FB_ResponseFirst) m-> Message(m->INFO, "%s", FBState_Description[FBMode]);283 else m-> Message(m->INFO, "%s (voltage difference %.3f)", FBState_Description[FBMode], DiffVoltage);282 if (Mode != FB_ResponseFirst) m->PrintMessage("%s\n", FBState_Description[FBMode]); 283 else m->PrintMessage("%s (voltage difference %.3f)\n", FBState_Description[FBMode], DiffVoltage); 284 284 ClearAverages(); 285 286 // Update state service 287 State.State = FBMode; 288 strncpy(State.Text, FBState_Description[FBMode], sizeof(State.Text)); 289 FeedbackState->updateService(&State, sizeof(State)); 285 290 } 286 291 } … … 374 379 // Print feedback configuration 375 380 // 376 void HVFeedback::PrintConfig( int Target) {377 378 m->PrintMessage( Target,"LedTrigBoard: %d\t\tLedTrigChip: %d\t\tLedTrigChannel: %d\n"381 void HVFeedback::PrintConfig() { 382 383 m->PrintMessage("LedTrigBoard: %d\t\tLedTrigChip: %d\t\tLedTrigChannel: %d\n" 379 384 "LedTrigSample: %d\tLedTrigThreshold: %.2f\n" 380 385 "LedSignalSample: %d\tLedBaselineSample: %d\tDefaultNumAverage: %d\n" -
drsdaq/HVFeedback.h
r229 r254 33 33 DimService *FeedbackTarget; 34 34 DimService *CountService; 35 DimService *FeedbackState; 36 37 struct { 38 int State; 39 char Text[BUF_LENGTH]; 40 } State; 35 41 36 42 int NumAverages; // Events to take before feedback acts … … 72 78 void GetResponse(); 73 79 void ClearAverages(); 74 void PrintConfig( int);80 void PrintConfig(); 75 81 }; 76 82 -
drsdaq/History.txt
r211 r254 58 58 16/12/2009 Removed automatic gain adaption in feedback (caused spikes in the correction) 59 59 9/3/2010 Feedback now depended on DIM for communication with bias server. 60 Started migration to DRS4 (last tested revision as daqct3 for DRS2 is 161). DRS class will not run anymore with DRS2 FPGA firmware. 60 Started migration to DRS4 (last tested revision as daqct3 for DRS2 is 161). 61 DRS class will not run anymore with DRS2 FPGA firmware. 61 62 11/3/2010 Removed SlowData class. 62 63 12/3/2010 Removed local configuration and logging. … … 67 68 18/5/2010 Rate of event service adjustable with command 'update'. 68 69 21/5/2010 Fix so that 'exit' command also works as DimCommand. 70 20/7/2010 Replaced mutex with Lock()/Unlock() from Evidence class, introduced DIM feedback state service, 71 streamlined PrintMessage(). -
drsdaq/drsdaq.cpp
r226 r254 91 91 DimClient::sendCommand(SERVER_NAME"/Command", Command); 92 92 free(Command); 93 } 93 } 94 94 } 95 95 … … 97 97 // Remove lock file before running default signal code 98 98 void CrashHandler(int Signal) { 99 99 100 remove(LOCKFILE); 100 101 printf("Caught signal number %d. Removed lockfile and performing standard signal action. Good luck.\n",Signal);
Note:
See TracChangeset
for help on using the changeset viewer.