/*************************************************************************** BocAnalysisPanel.cxx - description ------------------- begin : Dez 9 2005 author : by Iris Rottlaender ***************************************************************************/ #include "BocAnalysisPanel.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef WIN32 #include #endif #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include BocAnalysisPanel::BocAnalysisPanel(STControlEngine &engine_in, QWidget* parent, const char* , Qt::WFlags fl) : QWidget(parent,fl), m_engine( engine_in ){ setupUi(this); AnalyseButton->setEnabled(true); AnaBocScanButton->setEnabled(true); keepDataBox->setEnabled(true); writeDataBox->setEnabled(true); scanFileName->setEnabled(true); Browse2Button->setEnabled(true); fileNameLabel->setEnabled(true); WriteDataButton->setEnabled(false); crateBox->setEnabled(false); cratelabel->setEnabled(false); Config &conf = m_engine.getOptions(); ConfString &out =dynamic_cast (conf["paths"]["defDataPath"]); m_dataPath = out.value(); scanFileName->setText((m_dataPath +"/BocScan.root").c_str()); scanfilename=""; scanlabelname=""; newfileflag = false; m_scanTimer = new QTimer(this); QObject::connect(AnaBocScanButton, SIGNAL(clicked()), this, SLOT(AnaScan())); QObject::connect(AnalyseButton, SIGNAL(clicked()), this, SLOT(Analyse())); QObject::connect(Browse1Button, SIGNAL(clicked()), this, SLOT(Browse1())); QObject::connect(Browse2Button, SIGNAL(clicked()), this, SLOT(Browse2())); QObject::connect(WriteDataButton, SIGNAL(clicked()), this, SLOT(WriteData())); QObject::connect(anaFileName, SIGNAL(returnPressed()), this, SLOT(OpenFile())); //QObject::connect(anaFileName, SIGNAL(lostFocus()), this, SLOT(OpenFile())); QObject::connect( &m_engine, SIGNAL(crateListChanged()), this, SLOT(updateCrateGrpSel()) ); } BocAnalysisPanel::~BocAnalysisPanel(){ } void BocAnalysisPanel::Analyse(string filename ="", string scanlabel=""){ // bool notWriting = false; try{ enableAnaScan(false); resultsTable->setNumRows(0); resultsTable->setNumCols(0); writeResults.clear(); writeLinks.clear(); writeSlots.clear(); int rowcount = 0; string inputfile, scanname, groupname, modulename; if(filename=="") { inputfile = anaFileName->text().latin1(); if(inputfile =="") { emit errorMessage("Error in BocAnalysisPanel::Analyse - No file name given!"); enableAnaScan(true); return; } scanname = m_scanLabels.at(scanLabel->currentItem()); } else { inputfile = filename; scanname = scanlabel; } cout<readRootRecord(1); DBInquire *scanInq = *(root->findRecord(scanname+"/PixScanResult")); for(recordIterator it = scanInq->recordBegin(); it!=scanInq->recordEnd(); it++){ string slotname = (*it)->getDecName().c_str(); slotname.erase(0,scanname.length()+2); slotname.erase(slotname.length()-1); string name1 = (*it)->getName().c_str(); if(name1=="PixModuleGroup") { groupname = slotname; cout<findRecord(groupname+"/PixModuleGroup")); for(recordIterator it = grpInq->recordBegin(); it!=grpInq->recordEnd(); it++) { string modname = (*it)->getDecName().c_str(); modname.erase(0,slotname.length()+scanname.length()+3); modname.erase(modname.length()-1); string name2 =(*it)->getName().c_str(); if(name2=="PixModule") { modulename = modname; cout<isChecked()) ana.shiftResults(&results); results.DumpResults(); // remember results for writing on the Boc, currently last parameter set per module. if((results.seenError)&&(results.bestX.size()>0)) { vector tmpvec; tmpvec.push_back(results.bestX.at(results.bestX.size()-1)); if(results.dim>1) tmpvec.push_back(results.bestY.at(results.bestY.size()-1)); if(results.dim==3) tmpvec.push_back(results.bestZ.at(results.bestZ.size()-1)); writeResults.push_back(tmpvec); tmpvec.clear(); tmpvec.push_back(results.inlink); for(int i = 0; i<4; i++) { if(results.outlink[i]!=-1) tmpvec.push_back(results.outlink[i]); } writeLinks.push_back(tmpvec); writeSlots.push_back(groupname); } // set up results table. resultsTable->setNumCols(results.dim+4); QStringList labels; labels.append("module"); labels.append("group"); labels.append("Boc-Inlink"); labels.append("Boc-Outlinks"); currentScanPars.clear(); for(int i = 0; isetColumnLabels(labels); if(results.seenError==false) { stringstream il,ol; resultsTable->setNumRows(resultsTable->numRows()+1); resultsTable->setText(rowcount,0,modulename.c_str()); resultsTable->setText(rowcount,1,groupname.c_str()); il<setText(rowcount,2,il.str().c_str()); ol<setText(rowcount,3,ol.str().c_str()); resultsTable->setText(rowcount,4,"ALL"); if(results.dim>1) resultsTable->setText(rowcount,5,"ALL"); if(results.dim==3) resultsTable->setText(rowcount,6,"ALL"); // notWriting = true; } else { if(results.bestX.size()==0) { stringstream il,ol; resultsTable->setNumRows(resultsTable->numRows()+1); resultsTable->setText(rowcount,0,modulename.c_str()); resultsTable->setText(rowcount,1,groupname.c_str()); il<setText(rowcount,2,il.str().c_str()); ol<setText(rowcount,3,ol.str().c_str()); resultsTable->setText(rowcount,4,"NONE"); if(results.dim>1) resultsTable->setText(rowcount,5,"NONE"); if(results.dim==3) resultsTable->setText(rowcount,6,"NONE"); // notWriting = true; } else { resultsTable->setNumRows(resultsTable->numRows() + results.bestX.size()); for(unsigned int i = 0; isetText(rowcount+i,0,modulename.c_str()); resultsTable->setText(rowcount+i,1,groupname.c_str()); stringstream il,ol; il<setText(rowcount+i,2,il.str().c_str()); ol<setText(rowcount+i,3,ol.str().c_str()); stringstream b1,b2,b3; b1 << results.bestX.at(i)<<" (0x"<setText(rowcount+i,4,b1.str().c_str()); if(results.dim >1) { b2 << results.bestY.at(i)<<" (0x"<setText(rowcount+i,5,b2.str().c_str()); } if(results.dim == 3) { b3 << results.bestZ.at(i)<<" (0x"<setText(rowcount+i,6,b3.str().c_str()); } } } } for(int i = 0; iadjustColumn(i); rowcount=resultsTable->numRows(); for(int j =0;jadjustRow(j); } } } } } catch(...) { emit errorMessage("Unknown Error in BocAnalyisPanel::Analyse - Please check if selected scan is really a Boc Parameter Scan!"); } enableAnaScan(true); // if(notWriting) // WriteDataButton->setEnabled(false); return; } void BocAnalysisPanel::Browse(const char *in_path, QLineEdit * field){ // create new file with just a few defaults (includes scan stuff for now) bool go_for_it = (in_path!=0); QString fname; if(!go_for_it){ QString old_path = QString::null; if(!field->text().isEmpty()){ old_path = field->text(); int pos = old_path.findRev("/"); if(pos>=0) old_path.remove(pos,old_path.length()-pos); } QStringList filter; filter += "DB ROOT file (*.root)"; filter += "Any file (*.*)"; Q3FileDialog fdia(old_path,QString::null,this,"newrootfile",TRUE); fdia.setCaption("Specify name of new RootDB data-file"); fdia.setFilters(filter); fdia.setMode(Q3FileDialog::AnyFile); go_for_it = (fdia.exec() == QDialog::Accepted); if(go_for_it) fname = fdia.selectedFile(); } else fname = in_path; if(go_for_it){ if(fname.right(5)!=".root") fname+=".root"; field->setText(fname); // enableMonitor(); // get list of scan labels and fill local memory of it m_scanLabels.clear(); scanLabel->clear(); try{ RootDB *myDB = new RootDB(fname.latin1()); DBInquire *root = myDB->readRootRecord(1); for(recordIterator it = root->recordBegin(); it!=root->recordEnd(); it++){ QString scname = (*it)->getDecName().c_str(); scname.remove(0,1); scname.remove(scname.length()-1,1); m_scanLabels.push_back(scname.latin1()); } } catch(...){ m_scanLabels.clear(); } if(field==anaFileName) { for(unsigned int i = 0; iinsertItem(m_scanLabels.at(i).c_str()); } } return; } void BocAnalysisPanel::OpenFile(){ QString fname = anaFileName->text(); if(fname.right(5)!=".root") fname+=".root"; anaFileName->setText(fname); // get list of scan labels and fill local memory of it m_scanLabels.clear(); scanLabel->clear(); try{ RootDB *myDB = new RootDB(fname.latin1()); DBInquire *root = myDB->readRootRecord(1); for(recordIterator it = root->recordBegin(); it!=root->recordEnd(); it++){ QString scname = (*it)->getDecName().c_str(); scname.remove(0,1); scname.remove(scname.length()-1,1); m_scanLabels.push_back(scname.latin1()); } } catch(...){ m_scanLabels.clear(); } for(unsigned int i = 0; iinsertItem(m_scanLabels.at(i).c_str()); return; } void BocAnalysisPanel::AnaScan() { enableAnaScan(false); QString filename = scanFileName->text().latin1(); bool newfile = true; m_scanLabels.clear(); if(filename =="") { emit errorMessage("Error in BocAnalysisPanel::AnaScan - No file name given!"); enableAnaScan(true); return; } if(filename.right(5)!=".root") filename+=".root"; scanFileName->setText(filename); // check if file exists FILE* fp = fopen(filename, "r"); if (fp) { fclose(fp); // remembers scan labels already in file RootDB *myDB = new RootDB(filename.latin1()); DBInquire *root = myDB->readRootRecord(1); for(recordIterator it = root->recordBegin(); it!=root->recordEnd(); it++){ QString scname = (*it)->getDecName().c_str(); scname.remove(0,1); scname.remove(scname.length()-1,1); m_scanLabels.push_back(scname.latin1()); } newfile = false; } // start a default BocScan. PixScan * m_stdScan = new PixScan(PixScan::BOC_THR_RX_DELAY_SCAN); STControlEngine::pixScanRunOptions m_scanOpt; m_stdScan->setLoopVarValues(1,0,255,16); // m_stdScan->setLoopVarValues(0,0,25,1); m_scanOpt.scanConfig = m_stdScan; string scanlabel; int index=1; bool newlabel; stringstream ind; // look for an unused scan label while(true) { newlabel = true; ind.str(""); ind.clear(); ind<not scanning."); } } else { emit sendPixScanStatus(0,0,0,0,-1,0,0,0,1); QMessageBox::warning(this,"BocAnalysisPanel","Error in initialising RODs\n->not scanning."); } } else if (nRods==-1) { QMessageBox::warning(this,"BocAnalysisPanel","No RODs found.\n->not scanning."); emit sendPixScanStatus(0,0,0,0,-1,0,0,0,1); } else if (nRods<0) { QMessageBox::warning(this,"BocAnalysisPanel","Strange Output from STControlEngine::CtrlStatusSummary().\n->not scanning."); emit sendPixScanStatus(0,0,0,0,-1,0,0,0,1); } if (nRods>0) { // int status = m_engine.pixScan(m_scanOpt); m_engine.pixScan(m_scanOpt); } PixLib::sleep(10); //give ScanThreads some time to set PixCtrlStatus to busy scanfilename = filename.latin1(); scanlabelname = scanlabel; newfileflag = newfile; connect( m_scanTimer, SIGNAL(timeout()), this, SLOT(FinishAnaScan()) ); m_scanTimer->start( 2000, FALSE ); return; } void BocAnalysisPanel::FinishAnaScan() { try{ disconnect( m_scanTimer, SIGNAL(timeout()), this, SLOT(FinishAnaScan()) ); m_scanTimer->stop(); //wait if scan is still running // if (m_engine.RodProcessing() || m_engine.getFinishScanRunning()) if (m_engine.RodProcessing()) { connect( m_scanTimer, SIGNAL(timeout()), this, SLOT(FinishAnaScan()) ); m_scanTimer->start( 2000, FALSE ); return; } // otherwise finish scan analysis tasks else { // see if results file is really there, i.e successful scan! FILE* fp = fopen(scanfilename.c_str(), "r"); if (fp) { fclose(fp); Analyse(scanfilename, scanlabelname); if(writeDataBox->isChecked()) WriteData(); if((!(keepDataBox->isChecked()))&&(newfileflag)) if(remove(scanfilename.c_str()) == -1) cout<<" Error deleting file "<currentItem()).empty()) { emit errorMessage("Error in BocAnalysisPanel::WriteData() - No Crates or Rods found."); return; } if(currentScanPars.empty()) { emit errorMessage("Error in BocAnalysisPanel::WriteData() - No Scan Parameters found"); return; } if((writeResults.size()!=writeLinks.size())||(writeResults.size()!=writeSlots.size())) { emit errorMessage("Error in BocAnalysisPanel::WriteData() - Number of results unequal to number of links"); return; } // write results to BOC STPixModuleGroup * modgroup =0; PixBoc * pixboc =0; RodPixController *rod =0; // loop over all modules for(unsigned int l =0; lcurrentItem())).size(); hh++) { if(( (CrateRodList.at(crateBox->currentItem())).at(hh))->getName() == writeSlots.at(l)) { modgroup = (CrateRodList.at(crateBox->currentItem())).at(hh); cout<<"Writing for modgroup "<getName()<getPixBoc(); rod = dynamic_cast(modgroup->getPixController()); } } if(slotfound==false) cout<<"Not writing to "<editedCfg(42); // loop over all scanned parameters for(unsigned int k =0; kgetRx(tmplink)->getConfigRx()); if(currentScanPars.at(k)=="BOC_RX_DELAY") { PixLib::WriteIntConf( (ConfInt&)conf["General"]["DataDelay"+tmpstream.str()],(writeResults.at(l)).at(k)); if((rod!=0)&&(modgroup->getPixCtrlStatus()==tOK)&&(modgroup->getPixBocStatus()==tOK)) rod->setBocRegister("DataDelay",(writeLinks.at(l)).at(n), (writeResults.at(l)).at(k)); else cout<<"Not writing to BOC - HW not found or initialised."<getPixCtrlStatus()==tOK)&&(modgroup->getPixBocStatus()==tOK)) rod->setBocRegister("RxThreshold",(writeLinks.at(l)).at(n), (writeResults.at(l)).at(k)); else cout<<"Not writing to BOC - HW not found or initialised."<getTx(tmplink)->getConfigTx()); if(currentScanPars.at(k)=="BOC_TX_BPM") { PixLib::WriteIntConf( (ConfInt&)conf["Bpm"]["CoarseDelay"+tmpstream.str()],(writeResults.at(l)).at(k)); if((rod!=0)&&(modgroup->getPixCtrlStatus()==tOK)&&(modgroup->getPixBocStatus()==tOK)) rod->setBocRegister("BpmCoarseDelay",(writeLinks.at(l)).at(0), (writeResults.at(l)).at(k)); else cout<<"Not writing to BOC - HW not found or initialised."<getPixCtrlStatus()==tOK)&&(modgroup->getPixBocStatus()==tOK)) rod->setBocRegister("BpmFineDelay",(writeLinks.at(l)).at(0), (writeResults.at(l)).at(k)); else cout<<"Not writing to BOC - HW not found or initialised."<getPixCtrlStatus()==tOK)&&(modgroup->getPixBocStatus()==tOK)) rod->setBocRegister("LaserCurrent",(writeLinks.at(l)).at(0), (writeResults.at(l)).at(k)); else cout<<"Not writing to BOC - HW not found or initialised."<getPixCtrlStatus()==tOK)&&(modgroup->getPixBocStatus()==tOK)) rod->setBocRegister("BpmMarkSpace",(writeLinks.at(l)).at(0), (writeResults.at(l)).at(k)); else cout<<"Not writing to BOC - HW not found or initialised."<1) cout<<"Writing global parameter "<getConfig()); if(currentScanPars.at(k)=="BOC_BPH") { PixLib::WriteIntConf( (ConfInt&)conf["Clocks"]["BRegClockPhase"],(writeResults.at(l)).at(k)); if((rod!=0)&&(modgroup->getPixCtrlStatus()==tOK)&&(modgroup->getPixBocStatus()==tOK)) rod->setBocRegister("BRegClockPhase",(writeResults.at(l)).at(k)); else cout<<"Not writing to BOC - HW not found or initialised."<getPixCtrlStatus()==tOK)&&(modgroup->getPixBocStatus()==tOK)) rod->setBocRegister("BpmClockPhase",(writeResults.at(l)).at(k)); else cout<<"Not writing to BOC - HW not found or initialised."<getPixCtrlStatus()==tOK)&&(modgroup->getPixBocStatus()==tOK)) rod->setBocRegister("VernierFinePhase",(writeResults.at(l)).at(k)); else cout<<"Not writing to BOC - HW not found or initialised."<getPixCtrlStatus()==tOK)&&(modgroup->getPixBocStatus()==tOK)) rod->setBocRegister("VernierFinePhase",(writeResults.at(l)).at(k)); else cout<<"Not writing to BOC - HW not found or initialised."<getPixCtrlStatus()==tOK)&&(modgroup->getPixBocStatus()==tOK)) rod->setBocRegister("VernierClockPhase0",(writeResults.at(l)).at(k)); else cout<<"Not writing to BOC - HW not found or initialised."<getPixCtrlStatus()==tOK)&&(modgroup->getPixBocStatus()==tOK)) rod->setBocRegister("VernierClockPhase1",(writeResults.at(l)).at(k)); else cout<<"Not writing to BOC - HW not found or initialised."<clear(); CrateRodList.clear(); for(std::vector::iterator crIT = m_engine.getSTRodCrates().begin(); crIT != m_engine.getSTRodCrates().end(); crIT++){ crateBox->insertItem((*crIT)->getName().c_str()); std::vector mgr = (*crIT)->getSTPixModuleGroups(); CrateRodList.push_back(mgr); } } void BocAnalysisPanel::enableAnaScan(bool flag) { AnaBocScanButton->setEnabled(flag); AnalyseButton->setEnabled(flag); WriteDataButton->setEnabled(flag); }