pxar
 All Classes Namespaces Functions Variables Typedefs Friends
PixTestBareModule.cc
1 #include <stdlib.h> /* atof, atoi */
2 #include <algorithm> // std::find
3 #include <iostream>
4 #include <TSystem.h>
5 #include "PixUtil.hh"
6 #include "PixTestFactory.hh"
7 #include "PixTestBareModule.hh"
8 
9 #include "log.h"
10 #include "helper.h"
11 #include <TH2.h>
12 
13 using namespace std;
14 using namespace pxar;
15 
16 ClassImp(PixTestBareModule)
17 
18 // ----------------------------------------------------------------------
19 PixTestBareModule::PixTestBareModule(PixSetup *a, std::string name) : PixTest(a, name), fParMaxSteps(1), fStop(false), fBBMap(false), fBB2Map(false), fminIa(10.){
20  PixTest::init();
21  init();
22  LOG(logDEBUG) << "PixTestBareModule ctor(PixSetup &a, string, TGTab *)";
23 }
24 
25 
26 //----------------------------------------------------------
27 PixTestBareModule::PixTestBareModule() : PixTest() {
28  LOG(logDEBUG) << "PixTestBareModule ctor()";
29 }
30 
31 // ----------------------------------------------------------------------
32 bool PixTestBareModule::setParameter(string parName, string sval) { //debug - add roc num
33  bool found(false);
34  string stripParName;
35  for (unsigned int i = 0; i < fParameters.size(); ++i) {
36  if (fParameters[i].first == parName) {
37  found = true;
38  if (!parName.compare("stepmax(1-3)")) {
39  fParMaxSteps = atoi(sval.c_str());
40  LOG(logDEBUG) << " setting fParNSteps -> " << fParMaxSteps;
41  setToolTips();
42  }
43  if (!parName.compare("bbmap")) {
44  PixUtil::replaceAll(sval, "checkbox(", "");
45  PixUtil::replaceAll(sval, ")", "");
46  fBBMap = atoi(sval.c_str());
47  setToolTips();
48  }
49  if (!parName.compare("bb2map(desy)")) {
50  PixUtil::replaceAll(sval, "checkbox(", "");
51  PixUtil::replaceAll(sval, ")", "");
52  fBB2Map = atoi(sval.c_str());
53  setToolTips();
54  }
55  if (!parName.compare("mincurrent(ma)")) {
56  PixUtil::replaceAll(sval, "checkbox(", "");
57  PixUtil::replaceAll(sval, ")", "");
58  fminIa = atof(sval.c_str());
59  setToolTips();
60  }
61  break;
62  }
63  }
64  return found;
65 }
66 
67 
68 // ----------------------------------------------------------------------
69 void PixTestBareModule::init() {
70  LOG(logDEBUG) << "PixTestBareModule::init()";
71  setToolTips();
72  fDirectory = gFile->GetDirectory(fName.c_str());
73  if (!fDirectory) {
74  fDirectory = gFile->mkdir(fName.c_str());
75  }
76  fDirectory->cd();
77 }
78 
79 // ----------------------------------------------------------------------
81  fTestTip = string("run the test sequence for one ROC up to 'stepmax'.\n")
82  + string("stepmax: 1=pretest, 2=alive, 3=BB.");
83  fSummaryTip = string("to be implemented");
84  fStopTip = string("stop the BareModuleTest after that \n")
85  + string("the current step is finished.");
86 }
87 
88 
89 // ----------------------------------------------------------------------
90 void PixTestBareModule::bookHist(string name) {
91  LOG(logDEBUG) << "nothing done with " << name;
92  fDirectory->cd();
93 }
94 
95 //----------------------------------------------------------
96 PixTestBareModule::~PixTestBareModule() {
97  LOG(logDEBUG) << "PixTestBareModule dtor";
98 }
99 
100 // ----------------------------------------------------------------------
101 void PixTestBareModule::runCommand(std::string command) {
102  std::transform(command.begin(), command.end(), command.begin(), ::tolower);
103  LOG(logDEBUG) << "running command: " << command;
104 
105  if (!command.compare("stop")){ // Interrupt the test
106  fStop = true;
107  LOG(logINFO) << "PixTestBareModule:: STOP PRESSED. Ending test.";
108  }
109  else if (!command.compare("checkcontact")) {
110  checkIfInContact(0);
111  mDelay(1000);
112  PixTest::update();
113 
114  PixTest::hvOff();
115  mDelay(2000);
117  mDelay(1000);
118  PixTest::update();
119 
120  LOG(logINFO) << "PixTestBareModule:: HV and Power are off.";
121  }
122  else if (!command.compare("dofullsequence")) {
123  fParMaxSteps = 3;
124  doTest();
125  }
126  else
127  LOG(logINFO) << "Command " << command << " not implemented.";
128 }
129 
130 // ----------------------------------------------------------------------
131 bool PixTestBareModule::checkIfInContact(bool fullSeq) {
132 
133  PixTest::hvOff();
134  LOG(logINFO) << "PixTestBareModule:: HV off for safety.";
135  mDelay(2000);
136 
137  //check if probes are in contact
138  LOG(logINFO) << "PixTestBareModule:: checking if probes are in contact.";
140  LOG(logINFO) << "PixTestBareModule:: Power on.";
141  mDelay(1000);
142  double ia = fApi->getTBia()*1E3; // [mA]
143  bool checkgood = false;
144 
145  if (ia > fminIa) {
146  LOG(logINFO) << "PixTestBareModule:: contact OK, ia = " << ia << " mA";
147  checkgood = true;
148  }
149  else {
150  LOG(logWARNING) << "PixTestBareModule:: ia < " << fminIa << " mA - PLEASE CHECK THE PROBES CONTACT.";
151  if (fullSeq){
152  LOG(logWARNING) << "PixTestBareModule:: enter 'c' to continue OR 's' to stop.";
153  bool goodIn = false;
154  do{
155  string input;
156  std::getline(cin, input);
157  string::size_type m1 = input.find(" ");
158  if (m1 != string::npos) {
159  string parameters = input.substr(m1);
160  input = input.substr(0, m1);
161  }
162  std::transform(input.begin(), input.end(), input.begin(), ::tolower);
163 
164  if (!input.compare("c") || !input.compare("C")) {
165  LOG(logINFO) << "PixTestBareModule:: test will continue.";
166  checkgood = true;
167  goodIn = true;
168  }
169  else if (!input.compare("s") || !input.compare("S")) {
170  LOG(logINFO) << "PixTestBareModule:: bare module test will be stopped.";
171  checkgood = false;
172  goodIn = true;
173  }
174  else {
175  LOG(logINFO) << "PixTestBareModule:: unvalid input. Please retry.";
176  checkgood = false;
177  }
178  } while (!goodIn);
179  }
180  else checkgood = false;
181  }
182  if (checkgood){
183  if (fullSeq){
184  PixTest::hvOn();
185  LOG(logINFO) << "PixTestBareModule:: HV on.";
186  mDelay(2000);
187  }
188  LOG(logINFO) << "PixTestBareModule:: checkIfInContact done.";
189  return true;
190  }
191  else {
192  mDelay(2000);
193  return false;
194  }
195 }
196 
197 //----------------------------------------------------------
198 bool PixTestBareModule::doStdTest(std::string test) {
199 
200  PixTestFactory *factory = PixTestFactory::instance();
201  PixTest *t(0);
202  t = factory->createTest(test, fPixSetup);
203  t->doTest();
204 
205  //to copy 'locally' the test histos
206  bool newHist = true;
207  string firstname, name;
208  while (newHist){
209  TH1* h = t->nextHist();
210  if (firstname == "") firstname = h->GetName();
211  else name = h->GetName();
212  if (firstname == name) newHist = false;
213  else {
214  fHistList.push_back(h);
215  fHistOptions.insert(make_pair(h, t->getHistOption(h)));
216  h->Draw(t->getHistOption(h).c_str());
217  fDisplayedHist = find(fHistList.begin(), fHistList.end(), h);
218  PixTest::update();
219  }
220  }
221 
222  PixTest::update();
223  bool problem = !(t->testProblem());
224  delete t;
225  cout << problem << endl; //debug
226  return problem;
227 }
228 
229 // ----------------------------------------------------------------------
230 bool PixTestBareModule::doRocTests(int MaxStep) {
231 
232  vector<string> suite;
233  suite.push_back("pretest");
234  suite.push_back("alive");
235  suite.push_back("bb");
236  suite.push_back("bb2");
237 
238  //Pretest
239  if (MaxStep >= 1 && !fStop) {
240  if (!doStdTest(suite[0])) {
241  LOG(logWARNING) << "PixTestBareModule:: Pretest failed. Sequence stopped.";
242  return false;
243  }
244  }
245  mDelay(1000);
246  PixTest::update();
247 
248  //Alive
249  if (MaxStep >= 2 && !fStop) {
250  if (!doStdTest(suite[1])) {
251  LOG(logWARNING) << "PixTestBareModule:: Alive failed. Sequence stopped.";
252  return false;
253  }
254  }
255  mDelay(1000);
256  PixTest::update();
257 
258  //BumpBonding
259  if (MaxStep >= 3 && !fStop) {
260  cout << fBBMap << fBB2Map << endl;
261  if (fBBMap && !fBB2Map) {
262  if (!doStdTest(suite[2])) {
263  LOG(logWARNING) << "PixTestBareModule:: BBMap failed. Sequence stopped.";
264  return false;
265  }
266  }
267  else if (fBB2Map && !fBBMap) {
268  if (!doStdTest(suite[3])) {
269  LOG(logWARNING) << "PixTestBareModule:: BB2Map failed. Sequence stopped.";
270  return false;
271  }
272  }
273  else {
274  LOG(logWARNING) << "PixTestBareModule:: Please select the BB test mode.";
275  LOG(logINFO) << "PixTestBareModule:: Test stopped.";
276  return false;
277  }
278  }
279  mDelay(1000);
280  PixTest::update();
281  return true;
282 }
283 
284 // ----------------------------------------------------------------------
286 
287  LOG(logINFO) << "PixTestBareModule:: *******************************";
288  LOG(logINFO) << "PixTestBareModule::doTest() start with " << fParMaxSteps << " test steps.";
289 
290  fDirectory->cd();
291  bool sequenceEnded = false; //to handle pretest exception
292 
293  //ROC test (only if iA > 10 mA)
294  if (checkIfInContact(1)) {
295  //to do test sequence:
296  sequenceEnded = doRocTests(fParMaxSteps);
297  PixTest::update();
298  }
299 
300  PixTest::hvOff();
301  mDelay(2000);
303  mDelay(1000);
304 
305  //separation
306  LOG(logINFO) << "PixTestBareModule:: HV and Power are off.";
307  if(sequenceEnded) LOG(logINFO) << "PixTestBareModule:: Tests finished, now you can separate.";
308 
309  LOG(logINFO) << "PixTestBareModule::doTest() done for.";
310 }
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
void hvOff()
turn HV off
Definition: PixTest.cc:583
virtual void doTest()
function connected to "DoTest" button of PixTab
Definition: PixTest.cc:602
std::map< TH1 *, std::string > fHistOptions
options can be stored with each histogram
Definition: PixTest.hh:308
void hvOn()
turn HV on
Definition: PixTest.cc:577
std::string fStopTip
information for this test
Definition: PixTest.hh:300
void powerOff()
turn DTB power off
Definition: PixTest.cc:595
PixSetup * fPixSetup
all necessary stuff in one place
Definition: PixTest.hh:290
std::vector< std::pair< std::string, std::string > > fParameters
the parameters of this test
Definition: PixTest.hh:302
TDirectory * fDirectory
where the root histograms will end up
Definition: PixTest.hh:306
void setToolTips()
implement this to provide updated tool tips if the user changes test parameters
void runCommand(std::string)
allow execution of any button in the test
std::list< TH1 * >::iterator fDisplayedHist
pointer to the histogram currently displayed
Definition: PixTest.hh:309
std::list< TH1 * > fHistList
list of histograms available in PixTab::next and PixTab::previous
Definition: PixTest.hh:307
virtual bool setParameter(std::string parName, std::string sval)
set the string value of a parameter
double getTBia()
Definition: api.cc:424
void update()
signal to PixTab to update the canvas
Definition: PixTest.cc:569
void doTest()
function connected to "DoTest" button of PixTab
void powerOn()
turn DTB power on
Definition: PixTest.cc:589
pxar::pxarCore * fApi
pointer to the API
Definition: PixTest.hh:289
void init()
sets all test parameters
Definition: PixTest.cc:62
void mDelay(uint32_t ms)
Definition: helper.h:40