10 #include <Windows4Root.h>
13 #include <TApplication.h>
20 #include "ConfigParameters.hh"
21 #include "PixTestParameters.hh"
24 #include "PixTestFactory.hh"
25 #include "PixUserTestFactory.hh"
27 #include "PixSetup.hh"
37 void runGui(
PixSetup &a,
int argc = 0,
char *argv[] = 0);
38 void createBackup(
string a,
string b);
41 int main(
int argc,
char *argv[]){
43 LOG(logINFO) <<
"*** Welcome to pxar ***";
44 gSystem->Exec(
"git status");
47 string dir(
"."), cmdFile(
"nada"), rootfile(
"nada.root"), logfile(
"nada.log"),
48 verbosity(
"INFO"), flashFile(
"nada"), runtest(
"fulltest"), trimVcal(
""), testParameters(
"nada");
51 doRunSingleTest(
false),
53 doUpdateRootFile(
false),
56 for (
int i = 0; i < argc; i++){
57 if (!strcmp(argv[i],
"-h")) {
58 cout <<
"List of arguments:" << endl;
59 cout <<
"-a do not do tests, do not recreate rootfile, but read in existing rootfile" << endl;
60 cout <<
"-c filename read in commands from filename" << endl;
61 cout <<
"-d [--dir] path directory with config files" << endl;
62 cout <<
"-g start with GUI" << endl;
63 cout <<
"-p \"p1=v1[;p2=v2]\" set parameters for test" << endl;
64 cout <<
"-r rootfilename set rootfile (and logfile) name" << endl;
65 cout <<
"-t test run test" << endl;
66 cout <<
"-T [--vcal] XX read in DAC and Trim parameter files corresponding to trim VCAL = XX" << endl;
67 cout <<
"-v verbositylevel set verbosity level: QUIET CRITICAL ERROR WARNING DEBUG DEBUGAPI DEBUGHAL ..." << endl;
70 if (!strcmp(argv[i],
"-c")) {cmdFile = string(argv[++i]); doRunScript =
true;}
71 if (!strcmp(argv[i],
"-d") || !strcmp(argv[i],
"--dir")) {dir = string(argv[++i]); }
72 if (!strcmp(argv[i],
"-f")) {doUpdateFlash =
true; flashFile = string(argv[++i]);}
73 if (!strcmp(argv[i],
"-g")) {doRunGui =
true; }
74 if (!strcmp(argv[i],
"-p")) {testParameters = string(argv[++i]); }
75 if (!strcmp(argv[i],
"-r")) {rootfile = string(argv[++i]); }
76 if (!strcmp(argv[i],
"-t")) {doRunSingleTest =
true; runtest = string(argv[++i]); }
77 if (!strcmp(argv[i],
"-T") || !strcmp(argv[i],
"--vcal")) {trimVcal = string(argv[++i]); }
78 if (!strcmp(argv[i],
"-u")) {doUpdateRootFile =
true;}
79 if (!strcmp(argv[i],
"-v")) {verbosity = string(argv[++i]); }
83 if (stat(
"rootlogon.C", &buffer) == 0) {
84 LOG(logINFO) <<
"reading rootlogon.C, will use gStyle settings from there";
85 gROOT->Macro(
"rootlogon.C");
86 doUseRootLogon =
true;
88 LOG(logINFO) <<
"no rootlogon.C found, live with the defaults provided";
92 TRint *interpreter =
new TRint(
"pXar", 0, 0, 0,
true);
93 interpreter->ExecuteFile(cmdFile.c_str());
94 interpreter->Terminate(0);
95 LOG(logINFO) <<
"terminate and shut down";
103 if (stat(flashFile.c_str(), &buffer) == 0) {
105 api->flashTB(flashFile);
107 LOG(logINFO) <<
"error: File " << flashFile <<
" not found" << endl;
115 configParameters->setDirectory(dir);
116 string cfgFile = configParameters->getDirectory() + string(
"/configParameters.dat");
117 LOG(logINFO) <<
"pxar: reading config parameters from " << cfgFile;
118 if (!configParameters->readConfigParameterFile(cfgFile))
return 1;
120 if (!rootfile.compare(
"nada.root")) {
121 rootfile = configParameters->getDirectory() +
"/" + configParameters->getRootFileName();
123 configParameters->setRootFileName(rootfile);
124 rootfile = configParameters->getDirectory() +
"/" + rootfile;
127 if (trimVcal.compare(
"")) {
128 configParameters->setTrimVcalSuffix(trimVcal);
134 LOG(logINFO)<<
"pxar: dumping results into " << rootfile <<
" logfile = " << logfile;
137 if (doUpdateRootFile) {
138 rfile = TFile::Open(rootfile.c_str(),
"UPDATE");
139 lfile = fopen(logfile.c_str(),
"a");
140 SetLogOutput::Stream() = lfile;
141 SetLogOutput::Duplicate() =
true;
143 createBackup(rootfile, logfile);
144 rfile = TFile::Open(rootfile.c_str(),
"RECREATE");
145 lfile = fopen(logfile.c_str(),
"a");
146 SetLogOutput::Stream() = lfile;
147 SetLogOutput::Duplicate() =
true;
151 string tstamp = Form(
"%d/%02d/%02d", today.GetYear(), today.GetMonth(), today.GetDay());
153 LOG(logINFO) <<
"*** Welcome to pxar ***";
154 LOG(logINFO) << Form(
"*** Today: %s", tstamp.c_str());
156 vector<vector<pair<string,uint8_t> > > rocDACs = configParameters->getRocDacs();
157 vector<vector<pair<string,uint8_t> > > tbmDACs = configParameters->getTbmDacs();
158 vector<vector<pixelConfig> > rocPixels = configParameters->getRocPixelConfig();
159 vector<pair<string,uint8_t> > sig_delays = configParameters->getTbSigDelays();
160 vector<pair<string, double> > power_settings = configParameters->getTbPowerSettings();
161 vector<pair<std::string, uint8_t> > pg_setup = configParameters->getTbPgSettings();
163 if (configParameters->getTbName() !=
"")
164 tbname = configParameters->getTbName();
169 api->initTestboard(sig_delays, power_settings, pg_setup);
170 if (configParameters->customI2cAddresses()) {
171 string i2cstring(
"");
172 vector<uint8_t> i2cAddr = configParameters->getI2cAddresses();
173 for (
unsigned int i = 0; i < i2cAddr.size(); ++i) i2cstring += Form(
" %d", (
int)i2cAddr[i]);
174 LOG(logINFO) <<
"custom i2c addresses: " << i2cstring;
175 api->initDUT(configParameters->getHubId(),
176 configParameters->getTbmType(), tbmDACs,
177 configParameters->getRocType(), rocDACs,
181 api->initDUT(configParameters->getHubId(),
182 configParameters->getTbmType(), tbmDACs,
183 configParameters->getRocType(), rocDACs,
188 api->SignalProbe(
"a1", configParameters->getProbe(
"a1"));
189 api->SignalProbe(
"a2", configParameters->getProbe(
"a2"));
190 api->SignalProbe(
"d1", configParameters->getProbe(
"d1"));
191 api->SignalProbe(
"d2", configParameters->getProbe(
"d2"));
193 LOG(logINFO) <<
"DUT info: ";
197 std::cout <<
"pxar caught an exception due to invalid configuration settings: " << e.what() << std::endl;
202 std::cout <<
"pxar caught an internal exception: " << e.what() << std::endl;
207 std::cout <<
"pxar caught an unknown exception. Exiting." << std::endl;
213 + configParameters->getTestParameterFileName()
215 PixSetup a(api, ptp, configParameters);
216 a.setUseRootLogon(doUseRootLogon);
217 a.setRootFileUpdate(doUpdateRootFile);
220 runGui(a, argc, argv);
221 }
else if (doRunSingleTest) {
224 if (configParameters->getHvOn()) api->HVon();
227 string::size_type m0 = runtest.find(
":");
228 string subtest(
"nada");
229 if (m0 != string::npos) {
230 subtest = runtest.substr(m0+1);
231 runtest = runtest.substr(0, m0);
234 if (testParameters.compare(
"nada")) {
235 ptp->setTestParameters(runtest, testParameters);
237 PixTest *t = factory->createTest(runtest, &a);
238 if (0 == t) t = userfactory->createTest(runtest, &a);
240 if (subtest.compare(
"nada")) {
252 if (configParameters->getHvOn()) api->HVon();
253 LOG(logINFO) <<
"enter 'restricted' command line mode";
255 LOG(logINFO) <<
"enter test to run";
258 std::getline(cin, input);
259 if (input.size() == 0) stop =
true;
260 string parameters(
"nada"), subtest(
"nada");
262 string::size_type m1 = input.find(
" ");
263 if (m1 != string::npos) {
264 parameters = input.substr(m1+1);
265 input = input.substr(0, m1);
266 cout <<
"parameters: ->" << parameters <<
"<- input: ->" << input <<
"<-" << endl;
269 string::size_type m0 = input.find(
":");
270 if (m0 != string::npos) {
271 subtest = input.substr(m0+1);
272 input = input.substr(0, m0);
273 cout <<
"subtest: ->" << subtest <<
"<- input: ->" << input <<
"<-" << endl;
277 if (!parameters.compare(
"nada")) {
278 LOG(logINFO) <<
" test: " << input <<
" no parameter change";
280 LOG(logINFO) <<
" test: " << input <<
" setting parameters: ->" << parameters <<
"<-";
281 ptp->setTestParameters(input, parameters);
284 std::transform(subtest.begin(), subtest.end(), subtest.begin(), ::tolower);
285 std::transform(input.begin(), input.end(), input.begin(), ::tolower);
287 if (!input.compare(
"savedacs")) {
288 a.writeDacParameterFiles();
291 if (!input.compare(
"savetrims")) {
295 if (!input.compare(
"savetbm")) {
296 a.writeTbmParameterFiles();
300 if (!input.compare(
"gui")) runGui(a, argc, argv);
301 if (!input.compare(
"exit")) stop =
true;
302 if (!input.compare(
"quit")) stop =
true;
303 if (!input.compare(
"q")) stop =
true;
306 LOG(logINFO) <<
" running: " << input;
307 PixTest *t = factory->createTest(input, &a);
308 if (0 == t) t = userfactory->createTest(input, &a);
310 if (subtest.compare(
"nada")) {
317 LOG(logINFO) <<
"command ->" << input <<
"<- not known, ignored";
325 a.getPixMonitor()->dumpSummaries();
329 LOG(logINFO) <<
"pXar: this is the end, my friend";
336 void runGui(
PixSetup &a,
int ,
char ** ) {
338 TApplication theApp(
"App", 0, 0);
339 theApp.SetReturnFromRun(
true);
340 PixGui gui(gClient->GetRoot(), 1300, 800, &a);
342 LOG(logINFO) <<
"closing down 0 ";
347 void createBackup(
string rootfile,
string logfile) {
349 Long_t id, flags, modtime;
352 string nrootfile(rootfile), nlogfile(logfile);
353 const char *path = rootfile.c_str();
354 int result = gSystem->GetPathInfo(path, &
id, &size, &flags, &modtime);
355 if (1 == result)
return;
358 string tstamp = Form(
"_%d%02d%02d_%02d%02d%02d", d.GetYear(), d.GetMonth(), d.GetDay(), d.GetHour(), d.GetMinute(), d.GetSecond());
362 LOG(logINFO) <<
"creating backup files for previous run: " << nrootfile <<
" and " << nlogfile;
363 if (!gSystem->AccessPathName(rootfile.c_str())) gSystem->Rename(rootfile.c_str(), nrootfile.c_str());
364 if (!gSystem->AccessPathName(logfile.c_str())) gSystem->Rename(logfile.c_str(), nlogfile.c_str());
static void replaceAll(std::string &str, const std::string &from, const std::string &to)
in str, replace all occurences of from to to
virtual void runCommand(std::string command)
allow execution of any button in the test
virtual void doTest()
function connected to "DoTest" button of PixTab