#include "ModList.h" #include "MainPanel.h" #include "STControlEngine.h" #include "STRodCrate.h" #include "STPixModuleGroup.h" #include "ConfigEdit.h" #include "ConfigEditI4.h" #include "RodEditor.h" #include "USBCtrlEdit.h" #include "GroupEditor.h" #include "BocEditor_Impl.h" #include "OptionsPanel.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef WIN32 #include #endif using namespace PixLib; using namespace SctPixelRod; ModListItem::ModListItem(STControlEngine &engine_in, Q3ListView *parent, const char *name) : Q3ListViewItem(parent,name," ") , m_engine(engine_in) { m_type = tnone; m_crateId = -1; m_grpId = -1; m_modId = -1; m_enabled = true; } ModListItem::ModListItem(STControlEngine &engine_in, Q3ListViewItem *parent, ContentType type_in, int id_in) : Q3ListViewItem(parent,"new module","untested","undef"), m_engine(engine_in) { m_type = type_in;; m_enabled = true; m_crateId = -1; m_grpId = -1; m_modId = -1; ModListItem *mlp = dynamic_cast(parent); switch(m_type){ case tmodule:{ if(mlp!=0){ m_crateId = mlp->crateId(); m_grpId = mlp->grpId(); } m_modId = id_in; if(m_crateId<0 || m_grpId<0 || m_modId<0) return; if(getCrate()==0) return; // get the real name of this module std::string actname; try{ actname = getCrate()->getModName(m_grpId, m_modId); } catch(...){ std::cerr << "error getting name" << std::endl; } actname = TLogFile::GetNameFromPath(actname.c_str()); if(actname!="") setText(0,actname.c_str()); // check module config if module is active try{ Config &conf = getCrate()->getPixModuleConf(m_grpId, m_modId); if(conf["general"].name()!="__TrashConfGroup__" && conf["general"]["Active"].name()!="__TrashConfObj__"){ if(((ConfList&)conf["general"]["Active"]).sValue()=="TRUE"){ setText(2,"enabled"); m_enabled = true; } else{ setText(2,"disabled"); m_enabled = false; } } }catch(...){ std::cerr << "error getting active status" << std::endl; } break;} case tgroup: if(mlp!=0){ m_crateId = mlp->crateId(); } m_grpId = id_in; if(m_crateId<0 || m_grpId<0) return; if(getCrate()==0) return; setText(0,getCrate()->getGrpName(m_grpId).c_str());//TLogFile::GetNameFromPath(getCrate()->getGrpName(m_grpId).c_str()).c_str()); setText(1," "); setText(2,""); break; case tROD: if(mlp!=0){ m_crateId = mlp->crateId(); m_grpId = mlp->grpId(); } setText(0,"ROD"); setText(1,"uninit."); setText(2,""); break; case tBOC: if(mlp!=0){ m_crateId = mlp->crateId(); m_grpId = mlp->grpId(); } setText(0,"BOC"); setText(1,"uninit."); setText(2,""); break; case tUSB: if(mlp!=0){ m_crateId = mlp->crateId(); m_grpId = mlp->grpId(); } setText(0,"USB-controller"); setText(1,"uninit."); setText(2,""); break; case tTPLL: if(mlp!=0){ m_crateId = mlp->crateId(); m_grpId = mlp->grpId(); } setText(0,"TPLL"); setText(1,"uninit."); setText(2,""); break; case tDCS: case tDCSC: if(mlp!=0) m_crateId = mlp->crateId(); m_grpId = id_in; if(m_crateId<0 || m_grpId<0) return; if(getCrate()==0) return; setText(0,"PixDcsChan"); setText(1,"uninit."); setText(2,""); break; default: break; } } ModListItem::ModListItem(STControlEngine &engine_in, Q3ListView *parent, STRodCrate *crate) : Q3ListViewItem(parent," "," ") , m_engine(engine_in) { QString baseName; switch(m_engine.whichIFtype()){ case tRCCVME: baseName="RCC"; break; case tUSBSys: baseName="USB"; break; default: baseName="---"; } m_type = tcrate;; m_enabled = true; m_grpId = -1; m_modId = -1; m_crateId = -1; if(crate==0) return; m_crateId = crate->getID(); setText(0,crate->getName().c_str()); if(baseName!="---") setText(1,crate->vmeOK()?(baseName+" OK"):("no "+baseName)); else setText(1,baseName); setText(2,""); } ModListItem::~ModListItem(){ } ModListItem::ContentType ModListItem::getType(){ // make sure we return the correct type // if( m_type==tmodule && (m_mod==0 || m_grp!=0) ){ // std::cerr << "[WARNING] ModListItem::getType() :\n" // << "[WARNING] m_type inconsistent" << endl; // } // if( m_type==tgroup && (m_mod!=0 || m_grp==0) ){ // std::cerr << "[WARNING] ModListItem::getType() :\n" // << "[WARNING] m_type inconsistent" << endl; // } return m_type; } ModListItem* ModListItem::parentGroup(){ ModListItem *modit, *parnt; parnt = dynamic_cast(this); modit = parnt; while(parnt->parent()!=0 && parnt->getType()!=tgroup){ modit = parnt; parnt = dynamic_cast(modit->parent()); } if(parnt->getType()==tgroup) return parnt; else return 0; } ModListItem* ModListItem::parentCrate(){ ModListItem *modit, *parnt; parnt = dynamic_cast(this); modit = parnt; while(parnt->parent()!=0 && parnt->getType()!=tcrate){ modit = parnt; parnt = dynamic_cast(modit->parent()); } if(parnt->getType()==tcrate) return parnt; else return 0; } STRodCrate * ModListItem::getCrate() { if(m_crateId>=0 && (int)m_engine.getSTRodCrates().size()>m_crateId) return m_engine.getSTRodCrates()[m_crateId]; else return 0; } /** Read property of Bool enabled. */ const bool& ModListItem::isEnabled(){ return m_enabled; } /** Write property of Bool enabled. */ void ModListItem::setEnabled( const bool& _newVal){ if( _newVal != m_enabled ) { m_enabled = _newVal; if( m_enabled ) { setText(2, "enabled"); } else { setText(2, "disabled"); } if(m_modId>=0 && m_grpId>=0 && parentCrate()!=0 && parentCrate()->getCrate()!=0) parentCrate()->getCrate()->setModuleActive(m_grpId, m_modId, m_enabled); ModList *ml = dynamic_cast(listView()->parent()); if(ml!=0) ml->emitStatusChanged(); } } /** Toggles the enable flag */ void ModListItem::toggleEnable(){ if( m_enabled ) { setEnabled( false ); } else { setEnabled( true ); } } // ModList class starts here ModList::ModList( STControlEngine &engine_in, QWidget* parent, const char*, Qt::WFlags fl, MLmode mode) : QWidget( parent, fl ), m_engine( engine_in ), m_mode(mode), m_scanBusy(false) // ModListBase( parent, name, fl ), m_engine( engine_in ) { setupUi(this); switch(m_mode){ case DAQList: textLabel1->setText("read-out configuration"); turnoffButton->hide(); turnonButton->hide(); readButton->hide(); offReverse->hide(); noUpdateInScan->hide(); break; case DCSList: noUpdateInScan->setChecked(true); offReverse->setChecked(true); textLabel1->setText("monitoring configuration"); ModListView->addColumn(QApplication::translate("ModListBase", "Voltage (V)", 0, QApplication::UnicodeUTF8)); ModListView->header()->setClickEnabled(true, ModListView->header()->count() - 1); ModListView->header()->setResizeEnabled(true, ModListView->header()->count() - 1); ModListView->addColumn(QApplication::translate("ModListBase", "Current (A)", 0, QApplication::UnicodeUTF8)); ModListView->header()->setClickEnabled(true, ModListView->header()->count() - 1); ModListView->header()->setResizeEnabled(true, ModListView->header()->count() - 1); ModListView->addColumn(QApplication::translate("ModListBase", "Temp. (°C)", 0, QApplication::UnicodeUTF8)); ModListView->header()->setClickEnabled(true, ModListView->header()->count() - 1); ModListView->header()->setResizeEnabled(true, ModListView->header()->count() - 1); ModListView->addColumn(QApplication::translate("ModListBase", "Index", 0, QApplication::UnicodeUTF8)); ModListView->header()->setClickEnabled(true, ModListView->header()->count() - 1); ModListView->header()->setResizeEnabled(true, ModListView->header()->count() - 1); ModListView->setSortColumn(ModListView->columns()-1); // set ordering by last column (i.e. index) QObject::connect(turnoffButton, SIGNAL(clicked()), this, SLOT(allOff())); QObject::connect(turnonButton, SIGNAL(clicked()), this, SLOT(allOn())); QObject::connect(readButton, SIGNAL(clicked()), this, SLOT(updateView())); break; default: textLabel1->setText("unknown view-mode"); } m_waitForGeoView = false; m_cfgEditOpen = false; m_edtCrate=0; m_edtItem=0; m_lastDcsRead = new QTime(); m_lastDcsRead->start(); QObject::connect(ModListView, SIGNAL(doubleClicked(Q3ListViewItem*)), this, SLOT(editModule(Q3ListViewItem*))); QObject::connect(ModListView, SIGNAL(rightButtonClicked(Q3ListViewItem*,QPoint,int)), this, SLOT(rightClick(Q3ListViewItem*,QPoint,int))); // get updates from engine QObject::connect( &m_engine, SIGNAL( crateListChanged() ), this, SLOT( updateView() ) ); QObject::connect( &m_engine, SIGNAL( configChanged() ), this, SLOT( updateView() ) ); QObject::connect( &m_engine, SIGNAL( statusChanged() ), this, SLOT( changeStatus() ) ); } ModList::~ModList(){ delete m_lastDcsRead; } void ModList::editModule(Q3ListViewItem *in_item){ editModule(in_item,true); } void ModList::editModule(Q3ListViewItem *in_item, bool doubleClick){ // Make sure in_item is not 0. if(in_item==0) return; m_edtItem = dynamic_cast(in_item); ModListItem* item = m_edtItem; // if in-item is module group, avoid change in open state if(m_edtItem!=0 && (m_edtItem->getType()==ModListItem::tgroup || m_edtItem->getType()==ModListItem::tDCS) && doubleClick) m_edtItem->setOpen(!m_edtItem->isOpen()); ModListItem *group=0; // cast only works for ModuleList items if(m_edtItem!=0 && m_edtItem->getType()==ModListItem::tmodule ){ if(m_cfgEditOpen){ QMessageBox::warning(this,"ModList::editModule()","Another config editor is already open, can't proceed"); return; } m_edtCrate = m_edtItem->getCrate(); if(m_edtCrate==0) return; if(m_edtCrate->getPixCtrlStatus(m_edtItem->grpId())==tbusy || m_edtCrate->getPixCtrlStatus(m_edtItem->grpId())==tscanning || m_edtItem->text(1)=="testing"){ // module or ROD is doing something, do not disturb QMessageBox::information(this,"ModList::editModule()","ROD or module is busy, can't edit config."); return; } Config &mcfg = m_edtCrate->getPixModuleConf(m_edtItem->grpId(), m_edtItem->modId()); std::string fetype="unknown"; if(mcfg["general"].name()!="__TrashConfGroup__" && mcfg["general"]["FE_Flavour"].name()!="__TrashConfObj__") fetype = ((ConfList&)mcfg["general"]["FE_Flavour"]).sValue(); if(fetype=="FE_I2"){ // FE-I2/3 Config* conf[18];// elements 0...15 are FEs, 16 is MCC, 17 is module for(int chipID=0;chipID<17;chipID++) conf[chipID] = &(m_edtCrate->getPixModuleChipConf(m_edtItem->grpId(), m_edtItem->modId(), chipID)); conf[17] = &mcfg; ConfigEdit *cfgedt = new ConfigEdit(conf, 0,"cfgedit",FALSE,0); cfgedt->setAttribute(Qt::WA_DeleteOnClose); // read module name cfgedt->ModName->setText(TLogFile::GetNameFromPath(m_edtCrate->getModName(m_edtItem->grpId(), m_edtItem->modId()).c_str()).c_str()); cfgedt->GroupName->setText(m_edtCrate->getGrpName(m_edtItem->grpId()).c_str()); m_cfgEditOpen = true; QObject::connect(cfgedt, SIGNAL(cfgSaved(int)), this, SLOT(saveFromEdit(int))); QObject::connect(cfgedt, SIGNAL(cfgDone()), this, SLOT(editClosed())); cfgedt->show(); } else if(fetype=="FE_I4A" || fetype=="FE_I4B"){ // FE-I4 // create and open editor panel Config* conf[3];// elements 0,1 are FEs, 2 is module for(int chipID=0;chipID<2;chipID++) conf[chipID] = &(m_edtCrate->getPixModuleChipConf(m_edtItem->grpId(), m_edtItem->modId(), chipID)); conf[2] = &mcfg; ConfigEditI4 *cfgedt = new ConfigEditI4(conf, 0,0); cfgedt->setAttribute(Qt::WA_DeleteOnClose); // read module name cfgedt->ModName->setText(TLogFile::GetNameFromPath(m_edtCrate->getModName(m_edtItem->grpId(), m_edtItem->modId()).c_str()).c_str()); //cfgedt->GroupName->setText(m_edtCrate->getGrpName(m_edtItem->grpId()).c_str()); m_cfgEditOpen = true; QObject::connect(cfgedt, SIGNAL(cfgSaved(int)), this, SLOT(saveFromEdit(int))); QObject::connect(cfgedt, SIGNAL(cfgDone()), this, SLOT(editClosed())); cfgedt->show(); } else { // something unknown // use generic config editor optionsPanel op(mcfg,this,"FEpan",true, 0, true); if(op.exec()==QDialog::Accepted) saveFromEdit(m_edtItem->modId()); } } else if(item!=0 && item->getType()==ModListItem::tBOC && item->parentGroup()!=0 && item->parentGroup()->getType()==ModListItem::tgroup){ STRodCrate *crt = item->getCrate(); if(crt==0) return; // KEPTOLDCRATE STPixModuleGroup *grp = crt->getSTPixModuleGroups()[item->grpId()]; if(grp==0) return; bool have_rod=false; PixBoc *pb = grp->getPixBoc(); #ifndef NOTDAQ RodPixController *rpc = dynamic_cast(grp->getPixController()); if(rpc!=0 && pb!=0) have_rod = (rpc->rodMod()!=0); #endif BocEditor_Impl *m = new BocEditor_Impl(0, have_rod, pb, this, m_boceditors.size(), "boccontrol",false, Qt::WDestructiveClose ); m->updateBocHandlersAll(); m->SlotRemoveWarnings(); // end KEPTOLDCRATE // store globally and individ. that this BOC was edited m_engine.editedCfg(); // store individ. that this BOC was edited crt->editedCfg(item->grpId(),42); m->show(); m_boceditors.push_back(*(&m)); } else if(item!=0 && item->getType()==ModListItem::tROD && item->parentGroup()!=0 && item->parentGroup()->getType()==ModListItem::tgroup){ STRodCrate *crt = item->getCrate(); if(crt==0) return; if(crt->getPixCtrlStatus(item->grpId())==tbusy || crt->getPixCtrlStatus(item->grpId())==tscanning) return; // ROD is doing something // do not disturb Config &cfgROD = crt->getPixCtrlConf(item->grpId()); RodEditor redt(cfgROD, m_engine, crt, this, "RODedit",false); if(item->grpId()>=0 && crt->hasBoc(item->grpId())){ // KEPTOLDCRATE STPixModuleGroup *grp = crt->getSTPixModuleGroups()[item->grpId()]; if(grp!=0) redt.setPixBoc(grp->getPixBoc()); // end KEPTOLDCRATE if(crt->getPixBocStatus(item->grpId())==tOK) redt.setBocOK(true); } if(redt.exec()){ m_engine.editedCfg(); // store individ. that this ROD was edited crt->editedCfg(item->grpId(),41); // set group name as per ROD slot if((group=item->parentGroup())!=0) group->setText(0,"SLOT "+QString::number(redt.loaded_RODslots[redt.RodSlotBox->currentItem()])); Config &conf = crt->getGrpConf(item->grpId()); std::string new_name = ("SLOT "+QString::number(redt.loaded_RODslots[redt.RodSlotBox->currentItem()])).latin1(); if(conf["general"].name()!="__TrashConfGroup__" && conf["general"]["ModuleGroupName"].name()!="__TrashConfObj__") ((ConfString&)conf["general"]["ModuleGroupName"]).m_value = new_name; // make sure all BOC editors update DTO speed if(m_boceditors.size() != 0){ for(std::vector::iterator BEIT = m_boceditors.begin(); BEIT != m_boceditors.end(); BEIT++){ if (!(*BEIT == 0)) (*BEIT)->setBocMode(); } } // set DTO speed of all modules STRodCrate *crt = item->getCrate(); if(crt!=0){ std::vector< std::pair > list; crt->getModules(item->grpId(), list); for(int iMod=0; iMod<(int)list.size(); iMod++){ Config &mccconf = crt->getPixModuleChipConf(item->grpId(), iMod, 16); int mccmod = redt.SetupBox->currentItem(); if(mccmod>0) mccmod++; // 1==40MHz dual is not used if(mccconf["Registers"].name()!="__TrashConfGroup__" && mccconf["Registers"]["CSR_OutputMode"].name()!="__TrashConfObj__") WriteIntConf((ConfInt&)mccconf["Registers"]["CSR_OutputMode"], mccmod); } } // change ROD-status back to unitialised crt->setPixCtrlStatus(item->grpId(), tblocked); // NB: the following call is the last thing to do!!!! // crate list will be changed by this call, item pointer is nonsense! // m_engine.changedConfigs(); // shouldn't be necessary anymore } } else if(item!=0 && item->getType()==ModListItem::tgroup){ STRodCrate *crt = item->getCrate(); if(crt==0) return; if(crt->getPixCtrlStatus(item->grpId())==tbusy || crt->getPixCtrlStatus(item->grpId())==tscanning) return; // ROD is doing something // do not disturb bool wasEdited=false; std::vector mods; if(m_engine.whichIFtype()==tRCCVME){ GroupEditor gedt(m_engine,item->crateId(),item->grpId(),this,"grpedt"); if(gedt.exec()==QDialog::Accepted){ mods = gedt.editedModules(); wasEdited = true; } } else{ optionsPanel op(crt->getGrpConf(item->grpId()),this,"grppan",true); wasEdited = (op.exec()==QDialog::Accepted); } if(wasEdited){ m_engine.editedCfg(); // store individ. that this group was edited crt->editedCfg(item->grpId(),40); // set item name as it is in config Config &conf = crt->getGrpConf(item->grpId()); if(conf["general"].name()!="__TrashConfGroup__" && conf["general"]["ModuleGroupName"].name()!="__TrashConfObj__") item->setText(0,((ConfString&)conf["general"]["ModuleGroupName"]).value().c_str()); for(std::vector::iterator it=mods.begin(); it!=mods.end(); it++) crt->editedCfg(item->grpId(), (*it)); // store individ. that this module was edited // send modified module config to PixController if that's initialised // and ask edit panel if anything was acutally changed if(crt->getPixCtrlStatus(item->grpId())==tOK && mods.size()>0){ for(std::vector::iterator it=mods.begin(); it!=mods.end(); it++){ crt->editedCfg(item->grpId(), (*it)); // store individ. that this module was edited try{ crt->writeConfig(item->grpId(), (*it)); } catch(...){ QMessageBox::warning(this,"ModList::editModule","Error sending edited configuration to PixController!"); } } m_engine.readRodBuff("Post-config:"); } // NB: the following call is the last thing to do!!!! // crate list will be changed by this call, item pointer is nonsense! m_engine.changedConfigs(); } } else if(item!=0 && item->getType()==ModListItem::tUSB && item->parentGroup()!=0 && item->parentGroup()->getType()==ModListItem::tgroup){ STRodCrate *crt = item->getCrate(); if(crt==0) return; if(crt->getPixCtrlStatus(item->grpId())==tbusy || crt->getPixCtrlStatus(item->grpId())==tscanning) return; // system is doing something // do not disturb Config &cfgUSB = crt->getPixCtrlConf(item->grpId()); USBCtrlEdit *uce = new USBCtrlEdit(cfgUSB,this); //optionsPanel *op = new optionsPanel(cfgROD,this,"conntabs",false,0,true); //op->setCaption("USB config editor"); if(uce->exec()){ m_engine.editedCfg(); // store individ. that this PixController was edited crt->editedCfg(item->grpId(),41); if(uce->recfgNeeded()) crt->setPixCtrlStatus(item->grpId(), tblocked); else crt->reloadCtrlCfg(item->grpId()); } delete uce; } else if(item!=0 && item->getType()==ModListItem::tTPLL && item->parentGroup()!=0 && item->parentGroup()->getType()==ModListItem::tgroup){ STRodCrate *crt = item->getCrate(); if(crt==0) return; if(crt->getPixCtrlStatus(item->grpId())==tbusy || crt->getPixCtrlStatus(item->grpId())==tscanning) return; // system is doing something // do not disturb Config &cfgROD = crt->getPixCtrlConf(item->grpId()); optionsPanel *op = new optionsPanel(cfgROD,this,"conntabs",false,0,true); op->setCaption("TPLL config editor"); if(op->exec()){ m_engine.editedCfg(); // store individ. that this PixController was edited crt->editedCfg(item->grpId(),41); crt->setPixCtrlStatus(item->grpId(), tblocked); } delete op; } else if(item!=0 && item->getType()==ModListItem::tDCSC){ STRodCrate *crt = item->getCrate(); if(crt==0 || item->parent()==0) return; //if(crt->getPixCtrlStatus(item->grpId())==tbusy || // crt->getPixCtrlStatus(item->grpId())==tscanning) return; // system is doing something // do not disturb std::vector dcs = crt->getPixDcs(); if(((ModListItem*)item->parent())->grpId()>=0 && ((ModListItem*)item->parent())->grpId()<(int)dcs.size()){ if(item->grpId()>=0 && item->grpId()parent())->grpId()]->nchan()){ Config &cfgDcs = dcs[((ModListItem*)item->parent())->grpId()]->getChan(item->grpId())->config(); optionsPanel *op = new optionsPanel(cfgDcs,this,"conntabs",false,0,true, false, false); op->setCaption("PixDcs config editor - channel "+QString::number(item->grpId())); if(op->exec()){ m_engine.editedCfg(); } delete op; } } updateViewDCS(); } else if(item!=0 && item->getType()==ModListItem::tDCS){ STRodCrate *crt = item->getCrate(); if(crt==0) return; //if(crt->getPixCtrlStatus(item->grpId())==tbusy || // crt->getPixCtrlStatus(item->grpId())==tscanning) return; // system is doing something // do not disturb std::vector dcs = crt->getPixDcs(); if(item->grpId()>=0 && item->grpId()<(int)dcs.size()){ Config &cfgDcs = dcs[item->grpId()]->config(); optionsPanel *op = new optionsPanel(cfgDcs,this,"conntabs",false,0,false, false, false); op->setCaption("PixDcs config editor"); if(op->exec()){ m_engine.editedCfg(); } delete op; } updateViewDCS(); } return; } void ModList::editClosed(){ m_edtItem = 0; m_edtCrate = 0; m_cfgEditOpen = false; } void ModList::saveFromEdit(int new_modID){ //if(cfgedt.editState()){ // ask edit panel if anything was acutally changed if(m_edtCrate!=0 && m_edtItem!=0){ m_edtItem->m_modId = new_modID; m_engine.editedCfg(); // store generally that something was edited m_edtCrate->editedCfg(m_edtItem->grpId(), m_edtItem->modId()); // store individ. that this module was edited // send modified module config to PixController if that's initialised if(m_edtCrate->getPixCtrlStatus(m_edtItem->grpId())==tOK){ try{ m_edtCrate->writeConfig(m_edtItem->grpId(), m_edtItem->modId()); } catch(...){ QMessageBox::warning(this,"ModList::saveFromEdit","Error sending edited configuration to PixController!"); } m_engine.readRodBuff("Post-config:"); } // update module lists updateView(); } else QMessageBox::warning(this,"ModList::saveFromEdit","Function called, but needed member variables are NULL"); } void ModList::rightClick(Q3ListViewItem *item, const QPoint &, int col){ if(item==0) return; // nothing to do if(item->text(2)=="busy") return; // must not touch busy modules if(((ModListItem*)item)->getType()!=ModListItem::tmodule && ((ModListItem*)item)->getType()!=ModListItem::tDCS && ((ModListItem*)item)->getType()!=ModListItem::tDCSC) return; // not a valid operation on RODs and crates switch(col){ default: break; case 2: // toggle enable/disable toggleEnable(item); break; } return; } void ModList::toggleEnable(Q3ListViewItem *in_item) { // Make sure that in_item was a ModListItem ModListItem *item = dynamic_cast(in_item); if(item==0) return; if(item->getType()==ModListItem::tmodule) item->toggleEnable(); else if(item->getType()==ModListItem::tDCS && item->getCrate()!=0){ std::vector dcsvec = item->getCrate()->getPixDcs(); if(item->grpId()>=0 && item->grpId()<(int)dcsvec.size()){ std::string state = dcsvec[item->grpId()]->ReadState(""); if((state=="ON" || state =="OFF" || state=="ALL ON" || state =="ALL OFF") && dcsvec[item->grpId()]->getDevType()==PixDcs::SUPPLY){ if(state=="ON" || state=="ALL ON"){ QApplication::setOverrideCursor(Qt::waitCursor); dcsvec[item->grpId()]->SetState("OFF"); QApplication::restoreOverrideCursor(); }else{ QApplication::setOverrideCursor(Qt::waitCursor); dcsvec[item->grpId()]->SetState("ON"); QApplication::restoreOverrideCursor(); } } } updateViewDCS(); } else if(item->getType()==ModListItem::tDCSC && item->getCrate()!=0){ std::vector dcsvec = item->getCrate()->getPixDcs(); if(((ModListItem*)(item->parent()))->grpId()>=0 && ((ModListItem*)(item->parent()))->grpId()<(int)dcsvec.size()){ PixDcs *dev = dcsvec[((ModListItem*)(item->parent()))->grpId()]; if(item->grpId()>=0 && item->grpId()nchan()){ std::string state = dev->getChan(item->grpId())->ReadState(""); if((state=="ON" || state =="OFF") && dev->getDevType()==PixDcs::SUPPLY){ if(state=="ON"){ QApplication::setOverrideCursor(Qt::waitCursor); dev->getChan(item->grpId())->SetState("OFF"); QApplication::restoreOverrideCursor(); }else{ QApplication::setOverrideCursor(Qt::waitCursor); dev->getChan(item->grpId())->SetState("ON"); QApplication::restoreOverrideCursor(); } } } } updateViewDCS(); } return; } void ModList::allSwitch(bool in_on){ std::map myDcs; ModListItem *item = dynamic_cast(ModListView->firstChild()); if(item!=0){ QApplication::setOverrideCursor(Qt::waitCursor); item = dynamic_cast(item->firstChild()); while(item!=0){ if( item->getType()==ModListItem::tDCS && item->getCrate()!=0){ std::vector dcsvec = item->getCrate()->getPixDcs(); if(item->grpId()>=0 && item->grpId()<(int)dcsvec.size()){ if(dcsvec[item->grpId()]->getDevType()==PixDcs::SUPPLY){ int myInd = dcsvec[item->grpId()]->getIndex(); if(!in_on && offReverse->isChecked()) myInd *= (-1); myDcs[myInd] = dcsvec[item->grpId()]; } } } item = dynamic_cast(item->nextSibling()); } for(std::map::iterator IT=myDcs.begin(); IT!=myDcs.end();IT++) IT->second->SetState(in_on?"ON":"OFF"); //printf("turning %s device %s\n", in_on?"ON":"OFF", IT->second->name().c_str()); updateViewDCS(); QApplication::restoreOverrideCursor(); } else m_engine.toErrLog("ModList::allSwitch : List contains no main item"); return; } void ModList::deleteModuleGroup(ModListItem *item){ // Make sure item is not 0. if(item==0) { return; } if( item->getType()==ModListItem::tgroup ) { delete item; return; } else { std::cerr << "[Note] ModList::deleteModuleGroup(ModListItem *item) :\n" << "[Note] *item does not contain a PixModuleGroup according to getType()\n" << "[Note] returning" << endl; return; } } /** Return the currently selected Module as given by currentItem() */ ModListItem * ModList::currentModule() const{ ModListItem *item = dynamic_cast( this->ModListView->currentItem() ); // We promised we'd return a module if( item->getType() == ModListItem::tmodule ) { return item; } else { return 0; } } /** Return the currently selected Module as given by currentItem() */ ModListItem * ModList::currentROD() const{ ModListItem *item = dynamic_cast( this->ModListView->currentItem() ); // We promised we'd return a module if( item->getType() == ModListItem::tROD ) { return item; } else { return 0; } } /** Return the currently selected Module as given by currentItem() */ ModListItem * ModList::currentUSB() const{ ModListItem *item = dynamic_cast( this->ModListView->currentItem() ); // We promised we'd return a module if( item->getType() == ModListItem::tUSB ) { return item; } else { return 0; } } /** Return the currently selected Module as given by currentItem() */ ModListItem * ModList::currentBOC() const{ ModListItem *item = dynamic_cast( this->ModListView->currentItem() ); // We promised we'd return a module if( item->getType() == ModListItem::tBOC ) { return item; } else { return 0; } } /** Return the currently selected Group as given by currentItem(), or its parent Group */ ModListItem * ModList::currentGroup() const{ ModListItem *item = dynamic_cast( this->ModListView->currentItem() ); if( item == 0 ) return 0; switch( item->getType() ) { case ModListItem::tgroup: return item; break; case ModListItem::tmodule: return item->parentGroup(); break; default: return 0; } return 0; } /** Return the currently selected crate as given by currentItem() */ ModListItem * ModList::currentCrate() const{ ModListItem *item = dynamic_cast( this->ModListView->currentItem() ); if( item == 0 ) return 0; switch( item->getType() ) { case ModListItem::tcrate: return item; break; default: return 0; } return 0; } /** Update the ListView */ void ModList::updateView() { if(m_scanBusy && noUpdateInScan->isChecked()) return; switch(m_mode){ case DAQList: updateViewDAQ(); break; case DCSList: updateViewDCS(); break; default: QMessageBox::warning(this,"ModList::updateView","Mode is undefined, can't select correct function"); } } void ModList::updateViewDCS(){ // check time since last read and skip if too shortly ago - otherwise GUI freezes during certain scans if(m_scanBusy && m_lastDcsRead->elapsed()<1500) return; m_lastDcsRead->restart(); // We regenerate the whole view from scratch. // Delete all items ModListView->clear(); QApplication::setOverrideCursor(Qt::waitCursor); unsigned int crateID=0; for( std::vector::iterator crate = m_engine.getSTRodCrates().begin(); crate != m_engine.getSTRodCrates().end(); crate++ ) { ModListItem *crateItem = new ModListItem( m_engine, ModListView, *crate); crateID++; crateItem->setOpen( true ); crateItem->setText(1,"DCS"); std::vector dcsvec = (*crate)->getPixDcs(); int ID=0; for(std::vector::iterator dcs = dcsvec.begin(); dcs!=dcsvec.end(); dcs++){ ModListItem *dcsItem = new ModListItem( m_engine, crateItem, ModListItem::tDCS, ID ); dcsItem->setText(6,QString::number((*dcs)->getIndex())); dcsItem->setText(0,(*dcs)->name().c_str()); std::string state = (*dcs)->ReadState(""); if(state=="ON" || state =="OFF" || state=="ALL ON" || state =="ALL OFF" ){ dcsItem->setText(1,"OK"); dcsItem->setText(2,state.c_str()); } if(state =="OK" || state=="CHAN"){ dcsItem->setText(1,"OK"); dcsItem->setText(2,""); } if(state=="ERROR"){ dcsItem->setText(1,"problem"); dcsItem->setText(2,"--"); } int cID=0; dcsItem->setOpen( true ); for(std::vector::iterator dcsc = (*dcs)->chanBegin(); dcsc!=(*dcs)->chanEnd(); dcsc++){ ModListItem *dcscItem = new ModListItem( m_engine, dcsItem, ModListItem::tDCSC, cID ); dcscItem->setText(0,(*dcsc)->name().c_str()); dcscItem->setText(6,""); dcscItem->setText(1,"---"); dcscItem->setText(2,"---"); if(state=="ON" || state =="OFF" || state=="OK" || state=="ALL ON" || state =="ALL OFF" || state=="CHAN"){ dcscItem->setText(1,"OK"); if(state=="ON" || state =="OFF" || state =="OK") dcscItem->setText(2,""); else dcscItem->setText(2,(*dcsc)->ReadState("").c_str()); try{ float volts = (*dcsc)->ReadParam("voltage"); if(fabs(volts)<1e-2) dcscItem->setText(3,QString::number(volts,'g',4)); else dcscItem->setText(3,QString::number(volts,'f',4)); }catch(...){ dcscItem->setText(3,"---"); } try{ float curr = (*dcsc)->ReadParam("current"); if(fabs(curr)<1e-2) dcscItem->setText(4,QString::number(curr,'g',4)); else dcscItem->setText(4,QString::number(curr,'f',4)); }catch(...){ dcscItem->setText(4,"---"); } try{ float curr = (*dcsc)->ReadParam("temperature"); dcscItem->setText(5,QString::number(curr,'f',1)); }catch(...){ dcscItem->setText(5,"---"); } } else{ dcscItem->setText(3,"---"); dcscItem->setText(4,"---"); dcscItem->setText(5,"---"); } cID++; } ID++; } } QApplication::restoreOverrideCursor(); } void ModList::updateViewDAQ() { while(m_waitForGeoView) PixLib::sleep(500); // wait for other viewer to finish before we start // We regenerate the whole view from scratch. // Delete all items ModListView->clear(); unsigned int crateID=0; for( std::vector::iterator crate = m_engine.getSTRodCrates().begin(); crate != m_engine.getSTRodCrates().end(); crate++ ) { ModListItem *crateItem = new ModListItem( m_engine, ModListView, *crate); crateID++; crateItem->setOpen( true ); // for( std::vector::iterator group = (*crate)->getSTPixModuleGroups().begin(); // group != (*crate)->getSTPixModuleGroups().end(); group++ ) { for(int iGrp=0; iGrp<(*crate)->nGroups(); iGrp++){ ModListItem *grpItem = new ModListItem( m_engine, crateItem, ModListItem::tgroup, iGrp ); grpItem->setOpen( true ); // add separate ROD and BOC items if((*crate)->hasCtrl(iGrp)==1){ ModListItem *rodItem = new ModListItem( m_engine, grpItem, ModListItem::tROD, iGrp); switch((*crate)->getPixCtrlStatus(iGrp)){ case tOK: rodItem->setText(1,"OK"); break; case tproblem: rodItem->setText(1,"problem"); break; case tbusy: rodItem->setText(1,"busy"); break; case tscanning: rodItem->setText(1,"scanning"); break; case tblocked: default: rodItem->setText(1,"uninit."); } if((*crate)->hasBoc(iGrp)){ ModListItem *bocItem = new ModListItem( m_engine, grpItem, ModListItem::tBOC, iGrp); switch((*crate)->getPixBocStatus(iGrp)){ case tOK: bocItem->setText(1,"OK"); break; case tproblem: bocItem->setText(1,"problem"); break; case tbusy: bocItem->setText(1,"busy"); break; case tblocked: default: bocItem->setText(1,"uninit."); } } } // add separate item for USB board if((*crate)->hasCtrl(iGrp)==2){ ModListItem *rodItem = new ModListItem( m_engine, grpItem, ModListItem::tUSB, iGrp); switch((*crate)->getPixCtrlStatus(iGrp)){ case tOK: rodItem->setText(1,"OK"); break; case tproblem: rodItem->setText(1,"problem"); break; case tbusy: rodItem->setText(1,"busy"); break; case tscanning: rodItem->setText(1,"scanning"); break; case tblocked: default: rodItem->setText(1,"uninit."); } } // add separate item for TPLL if((*crate)->hasCtrl(iGrp)==3){ ModListItem *rodItem = new ModListItem( m_engine, grpItem, ModListItem::tTPLL, iGrp); switch((*crate)->getPixCtrlStatus(iGrp)){ case tOK: rodItem->setText(1,"OK"); break; case tproblem: rodItem->setText(1,"problem"); break; case tbusy: rodItem->setText(1,"busy"); break; case tscanning: rodItem->setText(1,"scanning"); break; case tblocked: default: rodItem->setText(1,"uninit."); } } // now add all modules // for( PixModuleGroup::moduleIterator mod = (*group)->modBegin(); mod != (*group)->modEnd(); mod++ ){ std::vector< std::pair > list; (*crate)->getModules(iGrp, list); // for(int iMod=0; iMod<(int)list.size(); iMod++){ for(std::vector< std::pair >::iterator IT=list.begin(); IT!=list.end(); IT++){ ModListItem *modItem = new ModListItem( m_engine, grpItem, ModListItem::tmodule, IT->second); modStatus modS = (*crate)->getPixModuleStatus(iGrp,IT->second); switch(modS.modStat){ case tOK: modItem->setText(1,"OK"); break; case tbusy: modItem->setText(1,"testing"); break; case tproblem: modItem->setText(1,"problem"); break; case tfailed: modItem->setText(1,"failed"); break; case tblocked: case tunknown: default: modItem->setText(1,"untested"); } } } } ModListView->setCurrentItem(ModListView->firstChild()); m_waitForGeoView = true; emit listUpdated(ModListView->firstChild()); m_waitForGeoView= false; } void ModList::changeStatus() { if(m_scanBusy && noUpdateInScan->isChecked()) return; switch(m_mode){ case DCSList: updateViewDCS(); break; default: QMessageBox::warning(this,"ModList::updateView","Mode is undefined, can't select correct function"); break; case DAQList:{ while(m_waitForGeoView) PixLib::sleep(100); // wait for other viewer to finish before we start ModListItem *crIt = (ModListItem *)ModListView->firstChild(); while(crIt!=0){ STRodCrate *crt = crIt->getCrate(); ModListItem *grpIt = (ModListItem *)crIt->firstChild(); while(grpIt!=0){ ModListItem *objIt = (ModListItem *)grpIt->firstChild(); while(objIt!=0){ if(objIt->getType()==ModListItem::tROD || objIt->getType()==ModListItem::tUSB || objIt->getType()==ModListItem::tTPLL){ switch(crt->getPixCtrlStatus(objIt->grpId())){ case tOK: objIt->setText(1,"OK"); break; case tproblem: objIt->setText(1,"problem"); break; case tbusy: objIt->setText(1,"busy"); break; case tscanning: objIt->setText(1,"scanning"); break; case tblocked: default: objIt->setText(1,"uninit."); } } else if(objIt->getType()==ModListItem::tBOC){ switch(crt->getPixBocStatus(objIt->grpId())){ case tOK: objIt->setText(1,"OK"); break; case tproblem: objIt->setText(1,"problem"); break; case tbusy: objIt->setText(1,"busy"); break; case tblocked: default: objIt->setText(1,"uninit."); } } else if(objIt->getType()==ModListItem::tmodule){ switch(crt->getPixModuleStatus(objIt->grpId(),objIt->modId()).modStat){ case tOK: objIt->setText(1,"OK"); break; case tbusy: objIt->setText(1,"testing"); break; case tproblem: objIt->setText(1,"problem"); break; case tfailed: objIt->setText(1,"failed"); break; case tblocked: case tunknown: default: objIt->setText(1,"untested"); } objIt->setEnabled(crt->getModuleActive(objIt->grpId(),objIt->modId())); } objIt = (ModListItem *)objIt->nextSibling(); } grpIt = (ModListItem *)grpIt->nextSibling(); } crIt = (ModListItem *)crIt->nextSibling(); } ModListView->setCurrentItem(ModListView->firstChild()); m_waitForGeoView = true; emit statusChanged(); m_waitForGeoView= false; } } } void ModList::updateBocEditors() { if(m_boceditors.size() != 0) { for(std::vector::iterator BEIT = m_boceditors.begin(); BEIT != m_boceditors.end(); BEIT++) { if (!(*BEIT == 0)) { bool warningcl = (*BEIT)->getWarningCl(); bool warningrx[4]; bool warningtx[4]; for(int i = 0; i<4; i++) { warningrx[i] = (*BEIT)->getWarningRx(i); warningtx[i] = (*BEIT)->getWarningTx(i); } // update GUI (*BEIT)->updateBocHandlersAll(); // redraw original warnings (*BEIT)->SlotRemoveWarnings(); if(warningcl) (*BEIT)->SlotSetClocksWarning(); if(warningrx[0]) (*BEIT)->SlotSetRxWarning(); if(warningrx[1]) (*BEIT)->SlotSetRxWarning1(); if(warningrx[2]) (*BEIT)->SlotSetRxWarning2(); if(warningrx[3]) (*BEIT)->SlotSetRxWarning3(); if(warningtx[0]) (*BEIT)->SlotSetTxWarning(); if(warningtx[1]) (*BEIT)->SlotSetTxWarning1(); if(warningtx[2]) (*BEIT)->SlotSetTxWarning2(); if(warningtx[3]) (*BEIT)->SlotSetTxWarning3(); } } } return; }