| 1 |
|
|---|
| 2 | #ifndef DRS_H
|
|---|
| 3 | #define DRS_H
|
|---|
| 4 |
|
|---|
| 5 | #include <stdio.h>
|
|---|
| 6 | #include <math.h>
|
|---|
| 7 | #include <string.h>
|
|---|
| 8 | #include <stdlib.h>
|
|---|
| 9 | #include <time.h>
|
|---|
| 10 | #include <sys/time.h>
|
|---|
| 11 | #include <assert.h>
|
|---|
| 12 | #include <algorithm>
|
|---|
| 13 | #include <sys/stat.h>
|
|---|
| 14 | #include <unistd.h>
|
|---|
| 15 | #include <sys/ioctl.h>
|
|---|
| 16 |
|
|---|
| 17 | #include "mxml.h"
|
|---|
| 18 | #include "strlcpy.h"
|
|---|
| 19 |
|
|---|
| 20 | // Concurrent Technologies VME single board computer
|
|---|
| 21 | #ifdef CT_VME
|
|---|
| 22 | #include "rcc_error/rcc_error.h" // Error reporting
|
|---|
| 23 | #include "vme_rcc/vme_rcc.h" // VME access
|
|---|
| 24 | #include "cmem_rcc/cmem_rcc.h" // Allocation of contiguous memory
|
|---|
| 25 | #include "rcc_time_stamp/tstamp.h" // Time stamp library
|
|---|
| 26 | #endif
|
|---|
| 27 |
|
|---|
| 28 | // Struck VME interface
|
|---|
| 29 | #ifdef STRUCK_VME
|
|---|
| 30 | #include "mvmestd.h"
|
|---|
| 31 | #endif
|
|---|
| 32 |
|
|---|
| 33 | // Control register bit definitions
|
|---|
| 34 | #define BIT_START_TRIG (1<<0) // Write a "1" to start domino wave
|
|---|
| 35 | #define BIT_REINIT_TRIG (1<<1) // Write a "1" to stop & reset DRS
|
|---|
| 36 | #define BIT_SOFT_TRIG (1<<2) // Write a "1" to stop and read data to RAM
|
|---|
| 37 | #define BIT_FLASH_TRIG (1<<3) // Write a "1" to write DAC0 & DAC1 into serial EEPROM
|
|---|
| 38 | #define BIT_AUTOSTART (1<<16)
|
|---|
| 39 | #define BIT_DMODE (1<<17) // 0: single shot, 1: circular
|
|---|
| 40 | #define BIT_LED (1<<18) // 1=on, 0=blink during readout
|
|---|
| 41 | #define BIT_TCAL_EN (1<<19) // Switch on (1) / off (0) for 33 MHz calib signal
|
|---|
| 42 | #define BIT_ZERO_SUPP (1<<20)
|
|---|
| 43 | #define BIT_FREQ_AUTO_ADJ (1<<21)
|
|---|
| 44 | #define BIT_ENABLE_TRIGGER (1<<22)
|
|---|
| 45 | #define BIT_LONG_START_PULSE (1<<23) // (*DRS2*) 0:short start pulse (> 0.8 GHz), 1:long start pulse (< 0.8 GHz)
|
|---|
| 46 | #define BIT_READOUT_MODE (1<<23) // (*DRS3*) 0:start from first bin, 1:start from domino stop
|
|---|
| 47 | #define BIT_DELAYED_START (1<<24) // Start domino wave 400 ns after soft trigger, used for waveform
|
|---|
| 48 | // Generator startup
|
|---|
| 49 | #define BIT_ACAL_EN (1<<25) // Connect DRS to inputs (0) or to DAC6 (1)
|
|---|
| 50 | #define BIT_TRIGGER_DELAYED (1<<26) // Select delayed trigger from trigger bus
|
|---|
| 51 | #define BIT_DACTIVE (1<<27) // Keep domino wave running during readout
|
|---|
| 52 |
|
|---|
| 53 | // Status register bit definitions
|
|---|
| 54 | #define BIT_RUNNING (1<<0) // One if domino wave running or readout in progress
|
|---|
| 55 | #define BIT_NEW_FREQ1 (1<<1) // One if new frequency measurement available
|
|---|
| 56 | #define BIT_NEW_FREQ2 (1<<2)
|
|---|
| 57 |
|
|---|
| 58 | enum DRSBoardConstants {
|
|---|
| 59 | kNumberOfChannels = 10,
|
|---|
| 60 | kNumberOfCalibChannels = 10,
|
|---|
| 61 | kNumberOfBins = 1024,
|
|---|
| 62 | kNumberOfChips = 2,
|
|---|
| 63 | kFrequencyCacheSize = 10,
|
|---|
| 64 | kBSplineOrder = 4,
|
|---|
| 65 | kPreCaliculatedBSplines = 1000,
|
|---|
| 66 | kPreCaliculatedBSplineGroups = 5,
|
|---|
| 67 | kNumberOfADCBins = 4096,
|
|---|
| 68 | kBSplineXMinOffset = 20,
|
|---|
| 69 | kMaxNumberOfClockCycles = 100,
|
|---|
| 70 | };
|
|---|
| 71 |
|
|---|
| 72 | enum DRSErrorCodes {
|
|---|
| 73 | kSuccess = 0,
|
|---|
| 74 | kInvalidTriggerSignal = -1,
|
|---|
| 75 | kWrongChannelOrChip = -2,
|
|---|
| 76 | kInvalidTransport = -3,
|
|---|
| 77 | kZeroSuppression = -4,
|
|---|
| 78 | kWaveNotAvailable = -5
|
|---|
| 79 | };
|
|---|
| 80 |
|
|---|
| 81 | class DRSBoard;
|
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 | class ResponseCalibration {
|
|---|
| 85 | protected:
|
|---|
| 86 |
|
|---|
| 87 | class CalibrationData {
|
|---|
| 88 | public:
|
|---|
| 89 | class CalibrationDataChannel {
|
|---|
| 90 | public:
|
|---|
| 91 | unsigned char fLimitGroup[kNumberOfBins]; //!
|
|---|
| 92 | float fMin[kNumberOfBins]; //!
|
|---|
| 93 | float fRange[kNumberOfBins]; //!
|
|---|
| 94 | short fOffset[kNumberOfBins]; //!
|
|---|
| 95 | short fGain[kNumberOfBins]; //!
|
|---|
| 96 | unsigned short fOffsetADC[kNumberOfBins]; //!
|
|---|
| 97 | short *fData[kNumberOfBins]; //!
|
|---|
| 98 | unsigned char *fLookUp[kNumberOfBins]; //!
|
|---|
| 99 | unsigned short fLookUpOffset[kNumberOfBins]; //!
|
|---|
| 100 | unsigned char fNumberOfLookUpPoints[kNumberOfBins]; //!
|
|---|
| 101 | float *fTempData; //!
|
|---|
| 102 |
|
|---|
| 103 | private:
|
|---|
| 104 | CalibrationDataChannel(const CalibrationDataChannel &c); // Not implemented
|
|---|
| 105 | CalibrationDataChannel &operator=(const CalibrationDataChannel &rhs); // Not implemented
|
|---|
| 106 |
|
|---|
| 107 | public:
|
|---|
| 108 | CalibrationDataChannel(int numberOfGridPoints)
|
|---|
| 109 | :fTempData(new float[numberOfGridPoints]) {
|
|---|
| 110 | int i;
|
|---|
| 111 | for (i = 0; i < kNumberOfBins; i++) {
|
|---|
| 112 | fData[i] = new short[numberOfGridPoints];
|
|---|
| 113 | fLookUp[i] = NULL;
|
|---|
| 114 | }
|
|---|
| 115 | }
|
|---|
| 116 | ~CalibrationDataChannel() {
|
|---|
| 117 | int i;
|
|---|
| 118 | delete fTempData;
|
|---|
| 119 | for (i = 0; i < kNumberOfBins; i++) {
|
|---|
| 120 | delete fData[i];
|
|---|
| 121 | delete fLookUp[i];
|
|---|
| 122 | }
|
|---|
| 123 | }
|
|---|
| 124 | };
|
|---|
| 125 |
|
|---|
| 126 | bool fRead; //!
|
|---|
| 127 | CalibrationDataChannel *fChannel[kNumberOfCalibChannels]; //!
|
|---|
| 128 | unsigned char fNumberOfGridPoints; //!
|
|---|
| 129 | int fHasOffsetCalibration; //!
|
|---|
| 130 | float fStartTemperature; //!
|
|---|
| 131 | float fEndTemperature; //!
|
|---|
| 132 | int *fBSplineOffsetLookUp[kNumberOfADCBins]; //!
|
|---|
| 133 | float **fBSplineLookUp[kNumberOfADCBins]; //!
|
|---|
| 134 | float fMin; //!
|
|---|
| 135 | float fMax; //!
|
|---|
| 136 | unsigned char fNumberOfLimitGroups; //!
|
|---|
| 137 | static float fIntRevers[2 * kBSplineOrder - 2];
|
|---|
| 138 |
|
|---|
| 139 | private:
|
|---|
| 140 | CalibrationData(const CalibrationData &c); // Not implemented
|
|---|
| 141 | CalibrationData &operator=(const CalibrationData &rhs); // Not implemented
|
|---|
| 142 |
|
|---|
| 143 | public:
|
|---|
| 144 | CalibrationData(int numberOfGridPoints);
|
|---|
| 145 | ~CalibrationData();
|
|---|
| 146 | static int CalculateBSpline(int nGrid, float value, float *bsplines);
|
|---|
| 147 | void PreCalculateBSpline();
|
|---|
| 148 | void DeletePreCalculatedBSpline();
|
|---|
| 149 | };
|
|---|
| 150 |
|
|---|
| 151 | // General Fields
|
|---|
| 152 | DRSBoard *fBoard;
|
|---|
| 153 |
|
|---|
| 154 | double fPrecision;
|
|---|
| 155 |
|
|---|
| 156 | // Fields for creating the Calibration
|
|---|
| 157 | bool fInitialized;
|
|---|
| 158 | bool fRecorded;
|
|---|
| 159 | bool fFitted;
|
|---|
| 160 | bool fOffset;
|
|---|
| 161 | bool fCalibrationValid[2];
|
|---|
| 162 |
|
|---|
| 163 | int fNumberOfPointsLowVolt;
|
|---|
| 164 | int fNumberOfPoints;
|
|---|
| 165 | int fNumberOfMode2Bins;
|
|---|
| 166 | int fNumberOfSamples;
|
|---|
| 167 | int fNumberOfGridPoints;
|
|---|
| 168 | int fNumberOfXConstPoints;
|
|---|
| 169 | int fNumberOfXConstGridPoints;
|
|---|
| 170 | double fTriggerFrequency;
|
|---|
| 171 | int fShowStatistics;
|
|---|
| 172 | FILE *fCalibFile;
|
|---|
| 173 |
|
|---|
| 174 | int fCurrentLowVoltPoint;
|
|---|
| 175 | int fCurrentPoint;
|
|---|
| 176 | int fCurrentSample;
|
|---|
| 177 | int fCurrentFitChannel;
|
|---|
| 178 | int fCurrentFitBin;
|
|---|
| 179 |
|
|---|
| 180 | float *fResponseX[kNumberOfCalibChannels][kNumberOfBins];
|
|---|
| 181 | float *fResponseY;
|
|---|
| 182 | unsigned short **fWaveFormMode3[kNumberOfCalibChannels];
|
|---|
| 183 | unsigned short **fWaveFormMode2[kNumberOfCalibChannels];
|
|---|
| 184 | short **fWaveFormOffset[kNumberOfCalibChannels];
|
|---|
| 185 | unsigned short **fWaveFormOffsetADC[kNumberOfCalibChannels]; // Is this used?
|
|---|
| 186 | unsigned short *fSamples;
|
|---|
| 187 | int *fSampleUsed;
|
|---|
| 188 |
|
|---|
| 189 | float *fPntX[2];
|
|---|
| 190 | float *fPntY[2];
|
|---|
| 191 | float *fUValues[2];
|
|---|
| 192 | float *fRes[kNumberOfBins];
|
|---|
| 193 | float *fResX[kNumberOfBins];
|
|---|
| 194 |
|
|---|
| 195 | double *fXXFit;
|
|---|
| 196 | double *fYYFit;
|
|---|
| 197 | double *fWWFit;
|
|---|
| 198 | double *fYYFitRes;
|
|---|
| 199 | double *fYYSave;
|
|---|
| 200 | double *fXXSave;
|
|---|
| 201 |
|
|---|
| 202 | float **fStatisticsApprox;
|
|---|
| 203 | float **fStatisticsApproxExt;
|
|---|
| 204 |
|
|---|
| 205 | // Fields for applying the Calibration
|
|---|
| 206 | CalibrationData *fCalibrationData[kNumberOfChips];
|
|---|
| 207 |
|
|---|
| 208 | private:
|
|---|
| 209 | ResponseCalibration(const ResponseCalibration &c); // Not implemented
|
|---|
| 210 | ResponseCalibration &operator=(const ResponseCalibration &rhs); // Not implemented
|
|---|
| 211 |
|
|---|
| 212 | public:
|
|---|
| 213 | ResponseCalibration(DRSBoard* board);
|
|---|
| 214 | ~ResponseCalibration();
|
|---|
| 215 |
|
|---|
| 216 | void SetCalibrationParameters(int numberOfPointsLowVolt, int numberOfPoints, int numberOfMode2Bins,
|
|---|
| 217 | int numberOfSamples, int numberOfGridPoints, int numberOfXConstPoints,
|
|---|
| 218 | int numberOfXConstGridPoints, double triggerFrequency, int showStatistics = 0);
|
|---|
| 219 | void ResetCalibration();
|
|---|
| 220 | bool RecordCalibrationPoints(int chipNumber);
|
|---|
| 221 | bool RecordCalibrationPointsV3(int chipNumber);
|
|---|
| 222 | bool RecordCalibrationPointsV4(int chipNumber);
|
|---|
| 223 | bool FitCalibrationPoints(int chipNumber);
|
|---|
| 224 | bool FitCalibrationPointsV3(int chipNumber);
|
|---|
| 225 | bool FitCalibrationPointsV4(int chipNumber);
|
|---|
| 226 | bool OffsetCalibration(int chipNumber);
|
|---|
| 227 | double GetTemperature(unsigned int chipIndex);
|
|---|
| 228 |
|
|---|
| 229 | bool WriteCalibration(unsigned int chipIndex);
|
|---|
| 230 | bool WriteCalibrationV3(unsigned int chipIndex);
|
|---|
| 231 | bool WriteCalibrationV4(unsigned int chipIndex);
|
|---|
| 232 | bool ReadCalibration(unsigned int chipIndex);
|
|---|
| 233 | bool ReadCalibrationV3(unsigned int chipIndex);
|
|---|
| 234 | bool ReadCalibrationV4(unsigned int chipIndex);
|
|---|
| 235 | bool Calibrate(unsigned int chipIndex, unsigned int channel, float *adcWaveform,
|
|---|
| 236 | float *uWaveform, float threshold);
|
|---|
| 237 | bool Calibrate(unsigned int chipIndex, unsigned int channel, unsigned short *adcWaveform, short *uWaveform,
|
|---|
| 238 | int triggerCell, float threshold);
|
|---|
| 239 | bool SubtractADCOffset(unsigned int chipIndex, unsigned int channel, unsigned short *adcWaveform,
|
|---|
| 240 | unsigned short *adcCalibratedWaveform, unsigned short newBaseLevel);
|
|---|
| 241 | bool IsRead(int chipIndex) const { return fCalibrationValid[chipIndex]; }
|
|---|
| 242 | double GetPrecision() const { return fPrecision; };
|
|---|
| 243 |
|
|---|
| 244 | double GetOffsetAt(int chip,int chn,int bin) const { return fCalibrationData[chip]->fChannel[chn]->fOffset[bin]; };
|
|---|
| 245 | double GetGainAt(int chip,int chn,int bin) const { return fCalibrationData[chip]->fChannel[chn]->fGain[bin]; };
|
|---|
| 246 | double GetMeasPointXAt(int ip) const { return fXXSave[ip]; };
|
|---|
| 247 | double GetMeasPointYAt(int ip) const { return fYYSave[ip]; };
|
|---|
| 248 |
|
|---|
| 249 | protected:
|
|---|
| 250 | void InitFields(int numberOfPointsLowVolt, int numberOfPoints, int numberOfMode2Bins, int numberOfSamples,
|
|---|
| 251 | int numberOfGridPoints, int numberOfXConstPoints, int numberOfXConstGridPoints,
|
|---|
| 252 | double triggerFrequency, int showStatistics);
|
|---|
| 253 | void DeleteFields();
|
|---|
| 254 | void CalibrationTrigger(int mode, double voltage);
|
|---|
| 255 | void CalibrationStart(double voltage);
|
|---|
| 256 |
|
|---|
| 257 | static float GetValue(float *coefficients, float u, int n);
|
|---|
| 258 | static int Approx(float *p, float *uu, int np, int nu, float *coef);
|
|---|
| 259 | static void LeastSquaresAccumulation(float **matrix, int nb, int *ip, int *ir, int mt, int jt);
|
|---|
| 260 | static int LeastSquaresSolving(float **matrix, int nb, int ip, int ir, float *x, int n);
|
|---|
| 261 | static void Housholder(int lpivot, int l1, int m, float **u, int iU1, int iU2, float *up, float **c, int iC1,
|
|---|
| 262 | int iC2, int ice, int ncv);
|
|---|
| 263 |
|
|---|
| 264 | static int MakeDir(const char *path);
|
|---|
| 265 | static void Average(int method,float *samples,int numberOfSamples,float &mean,float &error,float sigmaBoundary);
|
|---|
| 266 | };
|
|---|
| 267 |
|
|---|
| 268 |
|
|---|
| 269 |
|
|---|
| 270 | class DRSBoard {
|
|---|
| 271 | protected:
|
|---|
| 272 | class TimeData {
|
|---|
| 273 | public:
|
|---|
| 274 | class FrequencyData {
|
|---|
| 275 | public:
|
|---|
| 276 | int fFrequency;
|
|---|
| 277 | double fBin[kNumberOfBins];
|
|---|
| 278 | };
|
|---|
| 279 |
|
|---|
| 280 | enum {
|
|---|
| 281 | kMaxNumberOfFrequencies = 4000
|
|---|
| 282 | };
|
|---|
| 283 | int fChip;
|
|---|
| 284 | int fNumberOfFrequencies;
|
|---|
| 285 | FrequencyData *fFrequency[kMaxNumberOfFrequencies];
|
|---|
| 286 |
|
|---|
| 287 | private:
|
|---|
| 288 | TimeData(const TimeData &c); // Not implemented
|
|---|
| 289 | TimeData &operator=(const TimeData &rhs); // Not implemented
|
|---|
| 290 |
|
|---|
| 291 | public:
|
|---|
| 292 | TimeData()
|
|---|
| 293 | :fChip(0)
|
|---|
| 294 | ,fNumberOfFrequencies(0) {
|
|---|
| 295 | }
|
|---|
| 296 | ~TimeData() {
|
|---|
| 297 | int i;
|
|---|
| 298 | for (i = 0; i < fNumberOfFrequencies; i++) {
|
|---|
| 299 | delete fFrequency[i];
|
|---|
| 300 | }
|
|---|
| 301 | }
|
|---|
| 302 | };
|
|---|
| 303 |
|
|---|
| 304 | public:
|
|---|
| 305 | // DAC channels (CMC Version 1 : DAC_COFSA,DAC_COFSB,DAC_DRA,DAC_DSA,DAC_TLEVEL,DAC_ACALIB,DAC_DSB,DAC_DRB)
|
|---|
| 306 | unsigned int fDAC_COFSA;
|
|---|
| 307 | unsigned int fDAC_COFSB;
|
|---|
| 308 | unsigned int fDAC_DRA;
|
|---|
| 309 | unsigned int fDAC_DSA;
|
|---|
| 310 | unsigned int fDAC_TLEVEL;
|
|---|
| 311 | unsigned int fDAC_ACALIB;
|
|---|
| 312 | unsigned int fDAC_DSB;
|
|---|
| 313 | unsigned int fDAC_DRB;
|
|---|
| 314 | // DAC channels (CMC Version 2+3 : DAC_COFS,DAC_DSA,DAC_DSB,DAC_TLEVEL,DAC_ADCOFS,DAC_CLKOFS,DAC_ACALIB)
|
|---|
| 315 | unsigned int fDAC_COFS;
|
|---|
| 316 | unsigned int fDAC_ADCOFS;
|
|---|
| 317 | unsigned int fDAC_CLKOFS;
|
|---|
| 318 | // DAC channels (CMC Version 4 : DAC_ROFS_1,DAC_DSA,DAC_DSB,DAC_ROFS_2,DAC_ADCOFS,DAC_ACALIB,DAC_INOFS,DAC_BIAS)
|
|---|
| 319 | unsigned int fDAC_ROFS_1;
|
|---|
| 320 | unsigned int fDAC_ROFS_2;
|
|---|
| 321 | unsigned int fDAC_INOFS;
|
|---|
| 322 | unsigned int fDAC_BIAS;
|
|---|
| 323 |
|
|---|
| 324 | protected:
|
|---|
| 325 | // Fields for DRS
|
|---|
| 326 | int fRequiredFirmwareVersion;
|
|---|
| 327 | int fFirmwareVersion;
|
|---|
| 328 | int fChipVersion;
|
|---|
| 329 | int fBoardVersion;
|
|---|
| 330 | int fCMCSerialNumber;
|
|---|
| 331 | unsigned int fTransport;
|
|---|
| 332 | unsigned int fCtrlBits;
|
|---|
| 333 | int fNumberOfReadoutChannels;
|
|---|
| 334 | double fExternalClockFrequency;
|
|---|
| 335 |
|
|---|
| 336 | // VME
|
|---|
| 337 | #ifdef CT_VME
|
|---|
| 338 | VME_ErrorCode_t ErrorCode;
|
|---|
| 339 | VME_BlockTransferList_t BLT_List;
|
|---|
| 340 |
|
|---|
| 341 | char ErrorString[VME_MAXSTRING];
|
|---|
| 342 |
|
|---|
| 343 | int CMEM_SegIdentifier;
|
|---|
| 344 |
|
|---|
| 345 | unsigned long PCIAddress; // Physical address of contiguous buffer
|
|---|
| 346 | unsigned long VirtualAddress; // Virtual address of contiguous buffer
|
|---|
| 347 |
|
|---|
| 348 | unsigned int fBaseAddress;
|
|---|
| 349 | unsigned int fBoardAddress;
|
|---|
| 350 | int fMasterMapping;
|
|---|
| 351 | #endif
|
|---|
| 352 | #ifdef STRUCK_VME
|
|---|
| 353 | mvme_addr_t fBaseAddress;
|
|---|
| 354 | MVME_INTERFACE *fVMEInterface;
|
|---|
| 355 | #endif
|
|---|
| 356 |
|
|---|
| 357 | int fSlotNumber;
|
|---|
| 358 | double fFrequency;
|
|---|
| 359 | int fDominoMode;
|
|---|
| 360 | int fReadoutMode;
|
|---|
| 361 | int fTriggerEnable;
|
|---|
| 362 | int fDelayedStart;
|
|---|
| 363 | int fTriggerCell;
|
|---|
| 364 |
|
|---|
| 365 | #ifdef STRUCK_VME
|
|---|
| 366 | unsigned char fWaveforms[kNumberOfChips * kNumberOfChannels * 2 * kNumberOfBins];
|
|---|
| 367 | #endif
|
|---|
| 368 | #ifdef CT_VME
|
|---|
| 369 | unsigned long fWaveforms[kNumberOfChannels * kNumberOfBins];
|
|---|
| 370 | #endif
|
|---|
| 371 |
|
|---|
| 372 | // Fields for Calibration
|
|---|
| 373 | int fMaxChips;
|
|---|
| 374 | char fCalibDirectory[1000];
|
|---|
| 375 |
|
|---|
| 376 | // Fields for Response Calibration
|
|---|
| 377 | ResponseCalibration *fResponseCalibration;
|
|---|
| 378 |
|
|---|
| 379 | // Fields for Time Calibration
|
|---|
| 380 | TimeData **fTimeData;
|
|---|
| 381 | int fNumberOfTimeData;
|
|---|
| 382 |
|
|---|
| 383 | // General debugging flag
|
|---|
| 384 | int fDebug;
|
|---|
| 385 |
|
|---|
| 386 | // Fields for wave transfer
|
|---|
| 387 | bool fWaveTransferred[kNumberOfChips * kNumberOfChannels];
|
|---|
| 388 |
|
|---|
| 389 | // Waveform Rotation
|
|---|
| 390 | int fTriggerStartBin; // Start bin of the trigger
|
|---|
| 391 | bool kRotateWave;
|
|---|
| 392 |
|
|---|
| 393 | private:
|
|---|
| 394 | DRSBoard(const DRSBoard &c); // Not implemented
|
|---|
| 395 | DRSBoard &operator=(const DRSBoard &rhs); // Not implemented
|
|---|
| 396 |
|
|---|
| 397 | public:
|
|---|
| 398 |
|
|---|
| 399 | ~DRSBoard();
|
|---|
| 400 |
|
|---|
| 401 | void SetCMCSerialNumber(unsigned int serialNumber) { fCMCSerialNumber = serialNumber; }
|
|---|
| 402 | int GetCMCSerialNumber() const { return fCMCSerialNumber; }
|
|---|
| 403 | int GetFirmwareVersion() const { return fFirmwareVersion; }
|
|---|
| 404 | int GetRequiredFirmwareVersion() const { return fRequiredFirmwareVersion; }
|
|---|
| 405 | int GetChipVersion() const { return fChipVersion; }
|
|---|
| 406 | int GetCMCVersion() const { return fBoardVersion; }
|
|---|
| 407 |
|
|---|
| 408 | // VME
|
|---|
| 409 | int GetSlotNumber() const { return fSlotNumber; }
|
|---|
| 410 |
|
|---|
| 411 | #ifdef CT_VME
|
|---|
| 412 | unsigned int GetBaseAddress() const {return fBaseAddress; }
|
|---|
| 413 | unsigned int GetBoardAddress() const {return fBoardAddress; }
|
|---|
| 414 | #endif
|
|---|
| 415 |
|
|---|
| 416 | int Read(int type, void *data, unsigned int addr, int size);
|
|---|
| 417 | int Write(int type, unsigned int addr, void *data, int size);
|
|---|
| 418 |
|
|---|
| 419 | #ifdef CT_VME
|
|---|
| 420 | int AllocateSegmentCMEM(unsigned int SegSize, int *CMEM_SegIdentifier);
|
|---|
| 421 | int AssignPhysicalSegAddressCMEM(int CMEM_SegIdentifier, unsigned long* PCIAddress);
|
|---|
| 422 | int AssignVirtualSegAddressCMEM(int CMEM_SegIdentifier, unsigned long* VirtualAddress);
|
|---|
| 423 | int FreeSegmentCMEM(int CMEM_SegIdentifier);
|
|---|
| 424 | #endif
|
|---|
| 425 |
|
|---|
| 426 | void RegisterTest(void);
|
|---|
| 427 | int RAMTest(int flag);
|
|---|
| 428 | unsigned int GetCtrlReg(void);
|
|---|
| 429 | unsigned int GetStatusReg(void);
|
|---|
| 430 |
|
|---|
| 431 | void SetLED(int state);
|
|---|
| 432 |
|
|---|
| 433 | void SetChannelConfig(int firstChannel, int lastChannel, int nConfigChannels);
|
|---|
| 434 | void SetNumberOfChannels(int nChannels);
|
|---|
| 435 | int EnableTrigger(int mode);
|
|---|
| 436 | int SetDelayedStart(int flag);
|
|---|
| 437 | int IsBusy(void);
|
|---|
| 438 | int IsNewFreq(unsigned char chipIndex);
|
|---|
| 439 | int SetDAC(unsigned char channel, double value);
|
|---|
| 440 | int ReadDAC(unsigned char channel, double *value);
|
|---|
| 441 | int GetRegulationDAC(double *value);
|
|---|
| 442 |
|
|---|
| 443 | int StartDomino();
|
|---|
| 444 | int Reinit();
|
|---|
| 445 | int Init();
|
|---|
| 446 |
|
|---|
| 447 | void SetDebug(int debug) { fDebug = debug; }
|
|---|
| 448 |
|
|---|
| 449 | int SetDominoMode(unsigned char mode);
|
|---|
| 450 |
|
|---|
| 451 | int SetDominoActive(unsigned char mode);
|
|---|
| 452 | int SetReadoutMode(unsigned char mode);
|
|---|
| 453 |
|
|---|
| 454 | int SoftTrigger(void);
|
|---|
| 455 | int ReadFrequency(unsigned char chipIndex, double *f);
|
|---|
| 456 | int SetFrequency(double freq);
|
|---|
| 457 | double VoltToFreq(double volt);
|
|---|
| 458 | double FreqToVolt(double freq);
|
|---|
| 459 | double GetFrequency() const { return fFrequency; }
|
|---|
| 460 |
|
|---|
| 461 | int RegulateFrequency(double freq);
|
|---|
| 462 | int SetExternalClockFrequency(double frequencyMHz);
|
|---|
| 463 | double GetExternalClockFrequency();
|
|---|
| 464 |
|
|---|
| 465 | void SetVoltageOffset(double offset1, double offset2);
|
|---|
| 466 |
|
|---|
| 467 |
|
|---|
| 468 | int TestRead(unsigned int n, int type);
|
|---|
| 469 |
|
|---|
| 470 | int TransferWaves(int numberOfChannels = kNumberOfChips * kNumberOfChannels);
|
|---|
| 471 | int TransferWaves(unsigned char *p, int numberOfChannels = kNumberOfChips * kNumberOfChannels);
|
|---|
| 472 | int TransferWaves(unsigned char *p, int firstChannel, int lastChannel);
|
|---|
| 473 | int TransferWaves(unsigned long *p, int numberOfChannels = kNumberOfChips * kNumberOfChannels);
|
|---|
| 474 | int TransferWaves(unsigned long *p, int firstChannel, int lastChannel);
|
|---|
| 475 | int TransferWaves(int firstChannel, int lastChannel);
|
|---|
| 476 |
|
|---|
| 477 | int DecodeWave(unsigned char *waveforms, unsigned int chipIndex, unsigned char channel,
|
|---|
| 478 | unsigned short *waveform);
|
|---|
| 479 | int DecodeWave(unsigned long *waveforms, unsigned int chipIndex, unsigned char channel,
|
|---|
| 480 | unsigned short *waveform);
|
|---|
| 481 | int DecodeWave(unsigned int chipIndex, unsigned char channel, unsigned short *waveform);
|
|---|
| 482 |
|
|---|
| 483 | int GetWave(unsigned long *waveforms, unsigned int chipIndex, unsigned char channel, short *waveform,
|
|---|
| 484 | bool responseCalib = false, int triggerCell = -1, bool adjustToClock = false,
|
|---|
| 485 | float threshold = 0);
|
|---|
| 486 | int GetWave(unsigned char *waveforms, unsigned int chipIndex, unsigned char channel, short *waveform,
|
|---|
| 487 | bool responseCalib = false, int triggerCell = -1, bool adjustToClock = false,
|
|---|
| 488 | float threshold = 0);
|
|---|
| 489 | int GetWave(unsigned char *waveforms, unsigned int chipIndex, unsigned char channel, float *waveform,
|
|---|
| 490 | bool responseCalib = false, int triggerCell = -1, bool adjustToClock = false,
|
|---|
| 491 | float threshold = 0);
|
|---|
| 492 | int GetWave(unsigned int chipIndex, unsigned char channel, short *waveform, bool responseCalib = false,
|
|---|
| 493 | int triggerCell = -1, bool adjustToClock = false, float threshold = 0);
|
|---|
| 494 | int GetWave(unsigned int chipIndex, unsigned char channel, float *waveform, bool responseCalib = false,
|
|---|
| 495 | int triggerCell = -1, bool adjustToClock = false, float threshold = 0);
|
|---|
| 496 | int GetADCWave(unsigned int chipIndex, unsigned char channel, unsigned short *waveform);
|
|---|
| 497 | int GetADCWave(unsigned char *waveforms,unsigned int chipIndex, unsigned char channel,
|
|---|
| 498 | unsigned short *waveform);
|
|---|
| 499 | int GetADCWave(unsigned long *waveforms,unsigned int chipIndex, unsigned char channel,
|
|---|
| 500 | unsigned short *waveform);
|
|---|
| 501 |
|
|---|
| 502 | void RotateWave(int triggerCell, short *waveform);
|
|---|
| 503 | void RotateWave(int triggerCell, float *waveform);
|
|---|
| 504 | void SetRotation(bool r) {kRotateWave = r;}
|
|---|
| 505 |
|
|---|
| 506 | int GetTime(unsigned int chipIndex, int frequencyMHz, float *time, int triggerCell);
|
|---|
| 507 | int GetTriggerCell(unsigned int chipIndex);
|
|---|
| 508 | int GetTriggerCell(unsigned char *waveforms,unsigned int chipIndex);
|
|---|
| 509 | int GetTriggerCell(unsigned long *waveforms,unsigned int chipIndex);
|
|---|
| 510 | int GetTriggerCell(float *waveform);
|
|---|
| 511 |
|
|---|
| 512 | void TestDAC(int channel);
|
|---|
| 513 | void MeasureSpeed();
|
|---|
| 514 | void InteractSpeed();
|
|---|
| 515 | void MonitorFrequency();
|
|---|
| 516 | int EnableTcal(int flag);
|
|---|
| 517 | int EnableAcal(int mode, double voltage);
|
|---|
| 518 | int SetCalibVoltage(double value);
|
|---|
| 519 | int SetCalibTiming(int t1, int t2);
|
|---|
| 520 | double GetTemperature();
|
|---|
| 521 | int GetTriggerBus();
|
|---|
| 522 | int FlashEEPROM(unsigned short serial_cmc);
|
|---|
| 523 | bool HasCorrectFirmware();
|
|---|
| 524 |
|
|---|
| 525 | bool InitTimeCalibration(unsigned int chipIndex);
|
|---|
| 526 | void SetCalibrationDirectory(const char *calibrationDirectoryPath);
|
|---|
| 527 | void GetCalibrationDirectory(char *calibrationDirectoryPath);
|
|---|
| 528 |
|
|---|
| 529 | ResponseCalibration *GetResponseCalibration() const { return fResponseCalibration; }
|
|---|
| 530 |
|
|---|
| 531 | int GetStoredTriggerCell() const { return fTriggerCell; }
|
|---|
| 532 | double GetPrecision() const { return fResponseCalibration->GetPrecision(); }
|
|---|
| 533 | int CalibrateWaveform(unsigned int chipIndex, unsigned char channel, unsigned short *adcWaveform,
|
|---|
| 534 | short *waveform, bool responseCalib, int triggerCell, bool adjustToClock,
|
|---|
| 535 | float threshold);
|
|---|
| 536 |
|
|---|
| 537 | static void LinearRegression(double *x, double *y, int n, double *a, double *b);
|
|---|
| 538 |
|
|---|
| 539 | protected:
|
|---|
| 540 | // Protected methods
|
|---|
| 541 | void ConstructBoard();
|
|---|
| 542 | void ReadSerialNumber();
|
|---|
| 543 |
|
|---|
| 544 |
|
|---|
| 545 | TimeData *GetTimeCalibration(unsigned int chipIndex, bool reinit = false);
|
|---|
| 546 |
|
|---|
| 547 | int GetStretchedTime(float *time, float *measurement, int numberOfMeasurements, float period);
|
|---|
| 548 |
|
|---|
| 549 | public:
|
|---|
| 550 |
|
|---|
| 551 | #ifdef CT_VME
|
|---|
| 552 | DRSBoard(int MasterMapping, unsigned int BaseAddress, unsigned int BoardAddress, int SlotNumber);
|
|---|
| 553 | #endif
|
|---|
| 554 |
|
|---|
| 555 | #ifdef STRUCK_VME
|
|---|
| 556 | DRSBoard(MVME_INTERFACE * MVME_Interface, mvme_addr_t BaseAddress, int SlotNumber);
|
|---|
| 557 | MVME_INTERFACE *GetVMEInterface() const { return fVMEInterface; };
|
|---|
| 558 | #endif
|
|---|
| 559 |
|
|---|
| 560 | void PrintBinary32(unsigned int i);
|
|---|
| 561 | long int GetMicroSeconds();
|
|---|
| 562 |
|
|---|
| 563 | };
|
|---|
| 564 |
|
|---|
| 565 |
|
|---|
| 566 |
|
|---|
| 567 | class DRS {
|
|---|
| 568 |
|
|---|
| 569 | protected:
|
|---|
| 570 | enum {
|
|---|
| 571 | kMaxNumberOfBoards = 40
|
|---|
| 572 | };
|
|---|
| 573 |
|
|---|
| 574 | protected:
|
|---|
| 575 |
|
|---|
| 576 | DRSBoard *fBoard[kMaxNumberOfBoards];
|
|---|
| 577 |
|
|---|
| 578 | #ifdef CT_VME
|
|---|
| 579 | VME_MasterMap_t MasterMap;
|
|---|
| 580 | VME_ErrorCode_t ErrorCode;
|
|---|
| 581 |
|
|---|
| 582 | char ErrorString[VME_MAXSTRING];
|
|---|
| 583 |
|
|---|
| 584 | int MasterMapping[kMaxNumberOfBoards];
|
|---|
| 585 | #endif
|
|---|
| 586 |
|
|---|
| 587 | int fNumberOfBoards;
|
|---|
| 588 |
|
|---|
| 589 | #ifdef STRUCK_VME
|
|---|
| 590 | MVME_INTERFACE *fVMEInterface;
|
|---|
| 591 | #endif
|
|---|
| 592 |
|
|---|
| 593 |
|
|---|
| 594 | private:
|
|---|
| 595 | DRS(const DRS &c); // Not implemented
|
|---|
| 596 | DRS &operator=(const DRS &rhs); // Not implemented
|
|---|
| 597 |
|
|---|
| 598 |
|
|---|
| 599 | #ifdef CT_VME
|
|---|
| 600 | int OpenVME();
|
|---|
| 601 | int MasterMapVME(int* MMap);
|
|---|
| 602 | int MasterUnMapVME(int MMap);
|
|---|
| 603 | int CloseVME();
|
|---|
| 604 |
|
|---|
| 605 | int OpenCMEM();
|
|---|
| 606 | int CloseCMEM();
|
|---|
| 607 | #endif
|
|---|
| 608 |
|
|---|
| 609 | int First_VME_Slot;
|
|---|
| 610 | int Last_VME_Slot;
|
|---|
| 611 |
|
|---|
| 612 | public:
|
|---|
| 613 | // Public Methods
|
|---|
| 614 | DRS();
|
|---|
| 615 | ~DRS();
|
|---|
| 616 |
|
|---|
| 617 | DRSBoard *GetBoard(int i) { return fBoard[i]; }
|
|---|
| 618 | DRSBoard **GetBoards() { return fBoard; }
|
|---|
| 619 | int GetNumberOfBoards() const { return fNumberOfBoards; }
|
|---|
| 620 |
|
|---|
| 621 | #ifdef STRUCK_VME
|
|---|
| 622 | MVME_INTERFACE *GetVMEInterface() const { return fVMEInterface; };
|
|---|
| 623 | #endif
|
|---|
| 624 |
|
|---|
| 625 | void InitialScan();
|
|---|
| 626 | void SetFirstVMESlot(int s) { First_VME_Slot = s; }
|
|---|
| 627 | void SetLastVMESlot(int s) { Last_VME_Slot = s; }
|
|---|
| 628 | int GetFirstVMESlot() { return First_VME_Slot; }
|
|---|
| 629 | int GetLastVMESlot() { return Last_VME_Slot; }
|
|---|
| 630 | };
|
|---|
| 631 |
|
|---|
| 632 | #endif // DRS_H
|
|---|