Changeset 182 for drsdaq


Ignore:
Timestamp:
03/12/10 15:53:20 (15 years ago)
Author:
ogrimm
Message:
Updates to DIM integration
Location:
drsdaq
Files:
2 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • drsdaq/DAQReadout.cc

    r176 r182  
    1010
    1111#include "DAQReadout.h"
    12 #include "SlowData.h"
    13 
    14 #define TMPNAME "/tmp/__tmp__drsdaq__"  // ..for log file truncation
    1512
    1613static const char* daq_state_str[] = {"active", "stopped"};
     
    6360//
    6461 
    65 DAQReadout::DAQReadout(const char *Configfile) {
     62DAQReadout::DAQReadout() :EvidenceServer(SERVER_NAME) {
    6663   
    6764  time(&StartTime);  // Start time of DAQ
     
    7875  LastBoard          = -1;
    7976  CmdFromSocket      = false;
    80   ConfigOK           = true;
    81  
    82   // Read configuration file (if any item missing, program will be terminated in main() routine)
    83   FILE *File;
    84   if ((File = fopen(Configfile,"r")) == NULL) {
    85     printf("Error: Could not open drsdaq configuration file '%s'\n", Configfile);
    86     ConfigOK = false;
    87     return;
    88   }
    89   else {
    90     printf("Reading drsdaq configuration file %s\n", Configfile);
    91     ConfigOK &= ReadCard("LogFile",             fLogFile,           's', File);
    92     ConfigOK &= ReadCard("SlowDataPath",        fSlowDataPath,      's', File);
    93     ConfigOK &= ReadCard("MaxLogLines",        &fMaxLogLines,       'U', File);
    94     ConfigOK &= ReadCard("RawDataPath",         fRawDataPath,       's', File);
    95     ConfigOK &= ReadCard("CalibDataPath",       fCalibDataPath,     's', File);
    96     ConfigOK &= ReadCard("FirstSample",        &fFirstSample,       'I', File);
    97     ConfigOK &= ReadCard("Samples",            &fSamples,           'U', File);
    98     ConfigOK &= ReadCard("MinDiskSpaceMB",     &fMinDiskSpaceMB,    'U', File);
    99     ConfigOK &= ReadCard("MaxFileSizeMB",      &fMaxFileSizeMB,     'I', File);
    100     ConfigOK &= ReadCard("CCPort",             &fCCPort,            'I', File);
    101     ConfigOK &= ReadCard("HVFeedbackConfig",    fHVFeedbackConfig,  's', File);
    102     ConfigOK &= ReadCard("DefaultFrequency",   &fDefaultFrequency , 'd', File);
    103     fclose(File);
    104     if (!ConfigOK) return;
    105   }
     77 
     78  // Get configuration data
     79  fRawDataPath = GetConfig("RawDataPath");
     80  fCalibDataPath = GetConfig("CalibDataPath");
     81  fFirstSample = atoi(GetConfig("FirstSample"));
     82  fSamples = atoi(GetConfig("Samples"));
     83  fMinDiskSpaceMB = atoi(GetConfig("MinDiskSpaceMB"));
     84  fMaxFileSizeMB = atoi(GetConfig("MaxFileSizeMB"));
     85  fCCPort = atoi(GetConfig("CCPort"));
     86  fDefaultFrequency = atof(GetConfig("DefaultFrequency"));
     87
    10688  if (fFirstSample < 0 || fFirstSample > kNumberOfBins || fSamples > kNumberOfBins) {
    10789    PrintMessage("Warning: Sample range in configuration beyond limits, setting to full range\n");
     
    10991    fSamples = kNumberOfBins;
    11092  }
    111  
    112   // Open log file and log configuration
    113   if ((Logfile = fopen(fLogFile, "a")) == NULL) printf("Warning: Could not open log file '%s'\n", fLogFile);
    114   PrintMessage(MsgToLog,"********** Logging started **********\n");
    115   PrintConfig(MsgToLog);
    116 
     93  snprintf(CalibInfoFilename,sizeof(CalibInfoFilename), "%s/CalibInfo", fCalibDataPath);
     94 
    11795  // Allocate headers and initialise to zero
    11896  RHeader = new RunHeader;
     
    12098  EHeader = new EventHeader;
    12199  memset(EHeader, 0, sizeof(EventHeader));
    122  
     100
    123101  // Scan for DRS boards
    124   DRSFreq = new float [GetNumberOfBoards()];
    125   ACalib = new bool [GetNumberOfBoards()];
    126   ACalibTemp = new double [GetNumberOfBoards()];
    127   TCalib = new bool [GetNumberOfBoards()];
    128 
    129   if (GetNumberOfBoards() == 0) PrintMessage("No DRS boards found - check VME crate and configuration file!\n");
    130 
    131   for (int i=0; i<GetNumberOfBoards(); i++) {
    132     NumBoards++;
     102  NumBoards = GetNumberOfBoards();
     103  DRSFreq = new float [NumBoards];
     104  ACalib = new bool [NumBoards];
     105  ACalibTemp = new double [NumBoards];
     106  TCalib = new bool [NumBoards];
     107
     108  if (NumBoards == 0) PrintMessage("No DRS boards found - check VME crate and configuration file!\n");
     109
     110  for (int i=0; i<NumBoards; i++) {
    133111    LastBoard++;
    134112    GetBoard(i)->Init();
     
    138116    TCalib[i] = false;     
    139117  }
    140   BStruct  = new BoardStructure [NumBoards == 0 ? 1:GetNumberOfBoards()];
    141   memset(BStruct, 0, sizeof(BoardStructure)*(NumBoards == 0 ? 1:GetNumberOfBoards()));
     118  BStruct  = new BoardStructure [NumBoards == 0 ? 1:NumBoards];
     119  memset(BStruct, 0, sizeof(BoardStructure)*(NumBoards == 0 ? 1:NumBoards));
    142120
    143121  WaveForm = new short [NumBoards == 0 ? 1:NumBoards][kNumberOfChipsMax][kNumberOfChannelsMax][kNumberOfBins];
     
    145123 
    146124  // Create instance of HV feedback (must be called after CMC board detection)
    147   HVFB    = new HVFeedback(this, fHVFeedbackConfig);
    148  
    149   // Create instance of slow data class for DAQ
    150   SlowDataClass = new SlowData("DAQ", fSlowDataPath);
    151   if(SlowDataClass->ErrorCode != 0) {
    152    PrintMessage("Warning: Could not open DAQ slowdata file (%s)\n", strerror(SlowDataClass->ErrorCode));
    153   }
    154   SlowDataClass->NewEntry("Runinfo-Info", "Run information written after completion or termination of run (Status can be OK or Error): Runnumber Status Runtype Events Files Description ");
     125  HVFB    = new HVFeedback(this); 
    155126}
    156127
     
    160131
    161132DAQReadout::~DAQReadout() {
    162   delete SlowDataClass;
     133
    163134  delete RHeader;     delete EHeader;
    164135  delete HVFB;        delete[] ACalibTemp;
     
    166137  delete[] DRSFreq;   delete[] BStruct;
    167138  delete[] WaveForm;  delete[] TriggerCell;
    168  
    169   if(Logfile) {
    170     if(!fclose(Logfile)) printf("Closing logfile\n");
    171     else perror("Error closing logfile");
    172   }
    173139}
    174140
     
    514480    }
    515481
    516     PrintMessage("Creating amplitude calibration of board %d (serial #%04d)\n", i, GetBoard(i)->GetBoardSerialNumber());
    517    
     482    PrintMessage("Creating amplitude calibration of board %d (serial #%04d)\n  Note: No input signals should be connected\n", i, GetBoard(i)->GetBoardSerialNumber());
     483               
    518484    GetBoard(i)->EnableTcal(0);
    519485    GetBoard(i)->SelectClockSource(0);
     
    545511    ACalib[i] = true;
    546512    ACalibTemp[i] = GetBoard(i)->GetTemperature();
     513       
    547514  } // Loop over boards
    548515  PrintMessage("Amplitude calibration finished\n");
     516 
     517  // Write short calibration information
     518  time_t Time = time(NULL);
     519  FILE *InfoFile = fopen(CalibInfoFilename, "w");
     520  if (InfoFile != NULL) {
     521        fprintf(InfoFile, "# Calibration information as of %s\n", ctime(&Time));
     522        for (int i=0; i<GetNumberOfBoards(); i++) {
     523          fprintf(InfoFile, "%d %d %.1f %d %.2f\n", GetBoard(i)->GetBoardSerialNumber(), ACalib[i], ACalibTemp[i], TCalib[i], DRSFreq[i]);
     524        }
     525        fclose(InfoFile);
     526  }
     527  else PrintMessage("Could not write calibration information to file '%s'\n", CalibInfoFilename);
     528
    549529}
    550530
     
    554534  if (!IsDRSFreqSet()) {
    555535    PrintMessage("Set sampling frequency for all boards first\n");
     536    return;
     537  }
     538  if (!ReadCalibration()) {
     539    PrintMessage("Amplitude calibration has to be done first\n");
    556540    return;
    557541  }
     
    562546      continue;
    563547    }
    564     if (!ACalib[i]) {
    565       PrintMessage("Amplitude calibration of board %d has to be done first, skipping this board\n", i);
    566       continue;
    567     }
    568     PrintMessage("Creating time calibration of board %d (serial #%04d)\n", i, GetBoard(i)->GetBoardSerialNumber());
     548    PrintMessage("Creating time calibration of board %d (serial #%04d)\n  Note: No input signals should be connected\n", i, GetBoard(i)->GetBoardSerialNumber());
    569549   
    570550    GetBoard(i)->SetFrequency(DRSFreq[i], true);
     
    586566      GetBoard(i)->GetTime(Chip, Time[Chip], true, false);
    587567        }
    588    
    589     if (asprintf(&Filename, "TCalib_%d_%.2fGHz.txt", GetBoard(i)->GetBoardSerialNumber(), DRSFreq[i]) == -1) {
     568
     569        // Write calibration data to file
     570    if (asprintf(&Filename, "%s/TCalib_%d_%.2fGHz.txt", fCalibDataPath, GetBoard(i)->GetBoardSerialNumber(), DRSFreq[i]) == -1) {
    590571      PrintMessage("Error: asprintf() failed, cannot generate filename (%s)\n", strerror(errno));
    591572      return;
     
    827808    GetBoard(i)->TransferWaves(GetBoard(i)->GetNumberOfChannels()*GetBoard(i)->GetNumberOfChips());
    828809
    829     for (int j=0; j<GetBoard(i)->GetNumberOfChannels(); j++) {
    830       for (int k=0; k<GetBoard(i)->GetNumberOfChips(); k++) {
    831         GetBoard(i)->GetWave(k, j, WaveForm[i][k][j], true, GetBoard(i)->GetTriggerCell(k));
    832         TriggerCell[i][k] = GetBoard(i)->GetTriggerCell(k);
     810    for (int k=0; k<GetBoard(i)->GetNumberOfChips(); k++) {
     811          TriggerCell[i][k] = GetBoard(i)->GetTriggerCell(k);
     812
     813          for (int j=0; j<GetBoard(i)->GetNumberOfChannels(); j++) {
     814        GetBoard(i)->GetWave(k, j, WaveForm[i][k][j], true, TriggerCell[i][k]);
    833815      }
    834816    }
     
    836818}
    837819
    838 // Read calibration file
     820// Read calibration data
    839821bool DAQReadout::ReadCalibration() {
    840822
     823  static char Buffer[MAX_COM_SIZE];
     824  int Serial, Calib;
     825  float Temp, Freq;
     826
    841827  for (int i=FirstBoard; i<=LastBoard; i++) {
    842     if (!TCalib[i]) PrintMessage("Warning: No time calibration for board %d\n", i);
    843    
    844828    if (GetBoard(i)->GetDRSType() == 4) {
    845       if (ACalib[i] == false) return false;
     829      if (ACalib[i] == false) {
     830            // Check calibration info file if EEPROM data on DRS board still valild
     831                FILE *CalibInfo = fopen(CalibInfoFilename, "r");
     832                if (CalibInfo == NULL) return false;
     833                fgets(Buffer, sizeof(Buffer), CalibInfo); // skip first two lines
     834                fgets(Buffer, sizeof(Buffer), CalibInfo);
     835
     836                while (fgets(Buffer, sizeof(Buffer), CalibInfo) != NULL) {
     837                  if (sscanf(Buffer, "%d %d %f %*d %f", &Serial, &Calib, &Temp, &Freq) != 4) {
     838                        fclose(CalibInfo);
     839                        return false;
     840                  }
     841
     842                  if (Serial==GetBoard(i)->GetBoardSerialNumber() && int(Freq*100)==int(DRSFreq[i]*100) && Calib==1) {
     843                        ACalib[i] = true;
     844                        ACalibTemp[i] = Temp;
     845                        break;
     846                  }
     847                }
     848                fclose(CalibInfo);
     849          }
    846850    }
    847851    else {
     
    855859      }
    856860    }
     861        if (fabs(ACalibTemp[i]-GetBoard(i)->GetTemperature())>2) PrintMessage("Warning: Large difference to calibration temperature for board %d\n", i);
    857862  } // Loop over boards
    858863  return true;
     
    11271132// Print configuration to target
    11281133void DAQReadout::PrintConfig(int Target) {
    1129   PrintMessage(Target, "LogFile: %s\tMaxLogLines: %u\tRawDataPath: %s\n"
     1134  PrintMessage(Target, "RawDataPath: %s\n"
    11301135               "DefaultFrequency: %.2f\tFirstSample: %d\tSamples: %u\n"
    11311136               "MinDiskSpaceMB: %u\tMaxFileSizeMB: %d\tCCPort: %d\n"
    1132                "CalibDataPath: %s\n"
    1133                "SlowDataPath: %s\tHVFeedbackConfig: %s\n",
    1134     fLogFile,fMaxLogLines,fRawDataPath,fDefaultFrequency,fFirstSample,fSamples,fMinDiskSpaceMB,
    1135     fMaxFileSizeMB,fCCPort,fCalibDataPath,fSlowDataPath,fHVFeedbackConfig);
     1137                           "CalibDataPath: %s\n",
     1138    fRawDataPath,fDefaultFrequency,fFirstSample,fSamples,fMinDiskSpaceMB,
     1139    fMaxFileSizeMB,fCCPort,fCalibDataPath);
    11361140}
    11371141
     
    11601164  va_list ArgumentPointer;
    11611165  va_start(ArgumentPointer, Format);
    1162   if(CmdFromSocket) DoPrintMessage(Format, ArgumentPointer, MsgToSocket|MsgToLog);
    1163   else DoPrintMessage(Format, ArgumentPointer, MsgToConsole|MsgToLog);
     1166  if(CmdFromSocket) DoPrintMessage(Format, ArgumentPointer, MsgToSocket);
     1167  else DoPrintMessage(Format, ArgumentPointer, MsgToConsole);
    11641168  va_end(ArgumentPointer);
    11651169}
     
    11791183    if(strlen(Textbuffer)>0 && Textbuffer[strlen(Textbuffer)-1]=='\n') {
    11801184      printf("\r%s%s", Textbuffer, Prompt);   // New prompt
    1181       fflush(stdout);
    11821185    }
    11831186    else printf("%s", Textbuffer);
    1184   }
    1185   // Print to log file
    1186   if((Target & MsgToLog) && Logfile!=NULL) {
    1187     time_t Time;
    1188     strftime(Textbuffer+strlen(Textbuffer)+1,MAX_COM_SIZE-strlen(Textbuffer)-1, "%d/%m/%y %X", localtime(&(Time=time(NULL))));
    1189     fprintf(Logfile, "%s: %s", Textbuffer+strlen(Textbuffer)+1, Textbuffer);
    1190     fflush(Logfile);
     1187        fflush(stdout);
     1188  }
     1189  // Send to log
     1190  if(Target & MsgToLog) {
     1191    char *Buf;
     1192    if (asprintf(&Buf, "%s %s", SERVER_NAME, Textbuffer) != -1) {
     1193      DimClient::sendCommandNB("DColl/Log", Buf);
     1194      free(Buf);
     1195    }
     1196    else DimClient::sendCommandNB("DColl/Log", SERVER_NAME" asprintf() failed");
    11911197  }
    11921198  // Print to socket
     
    12331239}
    12341240
    1235 // ReadCard function (original version by F. Goebel)
    1236 // Data is read into an array if MaxNum is larger than 1
    1237 bool ReadCard(const char *card_flag, void *store, char Type, FILE *File, unsigned int MaxNum) {
    1238  
    1239   char *card_name, *card_val, Buffer[MAX_COM_SIZE];
    1240   unsigned int Count=0;
    1241  
    1242   rewind(File);
    1243 
    1244   while (fgets(Buffer, sizeof(Buffer), File) != NULL) {    // Read line by line
    1245     card_name = strtok(Buffer," \t\n");
    1246    
    1247      // Ignore empty lines, comments, and skip if card name does not match
    1248     if (card_name==NULL || card_name[0]=='#' || strcmp(card_name, card_flag)!=0) continue;
    1249 
    1250     // Read numbers of given type (if MaxNum>1 read array)
    1251     while ((card_val=strtok(NULL," \t\n")) != NULL && Count++<MaxNum) {
    1252       switch (Type) {
    1253         case 'I': *(((int *&) store)++) = (int) strtol(card_val, NULL, 10);
    1254                   break;
    1255         case 'i': *(((short *&) store)++) = (short) strtol(card_val, NULL, 10);
    1256                   break;
    1257         case 'U': *(((unsigned int *&) store)++) = (unsigned int) strtoul(card_val, NULL, 10);
    1258                   break;
    1259         case 'u': *(((unsigned short *&) store)++) = (unsigned short) strtoul(card_val, NULL, 10);
    1260                   break;
    1261         case 'f': *(((float *&) store)++) = atof(card_val);
    1262                   break;
    1263         case 'd': *(((double *&) store)++) = atof(card_val);
    1264                   break;
    1265         case 's': sprintf((char *) store, "%s", card_val);
    1266                   break;
    1267         case 'c': *((char *) store) = card_val[0];
    1268                   break;
    1269         default:  fprintf(stderr,"Warning: Unknown type '%c' for reading of configuration file\n", Type);
    1270                   return false;
    1271       }
    1272     }
    1273     return true;  // Finished reading data for card name
    1274    
    1275   }
    1276   fprintf(stderr,"Warning: Configuration value %s not found\n", card_flag);
    1277   return false;
    1278 }
    1279 
    12801241
    12811242/********************************************************************\
     
    13681329
    13691330  // Write run summary to slow data file
    1370   m->SlowDataClass->NewEntry("Runinfo");
    1371   m->SlowDataClass->AddToEntry("%d %s %s %d %d %s", m->RunNumber, WriteError?"Error":"OK", daq_runtype_str[m->daq_runtype], m->NumEvents, m->FileNumber, m->RHeader->Description);
    1372   if(m->SlowDataClass->ErrorCode != 0) {
    1373     m->PrintMessage("Error: Could not write DAQ slow data to file (%s), file closed\n", strerror(m->SlowDataClass->ErrorCode));
    1374   }
     1331  //m->SlowDataClass->NewEntry("Runinfo");
     1332  //m->SlowDataClass->AddToEntry("%d %s %s %d %d %s", m->RunNumber, WriteError?"Error":"OK", daq_runtype_str[m->daq_runtype], m->NumEvents, m->FileNumber, m->RHeader->Description);
    13751333
    13761334  // Print run statistics
  • drsdaq/DAQReadout.h

    r176 r182  
    1414#include <sys/vfs.h>
    1515#include <signal.h>
     16#include <sys/time.h>
    1617
    1718#include "RawDataCTX.h"
     
    3233enum runtype_enum {data, pedestal, reserved, test};
    3334
    34 class DAQReadout : public DRS, public DRSCallback {
     35class DAQReadout : public DRS, public DRSCallback, public EvidenceServer {
    3536    time_t StartTime;
    3637
     
    3940
    4041    unsigned int CmdNumber;
    41     FILE *Logfile;   
    4242    void PrintUsage();
    4343       
     
    5252    int Rawfile;
    5353    class HVFeedback* HVFB;
    54     class SlowData *SlowDataClass;
    5554
    5655    // Configuration data
    57     char fLogFile[MAX_PATH];
    58     char fSlowDataPath[MAX_PATH];
    59     char fCalibDataPath[MAX_PATH];
    60     unsigned int fMaxLogLines;
    61     char fRawDataPath[MAX_PATH];
     56    char *fCalibDataPath;
     57    char *fRawDataPath;
    6258    int fMinDiskSpaceMB;   // Minimum required disk space in MBytes
    6359    int fMaxFileSizeMB;    // Maximum File size in Bytes
     
    6561    unsigned int fSamples;
    6662    int fCCPort;
    67     char fHVFeedbackConfig[MAX_PATH];
    6863    double fDefaultFrequency;
    6964   
     
    9287    char FileName[MAX_PATH];
    9388    char Prompt[MAX_COM_SIZE];
    94     bool ConfigOK;
     89    char CalibInfoFilename[MAX_PATH];
    9590       
    9691    // Public functions
    97     DAQReadout(const char*);
     92    DAQReadout();
    9893    ~DAQReadout();
    9994
     
    149144int ParseInput(char*, const char *Param[]);
    150145int CheckDisk(char*);
    151 bool ReadCard(const char *, void *, char, FILE *, unsigned int=1);
    152146
    153147#endif
  • drsdaq/DRS/DRS.cc

    r176 r182  
    183183#endif
    184184      /* check all VME slave slots */
    185       for (index = 2; index <= 10; index++) {     
     185      for (index = 2; index <= 9; index++) {     
    186186#ifdef CT_VME
    187187        MasterMap.vmebus_address        = GEVPC_BASE_ADDR + index * GEVPC_WINSIZE; // VME board base address
    188         MasterMapVME(&MasterMapping[index]);
     188        if (MasterMapVME(&MasterMapping[index]) != VME_SUCCESS) continue;
    189189#endif
    190190     
     
    48574857
    48584858   // use following lines to save calibration into an ASCII file
    4859 #if 1
     4859#if 0
    48604860   FILE *fh;
    48614861
     
    69076907  if ((ErrorCode = VME_Open()) != VME_SUCCESS) {
    69086908    VME_ErrorString(ErrorCode,ErrorString);
    6909     printf("Error: %s\n",ErrorString);
     6909    printf("VME_Open() %s\n",ErrorString);
    69106910  } 
    69116911  return ErrorCode;
     
    69176917  if (ErrorCode = VME_MasterMap(&MasterMap, MMap)) {
    69186918    VME_ErrorString(ErrorCode,ErrorString);
    6919     printf("Error: %s\n",ErrorString);
     6919    printf("VME_MasterMap() %s\n",ErrorString);
    69206920  }
    69216921  return(ErrorCode);
     
    69276927  if (ErrorCode = VME_MasterUnmap(MMap)) {
    69286928    VME_ErrorString(ErrorCode,ErrorString);
    6929     printf("Error: %s\n",ErrorString);
     6929    printf("VME_MasterUnmap() %s\n",ErrorString);
    69306930  } 
    69316931  return(ErrorCode); 
     
    69376937  if ((ErrorCode = VME_Close()) != VME_SUCCESS) {   
    69386938    VME_ErrorString(ErrorCode,ErrorString);
    6939     printf("Error: %s\n",ErrorString);
     6939    printf("VME_Close() %s\n",ErrorString);
    69406940  }
    69416941  return ErrorCode;
     
    69476947  if ((ErrorCode = CMEM_Open()) != CMEM_RCC_SUCCESS) {
    69486948    VME_ErrorString(ErrorCode,ErrorString);
    6949     printf("Error: %s\n",ErrorString);
     6949    printf("CMEM_Open() %s\n",ErrorString);
    69506950  }
    69516951  return ErrorCode;
     
    69576957  if ((ErrorCode = CMEM_Close()) != CMEM_RCC_SUCCESS) { 
    69586958    VME_ErrorString(ErrorCode,ErrorString);
    6959     printf("Error: %s\n",ErrorString);
     6959    printf("CMEM_Close %s\n",ErrorString);
    69606960  }
    69616961  return ErrorCode;
     
    69666966  if ((ErrorCode = CMEM_SegmentAllocate(SegSize, "DMA_BUFFER", CMEM_SegIdentifier)) != CMEM_RCC_SUCCESS) {
    69676967    VME_ErrorString(ErrorCode,ErrorString);
    6968     printf("Error: %s\n",ErrorString);
     6968    printf("CMEM_SegmentAllocate() %s\n",ErrorString);
    69696969  }
    69706970  return ErrorCode;
     
    69766976  if ((ErrorCode = CMEM_SegmentPhysicalAddress(CMEM_SegIdentifier, PCIAddress)) != CMEM_RCC_SUCCESS) {
    69776977    VME_ErrorString(ErrorCode,ErrorString);
    6978     printf("Error: %s\n",ErrorString);
     6978    printf("CMEM_SegmentPhysicalAddress() %s\n",ErrorString);
    69796979  }
    69806980  return ErrorCode;
     
    69866986  if ((ErrorCode = CMEM_SegmentVirtualAddress(CMEM_SegIdentifier, VirtualAddress)) != CMEM_RCC_SUCCESS) {
    69876987    VME_ErrorString(ErrorCode,ErrorString);
    6988     printf("Error: %s\n",ErrorString);
     6988    printf("CMEM_SegmentVirtualAddress() %s\n",ErrorString);
    69896989  }
    69906990  return ErrorCode;
     
    69966996  if ((ErrorCode = CMEM_SegmentFree(CMEM_SegIdentifier)) != CMEM_RCC_SUCCESS) {
    69976997    VME_ErrorString(ErrorCode,ErrorString);
    6998     printf("Error: %s\n",ErrorString);
     6998    printf("CMEM_SegmentFree() %s\n",ErrorString);
    69996999  } 
    70007000  return ErrorCode;
  • drsdaq/HVFeedback.cc

    r176 r182  
    2525// Constructor: Initialise feedback
    2626//
    27 HVFeedback::HVFeedback(DAQReadout* DAQClass, char* Configfile):
    28                         EvidenceServer(SERVER_NAME){
     27HVFeedback::HVFeedback(DAQReadout* DAQClass){//:
     28                        //EvidenceServer(SERVER_NAME){
    2929
    3030  m = DAQClass;
    3131
    32   fNumberOfChannels = m->fNumberOfChannels;
    33   fNumberOfChips = m->fNumberOfChips
     32  fNumberOfChannels = m->GetBoard(0)->GetNumberOfChannels();
     33  fNumberOfChips = m->GetBoard(0)->GetNumberOfChips()
    3434
    3535  PixMap = new PixelMap(PIXMAP_LOCATION, false);
     
    4545  DIMSigma   = new float [m->NumBoards][kNumberOfChipsMax][kNumberOfChannelsMax]();
    4646
    47   // Read configuration file
    48   FILE *File;
    49   if ((File = fopen(Configfile,"r")) == NULL) {
    50     printf("Error: Could not open feedback configuration file '%s'\n", Configfile);
    51   }
    52   else {
    53     printf("Reading feedback configuration file %s\n", Configfile);
    54     ReadCard("TrigBoard",           &fLedTrigBoard,      'I', File);
    55     ReadCard("TrigChannel",         &fLedTrigChannel,    'I', File);
    56     ReadCard("TrigChip",            &fLedTrigChip,       'I', File);
    57     ReadCard("TrigSample",          &fLedTrigSample,     'I', File);
    58     ReadCard("TrigThreshold",       &fLedTrigThreshold,  'f', File);
    59     ReadCard("SignalSample",        &fLedSignalSample,   'I', File);
    60     ReadCard("BaselineSample",      &fLedBaselineSample, 'I', File);
    61     ReadCard("IntHalfWidth",        &fIntHalfWidth,      'U', File);
    62     ReadCard("DefaultNumAverage",   &fDefaultNumAverage, 'I', File);
    63     ReadCard("DefaultResponse",      Response,           'f', File, m->NumBoards*fNumberOfChips*fNumberOfChannels);
    64     ReadCard("DefaultTarget",        Target,             'f', File, m->NumBoards*fNumberOfChips*fNumberOfChannels);
    65     // Add also initial gain to configuration parameters
    66     fclose(File);
    67   }
     47  // Get configuration data
     48  fLedTrigBoard = atoi(m->GetConfig("TrigBoard"));
     49  fLedTrigChannel = atoi(m->GetConfig("TrigChannel"));
     50  fLedTrigChip = atoi(m->GetConfig("TrigChip"));
     51  fLedTrigSample = atoi(m->GetConfig("TrigSample"));
     52  fLedTrigThreshold = atoi(m->GetConfig("TrigThreshold"));
     53  fLedSignalSample = atoi(m->GetConfig("SignalSample"));
     54  fLedBaselineSample = atoi(m->GetConfig("BaselineSample"));
     55  fIntHalfWidth = atoi(m->GetConfig("IntHalfWidth"));
     56  fDefaultNumAverage = atoi(m->GetConfig("DefaultNumAverage"));
     57
     58  char *Token = strtok(m->GetConfig("DefaultResponse"), " \t");
     59  for (int i=0; i<m->NumBoards*fNumberOfChips*fNumberOfChannels; i++) {
     60        if (Token == NULL) break;
     61    *(&Response[0][0][0]+i) = (float) atof(Token);
     62        Token = strtok(NULL, " \t");
     63  }
     64  Token = strtok(m->GetConfig("DefaultTarget"), " \t");
     65  for (int i=0; i<m->NumBoards*fNumberOfChips*fNumberOfChannels; i++) {
     66        if (Token == NULL) break;
     67    *(&Target[0][0][0]+i) = (float) atof(Token);
     68        Token = strtok(NULL, " \t");
     69  }
     70
    6871  PrintConfig(MsgToLog);
    6972
     
    7679
    7780  // Initial state
    78   Gain = 0.2;
     81  Gain = atoi(m->GetConfig("DefaultGain"));
    7982  SetFBMode(FB_Off);
    8083  SetNumAverages(fDefaultNumAverage);
     
    9497
    9598  delete[] Average;     delete[] Response;
     99  delete[] DIMAverage;          delete[] DIMSigma;
     100  delete[] Sigma;
    96101  delete[] Target;      delete[] Buffer;
    97102  delete PixMap;
     
    256261  else {
    257262    FBMode = Mode;
    258         if (Mode != FB_ResponseFirst) State(INFO, "%s", FBState_Description[FBMode]);
    259         else State(INFO, "%s (voltage difference %.3f)", FBState_Description[FBMode], DiffVoltage);
     263        if (Mode != FB_ResponseFirst) m->State(m->INFO, "%s", FBState_Description[FBMode]);
     264        else m->State(m->INFO, "%s (voltage difference %.3f)", FBState_Description[FBMode], DiffVoltage);
    260265    ClearAverages();
    261266  }
  • drsdaq/HVFeedback.h

    r175 r182  
    1313#include "DAQReadout.h"
    1414
    15 #define kNumberOfChipsMax 2
    16 #define kNumberOfChannelsMax 10
    17 
    1815enum FBState {FB_Off, FB_Active, FB_Targets, FB_ResponseFirst, FB_ResponseSecond};
    1916
    20 class HVFeedback: public EvidenceServer {
     17class HVFeedback: public DimServer {//EvidenceServer {
    2118
    2219    class DAQReadout *m;
     
    6057   
    6158  public:
    62     HVFeedback(class DAQReadout*, char*);
     59    HVFeedback(class DAQReadout*);
    6360    ~HVFeedback();
    6461
  • drsdaq/History.txt

    r176 r182  
    59599/3/2010        Feedback now depended on DIM for communication with bias server.
    6060                        Started migration to DRS4 (last tested revision as daqct3 for DRS2 is 161). DRS class will not run anymore with DRS2 FPGA firmware.
    61                        
     6111/3/2010       Removed SlowData class.                 
     6212/3/2010       Removed local configuration and logging.
  • drsdaq/Makefile

    r175 r182  
    1010CC      = g++           # Compiler to use
    1111
    12 SOURCES = HVFeedback.cc DAQReadout.cc RawDataCTX.cc SlowData.cc ../pixelmap/Pixel.cc ../pixelmap/PixelMap.cc DRS/DRS.cc DRS/mxml.c DRS/strlcpy.c drsdaq.cpp ../Evidence/Evidence.cc
     12SOURCES = HVFeedback.cc DAQReadout.cc RawDataCTX.cc ../pixelmap/Pixel.cc ../pixelmap/PixelMap.cc DRS/DRS.cc DRS/mxml.c DRS/strlcpy.c drsdaq.cpp ../Evidence/Evidence.cc
    1313OBJECTS = $(addsuffix .o, $(basename $(SOURCES)))
    1414INCDIRS   = -I. -IDRS -I../pixelmap -I../Evidence -I$(DIMDIR)/dim
  • drsdaq/drsdaq.cpp

    r110 r182  
    3030void SignalHandler(int);
    3131void CrashHandler(int);
     32void ExitFunction();
    3233
    3334// ================
     
    8485  signal(SIGINT, &CrashHandler);
    8586  signal(SIGHUP, &CrashHandler);
    86    
     87  atexit(&ExitFunction);
     88
    8789  // Construct main instance and create mutex for thread synchronization
    88   DAQReadout dreadout(argc==3 ? argv[2] : DEFAULT_CONFIG);
     90  DAQReadout dreadout;
    8991  if (pthread_mutex_init(&dreadout.control_mutex, NULL) != 0) {
    9092    perror("pthread_mutex_init failed");
     
    9294  }
    9395
    94   if (dreadout.ConfigOK) { // Normal program execution only if configuration was complete
    95     // Create threads
    96     if (pthread_mutex_init(&dreadout.control_mutex, NULL) != 0) {
    97       perror("pthread_mutex_init failed");
    98       throw;
    99     }
    100     if ((pthread_create(&thread_ConsoleCommand, NULL, (void * (*)(void *)) ConsoleCommand,(void *) &dreadout)) != 0) {
    101       perror("pthread_create failed with console thread");
    102       throw;
    103     }
    104     if ((pthread_create(&thread_CCCommand, NULL, (void * (*)(void *)) CCCommand,(void *) &dreadout)) != 0) {
    105       perror("pthread_create failed with socket thread");
    106       dreadout.SocketThread = NULL;
    107     }
    108     else dreadout.SocketThread = &thread_CCCommand;  // Thread should be accessible for sending signals 
    109 
    110     // Wait for threads to quit
    111     pthread_join(thread_ConsoleCommand, NULL);
    112     if(dreadout.SocketThread != NULL) pthread_join(thread_CCCommand, NULL);
    113   }
    114   else printf("Error: Configuration parameter missing in %s, terminating.\n", argc==3 ? argv[2] : DEFAULT_CONFIG);
     96  // Create threads
     97  if (pthread_mutex_init(&dreadout.control_mutex, NULL) != 0) {
     98    perror("pthread_mutex_init failed");
     99    throw;
     100  }
     101  if ((pthread_create(&thread_ConsoleCommand, NULL, (void * (*)(void *)) ConsoleCommand,(void *) &dreadout)) != 0) {
     102    perror("pthread_create failed with console thread");
     103    throw;
     104  }
     105  if ((pthread_create(&thread_CCCommand, NULL, (void * (*)(void *)) CCCommand,(void *) &dreadout)) != 0) {
     106    perror("pthread_create failed with socket thread");
     107    dreadout.SocketThread = NULL;
     108  }
     109  else dreadout.SocketThread = &thread_CCCommand;  // Thread should be accessible for sending signals 
     110
     111  // Wait for threads to quit
     112  pthread_join(thread_ConsoleCommand, NULL);
     113  if(dreadout.SocketThread != NULL) pthread_join(thread_CCCommand, NULL);
    115114 
    116115  // Destruct mutex and main instance
     
    282281  return;
    283282}
     283
     284// This function will be implicitly called by exit()
     285void ExitFunction() {
     286  remove(LOCKFILE);
     287  return;         
     288}
Note: See TracChangeset for help on using the changeset viewer.