pxar
All Classes Namespaces Functions Variables Typedefs Friends
PixSetup.cc
1 #include <iostream>
2 #include "PixSetup.hh"
3 #include "log.h"
4 #include <cstdlib>
5 
6 #include "rsstools.hh"
7 #include "shist256.hh"
8 
9 using namespace std;
10 using namespace pxar;
11 
12 // ----------------------------------------------------------------------
13 PixSetup::PixSetup(pxarCore *a, PixTestParameters *tp, ConfigParameters *cp) {
14  fApi = a;
15  fPixTestParameters = tp;
16  fConfigParameters = cp;
17  fPixMonitor = new PixMonitor(a);
18  fDoAnalysisOnly = false;
19  fDoUpdateRootFile = false;
20  init();
21 }
22 
23 
24 // ----------------------------------------------------------------------
25 PixSetup::PixSetup(string verbosity, PixTestParameters *tp, ConfigParameters *cp) {
26  fPixTestParameters = tp;
27  fConfigParameters = cp;
28  fDoAnalysisOnly = false;
29  init();
30 
31  vector<vector<pair<string,uint8_t> > > rocDACs = fConfigParameters->getRocDacs();
32  vector<vector<pair<string,uint8_t> > > tbmDACs = fConfigParameters->getTbmDacs();
33  vector<vector<pixelConfig> > rocPixels = fConfigParameters->getRocPixelConfig();
34  vector<pair<string,uint8_t> > sig_delays = fConfigParameters->getTbSigDelays();
35  vector<pair<string, double> > power_settings = fConfigParameters->getTbPowerSettings();
36  vector<pair<std::string, uint8_t> > pg_setup = fConfigParameters->getTbPgSettings();
37 
38  fApi = new pxar::pxarCore("*", verbosity);
39  fApi->initTestboard(sig_delays, power_settings, pg_setup);
40  fApi->initDUT(fConfigParameters->getHubId(),
41  fConfigParameters->getTbmType(), tbmDACs,
42  fConfigParameters->getRocType(), rocDACs,
43  rocPixels);
44  LOG(logINFO) << "DUT info: ";
45  fApi->_dut->info();
46 
47  fPixMonitor = new PixMonitor(fApi);
48 
49 
50 }
51 
52 // ----------------------------------------------------------------------
53 PixSetup::PixSetup() {
54  fApi = 0;
55  fPixTestParameters = 0;
56  fConfigParameters = 0;
57  fPixMonitor = 0;
58  fDoAnalysisOnly = false;
59  init();
60  LOG(logDEBUG) << "PixSetup ctor()";
61 }
62 
63 // ----------------------------------------------------------------------
64 PixSetup::~PixSetup() {
65  LOG(logDEBUG) << "PixSetup free fPxarMemory";
66  free(fPxarMemory);
67 }
68 
69 
70 // ----------------------------------------------------------------------
71 void PixSetup::killApi() {
72  if (fApi) delete fApi;
73 }
74 
75 // ----------------------------------------------------------------------
76 void PixSetup::init() {
77  rsstools rss;
78  LOG(logDEBUG) << "PixSetup init start; getCurrentRSS() = " << rss.getCurrentRSS();
79  int N(100000);
80  // fPxarMemory = std::malloc(300000000);
81  fPxarMemory = std::calloc(N, sizeof(shist256));
82  fPxarMemHi = ((shist256*)fPxarMemory) + N;
83 
84  LOG(logDEBUG) << "fPixTestParameters = " << fPixTestParameters;
85  LOG(logDEBUG) << " fConfigParameters = " << fConfigParameters;
86  LOG(logDEBUG) << " fPxarMemory = " << fPxarMemory;
87  LOG(logDEBUG) << " fPxarMemHi = " << fPxarMemHi;
88 
89  if (0 == fPxarMemory) {
90  LOG(logERROR) << "not enough memory; go invest money into a larger computer";
91  exit(1);
92  } else {
93  // shist256 *p = (shist256*)fPxarMemory;
94  // int cnt(0);
95  // while (p < fPxarMemHi) {
96  // if (cnt%100 == 0) cout << p << ": " << p->get(0) << ", " << (p - (shist256*)fPxarMemory) << endl;
97  // p += 1;
98  // ++cnt;
99  // }
100  // p -= 1;
101  // cout << p << ": " << p->get(0) << ", " << (p - (shist256*)fPxarMemory) << endl;
102  }
103  LOG(logDEBUG) << "PixSetup init done; getCurrentRSS() = " << rss.getCurrentRSS() << " fPxarMemory = " << fPxarMemory;
104 }
105 
106 
107 
108 // ----------------------------------------------------------------------
109 void PixSetup::writeDacParameterFiles() {
110  vector<uint8_t> rocs = fApi->_dut->getEnabledRocIDs();
111  for (unsigned int iroc = 0; iroc < rocs.size(); ++iroc) {
112  fConfigParameters->writeDacParameterFile(rocs[iroc], fApi->_dut->getDACs(iroc));
113  }
114 }
115 
116 // ----------------------------------------------------------------------
117 void PixSetup::writeTrimFiles() {
118  vector<uint8_t> rocs = fApi->_dut->getEnabledRocIDs();
119  for (unsigned int iroc = 0; iroc < rocs.size(); ++iroc) {
120  fConfigParameters->writeTrimFile(rocs[iroc], fApi->_dut->getEnabledPixels(rocs[iroc]));
121  }
122 }
123 
124 // ----------------------------------------------------------------------
125 void PixSetup::writeTbmParameterFiles() {
126  for (unsigned int itbm = 0; itbm < fApi->_dut->getNTbms(); itbm += 2) {
127  fConfigParameters->writeTbmParameterFile(itbm, fApi->_dut->getTbmDACs(itbm), fApi->_dut->getTbmDACs(itbm+1));
128  }
129 }
size_t getCurrentRSS()
Definition: rsstools.cc:59