Ignore:
Timestamp:
07/28/09 09:15:18 (15 years ago)
Author:
ogrimm
Message:
Added writing of slow data
File:
1 edited

Legend:

Unmodified
Added
Removed
  • hvcontrol/src/ProcessIO.cc

    r90 r93  
    1414static char* state_str[]    = {"active", "stopped", "n.a."};
    1515
    16 ProcessIO::ProcessIO(char *ConfigFile) {
     16
     17ProcessIO::ProcessIO(const char *ConfigFile) {
    1718
    1819  // Get program start time
     
    2021
    2122  // Create instances
    22   config = new HVConfig(stdout,ConfigFile);
     23  config = new HVConfig(ConfigFile);
    2324  calib  = new HVCalib(config);
    2425  pm     = new PixelMap(config->fPixMapTable);
     
    4445  if(config->TestMode){
    4546    fprintf(stdout,"Test mode: One HVBoard initialized as dummy.\n");
    46     fHVBoard[NumHVBoards] = new HVBoard(0, 0, config->TestMode, config->fTimeOut, Verbose);
     47    fHVBoard[NumHVBoards] = new HVBoard(0, 0, this);
    4748    NumHVBoards++;
    4849  }
    4950  else {
    5051    for (int i=0; i<config->NumHVBoards; i++) {
    51       fHVBoard[NumHVBoards] = new HVBoard(config->USBDeviceNumber[i], config->fUSBDevice[i], config->TestMode, config->fTimeOut, Verbose);
     52      fHVBoard[NumHVBoards] = new HVBoard(config->USBDeviceNumber[i], config->fUSBDevice[i], this);
    5253      if(fHVBoard[NumHVBoards]->fDescriptor >= 0) {
    5354         printf("Synchronized and reset HV board %d (%s)\n",i,config->fUSBDevice[i]);
     
    6667  PrintMessage(MsgToLog,"********** Logging started **********\n");
    6768
    68   // Print configuration to log file
    69   if(Logfile) config->PrintHVConfig(Logfile);
     69  // Create instance of slow data class
     70  SlowDataClass = new SlowData("HV", config->fSlowDir);
     71  if (SlowDataClass->ErrorCode != 0) {
     72    PrintMessage("Warning: Could not open slowdata file (%s)\n", strerror(SlowDataClass->ErrorCode));
     73  }
     74  SlowDataClass->NewEntry("Value-Info", "Issued if new HV value set successfull: Board-Num HV-Board-Name Chain Channel DAC-Target Converted-Value");
     75  SlowDataClass->NewEntry("Error-Info", "Issued if error occurs when trying to set new HV value: Board-Num HV-Board-Name Chain Channel Attempted-DAC-Target Converted-Value");
    7076}
    7177
     
    7581  for (int i=0; i<NumHVBoards; i++) delete fHVBoard[i];
    7682
    77   delete config;    delete pm;
     83  delete SlowDataClass;   delete config;    delete pm;
    7884 
    7985  if(Logfile != NULL) {
     
    156162  // Print HV utility configuration
    157163  else if (Match(Param[0], "config")) {
    158 
    159     config->PrintHVConfig(stdout);
    160    
     164    PrintMessage( " Log file:          %s\n"
     165                  " Pixel map table:   %s\n"
     166                  " Test mode:         %s\n"
     167                  " %d USB devices:\n", config->fLogFile, config->fPixMapTable,
     168                  config->TestMode ? "yes" : "no", config->NumHVBoards); 
     169    for (int i=0;i<NumHVBoards;i++) {
     170      PrintMessage(" Board%d: %s\n ", config->USBDeviceNumber[i], config->fUSBDevice[i]);
     171    }
     172    PrintMessage( "\n TimeOut:           %.2f s\n"
     173                  " StatusRefreshRate: %.2f Hz\n"
     174                  " CCPort:            %d\n"
     175                  " DACMin value:      %d\n"
     176                  " DACMax value:      %d\n"
     177                  " HVCalibOffset :    %f\n"
     178                  " HVCalibSlope :     %f\n"
     179                  " HVMaxDiff :        %u\n", config->fTimeOut,
     180                  config->fStatusRefreshRate, config->fCCPort, config->DACMin,
     181                  config->DACMax, config->fHVCalibOffset, config->fHVCalibSlope,
     182                  config->fHVMaxDiff);
     183
    161184    return;
    162185  }
     
    287310    }
    288311       
    289     StopMonitor();
    290 
    291312    while (fgets(Buffer, sizeof(Buffer), File) != NULL) {
    292313      for (int Board=0; Board<NumHVBoards; Board++) {
     
    314335    } // while()
    315336           
    316     StartMonitor();
    317        
    318337    if (NBoards != NumHVBoards) {
    319338      PrintMessage("Warning: Could not load HV settings for all connected HV boards\n");
     
    333352    double Rate;
    334353   
    335     if (!NumHVBoards) return;
    336 
    337354    if (NParam != 2) {
    338355      PrintMessage("Usage: rate <Hz>\n");
     
    351368    }
    352369
    353     StopMonitor();
    354370    fStatusRefreshRate = Rate;
    355371    PrintMessage("Refresh rate set to %.2f Hz\n", fStatusRefreshRate);
    356     StartMonitor();
    357372
    358373    return;
     
    363378
    364379    if (!NumHVBoards) return;
    365 
    366     StopMonitor();
    367     ResetActiveBoards();
    368     StartMonitor();
     380    for (int i=FirstBoard; i<=LastBoard; i++) ResetBoard(i);
    369381    return;
    370382  }
     
    416428  else if (Match(Param[0], "start")) {
    417429
    418     if (!NumHVBoards) return;
    419    
    420     StartMonitor();
     430    state = active;
     431    pthread_kill(HVMonitor, SIGUSR1);
    421432    PrintMessage("OK - status monitoring activated\n");
    422 
    423433    return; 
    424434  }
     
    463473  else if (Match(Param[0], "stop")) {
    464474
    465     if (!NumHVBoards) return;
    466    
    467     StopMonitor();   
     475    state = stopped;
     476    pthread_kill(HVMonitor, SIGUSR1);
    468477    PrintMessage("Status monitor stopped\n");
    469478
     
    594603bool ProcessIO::RampVoltage(unsigned int Target, int Board, int Chain, int Channel) {
    595604
    596   int Diff;
    597  
    598605  while (fHVBoard[Board]->HV[Chain][Channel] != (int) Target) {   
    599     Diff = Target - fHVBoard[Board]->HV[Chain][Channel];
     606    int Diff = Target - fHVBoard[Board]->HV[Chain][Channel];
    600607    if (Diff > (int) config->fHVMaxDiff) Diff = config->fHVMaxDiff;
    601608
    602     if (fHVBoard[Board]->SetHV(stdout, Chain, Channel, fHVBoard[Board]->HV[Chain][Channel]+Diff, Verbose)==1) {
     609    if (fHVBoard[Board]->SetHV(Chain, Channel, fHVBoard[Board]->HV[Chain][Channel]+Diff) == 1) {
    603610      fHVBoard[Board]->HV[Chain][Channel] += Diff;
    604611
     
    610617    else {
    611618      PrintMessage("ERROR - Could not set HV of board %d, chain %d, channel %d. Skipping channel\n",fHVBoard[Board]->GetBoardNumber(),Chain,Channel);
     619      SlowDataClass->NewEntry("Error");
     620      SlowDataClass->AddToEntry("%s %d %d %d %d %.2f ",fHVBoard[Board]->BoardName,Board, Chain, Channel, Target, calib->DACToHV(Target,Board,Chain,Channel));
    612621      return false;
    613622    }
    614623  }
     624  SlowDataClass->NewEntry("Value");
     625  SlowDataClass->AddToEntry("%s %d %d %d %d %.2f ",fHVBoard[Board]->BoardName,Board, Chain, Channel, Target, calib->DACToHV(Target,Board,Chain,Channel));
    615626  return true;
    616627}
    617628
    618 void ProcessIO::StartMonitor() {
    619 
    620   state = active;
    621   pthread_kill(HVMonitor, SIGUSR1);
    622 }
    623 
    624 
    625 void ProcessIO::StopMonitor() {
    626 
    627   state = stopped;
    628   pthread_kill(HVMonitor, SIGUSR1);
    629 }
    630 
    631 
     629
     630// Check board status
    632631void ProcessIO::Monitor() {
    633632
    634633  for (int i=0; i<NumHVBoards; i++) {
    635634
    636     if (fHVBoard[i]->GetStatus(stdout,false)!=1) {
     635    if (fHVBoard[i]->GetStatus() != 1) {
    637636      PrintMessage("Error: Monitor, could not read status of board %d\n", fHVBoard[i]->GetBoardNumber());
    638637    }
     
    653652      }
    654653    }
    655   }
    656 }
    657 
    658 
    659 void ProcessIO::ResetActiveBoards() {
    660  
    661   for (int i=FirstBoard; i<=LastBoard; i++) ResetBoard(i);
    662 }
    663 
    664 
     654   
     655  }
     656}
     657
     658
     659// Send reset to board and clear voltage arrays
    665660void ProcessIO::ResetBoard(int i) {
    666661   
    667   if (fHVBoard[i]->Reset(stdout,Verbose) == 1) {
     662  if (fHVBoard[i]->Reset() == 1) {
    668663    PrintMessage("Reset of board %d\n", fHVBoard[i]->GetBoardNumber());
    669664    PrintBoardStatus(i);
     
    673668
    674669
     670// Get index of board with sequential number board
    675671int ProcessIO::GetBoardIdx(int board) {
    676672
     
    681677}
    682678
    683 
     679// Print current board status
    684680void ProcessIO::PrintBoardStatus(int i) {
    685681
     
    716712}
    717713
     714
    718715// Check if two strings match (min 1 character must match)
    719716bool Match(const char *str, const char *cmd) {
     
    721718}
    722719
     720
    723721// Convert string to double
    724722// Returns false if conversion did not stop on whitespace or EOL character
Note: See TracChangeset for help on using the changeset viewer.