pxar
 All Classes Namespaces Functions Variables Typedefs Friends
PixTestPattern.cc
1 // to send different patterns and check the readout
2 
3 #include <stdlib.h> // atof, atoi
4 #include <algorithm> // std::find
5 #include <fstream>
6 #include <iostream>
7 #include <sstream>
8 #include <string>
9 
10 #include "PixTestPattern.hh"
11 
12 #include "log.h"
13 #include "constants.h"
14 #include "helper.h"
15 #include "timer.h"
16 
17 using namespace std;
18 using namespace pxar;
19 
20 ClassImp(PixTestPattern)
21 
22 //------------------------------------------------------------------------------
23 PixTestPattern::PixTestPattern(PixSetup *a, std::string name) : PixTest(a, name), fParPgCycles(0), fParTrigLoop(0), fParPeriod(0), fParSeconds(0), fPatternFromFile(0), fResultsOnFile(1), fBinOut(0), fInputFile("null"), fOutputFile("null"), fUnMaskAll(0), fExtClk(0), fParFillTree(0){
24  PixTest::init();
25  init();
26  LOG(logDEBUG) << "PixTestPattern ctor(PixSetup &a, string, TGTab *)";
27 }
28 
29 //------------------------------------------------------------------------------
30 PixTestPattern::PixTestPattern() : PixTest(){ //ctor
31 }
32 
33 //------------------------------------------------------------------------------
34 bool PixTestPattern::setParameter(string parName, string sval)
35 {
36  bool found(false);
37  fParOutOfRange = false;
38  std::transform(parName.begin(), parName.end(), parName.begin(), ::tolower);
39  for (unsigned int i = 0; i < fParameters.size(); ++i)
40  {
41  if (fParameters[i].first == parName)
42  {
43  found = true;
44  sval.erase(remove(sval.begin(), sval.end(), ' '), sval.end());
45 
46  if (!parName.compare("pgcycles")){
47  fParPgCycles = atoi(sval.c_str());
48  setToolTips();
49  if (fParPgCycles < 0) {
50  LOG(logWARNING) << "PixTestPattern::setParameter() pg_cycles must be positive";
51  found = false; fParOutOfRange = true;
52  }
53  }
54 
55  if (!parName.compare("triggerloop")) {
56  PixUtil::replaceAll(sval, "checkbox(", "");
57  PixUtil::replaceAll(sval, ")", "");
58  fParTrigLoop = atoi(sval.c_str());
59  setToolTips();
60  }
61 
62  if (!parName.compare("period")){
63  fParPeriod = atoi(sval.c_str());
64  setToolTips();
65  if (fParPeriod < 0) {
66  LOG(logWARNING) << "PixTestPattern::setParameter() period must be positive";
67  found = false; fParOutOfRange = true;
68  }
69  }
70 
71  if (!parName.compare("seconds")){
72  fParSeconds = atoi(sval.c_str());
73  setToolTips();
74  if (fParSeconds < 0) {
75  LOG(logWARNING) << "PixTestPattern::setParameter() seconds must be positive";
76  found = false; fParOutOfRange = true;
77  }
78  }
79 
80  if (!parName.compare("patternfromfile")) {
81  PixUtil::replaceAll(sval, "checkbox(", "");
82  PixUtil::replaceAll(sval, ")", "");
83  fPatternFromFile = atoi(sval.c_str());
84  setToolTips();
85  }
86 
87  if (!parName.compare("resultsonfile")){
88  PixUtil::replaceAll(sval, "checkbox(", "");
89  PixUtil::replaceAll(sval, ")", "");
90  fResultsOnFile = atoi(sval.c_str());
91  setToolTips();
92  }
93 
94  if (!parName.compare("binaryoutput")){
95  PixUtil::replaceAll(sval, "checkbox(", "");
96  PixUtil::replaceAll(sval, ")", "");
97  fBinOut = atoi(sval.c_str());
98  setToolTips();
99  }
100 
101  if (!parName.compare("inputfile")){
102  fInputFile = sval.c_str();
103  setToolTips();
104  }
105 
106  if (!parName.compare("outputfile")){
107  fOutputFile = sval.c_str();
108  setToolTips();
109  }
110 
111  if (!parName.compare("unmaskall")){
112  PixUtil::replaceAll(sval, "checkbox(", "");
113  PixUtil::replaceAll(sval, ")", "");
114  fUnMaskAll = atoi(sval.c_str());
115  setToolTips();
116  }
117 
118  if (!parName.compare("externalclk")){
119  PixUtil::replaceAll(sval, "checkbox(", "");
120  PixUtil::replaceAll(sval, ")", "");
121  fExtClk = atoi(sval.c_str());
122  setToolTips();
123  }
124 
125  if (!parName.compare("filltree")) {
126  PixUtil::replaceAll(sval, "checkbox(", "");
127  PixUtil::replaceAll(sval, ")", "");
128  fParFillTree = !(atoi(sval.c_str()) == 0);
129  setToolTips();
130  }
131 
132  break;
133  }
134  }
135  return found;
136 }
137 
138 //------------------------------------------------------------------------------
139 void PixTestPattern::init()
140 {
141  LOG(logDEBUG) << "PixTestPattern::init()";
142  setToolTips();
143  fDirectory = gFile->GetDirectory(fName.c_str());
144  if (!fDirectory)
145  fDirectory = gFile->mkdir(fName.c_str());
146  fDirectory->cd();
147  fTree = 0;
148 }
149 
150 // ----------------------------------------------------------------------
152 
153  fTestTip = string("run DAQ");
154  fSummaryTip = string("Show summary plot");
155  fStopTip = string("Stop DAQ");
156 }
157 
158 //------------------------------------------------------------------------------
159 PixTestPattern::~PixTestPattern(){ //dctor
160  fDirectory->cd();
161  if (fTree && fParFillTree) fTree->Write();
162 }
163 
164 // ----------------------------------------------------------------------
165 void PixTestPattern::stop()
166 {
167  // Interrupt the test
168  fDaq_loop = false;
169  LOG(logINFO) << "PixTestPattern:: STOP PRESSED. Ending test.";
170 }
171 
172 // ----------------------------------------------------------------------
173 void PixTestPattern::runCommand(std::string command) {
174  std::transform(command.begin(), command.end(), command.begin(), ::tolower);
175  LOG(logDEBUG) << "running command: " << command;
176 
177  if (!command.compare("resettodefault")) {
178  LOG(logINFO) << "PixTestPattern:: reset parameters from testParameters.dat";
179  for (unsigned int i = 0; i < fParameters.size(); ++i)
180  setParameter(fParameters[i].first, fParameters[i].second);
181  return;
182  }
183 
184  else if (!command.compare("stop")){
185  stop();
186  }
187 
188  else LOG(logDEBUG) << "did not find command ->" << command << "<-";
189 }
190 
191 // ----------------------------------------------------------------------
192 bool PixTestPattern::setPattern(string fname) {
193 
194  ifstream is(fname.c_str());
195  if (!is.is_open()) {
196  LOG(logWARNING) << "PixTestPattern::setPattern() cannot read " << fname;
197  return false;
198  }
199 
200  bool patternFound(false);
201  string line;
202 
203  while (is.good())
204  {
205  getline(is, line);
206 
207  // -- find Pattern section
208  if (string::npos != line.find("-- Pattern")){
209  patternFound = true;
210  continue;
211  }
212 
213  if (string::npos != line.find("-- Test Pixels")) break;
214 
215  if (patternFound)
216  {
217  std::string::size_type sep;
218  std::string sig, str;
219  int val(0);
220 
221  // -- remove tabs, adjacent spaces, leading and trailing spaces
222  PixUtil::replaceAll(line, "\t", " ");
223  string::iterator new_end = unique(line.begin(), line.end(), PixUtil::bothAreSpaces);
224  line.erase(new_end, line.end());
225  if (line.length() < 2) continue;
226 
227  sep = line.find(",");
228 
229  if (string::npos != sep)
230  {
231  sig = line.substr(0, sep - 1);
232  str = line.substr(sep + 1);
233  val = atoi(str.c_str());
234 
235  //check if delay stays within 8bit
236  if (val < 0 || val > 255) {
237  LOG(logWARNING) << "PixTestPattern::setPattern() delay out of range [0,255]";
238  return false;
239  }
240  uint8_t del = val;
241  fPg_setup.push_back(make_pair(sig, del));
242  LOG(logDEBUG) << " pg set to -> \"" << sig << "\" " << del;
243  }
244 
245  else
246  {
247  fPg_setup.push_back(make_pair("", 0));
248  LOG(logWARNING) << "PixTestPattern::setPattern() wrong ... "; //DEBUG
249  }
250  }
251 
252  }
253 
254  if (!patternFound){
255  LOG(logWARNING) << "PixTestPattern::setPattern() '-- Pattern' not found in testPattern.dat";
256  fPg_setup.push_back(make_pair("", 0));
257  return false;
258  }
259 
260  return true;
261 }
262 
263 // ----------------------------------------------------------------------
264 bool PixTestPattern::setPixels(string fname, string flag) {
265 
266  int npix = 0;
267  std::stringstream sstr;
268 
269  ifstream is(fname.c_str());
270  if (!is.is_open()) {
271  LOG(logWARNING) << "PixTestPattern::setPixels() cannot read " << fname;
272  return false;
273  }
274 
275  bool pixelFound(false);
276  string line;
277 
278  while (is.good())
279  {
280  getline(is, line);
281 
282  if (flag == "Test")
283  {
284  // -- find Test Pixels section
285  if (string::npos != line.find("-- Test Pixels")) {
286  pixelFound = true;
287  continue;
288  }
289 
290  if (string::npos != line.find("-- Unmask Pixels")) break;
291  }
292  else
293  {
294  // -- find Unmask Pixels section
295  if (string::npos != line.find("-- Unmask Pixels")) {
296  pixelFound = true;
297  continue;
298  }
299  }
300 
301  if (pixelFound)
302  {
303  int pixc, pixr;
304  std::string::size_type s0, s1;
305  std::string str1, str2;
306 
307  // -- remove tabs, adjacent spaces, leading and trailing spaces
308  PixUtil::replaceAll(line, "\t", " ");
309  string::iterator new_end = unique(line.begin(), line.end(), PixUtil::bothAreSpaces);
310  line.erase(new_end, line.end());
311  if (line.length() < 2) continue;
312 
313  s0 = line.find(" ");
314  s1 = line.find(",");
315  if (string::npos != s1)
316  {
317  str1 = line.substr(s0, s1);
318  pixc = atoi(str1.c_str());
319  str2 = line.substr(s1 + 1);
320  pixr = atoi(str2.c_str());
321  if (flag == "Test") fPIX.push_back(make_pair(pixc, pixr));
322  else fPIXm.push_back(make_pair(pixc, pixr));
323  sstr << " (" << pixc << "," << pixr << ")";
324  npix++;
325  }
326  else
327  {
328  fPIX.push_back(make_pair(-1, -1));
329  fPIXm.push_back(make_pair(-1, -1));
330  cout << "(null)";
331  }
332  }
333  }
334 
335  if (!pixelFound)
336  {
337  if (flag == "Test") {
338  LOG(logWARNING) << "PixTestPattern::setPixels() '-- Test Pixels' not found in testPattern.dat";
339  fPIX.push_back(make_pair(-1, -1));
340  }
341  else {
342  LOG(logWARNING) << "PixTestPattern::setPixels() '-- Unmask Pixels' not found in testPattern.dat";
343  fPIXm.push_back(make_pair(-1, -1));
344  }
345  return false;
346  }
347 
348  if (flag == "Test") {
349  LOG(logINFO) << "PixTestPattern:: " << npix << " 'armed' pixels:" << sstr.str();
350  fNpix = npix;
351  }
352  else LOG(logINFO) << "PixTestPattern:: " << npix << " unmasked pixels:" << sstr.str();
353  sstr.clear();
354 
355  return true;
356 }
357 
358 // ----------------------------------------------------------------------
359 void PixTestPattern::FillHistos(std::vector<pxar::Event> data, std::vector<TH2D*> hits, std::vector<TProfile2D*> phmap, std::vector<TH1D*> ph) {
360  std::vector<uint8_t> rocIds = fApi->_dut->getEnabledRocIDs();
361  int idx(-1);
362 
363  for (std::vector<pxar::Event>::iterator it = data.begin(); it != data.end(); ++it) {
364 
365  if (fParFillTree) {
366  fTreeEvent.header = it->header;
367  fTreeEvent.dac = 0;
368  fTreeEvent.trailer = it->trailer;
369  fTreeEvent.npix = it->pixels.size();
370  }
371  for (unsigned int ipix = 0; ipix < it->pixels.size(); ++ipix) {
372  idx = getIdxFromId(it->pixels[ipix].roc()) ;
373  if(idx == -1) {
374  LOG(logWARNING) << "PixTestPattern::FillHistos() wrong 'idx' value --> return";
375  return;
376  }
377  hits[idx]->Fill(it->pixels[ipix].column(), it->pixels[ipix].row());
378  phmap[idx]->Fill(it->pixels[ipix].column(), it->pixels[ipix].row(), it->pixels[ipix].value());
379  ph[idx]->Fill(it->pixels[ipix].value());
380  if (fParFillTree) {
381  fTreeEvent.proc[ipix] = it->pixels[ipix].roc();
382  fTreeEvent.pcol[ipix] = it->pixels[ipix].column();
383  fTreeEvent.prow[ipix] = it->pixels[ipix].row();
384  fTreeEvent.pval[ipix] = it->pixels[ipix].value();
385  fTreeEvent.pq[ipix] = 0; //no charge..
386  }
387  }
388  if (fParFillTree) fTree->Fill();
389  }
390  //to draw the hitsmap as 'online' check.
391  TH2D* h2 = (TH2D*)(hits.back());
392  h2->Draw(getHistOption(h2).c_str());
393  PixTest::update();
394 }
395 
396 // ----------------------------------------------------------------------
397 void PixTestPattern::PrintEvents(int par1, int par2, string flag, std::vector<TH2D*> hits, std::vector<TProfile2D*> phmap, std::vector<TH1D*> ph) {
398 
399  std::vector<pxar::Event> daqEvBuffer;
400  size_t daqEvBuffsiz;
401 
402  if (!fResultsOnFile)
403  {
404  daqEvBuffer = fApi->daqGetEventBuffer();
405  daqEvBuffsiz = daqEvBuffer.size();
406 
407  FillHistos(daqEvBuffer, hits, phmap, ph); //fill&print histos on the gui
408 
409  if (daqEvBuffsiz <= 201) {
410  LOG(logINFO) << "PixTestPattern:: data from buffer:";
411  cout << endl;
412  for (unsigned int i = 0; i < daqEvBuffsiz; i++) {
413  cout << i << " : " << daqEvBuffer[i] << endl;
414  }
415  cout << endl;
416  }
417  else {
418  cout << endl;
419  LOG(logINFO) << "PixTestPattern:: data from buffer:";
420  for (unsigned int i = 0; i <= 100; i++) {
421  cout << i << " : " << daqEvBuffer[i] << endl;
422  }
423  //skip events. If you want all the events printed select 'binaryoutput'.
424  cout << endl << "................... SKIP EVENTS TO NOT SATURATE THE SHELL ...................." << endl << endl;
425  for (unsigned int i = (daqEvBuffsiz - 100); i < daqEvBuffsiz; i++) {
426  cout << i << " : " << daqEvBuffer[i] << endl;
427  }
428  cout << endl;
429  }
430  LOG(logINFO) << "PixTestPattern:: " << daqEvBuffsiz << " events read from buffer";
431  cout << endl;
432  }
433 
434  else
435  {
436  LOG(logINFO) << "PixTestPattern:: Start reading data from DTB RAM";
437  std::stringstream sstr, sdata;
438  string FileName;
439  if (flag == "trg") sstr << "_" << par1 << "pgCycles";
440  else sstr << "_" << par1 << "sec" << "_" << par2;
441  if (fBinOut) FileName = f_Directory + "/" + fOutputFile.c_str() + sstr.str() + ".bin";
442  else FileName = f_Directory + "/" + fOutputFile.c_str() + sstr.str() + ".dat";
443 
444 
445  if (fBinOut)
446  {
447  std::vector<uint16_t> daqdat = fApi->daqGetBuffer();
448  if (daqdat.size() > 550000) sdata << (daqdat.size() / 524288) << "MB";
449  else sdata << (daqdat.size() / 512) << "kB";
450  LOG(logINFO) << "PixTestPattern:: " << daqdat.size() << " words of data read : " << sdata.str();
451  std::ofstream fout(FileName.c_str(), std::ios::out | std::ios::binary);
452  LOG(logINFO) << "PixTestPattern:: Writing binary";
453  fout.write(reinterpret_cast<const char*>(&daqdat[0]), sizeof(daqdat[0])*daqdat.size());
454  fout.close();
455  }
456 
457  else
458  {
459  daqEvBuffer = fApi->daqGetEventBuffer();
460  daqEvBuffsiz = daqEvBuffer.size();
461  LOG(logINFO) << "PixTestPattern:: " << daqEvBuffsiz << " events read";
462 
463  FillHistos(daqEvBuffer, hits, phmap, ph); //fill&print histos on the gui
464 
465  std::ofstream fout(FileName.c_str(), std::ofstream::out);
466  if (daqEvBuffsiz <= 201) {
467  LOG(logINFO) << "PixTestPattern:: Writing decoded events";
468  for (unsigned int i = 0; i < daqEvBuffsiz; ++i) {
469  fout << i << " : " << daqEvBuffer[i] << endl;
470  }
471  }
472  else {
473  LOG(logINFO) << "PixTestPattern:: Writing decoded events (a fraction of)";
474  for (unsigned int i = 0; i <= 100; i++) {
475  fout << i << " : " << daqEvBuffer[i] << endl;
476  }
477  //skip events. If you want all the events printed select 'binaryoutput'.
478  fout << endl << "................... SKIP EVENTS TO NOT TAKE TOO LONG ...................." << endl << endl;
479  for (unsigned int i = (daqEvBuffsiz - 100); i < daqEvBuffsiz; i++) {
480  fout << i << " : " << daqEvBuffer[i] << endl;
481  }
482  }
483  fout.close();
484  }
485 
486  LOG(logINFO) << "PixTestPattern:: Wrote data to " << FileName.c_str();
487  cout << endl;
488  FileName.clear();
489  }
490 
491 }
492 
493 // ----------------------------------------------------------------------
494 void PixTestPattern::TriggerLoop(int checkfreq, std::vector<TH2D*> hits, std::vector<TProfile2D*> phmap, std::vector<TH1D*> ph) {
495 
496  uint8_t perFull;
497  int nloop = 1;
498  uint64_t diff = 0, timepaused = 0, timeff = 0;
499  bool TotalTime = false;
500  timer t;
501  LOG(logINFO) << "PixTestPattern:: starting TriggerLoop for " << fParSeconds << " seconds";
502 
503  while (fDaq_loop)
504  {
505  if (nloop > 1){
506  diff = t.get() - diff;
507  timepaused += diff;
508  LOG(logDEBUG) << "PixTestPattern:: readout time " << timepaused / 1000 << " seconds";
509  LOG(logINFO) << "PixTestPattern:: restarting TriggerLoop for " << fParSeconds - (timeff / 1000) << " s";
510  }
511  //start triggerloop:
512  fPeriod = fApi->daqTriggerLoop(fParPeriod);
513  if (nloop == 1) { LOG(logINFO) << "PixTestPattern:: TriggerLoop period = " << fPeriod << " clks"; }
514 
515  //check every checkfreq seconds if buffer is full less then 80%:
516  while (fApi->daqStatus(perFull) && perFull < 80 && fDaq_loop) {
517  mDelay(checkfreq * 1000);
518  timeff = t.get() - timepaused;
519  LOG(logINFO) << "PixTestPattern:: elapsed time " << timeff / 1000 << " seconds";
520  if (timeff / 1000 >= (uint64_t)fParSeconds) {
521  fDaq_loop = false;
522  TotalTime = true;
523  break;
524  }
525  LOG(logINFO) << "PixTestPattern:: buffer not full, at " << (int)perFull << "%";
526  gSystem->ProcessEvents();
527  }
528 
529  if (fDaq_loop) {
530  LOG(logINFO) << "PixTestPattern:: buffer almost full, pausing triggers";
532  diff = t.get();
533  }
534  else {
535  if (TotalTime) { LOG(logINFO) << "PixTestPattern:: total time reached - DAQ stopped."; }
536  fApi->daqStop();
537  }
538  // Get events and Print results on shell/file:
539  PrintEvents(fParSeconds, nloop, "loop", hits, phmap, ph);
540  nloop++;
541  }
542 }
543 
544 // ----------------------------------------------------------------------
545 void PixTestPattern::pgToDefault() {
546  fPg_setup.clear();
547  fPg_setup = fPixSetup->getConfigParameters()->getTbPgSettings();
548  fApi->setPatternGenerator(fPg_setup);
549  LOG(logINFO) << "PixTestPattern:: pg_setup set to default";
550 }
551 
552 // ----------------------------------------------------------------------
553 void PixTestPattern::FinalCleaning() {
554  // Reset the pg_setup to default value.
555  pgToDefault();
556 
557  //clean local variables:
558  fPIX.clear();
559  fPIXm.clear();
560  fPg_setup.clear();
561 }
562 
563 //------------------------------------------------------------------------------
565 {
566  fDirectory->cd();
567  fPg_setup.clear();
568  PixTest::update();
569  fNpix = 0;
570 
571  //setparameters and check if in range
572  if (fParOutOfRange) return;
573 
574  LOG(logINFO) << "PixTestPattern::doTest() start";
575 
576  //set the input filename (for Pattern and Pixels)
577  string fname;
578  ConfigParameters* config = ConfigParameters::Singleton();
579  f_Directory = config->getDirectory();
580  fname = f_Directory + "/" + fInputFile + ".dat";
581 
582  // to unmask all or only selected pixels:
583  if (fUnMaskAll) {
584  fApi->_dut->maskAllPixels(false);
585  LOG(logINFO) << "PixTestPattern:: all pixels unmasked";
586  }
587  else {
588 
589  fApi->_dut->maskAllPixels(true);
590  if (!setPixels(fname, "Unmask")){ //READ FROM FILE
591  FinalCleaning();
592  return;
593  }
594  for (unsigned int i = 0; i < fPIXm.size(); ++i) {
595  if (fPIXm[i].first > -1) fApi->_dut->maskPixel(fPIXm[i].first, fPIXm[i].second, false);
596  }
597  }
598 
599  // to 'arm' only selected pixels:
600  fPIX.clear();
601  if (!setPixels(fname, "Test")){ //READ FROM FILE
602  FinalCleaning();
603  return;
604  }
605  fApi->_dut->testAllPixels(false);
606  for (unsigned int i = 0; i < fPIX.size(); ++i) {
607  if (fPIX[i].first > -1) {
608  fApi->_dut->testPixel(fPIX[i].first, fPIX[i].second, true);
609  fApi->_dut->maskPixel(fPIX[i].first, fPIX[i].second, false);
610  }
611  else {
612  fApi->_dut->maskPixel(fPIX[i].first, fPIX[i].second, true);
613  }
614  }
615 
616  //set the histos
617  std::vector<TH2D*> Hits;
618  std::vector<TProfile2D*> Phmap;
619  std::vector<TH1D*> Ph;
620  TH2D* h2;
621  TProfile2D* p2;
622  TH1D* h1;
623  if (fParFillTree) bookTree();
624  std::vector<uint8_t> rocIds = fApi->_dut->getEnabledRocIDs();
625  //set histos name according to input parameters:
626  std::stringstream strs;
627  strs << "_" << fNpix << "pix";
628  if (!fParTrigLoop) strs << "_" << fParPgCycles << "cyc";
629  else strs << "_" << fParSeconds << "sec";
630  if (!fPatternFromFile) strs << "_stdPG";
631  string histname = strs.str();
632 
633  for (unsigned int iroc = 0; iroc < rocIds.size(); ++iroc){
634  h2 = bookTH2D(Form("hits_C%d%s", rocIds[iroc], histname.c_str()), Form("hits_C%d%s", rocIds[iroc], histname.c_str()), 52, 0., 52., 80, 0., 80.);
635  h2->SetMinimum(0.);
636  h2->SetDirectory(fDirectory);
637  setTitles(h2, "col", "row");
638  fHistOptions.insert(make_pair(h2, "colz"));
639  Hits.push_back(h2);
640 
641  p2 = bookTProfile2D(Form("phMap_C%d%s", rocIds[iroc], histname.c_str()), Form("phMap_C%d%s", rocIds[iroc], histname.c_str()), 52, 0., 52., 80, 0., 80.);
642  p2 ->SetMinimum(0.);
643  p2->SetDirectory(fDirectory);
644  setTitles(p2, "col", "row");
645  fHistOptions.insert(make_pair(p2, "colz"));
646  Phmap.push_back(p2);
647 
648  h1 = bookTH1D(Form("ph_C%d%s", rocIds[iroc], histname.c_str()), Form("ph_C%d%s", rocIds[iroc], histname.c_str()), 256, 0., 256.);
649  h1->SetMinimum(0.);
650  h1->SetDirectory(fDirectory);
651  setTitles(h1, "ADC", "Entries/bin");
652  Ph.push_back(h1);
653  }
654 
655  // Select external clock (from input parameter)
656  if (fExtClk){
657  LOG(logINFO) << "PixTestPattern:: Setting CLK to external";
658  fApi->setExternalClock(false); //toggle needed (FW issue?)
659  fApi->setExternalClock(true);
660  }
661  else {
662  fApi->setExternalClock(true);
663  fApi->setExternalClock(false);
664  }
665 
666  // Start the DAQ:
667  //::::::::::::::::::::::::::::::::
668 
669  //first send only a RES:
670  fPg_setup.push_back(make_pair("resetroc", 0));
671  fPeriod = 28;
672 
673  // Set the pattern generator:
674  fApi->setPatternGenerator(fPg_setup);
675 
676  fApi->daqStart();
677 
678  // Send only one trigger to reset:
679  fApi->daqTrigger(1, fPeriod);
680  LOG(logINFO) << "PixTestPattern:: RES sent once ";
681 
682  fPg_setup.clear();
683  LOG(logINFO) << "PixTestPattern:: pg_setup clean";
684 
685  //select the pattern:
686  if (fPatternFromFile)
687  {
688  LOG(logINFO) << "PixTestPattern:: Set pattern from file: " << fname;
689  if (!setPattern(fname)){ //READ FROM FILE
690  fApi->daqStop();
691  FinalCleaning();
692  return;
693  }
694  }
695  else { //standard pattern from config parameters.
696  fPg_setup = fPixSetup->getConfigParameters()->getTbPgSettings();
697  }
698 
699  //set pattern generator:
700  fApi->setPatternGenerator(fPg_setup);
701  fPeriod = 0;
702 
703  //send Triggers (loop or single) wrt parameters selection:
704  if (!fParTrigLoop) {
705  //pg_cycles times the pg_Single() == pg_cycles times pattern sequence):
706  fPeriod = fApi->daqTrigger(fParPgCycles, fParPeriod);
707  LOG(logINFO) << "PixTestPattern:: " << fParPgCycles << " pg_Single() sent with period " << fPeriod;
708 
709  fApi->daqStop();
710 
711  // Get events and Print results on shell/file:
712  PrintEvents(fParPgCycles, 0, "trg", Hits, Phmap, Ph);
713  }
714  else {
715  fDaq_loop = true;
716  TriggerLoop(2, Hits, Phmap, Ph); //first argument == buffer check frequency (seconds)
717  }
718 
719  //::::::::::::::::::::::::::::::
720  //DAQ - THE END.
721 
722  //to draw and save histograms
723  copy(Ph.begin(), Ph.end(), back_inserter(fHistList));
724  copy(Phmap.begin(), Phmap.end(), back_inserter(fHistList));
725  copy(Hits.begin(), Hits.end(), back_inserter(fHistList));
726  for (list<TH1*>::iterator il = fHistList.begin(); il != fHistList.end(); ++il) {
727  (*il)->Draw((getHistOption(*il)).c_str());
728  }
729  fDisplayedHist = find(fHistList.begin(), fHistList.end(), p2);
730  fDisplayedHist = find(fHistList.begin(), fHistList.end(), h1);
731  fDisplayedHist = find(fHistList.begin(), fHistList.end(), h2);
732  PixTest::update();
733 
734  //set PG to default and clean everything:
735  FinalCleaning();
736  LOG(logINFO) << "PixTestPattern::doTest() done for.";
737 }
static void replaceAll(std::string &str, const std::string &from, const std::string &to)
in str, replace all occurences of from to to
Definition: PixUtil.cc:24
bool setExternalClock(bool enable)
Definition: api.cc:2188
void setPatternGenerator(std::vector< std::pair< std::string, uint8_t > > pg_setup)
Definition: api.cc:78
bool daqStart()
Definition: api.cc:1139
std::map< TH1 *, std::string > fHistOptions
options can be stored with each histogram
Definition: PixTest.hh:308
void daqTriggerLoopHalt()
Definition: api.cc:1257
std::string fStopTip
information for this test
Definition: PixTest.hh:300
PixSetup * fPixSetup
all necessary stuff in one place
Definition: PixTest.hh:290
std::vector< std::pair< int, int > > fPIX
range of enabled pixels for time-consuming tests
Definition: PixTest.hh:311
static bool bothAreSpaces(char lhs, char rhs)
what would you expect?
Definition: PixUtil.cc:79
void testPixel(uint8_t column, uint8_t row, bool enable)
Definition: dut.cc:432
std::vector< std::pair< std::string, std::string > > fParameters
the parameters of this test
Definition: PixTest.hh:302
int getIdxFromId(int id)
provide the mapping between ROC index and ID
Definition: PixTest.cc:1124
void maskAllPixels(bool mask, uint8_t rocid)
Definition: dut.cc:481
TDirectory * fDirectory
where the root histograms will end up
Definition: PixTest.hh:306
uint16_t daqTriggerLoop(uint16_t period=1000)
Definition: api.cc:1239
void bookTree()
book a minimal tree with pixel events
Definition: PixTest.cc:99
dut * _dut
Definition: api.h:728
std::vector< uint8_t > getEnabledRocIDs()
Definition: dut.cc:214
void testAllPixels(bool enable)
Definition: dut.cc:503
bool daqStop()
Definition: api.cc:1324
std::list< TH1 * >::iterator fDisplayedHist
pointer to the histogram currently displayed
Definition: PixTest.hh:309
void setToolTips()
implement this to provide updated tool tips if the user changes test parameters
TH1D * bookTH1D(std::string sname, std::string title, int nbins, double xmin, double xmax)
book a TH1D, adding version information to the name and title
Definition: PixTest.cc:895
virtual std::string getHistOption(TH1 *)
get the hist display options (if stored in fHistOptions)
Definition: PixTest.cc:941
void runCommand(std::string)
allow execution of any button in the test
std::vector< uint16_t > daqGetBuffer()
Definition: api.cc:1263
std::list< TH1 * > fHistList
list of histograms available in PixTab::next and PixTab::previous
Definition: PixTest.hh:307
void setTitles(TH1 *h, const char *sx, const char *sy, float size=0.05, float xoff=1.1, float yoff=1.1, float lsize=0.05, int font=42)
utility to set histogram titles
Definition: PixTest.cc:649
void doTest()
function connected to "DoTest" button of PixTab
TH2D * bookTH2D(std::string sname, std::string title, int nbinsx, double xmin, double xmax, int nbinsy, double ymin, double max)
book a TH2D, adding version information to the name and title
Definition: PixTest.cc:903
void maskPixel(uint8_t column, uint8_t row, bool mask)
Definition: dut.cc:397
virtual bool setParameter(std::string parName, std::string sval)
set the string value of a parameter
void update()
signal to PixTab to update the canvas
Definition: PixTest.cc:569
pxar::pxarCore * fApi
pointer to the API
Definition: PixTest.hh:289
std::vector< Event > daqGetEventBuffer()
Definition: api.cc:1285
TProfile2D * bookTProfile2D(std::string sname, std::string title, int nbinsx, double xmin, double xmax, int nbinsy, double ymin, double max, std::string option="")
book a TProfile2D, adding version information to the name and title
Definition: PixTest.cc:911
uint16_t daqTrigger(uint32_t nTrig=1, uint16_t period=0)
Definition: api.cc:1222
void init()
sets all test parameters
Definition: PixTest.cc:62
bool daqStatus()
Definition: api.cc:1191
void mDelay(uint32_t ms)
Definition: helper.h:40