pxar
 All Classes Namespaces Functions Variables Typedefs Friends
PixTestCmd.hh
1 // -- author: Wolfram Erdmann
2 #ifndef PIXTESTCMD_H
3 #define PIXTESTCMD_H
4 
5 #include "PixTest.hh"
6 #include "dictionaries.h"
7 
8 #if (defined WIN32)
9 #include <Windows4Root.h> //needed before any ROOT header
10 #endif
11 
12 #include <TGFrame.h>
13 #include <TGTextView.h>
14 #include <TGTextEntry.h>
15 #include <TGTextBuffer.h>
16 
17 #include <deque>
18 #include <string>
19 #include <vector>
20 #include <iostream> // cout, debugging only (need ostream, though)
21 #include <sstream> // for producing string representations
22 #include <fstream>
23 
24 
25 class CmdProc;
26 
27 class DLLEXPORT PixTestCmd: public PixTest {
28 public:
29  PixTestCmd(PixSetup *, std::string);
30  PixTestCmd();
31  virtual ~PixTestCmd();
32  virtual bool setParameter(std::string parName, std::string sval);
33  void init();
34  void setToolTips();
35  void bookHist(std::string);
36 
37  void doTest();
38  void createWidgets();
39  void DoTextField();
40  void DoUpArrow();
41  void DoDnArrow();
42 
43 private:
44 
45  TGTransientFrame * tf;
46  TGTextView * transcript;
47  TGHorizontalFrame * textOutputFrame;
48  TGHorizontalFrame * cmdLineFrame;
49  TGTextEntry * commandLine;
50  std::vector<std::string> cmdHistory;
51  unsigned int historyIndex;
52 
53  CmdProc * cmd;
54 
55  ClassDef(PixTestCmd, 1)
56 
57 };
58 
59 
60 
61 
62 /*====================================================================*/
63 /* command processor code */
64 /*====================================================================*/
65 
66 using namespace std;
67 
68 // forward declarations
69 class CmdProc;
70 class Statement;
71 class Token;
72 
73 
74 
75 class IntList{
76  int singleValue;
77  vector< pair<int,int> > ranges;
78 
79  public:
80  enum special{IMIN=-1, IMAX=-2, UNDEFINED=-3, IVAR=-4};
81  IntList():singleValue(UNDEFINED){ranges.clear();}
82  bool parse( Token & , const bool append=false );
83 
84  int value(){return singleValue;}
85  bool isSingleValue(){return (!(singleValue==UNDEFINED));}
86  bool isVariable(){return ( (singleValue==IVAR));}
87  vector<int> getVect(const int imin=0, const int imax=0);
88 
89 };
90 
91 class Arg{
92  public:
93  static int varvalue;
94  enum argtype {UNDEF,STRING_T, IVALUE_T, IVAR_T, ILIST_T};
95  Arg(string s):type(STRING_T),svalue(s){};
96  Arg(IntList v){
97  if( v.isSingleValue() ){
98  if (v.isVariable()){
99  type = IVAR_T;
100  ivalue=0; // determined at execution gime
101  }else{
102  type=IVALUE_T;
103  ivalue=v.value();
104  }
105  }else{
106  type=ILIST_T;
107  lvalue=v;
108  }
109  }
110  bool getInt(int & value){
111  if (type==IVALUE_T){value=ivalue; return true;}
112  if (type==IVAR_T){value=varvalue; return true;}
113  return false;
114  }
115 
116  bool getList(IntList & value){ if(type==ILIST_T){ value=lvalue; return true;} return false;}
117  bool getVect(vector<int> & value, const int imin=0, const int imax=0){
118  if(type==ILIST_T){
119  value=lvalue.getVect(imin, imax);
120  return true;
121  }else if(type==IVALUE_T){
122  value.push_back( ivalue);
123  return true;
124  }else if(type==IVAR_T){
125  value.push_back( varvalue );
126  return true;
127  }else{
128  return false;
129  }
130  }
131  bool getString(string & value){ if(type==STRING_T){ value=svalue; return true;}return false;}
132  bool scmp(const char *s){ return (type==STRING_T)&&( strcmp(s, svalue.c_str())==0 );}
133 
134  argtype type;
135  string svalue;
136  IntList lvalue;
137  int ivalue;
138 
139  string str(){
140  stringstream s;
141  if (type==IVALUE_T){ s << ivalue;}
142  else if (type==IVAR_T){ s << varvalue;}
143  else if (type==ILIST_T) { s << "vector("<<")";}
144  else if (type==STRING_T){ s << "'" << svalue <<"'";}
145  else s <<"???";
146  return s.str();
147  }
148 
149  string raw(){
150  stringstream s;
151  if (type==IVALUE_T){ s << ivalue;}
152  else if (type==IVAR_T){ s << varvalue;}
153  else if (type==STRING_T){ s << svalue;}
154  else s <<"0";
155  return s.str();
156  }
157 
158 };
159 
160 
161 class Keyword{
162  bool kw(const char* s){ return (strcmp(s, keyword.c_str())==0);};
163 
164  public:
165  Keyword():keyword(""){};
166  Keyword(string s):keyword(s){};
167 
168  bool match(const char * s){ return kw(s) && (narg()==0); };
169  bool match(const char * s, int & value, const char * s1);
170  bool match(const char * s1, const char * s2);
171  bool match(const char * s1, const char * s2, string &);
172  bool match(const char * s1 , const char * s2, int & );
173  bool match(const char * s, string & s1, vector<string> & options, ostream & err);
174  bool match(const char *, int &);
175  bool match(const char *, int &, int &);
176  bool match(const char *, int &, int &, int &);
177  bool match(const char *, string &);
178  bool match(const char * s, vector<int> & , vector<int> &);
179  bool match(const char * s, vector<int> &, const int, const int , vector<int> &, const int, const int);
180  bool greedy_match(const char *, string &);
181  bool greedy_match(const char *, int &, int&, int&, string &);
182  bool concat(unsigned int i, string &s){ s=""; for (;i<argv.size(); i++) s+=argv[i].str(); return true;}
183 
184  unsigned int narg(){return argv.size();};
185  string str();
186 
187  string keyword;
188  vector<Arg> argv;
189 };
190 
191 
192 class Token{
193  // container for a list of tokens, basically a deque<string>
194  // with the capability to replace tokens by macros
195  deque<string> token;
196  map<string, deque <string> >::iterator mi;
197  vector< deque <string> > stack;
198 
199  public:
200  Token(){ macros=NULL; token.clear(); stack.clear(); }
201  Token(const deque<string> tlist){ macros=NULL; token=tlist; stack.clear(); }
202  map<string, deque <string> > * macros;
203  //deque-like interface
204  string front(bool expand=true);
205  void pop_front();
206  void push_front(string s);
207  bool empty(){return (token.size()==0)&&(stack.size()==0);}
208  void push_back(string s){token.push_back(s);}
209  // parsing and macro handling
210  bool assignment(string & name);
211  void add_macro(string name, deque <string> t){ (*macros)[name]=t; }
212 };
213 
214 /* containers for syntax elements */
215 
216 
217 class Target{
218  public:
219  IntList lvalues; // parsed
220  vector<int> ivalues; // expanded
221  bool expanded;
222 
223  string name;
224  void expand( const int imin=0, const int imax=0 ){
225  if (expanded) return;
226  ivalues=lvalues.getVect(imin, imax); expanded=true;
227  }
228  unsigned int size(){ if (!expanded){ return 0;}else{ return ivalues.size();}}
229  vector<int> values(){return ivalues;}// todo fix unexpanded
230  Target():name(""){expanded=false;}
231  Target(string s):name(s){expanded=false;}
232 
233  // for single valued targets
234  int value(){ if (!expanded) {return 0;}else{return ivalues.size()==1 ? ivalues[0] : -1;}; }
235  Target(string name, const int value):name(name){ivalues.clear();ivalues.push_back( value );expanded=true;}
236  Target get(unsigned int i){ Target t(name, ivalues[i]); return t;};
237 
238  bool parse( Token & );
239  string str();
240 
241 };
242 
243 
244 class Block{
245  vector<Statement *> stmts;
246  public:
247  Block(){ stmts.clear();}
248  bool parse(Token &);
249  bool exec(CmdProc *, Target &);
250 };
251 
252 
253 class Statement{
254  bool isAssignment; // assign block or value or list or ...
255  string name; // variable/macro name
256 
257  bool has_localTarget; // true if the statement has a target identifier
258  Target localTarget; // target(s) for the following statement
259  Block * block;
260 
261  public:
262  Statement():
263  isAssignment(false), name(""), has_localTarget(false), keyword(""), redirected(false), out_filename(""){block=NULL;};
264  ~Statement(){ if (!(block==NULL)) delete block; }
265  bool parse( Token & );
266  bool exec(CmdProc *, Target &);
267 
268  Keyword keyword;
269  bool redirected;
270  string out_filename;
271 
272 };
273 
274 class DRecord{
275  public:
276  uint8_t type;
277  uint32_t w1,w2;
278  uint32_t data;
279  DRecord(uint8_t T=0xff, uint32_t D=0x00000000, uint16_t W1=0x000, uint16_t W2=0x0000){
280  type = T;
281  data = D;
282  w1 = W1;
283  w2 = W2;
284  }
285 };
286 
287 class CmdProc {
288 
289 
290  public:
291  CmdProc(){init();};
292  CmdProc( CmdProc* p);
293  ~CmdProc();
294  void init();
295  void setApi(pxar::pxarCore * api, PixSetup * setup );
296  int exec(string s);
297  int exec(const char* p){ return exec(string(p));}
298 
299  bool process(Keyword, Target, bool );
300  bool setDefaultTarget( Target t){ defaultTarget=t; return true; }
301 
302  pxar::pxarCore * fApi;
303  PixSetup * fPixSetup;
304 
305  stringstream out;
306  pxar::RegisterDictionary * _dict;
307  pxar::ProbeDictionary * _probeDict;
308  vector<string> fD_names;
309  vector<string> fA_names;
310  static const unsigned int fnDAC_names;
311  static const char * const fDAC_names[];
312  static int fGetBufMethod;
313 
314  bool fPixelConfigNeeded;
315  unsigned int fTCT, fTRC, fTTK;
316  unsigned int fBufsize;
317  vector<uint16_t> fBuf;
318  unsigned int fNumberOfEvents;
319  unsigned int fHeaderCount;
320  vector<unsigned int> fHeadersWithErrors;
321  unsigned int fSeq;
322  unsigned int fPeriod;
323  vector<pair<string,uint8_t> > fSigdelays;
324  vector<pair<string,uint8_t> > fSigdelaysSetup;
325  bool fPgRunning;
326 
327  int fDeser400XOR1;
328  int fDeser400XOR2;
329  int fDeser400XOR1sum[8];
330  int fDeser400err;
331  static int fPrerun;
332  static bool fFW35;
333 
334  bool verbose;
335  Target defaultTarget;
336  map<string, deque <string> > macros;
337 
338 
339  int tbmset(int address, int value);
340  int tbmset (string name, uint8_t coreMask, int value, uint8_t valueMask=0xff);
341  int tbmsetbit(string name, uint8_t coreMask, int bit, int value);
342  int tbmget(string name, const uint8_t core, uint8_t & value);
343  int tbmscan();
344  int rawscan(int level=0);
345  int rocscan();
346  int tctscan(unsigned int tctmin=0, unsigned int tctmax=0);
347  int levelscan();
348 
349  int countHits();
350  int countErrors(unsigned int ntrig=1, int ftrigkhz=0, int nroc_expected=-1, bool setup=true);
351  int countGood(unsigned int nloop, unsigned int ntrig, int ftrigkhz, int nroc);
352  int printData(vector<uint16_t> buf, int level);
353  int readRocs(uint8_t signal=0xff, double scale=0, std::string units="" );
354  int getBuffer(vector<uint16_t> & buf);
355  int setupDaq(int ntrig, int ftrigkhz, int verbosity=0);
356  int restoreDaq(int verbosity=0);
357  int runDaq(vector<uint16_t> & buf, int ntrig, int ftrigkhz, int verbosity=0, bool setup=true);
358  int runDaq(int ntrig, int ftrigkhz, int verbosity=0);
359  int burst(vector<uint16_t> & buf, int ntrig, int trigsep=6, int nburst=1, int verbosity=0);
360  int getData(vector<uint16_t> & buf, vector<DRecord > & data, int verbosity=1, int nroc_expected=-1);
361  int pixDecodeRaw(int, int level=1);
362  int setTestboardDelay(string name="all", uint8_t value=0);
363  int setTestboardPower(string name, uint16_t value);
364 
365  int bursttest(int ntrig, int trigsep=6, int nburst=1);
366  //int adctest0(const string s);
367  int adctest(const string s);
368  int sequence(int seq);
369  int pg_sequence(int seq, int length=0);
370  int pg_restore();
371  int pg_loop(int value=0);
372  int pg_stop();
373 
374  int tb(Keyword);
375  int tbm(Keyword, int cores=2);
376  int roc(Keyword, int rocid);
377 
378 
379 };
380 
381 
382 #endif
virtual void doTest()
function connected to "DoTest" button of PixTab
Definition: PixTest.cc:602
void bookHist(std::string name)
use if you want, or define the histograms in the specific member functions
Definition: PixTest.cc:93
virtual void setToolTips()
implement this to provide updated tool tips if the user changes test parameters
Definition: PixTest.cc:85
virtual bool setParameter(std::string parName, std::string sval)
set the string value of a parameter
Definition: PixTest.cc:433
void init()
sets all test parameters
Definition: PixTest.cc:62