7 #include <TGComboBox.h> 
    9 #include "PixParTab.hh" 
   10 #include "PixTestFactory.hh" 
   11 #include "PixUserTestFactory.hh" 
   14 #include "ConfigParameters.hh" 
   16 #include "PixTestParameters.hh" 
   17 #include "PixSetup.hh" 
   18 #include "PixMonitorFrame.hh" 
   20 #include "dictionaries.h" 
   29 TGMainFrame(p, 1, 1, kVerticalFrame), fWidth(w), fHeight(h) {
 
   35   SetWindowName(
"pXar");
 
   37   fOldDirectory = 
"nada"; 
 
   39   gClient->GetColorByName(
"red", fRed);
 
   40   gClient->GetColorByName(
"green", fGreen);
 
   41   gClient->GetColorByName(
"yellow", fYellow);
 
   42   gClient->GetColorByName(
"white", fWhite);
 
   43   gClient->GetColorByName(
"DarkSeaGreen", fDarkSeaGreen);
 
   44   gClient->GetColorByName(
"DarkOrange", fDarkOrange);
 
   45   gClient->GetColorByName(
"DarkGray", fDarkGray);
 
   46   gClient->GetColorByName(
"DarkSalmon", fDarkSalmon);
 
   49   fApi = fPixSetup->getApi();
 
   50   fConfigParameters = fPixSetup->getConfigParameters();
 
   51   fTestParameters = fPixSetup->getPixTestParameters(); 
 
   54   if (fConfigParameters->getHvOn()) {
 
   61   fH1 = 
new TGHorizontalFrame(
this, fWidth, static_cast<int>(fHeight*0.2), kFixedHeight);
 
   62   fH2 = 
new TGHorizontalFrame(
this, fWidth, static_cast<int>(fHeight*0.8), kFixedHeight);
 
   64   TGVerticalFrame *h1v1 = 
new TGVerticalFrame(fH1); 
 
   65   TGVerticalFrame *h1v2 = 
new TGVerticalFrame(fH1);
 
   66   TGVerticalFrame *h1v3 = 
new TGVerticalFrame(fH1);
 
   71   TGGroupFrame *pStuff = 
new TGGroupFrame(h1v1, 
"lost in space");
 
   72   h1v1->AddFrame(pStuff);
 
   73   pStuff->SetWidth(500); 
 
   74   TGVerticalFrame *FpStuff = 
new TGVerticalFrame(pStuff); 
 
   75   pStuff->AddFrame(FpStuff); 
 
   82   TGGroupFrame *hwControl = 
new TGGroupFrame(h1v2, 
"Hardware control");
 
   83   h1v2->AddFrame(hwControl);
 
   84   TGHorizontalFrame *FhwControl = 
new TGHorizontalFrame(hwControl); 
 
   85   hwControl->AddFrame(FhwControl);
 
   86   TGVerticalFrame *h1v2l = 
new TGVerticalFrame(FhwControl); 
 
   87   FhwControl->AddFrame(h1v2l);
 
   88   TGVerticalFrame *h1v2r = 
new TGVerticalFrame(FhwControl);
 
   89   FhwControl->AddFrame(h1v2r);
 
   92   TGHorizontalFrame *powerFrame = 
new TGHorizontalFrame(h1v2l, 150, 75);
 
   93   h1v2l->AddFrame(powerFrame);
 
   94   powerFrame->SetName(
"powerFrame");
 
   95   powerFrame->AddFrame(
new TGLabel(powerFrame, 
"Power: "), 
new TGLayoutHints(kLHintsLeft, fBorderN, fBorderN, fBorderN, fBorderN));
 
   97   fbtnPower = 
new TGTextButton(powerFrame, 
"Off", B_POWER);
 
   98   fbtnPower->SetToolTipText(fConfigParameters->getNrocs()>1?
"Turn on/off module low voltage":
"Turn on/off ROC low voltage");
 
   99   fbtnPower->Resize(70,35);
 
  100   fbtnPower->Connect(
"Clicked()", 
"PixGui", 
this, 
"handleButtons()");
 
  102     fbtnPower->ChangeBackground(fGreen);
 
  103     fbtnPower->SetText(
"On");
 
  105     fbtnPower->ChangeBackground(fRed);
 
  106     fbtnPower->SetText(
"Off");
 
  108   powerFrame->AddFrame(fbtnPower, 
new TGLayoutHints(kLHintsRight, fBorderN, fBorderN, fBorderN, fBorderN));
 
  111   TGHorizontalFrame *hvFrame = 
new TGHorizontalFrame(h1v2l, 150,75);
 
  112   h1v2l->AddFrame(hvFrame);
 
  113   hvFrame->SetName(
"hvFrame");
 
  114   hvFrame->AddFrame(
new TGLabel(hvFrame, 
"HV:     "), 
new TGLayoutHints(kLHintsLeft, fBorderN, fBorderN, fBorderN, fBorderN));
 
  116   fbtnHV = 
new TGTextButton(hvFrame, 
"Off", B_HV);
 
  117   hvFrame->AddFrame(fbtnHV, 
new TGLayoutHints(kLHintsRight, fBorderN, fBorderN, fBorderN, fBorderN));
 
  118   fbtnHV->SetToolTipText(fConfigParameters->getNrocs()>1?
"Turn on/off module bias voltage":
"Turn on/off ROC bias voltage");
 
  119   fbtnHV->Resize(70,35);
 
  120   fbtnHV->Connect(
"Clicked()", 
"PixGui", 
this, 
"handleButtons()");
 
  127   Connect(
"PixTest", 
"hvOn()", 
"PixGui", 
this, 
"hvOn()"); 
 
  128   Connect(
"PixTest", 
"hvOff()", 
"PixGui", 
this, 
"hvOff()"); 
 
  129   Connect(
"PixTest", 
"powerOn()", 
"PixGui", 
this, 
"powerOn()"); 
 
  130   Connect(
"PixTest", 
"powerOff()", 
"PixGui", 
this, 
"powerOff()"); 
 
  135   fTimer = 
new TTimer(1000);
 
  136   fTimer->Connect(
"Timeout()", 
"PixMonitorFrame", fMonitor, 
"Update()");
 
  141   TGComboBox *signalBoxA[2];
 
  142   TGComboBox *signalBoxD[2];
 
  144   TGHorizontalFrame *sigFrame(0); 
 
  146   sigFrame = 
new TGHorizontalFrame(h1v2r);
 
  147   h1v2r->AddFrame(sigFrame, 
new TGLayoutHints(kLHintsTop|kLHintsLeft, fBorderN, fBorderN, fBorderN, fBorderN));
 
  148   sigFrame->AddFrame(
new TGLabel(sigFrame, 
"A1:"), 
new TGLayoutHints(kLHintsLeft, fBorderN, fBorderN, fBorderN, fBorderN));
 
  149   sigFrame->AddFrame(signalBoxA[0] = 
new TGComboBox(sigFrame), 
new TGLayoutHints(kLHintsLeft, fBorderN, fBorderN, fBorderN, fBorderN));
 
  150   signalBoxA[0]->SetName(
"a1");
 
  152   sigFrame = 
new TGHorizontalFrame(h1v2r);
 
  153   h1v2r->AddFrame(sigFrame, 
new TGLayoutHints(kLHintsTop|kLHintsLeft, fBorderN, fBorderN, fBorderN, fBorderN));
 
  154   sigFrame->AddFrame(
new TGLabel(sigFrame, 
"A2:"), 
new TGLayoutHints(kLHintsLeft, fBorderN, fBorderN, fBorderN, fBorderN));
 
  155   sigFrame->AddFrame(signalBoxA[1] = 
new TGComboBox(sigFrame), 
new TGLayoutHints(kLHintsLeft, fBorderN, fBorderN, fBorderN, fBorderN));
 
  156   signalBoxA[1]->SetName(
"a2");
 
  158   sigFrame = 
new TGHorizontalFrame(h1v2r);
 
  159   h1v2r->AddFrame(sigFrame, 
new TGLayoutHints(kLHintsTop|kLHintsLeft, fBorderN, fBorderN, fBorderN, fBorderN));
 
  160   sigFrame->AddFrame(
new TGLabel(sigFrame, 
"D1:"), 
new TGLayoutHints(kLHintsLeft, fBorderN, fBorderN, fBorderN, fBorderN));
 
  161   sigFrame->AddFrame(signalBoxD[0] = 
new TGComboBox(sigFrame), 
new TGLayoutHints(kLHintsLeft, fBorderN, fBorderN, fBorderN, fBorderN));
 
  162   signalBoxD[0]->SetName(
"d1");
 
  164   sigFrame = 
new TGHorizontalFrame(h1v2r);
 
  165   h1v2r->AddFrame(sigFrame, 
new TGLayoutHints(kLHintsTop|kLHintsLeft, fBorderN, fBorderN, fBorderN, fBorderN));
 
  166   sigFrame->AddFrame(
new TGLabel(sigFrame, 
"D2:"), 
new TGLayoutHints(kLHintsLeft, fBorderN, fBorderN, fBorderN, fBorderN));
 
  167   sigFrame->AddFrame(signalBoxD[1] = 
new TGComboBox(sigFrame), 
new TGLayoutHints(kLHintsLeft, fBorderN, fBorderN, fBorderN, fBorderN));
 
  168   signalBoxD[1]->SetName(
"d2");
 
  170   signalBoxA[0]->SetWidth(75);
 
  171   signalBoxA[0]->SetHeight(20);
 
  172   signalBoxA[1]->SetWidth(75);
 
  173   signalBoxA[1]->SetHeight(20);
 
  174   signalBoxD[0]->SetWidth(75);
 
  175   signalBoxD[0]->SetHeight(20);
 
  176   signalBoxD[1]->SetWidth(75);
 
  177   signalBoxD[1]->SetHeight(20);
 
  183   std::vector<std::string> analogsignals = _dict->getAllAnalogNames();
 
  184   std::vector<std::string> digitalsignals = _dict->getAllDigitalNames();
 
  186   for(std::vector<std::string>::iterator it = analogsignals.begin(); it != analogsignals.end(); it++) {
 
  187     signalBoxA[0]->AddEntry(it->c_str(),_dict->getSignal(*it,PROBE_ANALOG));
 
  188     signalBoxA[1]->AddEntry(it->c_str(),_dict->getSignal(*it,PROBE_ANALOG));
 
  191   for(std::vector<std::string>::iterator it = digitalsignals.begin(); it != digitalsignals.end(); it++) {
 
  192     signalBoxD[0]->AddEntry(it->c_str(),_dict->getSignal(*it,PROBE_DIGITAL));
 
  193     signalBoxD[1]->AddEntry(it->c_str(),_dict->getSignal(*it,PROBE_DIGITAL));
 
  196   for(
int i = 0 ; i <= 1 ; i++) {
 
  197     signalBoxA[i]->Connect(
"Selected(Int_t)", 
"PixGui", 
this, 
"selectProbes(Int_t)");
 
  198     signalBoxD[i]->Connect(
"Selected(Int_t)", 
"PixGui", 
this, 
"selectProbes(Int_t)");
 
  201   signalBoxA[0]->Select(_dict->getSignal(fConfigParameters->getProbe(
"a1"),PROBE_ANALOG),
false);
 
  202   signalBoxA[1]->Select(_dict->getSignal(fConfigParameters->getProbe(
"a2"),PROBE_ANALOG),
false);
 
  203   signalBoxD[0]->Select(_dict->getSignal(fConfigParameters->getProbe(
"d1"),PROBE_DIGITAL),
false);
 
  204   signalBoxD[1]->Select(_dict->getSignal(fConfigParameters->getProbe(
"d2"),PROBE_DIGITAL),
false);
 
  211   TGGroupFrame *pControl = 
new TGGroupFrame(h1v3, 
"pXar control");
 
  212   h1v3->AddFrame(pControl);
 
  213   TGVerticalFrame *FpControl = 
new TGVerticalFrame(pControl); 
 
  214   pControl->AddFrame(FpControl); 
 
  216   TGHorizontalFrame *bFrame = 
new TGHorizontalFrame(FpControl); 
 
  217   FpControl->AddFrame(bFrame, 
new TGLayoutHints(kLHintsLeft | kLHintsTop, fBorderN, fBorderN, fBorderN, fBorderN)); 
 
  219   TGTextButton *exitButton = 
new TGTextButton(bFrame, 
"exit", B_EXIT);
 
  220   bFrame->AddFrame(exitButton, 
new TGLayoutHints(kLHintsBottom | kLHintsRight, fBorderN, fBorderN, fBorderN, fBorderN));
 
  221   exitButton->SetToolTipText(
"exit pxar,\nwrite rootfile,\ndo *not* write config files");
 
  222   exitButton->ChangeOptions(exitButton->GetOptions() );
 
  223   exitButton->Connect(
"Clicked()", 
"PixGui", 
this, 
"handleButtons()");
 
  224   exitButton->Resize(70,35);
 
  225   exitButton->ChangeBackground(fRed);
 
  228   TGTextButton *writeButton = 
new TGTextButton(bFrame, 
"write cfg files", B_WRITEALLFILES);
 
  229   bFrame->AddFrame(writeButton, 
new TGLayoutHints(kLHintsBottom | kLHintsLeft, fBorderN, fBorderN, fBorderN, fBorderN));
 
  230   writeButton->SetToolTipText(
"write all config files (ROC/TBM DAC, trim bits, DTB setup, config file)");
 
  231   writeButton->ChangeOptions(writeButton->GetOptions() );
 
  232   writeButton->Connect(
"Clicked()", 
"PixGui", 
this, 
"handleButtons()");
 
  233   writeButton->Resize(70,35);
 
  234   writeButton->ChangeBackground(fYellow);
 
  237   TGHorizontalFrame *rootfileFrame = 
new TGHorizontalFrame(FpControl, 150,75);
 
  238   FpControl->AddFrame(rootfileFrame, 
new TGLayoutHints(kLHintsTop|kLHintsLeft, fBorderN, fBorderN, fBorderN, fBorderN));
 
  239   rootfileFrame->SetName(
"rootfileFrame");
 
  241   TGTextButton *rootfileButton = 
new TGTextButton(rootfileFrame, 
" Change rootfile ", B_FILENAME);
 
  242   rootfileButton->SetToolTipText(
"change the rootfile name");
 
  243   rootfileButton->Connect(
"Clicked()", 
"PixGui", 
this, 
"handleButtons()");
 
  244   rootfileFrame->AddFrame(rootfileButton, 
new TGLayoutHints(kLHintsLeft, fBorderN, fBorderN, fBorderN, fBorderN));
 
  246   TGTextEntry *output = 
new TGTextEntry(rootfileFrame, fRootFileNameBuffer = 
new TGTextBuffer(200), B_FILENAME);
 
  247   output->SetText(fConfigParameters->getRootFileName().c_str());
 
  248   output->MoveResize(100, 60, 120, output->GetDefaultHeight());
 
  249   output->Connect(
"ReturnPressed()", 
"PixGui", 
this, 
"handleButtons()");
 
  250   rootfileFrame->AddFrame(output, 
new TGLayoutHints(kLHintsRight, fBorderN, fBorderN, fBorderN, fBorderN));
 
  254   TGHorizontalFrame *dirFrame = 
new TGHorizontalFrame(FpControl, 150,75);
 
  255   FpControl->AddFrame(dirFrame, 
new TGLayoutHints(kLHintsTop|kLHintsLeft, fBorderN, fBorderN, fBorderN, fBorderN));
 
  256   dirFrame->SetName(
"dirFrame");
 
  258   TGTextButton *dirButton = 
new TGTextButton(dirFrame, 
" Change directory ", B_DIRECTORY);
 
  259   dirButton->Connect(
"Clicked()", 
"PixGui", 
this, 
"handleButtons()");
 
  260   dirButton->SetToolTipText(
"change the output directory; will move the rootfile as well");
 
  261   dirFrame->AddFrame(dirButton, 
new TGLayoutHints(kLHintsLeft, fBorderN, fBorderN, fBorderN, fBorderN));
 
  263   TGTextEntry *doutput = 
new TGTextEntry(dirFrame, fDirNameBuffer = 
new TGTextBuffer(200), B_DIRECTORY);
 
  264   doutput->SetText(fConfigParameters->getDirectory().c_str());
 
  265   doutput->MoveResize(100, 60, 120, output->GetDefaultHeight());
 
  266   doutput->Connect(
"ReturnPressed()", 
"PixGui", 
this, 
"handleButtons()");
 
  267   dirFrame->AddFrame(doutput, 
new TGLayoutHints(kLHintsRight, fBorderN, fBorderN, fBorderN, fBorderN));
 
  270   h1v3->SetWidth(fWidth-h1v1->GetWidth()-h1v2->GetWidth());
 
  275   fTabs = 
new TGTab(fH2, fH2->GetDefaultWidth(), fH2->GetDefaultHeight());
 
  277   fTabs->Connect(
"Selected(Int_t)", 
"PixGui", 
this, 
"selectedTab(Int_t)");
 
  279   fH2->AddFrame(fTabs, 
new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, fBorderN, fBorderN, fBorderN, fBorderN));
 
  281   if(fApi) fParTab = 
new PixParTab(
this, fConfigParameters, 
"h/w"); 
 
  284   if (fApi) fParTab->updateSelection(); 
 
  286   vector<string> tests = fTestParameters->getTests();
 
  287   for (
unsigned int i = 0; i < tests.size(); ++i) {
 
  288     createTab(tests[i].c_str()); 
 
  291   fH1->AddFrame(h1v1, 
new TGLayoutHints(kLHintsLeft | kLHintsExpandX | kLHintsExpandY, fBorderN, fBorderN, fBorderN, fBorderN));
 
  292   fH1->AddFrame(h1v2, 
new TGLayoutHints(kLHintsCenterX , fBorderN, fBorderN, fBorderN, fBorderN));
 
  293   fH1->AddFrame(h1v3, 
new TGLayoutHints(kLHintsRight | kLHintsExpandX | kLHintsExpandY, fBorderN, fBorderN, fBorderN, fBorderN));
 
  295   AddFrame(fH1, 
new TGLayoutHints(kLHintsTop | kLHintsExpandX));
 
  296   AddFrame(fH2, 
new TGLayoutHints(kLHintsBottom | kLHintsExpandY | kLHintsExpandX));
 
  299   Resize(GetDefaultSize());
 
  306   LOG(logDEBUG) << 
"PixGui::destructor";
 
  311   delete fRootFileNameBuffer;
 
  325 void PixGui::Cleanup() {
 
  326   fPixSetup->getPixMonitor()->dumpSummaries();
 
  327   gApplication->Terminate(0);
 
  332 void PixGui::CloseWindow() {
 
  333   std::vector<PixTest*>::iterator il; 
 
  334   for (il = fTestList.begin(); il != fTestList.end(); ++il) {
 
  338   if (fTimer) fTimer->TurnOff();
 
  339   if (fApi) 
delete fApi; 
 
  340   fPixSetup->getPixMonitor()->dumpSummaries();
 
  343   gApplication->Terminate(0);
 
  348 void PixGui::selectProbes(Int_t ) {
 
  349    TGComboBox *box = (TGComboBox *) gTQSender;
 
  351    fApi->SignalProbe(box->GetName(),box->GetSelectedEntry()->GetTitle());
 
  355    fConfigParameters->setProbe(box->GetName(),box->GetSelectedEntry()->GetTitle());
 
  362 void PixGui::handleButtons(Int_t 
id) {
 
  364     TGButton *btn = (TGButton *) gTQSender;
 
  365     id = btn->WidgetId();
 
  370     LOG(logDEBUG) << Form(
"changing base directory: %s", fDirNameBuffer->GetString());
 
  371     fOldDirectory = fConfigParameters->getDirectory(); 
 
  372     if (0 == gSystem->OpenDirectory(fDirNameBuffer->GetString())) {
 
  373       LOG(logINFO) << 
"directory " << fDirNameBuffer->GetString() << 
" does not exist, creating it"; 
 
  374       int bla = gSystem->MakeDirectory(fDirNameBuffer->GetString()); 
 
  376     LOG(logWARNING) << 
" failed to create directory " << fDirNameBuffer->GetString();
 
  381     fConfigParameters->setDirectory(fDirNameBuffer->GetString()); 
 
  386     LOG(logINFO) << Form(
"changing rootfilenme: %s", fRootFileNameBuffer->GetString());
 
  391     LOG(logDEBUG) << 
"PixGui::exit called";
 
  396   case B_WRITEALLFILES: {
 
  397     LOG(logDEBUG) << 
"PixGui::writeAllFiles called";
 
  398     fConfigParameters->writeAllFiles();
 
  423 void PixGui::powerOn() {
 
  426     fbtnPower->ChangeBackground(fGreen);
 
  427     fbtnPower->SetText(
"On");
 
  429     LOG(logDEBUG) << 
"Power set On";
 
  434 void PixGui::powerOff() {
 
  437     fbtnPower->ChangeBackground(fRed);
 
  438     fbtnPower->SetText(
"Off");
 
  440     LOG(logDEBUG) << 
"Power set Off";
 
  446 void PixGui::hvOn() {
 
  449     fbtnHV->ChangeBackground(fGreen);
 
  450     fbtnHV->SetText(
"On");
 
  452     LOG(logDEBUG) << 
"HV set On";
 
  458 void PixGui::hvOff() {
 
  461     fbtnHV->ChangeBackground(fRed);
 
  462     fbtnHV->SetText(
"Off");
 
  464     LOG(logDEBUG) << 
"HV set Off";
 
  486 void PixGui::createTab(
const char* csel) {
 
  488   PixTest *pt = createTest(
string(csel));
 
  490     LOG(logDEBUG) << 
"ERROR: " << csel << 
" not known, nothing created";
 
  494   fTestList.push_back(pt); 
 
  496   fPixTabList.push_back(t);
 
  499   pt->Connect(
"update()", 
"PixTab", t, 
"update()"); 
 
  503   Resize(GetDefaultSize());
 
  511 PixTest* PixGui::createTest(
string testname) {
 
  514   PixTest *t =  factory->createTest(testname, fPixSetup);
 
  515   if (0 == t) t = userfactory->createTest(testname, fPixSetup);
 
  521 void PixGui::selectedTab(
int id) {
 
  524     fParTab->updateParameters();
 
  528   fPixTab = fPixTabList[
id-1];
 
  534 void PixGui::changeRootFile() {
 
  535   string oldRootFilePath = gFile->GetName();
 
  538   string newRootFilePath = fConfigParameters->getDirectory() + 
"/" + fRootFileNameBuffer->GetString();
 
  540   gSystem->Rename(oldRootFilePath.c_str(), newRootFilePath.c_str()); 
 
  541   TFile *f = TFile::Open(newRootFilePath.c_str(), 
"UPDATE"); 
 
  543   std::vector<PixTest*>::iterator il; 
 
  544   for (il = fTestList.begin(); il != fTestList.end(); ++il) {
 
  545     (*il)->resetDirectory();
 
  551 void PixGui::updateSelectedRocs(map<int, int> a) {
 
  553   for (
unsigned int i = 0; i < fTestList.size(); ++i) {
 
  554     fTestList[i]->setId2Idx(a); 
 
  561 std::string PixGui::getHdiType() {
 
  562   return fConfigParameters->getHdiType();