Changeset 226 for drsdaq/HVFeedback.cc


Ignore:
Timestamp:
06/18/10 12:25:29 (14 years ago)
Author:
ogrimm
Message:
Small changes to mutex handling in hvcontrol and drsdaq
File:
1 edited

Legend:

Unmodified
Added
Removed
  • drsdaq/HVFeedback.cc

    r211 r226  
    2525// Constructor: Initialise feedback
    2626//
    27 HVFeedback::HVFeedback(DAQReadout* DAQClass){//:
    28                         //EvidenceServer(SERVER_NAME){
     27HVFeedback::HVFeedback(DAQReadout* DAQClass){
    2928
    3029  m = DAQClass;
     
    139138  }
    140139 
    141   // Update DIM service regularly
     140  // Update DIM count service regularly
    142141  if (time(NULL)-LastServiceUpdate > 2) {
    143142    LastServiceUpdate = time(NULL);
     
    148147
    149148  // Feedback action
     149  std::stringstream Cmd;
     150 
    150151  for (i=m->FirstBoard; i<=m->LastBoard; i++) {
    151152  for (j=0; j<fNumberOfChips; j++) {
     
    165166
    166167                if(fabs(Average[i][j][k]) < 2*Sigma[i][j][k]) printf("Too noisy!\n");
    167                 else WriteHVCommand("hv %s %+f\n",PixMap->DRS_to_Pixel(i,j,k).c_str(), Correction);
    168 
     168                else {
     169                  Cmd << PixMap->DRS_to_Pixel(i,j,k)+" " << std::showpos << Correction << " ";
     170                }
    169171            break;
    170172
     
    175177          case FB_ResponseFirst:  // First point of response measurement done 
    176178            Buffer[i][j][k] = Average[i][j][k];
    177             if(!PixMap->DRS_to_Pixel(i,j,k).empty()) WriteHVCommand("hv %s %+f",PixMap->DRS_to_Pixel(i,j,k).c_str(), DiffVoltage);
     179            if(!PixMap->DRS_to_Pixel(i,j,k).empty()) {
     180                  Cmd << PixMap->DRS_to_Pixel(i,j,k) << " " << std::showpos << DiffVoltage << " ";               
     181                }
    178182            break;
    179183
     
    184188            }
    185189            else Response[i][j][k] = DiffVoltage/(Buffer[i][j][k]-Average[i][j][k]);
    186             if(!PixMap->DRS_to_Pixel(i,j,k).empty()) WriteHVCommand("hv %s %+f",PixMap->DRS_to_Pixel(i,j,k).c_str(), -DiffVoltage/2);
     190            if(!PixMap->DRS_to_Pixel(i,j,k).empty()) {
     191                  Cmd << PixMap->DRS_to_Pixel(i,j,k) << " " << std::showpos << -DiffVoltage/2 << " ";                             
     192                }
    187193            break;
    188194
     
    196202  FeedbackAverage->updateService();
    197203  FeedbackSigma->updateService();
     204
     205  // Send command
     206  if (!Cmd.str().empty()) {
     207        DimClient::sendCommand("Bias/Command", ("hv "+Cmd.str()).c_str());
     208  }
    198209
    199210  switch (FBMode) {
     
    269280  else {
    270281    FBMode = Mode;
    271         if (Mode != FB_ResponseFirst) m->State(m->INFO, "%s", FBState_Description[FBMode]);
    272         else m->State(m->INFO, "%s (voltage difference %.3f)", FBState_Description[FBMode], DiffVoltage);
     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);
    273284    ClearAverages();
    274285  }
     
    320331void HVFeedback::MeasureResponse(float U) {
    321332
     333  std::stringstream Cmd;
     334
    322335  if (U==0) {
    323336    m->PrintMessage("HV Feedback: Error, voltage difference must not non-zero.\n");
     
    325338  }
    326339
    327   for (int i=m->FirstBoard; i<=m->LastBoard; i++)
    328     for (int j=0; j<fNumberOfChips; j++)
    329       for (int k=0; k<fNumberOfChannels; k++) {
    330                 if(!PixMap->DRS_to_Pixel(i,j,k).empty()) {
    331           WriteHVCommand("hv %s %+f\n",PixMap->DRS_to_Pixel(i,j,k).c_str(), -U/2);
    332         }
    333       }
     340  for (int i=m->FirstBoard; i<=m->LastBoard; i++) {
     341  for (int j=0; j<fNumberOfChips; j++) {
     342  for (int k=0; k<fNumberOfChannels; k++) {
     343        if(!PixMap->DRS_to_Pixel(i,j,k).empty()) {
     344          Cmd << PixMap->DRS_to_Pixel(i,j,k) << " " << std::showpos << -U/2 << " ";                               
     345    }
     346  }
     347  }
     348  }
     349 
     350  // Send command
     351  if (!Cmd.str().empty()) {
     352        DimClient::sendCommand("Bias/Command", ("hv "+Cmd.str()).c_str());
     353  }
     354
    334355  DiffVoltage = U;
    335356  SetFBMode(FB_ResponseFirst, true);
     
    351372
    352373//
    353 // Write bias voltage commmand
    354 //
    355 bool HVFeedback::WriteHVCommand(const char *Format, ...) {
    356 
    357   char Textbuffer[MAX_COM_SIZE];
    358  
    359   va_list ArgumentPointer;  va_start(ArgumentPointer, Format);
    360   vsnprintf(Textbuffer, sizeof(Textbuffer), Format, ArgumentPointer);
    361 
    362   DimClient::sendCommand("Bias/Command", Textbuffer);
    363   return true;
    364 }
    365 
    366 //
    367374// Print feedback configuration
    368375//
Note: See TracChangeset for help on using the changeset viewer.