#include "ModGeoView.h" #include "ModList.h" #include "STControlEngine.h" #include "STRodCrate.h" #include #include #include #include #include #include #include #include #include ModGeoView::ModGeoView( STControlEngine &engine_in, QWidget* parent, const char*, Qt::WFlags fl, ModList *orgList) : QWidget(parent,fl), m_orgList(orgList), m_engine(engine_in){ //: ModGeoViewBase(parent,name,fl), m_orgList(orgList), m_engine(engine_in){ setupUi(this); updateList(); // signals and slots connections QObject::connect( modGeoView, SIGNAL( currentChanged(Q3ListViewItem*) ), this, SLOT( emitCurrChanged(Q3ListViewItem*) )); QObject::connect( modGeoView, SIGNAL( doubleClicked(Q3ListViewItem*) ), this, SLOT( editModule(Q3ListViewItem*) ) ); QObject::connect( modGeoView, SIGNAL( rightButtonClicked(Q3ListViewItem*,const QPoint&,int) ), this, SLOT( rightClick(Q3ListViewItem*,const QPoint&,int) ) ); } ModGeoView::~ModGeoView(){ } void ModGeoView::loadGeo(){ // if list of maps already exists, we have mothing to do if(m_strcutList.size()>0 && m_strcutList.begin()->second.second!=0) return; m_strcutList.clear(); // auto-load options, needed later Config &opts = m_engine.getOptions(); bool getAssyInfo = ((ConfBool&)opts["PDB"]["getAssyInfo"]).value(); // create disk and half shell maps m_qparSN[0] = "1A"; m_qparSN[1] = "2A"; m_qparSN[2] = "3A"; m_qparSN[3] = "1C"; m_qparSN[4] = "2C"; m_qparSN[5] = "3C"; m_qparSN[6] = "L2 top"; m_qparSN[7] = "L2 bottom"; m_qparSN[8] = "L1"; m_qparSN[9] = "L0"; for(int i=0;i=0){ testSN += "0"; mapAssType = ModuleMap::layer0; } else if(m_qparSN[i].find("L1")>=0){ testSN += "1"; mapAssType = ModuleMap::layer1; } else if(m_qparSN[i].find("L2")>=0){ testSN += "2"; mapAssType = ModuleMap::halfshell2; } testSN += "1"; if(m_qparSN[i].find("top")>=0) testSN += "2"; } // read structure from PDB (will become obsolete once conn. name convention is used) if(m_engine.m_userPDB!="" && m_engine.m_passwdPDB!="" && getAssyInfo){ // create maps for status viewing ModuleMap *mmap = new ModuleMap(mapAssType, label.latin1(), this, m_qparSN[i].latin1()); CDatabaseCom cdb(m_engine.m_userPDB.c_str(),m_engine.m_passwdPDB.c_str(),testSN); std::vector secSNs; secSNs = cdb.getStaveSNs(m_engine.getApp()); if(i>5){ // get staves from bistave std::vector tmpSecSNs, orgSecSNs = secSNs; secSNs.clear(); for(int j=0;j<(int)orgSecSNs.size();j++){ CDatabaseCom cdb2(m_engine.m_userPDB.c_str(),m_engine.m_passwdPDB.c_str(),"2021200"+orgSecSNs[j]); tmpSecSNs = cdb2.getStaveSNs(m_engine.getApp()); for(int k=0;k<(int)tmpSecSNs.size();k++) secSNs.push_back(tmpSecSNs[k]); } } for(int j=0; j<(int)secSNs.size(); j++){ std::string keptSN = secSNs[j]; if(i<6) // keep only last 4 digits for sectos keptSN.erase(0,3); m_strcutList.insert(std::make_pair(keptSN, std::make_pair(m_qparSN[i].latin1(),j+1))); mmap->loadModule("Module 1", j, 0,keptSN.c_str()); } mmap->repaint(); } } } void ModGeoView::changeStatus() { if(m_orgList==0) return; // individual modules - all in base item Q3ListViewItem *item = m_baseItems[0]->firstChild(); while(item!=0){ if(m_orgItems[(long int)item]!=0){ for(int j=0;j<3;j++) if(m_orgItems[(long int)item]!=0) item->setText(j, m_orgItems[(long int)item]->text(j)); } item = item->nextSibling(); } // individual staves/sectors - all in next level for(int i=1;i<3;i++){ Q3ListViewItem *sItem = m_baseItems[i]->firstChild(); ModuleMap *mmap = dynamic_cast(child(m_baseItems[i]->text(0))); std::map modSt; while(sItem!=0){ Q3ListViewItem *item = sItem->firstChild(); while(item!=0){ if(m_orgItems[(long int)item]!=0){ for(int j=0;j<3;j++) item->setText(j, m_orgItems[(long int)item]->text(j)); std::string status = "unknown"; if(m_orgItems[(long int)item]->text(1)=="failed") status = "failed"; if(m_orgItems[(long int)item]->text(1)=="OK") status = "passed"; if(m_orgItems[(long int)item]->text(1)=="problem") status = "attention"; modSt.insert(std::make_pair(m_orgItems[(long int)item]->text(0).latin1(), status)); } item = item->nextSibling(); } sItem = sItem->nextSibling(); } if(mmap!=0) mmap->updateStatus(modSt); } // assembled staves/sectors - all in level 3 for(int i=3;i<5;i++){ Q3ListViewItem *aItem = m_baseItems[i]->firstChild(); while(aItem!=0){ ModuleMap *mmap = dynamic_cast(child(aItem->text(0))); std::map modSt; Q3ListViewItem *sItem = aItem->firstChild(); while(sItem!=0){ Q3ListViewItem *item = sItem->firstChild(); while(item!=0){ if(m_orgItems[(long int)item]!=0){ for(int j=0;j<3;j++) item->setText(j, m_orgItems[(long int)item]->text(j)); ModListItem *modItem = (ModListItem*) m_orgItems[(long int)item]; Config &modconf = modItem->getCrate()->getPixModuleConf(modItem->grpId(), modItem->modId()); std::string connName=""; // is module attached to a stave/sector? if(modconf["geometry"].name()!="__TrashConfGroup__" && modconf["geometry"]["connName"].name()!="__TrashConfObj__"){ connName = ((ConfString&)modconf["geometry"]["connName"]).value(); if(connName!="") item->setText(0,connName.c_str()); } std::string status = "unknown"; if(m_orgItems[(long int)item]->text(1)=="failed") status = "failed"; if(m_orgItems[(long int)item]->text(1)=="OK") status = "passed"; if(m_orgItems[(long int)item]->text(1)=="problem") status = "attention"; modSt.insert(std::make_pair(item->text(0).latin1(), status)); } item = item->nextSibling(); } sItem = sItem->nextSibling(); } if(mmap!=0) mmap->updateStatus(modSt); aItem = aItem->nextSibling(); } } } void ModGeoView::updateList(){ if(m_orgList==0) return; std::map stave_items, sector_items, disk_items, hshell_items; modGeoView->clear(); m_orgItems.clear(); ModuleMap *mmap=0; // reset disk or half-shell maps for(int i=0;i(child(m_qparSN[i])); if(mmap!=0) mmap->reset(false); } // delete maps of individual staves/sectors mmap = dynamic_cast(child("indmap")); delete mmap; m_baseItems[0] = new Q3ListViewItem(modGeoView,"not assembled","","","0"); m_baseItems[1] = new Q3ListViewItem(modGeoView,"indiv. staves","","","1"); m_baseItems[2] = new Q3ListViewItem(modGeoView,"indiv. sectors","","","2"); m_baseItems[3] = new Q3ListViewItem(modGeoView,"disks","","","3"); m_baseItems[4] = new Q3ListViewItem(modGeoView,"barrel","","","4"); for(int i=0;isetOpen(true); // load module items as from the read-out list ModListItem *crateItem = (ModListItem*)m_orgList->ModListView->firstChild(); while(crateItem!=0){ ModListItem *grpItem = (ModListItem*) crateItem->firstChild(); while(grpItem!=0){ ModListItem *modItem = (ModListItem*) grpItem->firstChild(); while(modItem!=0){ Q3ListViewItem *parent = m_baseItems[0]; if(modItem->getType()==ModListItem::tmodule && modItem->getCrate()!=0){ Config &modconf = modItem->getCrate()->getPixModuleConf(modItem->grpId(), modItem->modId()); // Config &modconf = modItem->getModule()->config(); int assyType=0, staveSN=0, posOnStave=0; std::string connName=""; if(modconf["geometry"].name()!="__TrashConfGroup__" && modconf["geometry"]["connName"].name()!="__TrashConfObj__") connName = ((ConfString&)modconf["geometry"]["connName"]).value(); // is module attached to a stave/sector? if(modconf["geometry"].name()!="__TrashConfGroup__" && modconf["geometry"]["Type"].name()!="__TrashConfObj__"){ assyType = ((ConfInt&)modconf["geometry"]["Type"]).getValue(); if(assyType>0){ staveSN = ((ConfInt&)modconf["geometry"]["staveID"]).getValue(); posOnStave = ((ConfInt&)modconf["geometry"]["position"]).getValue(); } } switch(assyType){ case 1:{ //stave parent = stave_items[staveSN]; int assPos = 1; if(parent==0){ // check if item belongs to half shell already QString qcn = connName.c_str(); if(qcn.left(1)=="L"){// connectivity name is used, derive assy info from that int pos = qcn.find("-S"); QString staveName = qcn.left(pos+3); // e.g. L2-B14-S1 QString cpSN = staveName.left(2); QString parSN = "201"; int parPos; if(cpSN=="L2"){ parSN += "2"; parPos = 2; }else if(cpSN=="L1"){ parSN += "1"; parPos = 1; }else{ parSN += "0"; parPos = 0; } int bistNr = staveName.left(pos).right(staveName.length()-7).toInt(); if(parPos==2){ if(bistNr==26) bistNr = 1; else bistNr++; // split L2, too many staves for one object if(bistNr<14){ // top cpSN += " top"; parSN +="2"; } else{ // bottom cpSN += " bottom"; parPos++; parSN +="1"; } } else parSN +="1"; int iparSN = parSN.toInt(); parent = hshell_items[iparSN]; if(parent==0){ // barrel item does not exist yet, create parent = new Q3ListViewItem(m_baseItems[4], cpSN,"","",QString::number(parPos)); hshell_items[iparSN] = parent; parent->setOpen(true); } iparSN = staveName.right(1).toInt(); parent = new Q3ListViewItem(parent, staveName,"","",QString::number(iparSN+2*bistNr-2,10)); parent->setOpen(true); stave_items[staveSN] = parent; }else{ // PDB approach std::stringstream sSN; if(staveSN<10000) sSN << "001"; else if(staveSN<1110000) sSN << "00"; sSN << staveSN; if(m_strcutList[sSN.str()].second==0){ parent = m_baseItems[assyType]; assPos = 0; }else{ assPos = m_strcutList[sSN.str()].second; QString cpSN = m_strcutList[sSN.str()].first.c_str(); QString parSN = "201"; int parPos; if(cpSN.left(2)=="L2"){ parSN += "2"; parPos = 4; }else if(cpSN.left(2)=="L1"){ parSN += "1"; parPos = 2; }else{ parSN += "0"; parPos = 0; } if(cpSN.right(3)=="top"){ parSN += "2"; parPos += 2; }else{ parSN += "1"; parPos += 1; } int iparSN = parSN.toInt(); parent = hshell_items[iparSN]; if(parent==0){ parent = new Q3ListViewItem(m_baseItems[4], m_strcutList[sSN.str()].first.c_str(),"","",QString::number(parPos)); hshell_items[iparSN] = parent; parent->setOpen(true); } } QString qap = QString::number(assPos); if(assPos==0) qap = ""; parent = new Q3ListViewItem(parent, QString::number(staveSN),"","",qap); parent->setOpen(true); stave_items[staveSN] = parent; } } break; } case 2: { // sector parent = sector_items[staveSN]; int assPos = 1; if(parent==0){ // check if item belongs to disk already QString qcn = connName.c_str(); if(qcn.left(1)=="D"){// connectivity name is used, derive assy info from that QString sectorName = qcn.left(6); QString cpSN = sectorName.left(3).right(2); QString parSN = "81"+cpSN.left(1); int parPos; if(cpSN.right(1)=="A"){ parPos = cpSN.left(1).toInt(); parSN += "1"; }else{ parSN += "3"; parPos = 3+cpSN.left(1).toInt(); } int iparSN = parSN.toInt(); parent = disk_items[iparSN]; if(parent==0){ // disk item does not exist yet, create parent = new Q3ListViewItem(m_baseItems[3], cpSN,"","",QString::number(parPos)); disk_items[iparSN] = parent; parent->setOpen(true); } parent = new Q3ListViewItem(parent, sectorName,"","",sectorName.right(1)); parent->setOpen(true); sector_items[staveSN] = parent; } else{ // use PDB approach std::stringstream sSN; sSN << staveSN; if(m_strcutList[sSN.str()].second==0){ parent = m_baseItems[assyType]; assPos = 0; }else{ assPos = m_strcutList[sSN.str()].second; QString cpSN = m_strcutList[sSN.str()].first.c_str(); QString parSN = "81"+cpSN.left(1); int parPos; if(cpSN.right(1)=="A"){ parPos = cpSN.left(1).toInt(); parSN += "1"; }else{ parSN += "3"; parPos = 3+cpSN.left(1).toInt(); } int iparSN = parSN.toInt(); parent = disk_items[iparSN]; if(parent==0){ parent = new Q3ListViewItem(m_baseItems[3], m_strcutList[sSN.str()].first.c_str(),"","",QString::number(parPos)); disk_items[iparSN] = parent; parent->setOpen(true); } } QString qap = QString::number(assPos); if(assPos==0) qap = ""; parent = new Q3ListViewItem(parent, QString::number(staveSN),"","",qap); parent->setOpen(true); sector_items[staveSN] = parent; } } break; } default: break; } Q3ListViewItem *item = new Q3ListViewItem(parent,modItem->text(0), modItem->text(1), modItem->text(2),QString::number(posOnStave)); if(connName!="") item->setText(0,connName.c_str()); m_orgItems.insert(std::make_pair((long int)item,(Q3ListViewItem*)modItem)); ModuleMap *mmap = 0; if(parent->parent()!=0) mmap = dynamic_cast(child(parent->parent()->text(0))); if(mmap!=0 && parent->text(3)!="" && posOnStave>0) { // first, load assyinfo (was not requested from PDB above to speed up) mmap->loadModule(item->text(0).latin1(), parent->text(3).toInt()-1, posOnStave-1);//,parent->text(0).latin1()); // then, load pointer to PixModule object ModuleLabel *ml = mmap->loadModule((void*)item, item->text(0).latin1()); std::string status = "unknown"; if(modItem->text(1)=="failed") status = "failed"; if(modItem->text(1)=="OK") status = "passed"; if(modItem->text(1)=="problem") status = "attention"; ml->updateStatus(status.c_str()); connect(ml, SIGNAL(moduleDoubleClick(void*)), this, SLOT(mapAction(void *))); } } modItem = (ModListItem*) modItem ->nextSibling(); } grpItem = (ModListItem*) grpItem->nextSibling(); } crateItem = (ModListItem*) crateItem->nextSibling(); } modGeoView->setSorting(3,true); // explicit re-paint of disk maps for(int id=0;id<6;id++){ ModuleMap *mmap = dynamic_cast(child(m_qparSN[id])); if(mmap!=0) mmap->repaint(); } return; } void ModGeoView::editModule(Q3ListViewItem *item){ if(m_orgList==0) return; if(m_orgItems[(long int)item]!=0){ m_orgList->editModule(m_orgItems[(long int)item]); updateList(); } } void ModGeoView::rightClick(Q3ListViewItem *item, const QPoint &pt, int col){ if(m_orgList==0) return; ModuleMap *mmap=0; if(item==0) return; if(m_orgItems[(long int)item]!=0){ m_orgList->rightClick(m_orgItems[(long int)item],pt, col); item->setText(2,m_orgItems[(long int)item]->text(2)); }else if((mmap=dynamic_cast(child(item->text(0))))!=0) mmap->show(); else if(item->childCount()>0){ mmap = dynamic_cast(child(item->text(0))); if(mmap==0){ if((item->text(0)=="indiv. staves" || item->text(0)=="indiv. sectors")) mmap = new ModuleMap(item->childCount(), (item->text(0)=="indiv. staves")?13:6, item->text(0).latin1(), this, item->text(0).latin1(), false, Qt::WDestructiveClose); else if(item->parent()!=0 && item->parent()->text(0)=="disks"){ mmap = new ModuleMap(ModuleMap::disk, ("disk "+item->text(0)).latin1(), this, item->text(0).latin1(), false, Qt::WDestructiveClose); } else if(item->parent()!=0 && item->parent()->text(0)=="barrel"){ ModuleMap::assyType mapAssType = ModuleMap::halfshell2; if(item->text(0)=="L1") mapAssType = ModuleMap::layer1; if(item->text(0)=="L0") mapAssType = ModuleMap::layer0; mmap = new ModuleMap(mapAssType, item->text(0).latin1(), this, item->text(0).latin1(), false, Qt::WDestructiveClose); } else return; QApplication::setOverrideCursor(Qt::waitCursor); Q3ListViewItem *sit = item->firstChild(); int sID=0; while(sit!=0){ Q3ListViewItem *mit = sit->firstChild(); while(mit!=0){ if(m_orgItems[(long int)mit]!=0){ // first, load assy info (was not requested from PDB above to speed up) int stavePos=sID; if(item->parent()!=0) stavePos = sit->text(3).toInt()-1; mmap->loadModule(m_orgItems[(long int)mit]->text(0).latin1(),stavePos, mit->text(3).toInt()-1,sit->text(0).latin1()); // then, load pointer to PixModule object ModuleLabel *ml = mmap->loadModule((void*)mit, m_orgItems[(long int)mit]->text(0).latin1()); std::string status = "unknown"; if(mit->text(1)=="failed") status = "failed"; if(mit->text(1)=="OK") status = "passed"; if(mit->text(1)=="problem") status = "attention"; ml->updateStatus(status.c_str()); connect(ml, SIGNAL(moduleDoubleClick(void*)), this, SLOT(mapAction(void *))); mit = mit->nextSibling(); } else printf("Can't find r/o item for geo item %s\n",mit->text(0).latin1()); } sID++; sit = sit->nextSibling(); } QApplication::restoreOverrideCursor(); } mmap->show(); } } void ModGeoView::emitCurrChanged(Q3ListViewItem *item){ if(m_orgList==0) return; if(m_orgItems[(long int)item]!=0) emit currentChangedTransl(m_orgItems[(long int)item]); } void ModGeoView::mapAction(void *in_item) { Q3ListViewItem *item = (Q3ListViewItem*) in_item; if(m_orgList==0) return; if(m_orgItems[(long int)item]!=0) emit currentChangedTransl(m_orgItems[(long int)item]); }