/*************************************************************************** STRodCrate.cpp - description ------------------- begin : Fri Apr 16 2004 copyright : (C) 2004 by jschumac email : jschumac@silabsbc modifications : 2005 by rottlaen, 2005 and 2006 by jgrosse ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "STRodCrate.h" #include "STPixModuleGroup.h" #include #ifndef NOTDAQ #include #include #endif #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef HAVE_GPIB #include #endif #include #include #include #include #include #include #include #include #include #include #ifdef WIN32 #include #else #include #endif STRodCrate::STRodCrate( int ID, QApplication* application, QObject * parent, const char * name, const char *SBCaddr ) : QObject( parent, name ), m_ID(ID), m_SBCaddr(SBCaddr){ m_vmeInterface=0; m_app = application; m_IFtype = tundefIF; m_USBinit = false; m_timer = new QTimer( this ); m_filebusy = false; m_comInit = false; // the following doesn't work for linux at the moment, so don't bother to try //#ifdef WIN32 connect(m_timer, SIGNAL(timeout()), this, SLOT(checkUsbEvent()) ); //#endif } void STRodCrate::setupVme(){ // if there is already an interface, delete it clearVme(); try { // get VME interface or init. USB switch(m_IFtype){ default: case tundefIF: break; case tUSBSys: if(!m_USBinit){ InitUSB(); m_USBinit=true; } m_timer->start(50); break; case tRCCVME: #ifndef NOTDAQ m_vmeInterface = new RCCVmeInterface(); #endif break; } // init. RS232 interface if(!m_comInit){ ComInit(); m_comInit = true; } } catch (VmeException &v) { std::stringstream msg; msg << "STRodCrate::setupVme : VmeException:"; msg << " ErrorClass = " << v.getErrorClass(); msg << " ErrorCode = " << v.getErrorCode(); emit errorMessage(msg.str()); // sends to log container and makes engine open a warning box m_vmeInterface = 0; } catch (BaseException & exc){ std::stringstream msg; msg << "STRodCrate::setupVme : Base exception during creation of VME interface: "<< exc; emit errorMessage(msg.str()); // sends to log container and makes engine open a warning box m_vmeInterface = 0; } catch (...){ std::stringstream msg; msg << "STRodCrate::setupVme : Unknown exception during creation of VME interface."; emit errorMessage(msg.str()); // sends to log container and makes engine open a warning box m_vmeInterface = 0; } } void STRodCrate::clearVme(){ // RS232 stuff if(m_comInit){ ComExit(); m_comInit = false; } delete m_vmeInterface; m_vmeInterface=0; } STRodCrate::~STRodCrate(){ clear(); clearVme(); m_timer->stop(); } bool STRodCrate::vmeOK(){ switch(m_IFtype){ default: case tundefIF: case tUSBSys: return m_USBinit; case tRCCVME: return (m_vmeInterface!=0); } } /** returns the top part of the IP address of this SBC (i.e. its name)*/ std::string STRodCrate::getName(){ std::string tmpStr = m_SBCaddr; int pos = tmpStr.find("."); if(pos!=(int)std::string::npos) tmpStr.erase(pos,tmpStr.length()-pos); return tmpStr; } /** Read property of vector m_pixModuleGroups. */ std::vector & STRodCrate::getSTPixModuleGroups(){ return m_pixModuleGroups; } /** Read property of vector m_pixModuleGroups. */ std::vector & STRodCrate::getPixDcs(){ return m_pixDcs; } /** This deletes all PixModuleGroups */ void STRodCrate::clear(){ for(std::vector::iterator IT=m_dcsPrescanCfg.begin();IT!=m_dcsPrescanCfg.end();IT++){ delete (*IT); *IT = 0; } m_dcsPrescanCfg.clear(); // Only do anything if we have any module groups or DCS objects - otherwise we might create QT signal loops. // delete DCS first since USB devices might rely on module groups if(m_pixDcs.size()>0){ for(std::vector::iterator i=m_pixDcs.begin(); i != m_pixDcs.end(); i++) { if((*i)->getDevType()==PixDcs::SUPPLY) (*i)->SetState("OFF"); // turn off everything before leaving... delete *i; *i = 0; } m_pixDcs.clear(); emit groupListChanged(); } if( m_pixModuleGroups.size() > 0 ) { for(std::vector::iterator i=m_pixModuleGroups.begin(); i != m_pixModuleGroups.end(); i++) { delete *i; *i = 0; } m_pixModuleGroups.clear(); emit groupListChanged(); } } /** Loads PixelModuleGroups from inquire "decName in DB file "fname" */ void STRodCrate::loadDB( const char *fname, const char *decName ) { PixConfDBInterface * confDBInterface = DBEdtEngine::openFile(fname, false); DBInquire *appInq=0, *root = confDBInterface->readRootRecord(1); try{ std::vector inqVec; inqVec = confDBInterface->DBFindRecordByName(PixLib::BYDECNAME, root->getDecName()+ std::string(decName)+"/application"); if(inqVec.size()==1) appInq = inqVec[0]; else{ emit errorMessage("STRodCrate::loadDB : couldn't find unique crate inquire."); delete confDBInterface; return; } }catch (BaseException & exc){ QApplication::restoreOverrideCursor(); std::stringstream msg; msg << "STRodCrate::loadDB : Base exception: "<< exc; emit errorMessage(msg.str()); // sends to log container and makes engine open a warning box delete confDBInterface; return; }catch(...){ emit errorMessage("STRodCrate::loadDB : unknown exception while searching for crate inquire."); delete confDBInterface; return; } // loop over inquires in crate inquire and create a PixModuleGroup when an according entry is found for(recordIterator pmgIter = appInq->recordBegin();pmgIter!=appInq->recordEnd();pmgIter++){ if((*pmgIter)->getName().find("PixModuleGroup")!=std::string::npos){ loadModuleGroup(*pmgIter); } if((*pmgIter)->getName().find("PixDcs")!=std::string::npos){ loadDcs(*pmgIter); } } delete confDBInterface; return; } bool STRodCrate::saveDB(const char *fname) { PixConfDBInterface *myDB=0; QApplication::setOverrideCursor(Qt::waitCursor); try{ myDB = DBEdtEngine::openFile(fname,true); }catch(SctPixelRod::BaseException& exc){ QApplication::restoreOverrideCursor(); std::stringstream msg; msg << "STRodCrate::saveDB : exception while re-opening DB file " << std::string(fname) << ": " << exc; emit errorMessage(msg.str()); return false; }catch(...){ QApplication::restoreOverrideCursor(); emit errorMessage("STRodCrate::saveDB : unknown exception while re-opening DB file " + std::string(fname)); return false; } bool gotErr = false; // get groups in current crate and loop over them for(std::vector::iterator mgrIT = m_pixModuleGroups.begin(); mgrIT != m_pixModuleGroups.end();mgrIT++){ // save group config if((*mgrIT)->cfgEdited(40)){ // this group cfg was edited -> save Config &cfgGrp = (*mgrIT)->config(); // have to get decorated name from module... std::string find_name = (*(*mgrIT)->modBegin())->moduleName(); // remove module name find_name.erase(find_name.length()-1,1); int pos = (int)find_name.find_last_of("/"); if(pos!=(int)std::string::npos) find_name.erase(pos+1,find_name.length()-pos); // then add the PixModuleGroup-specific bits for the full decorated name // std::cout << "Saving group " << find_name << std::endl; find_name += "PixModuleGroup;1"; std::vector grpInq; try{ grpInq = myDB->DBFindRecordByName(PixLib::BYDECNAME, find_name); }catch(...){ // dealt with later grpInq.clear(); } if(grpInq.size()==0){ emit logMessage("STRodCrate::saveDB : Could not find group " + (*mgrIT)->getName() + " in DB object."); gotErr = true; } if(grpInq.size()>1){ emit logMessage("STRodCrate::saveDB : Got several DB objects for group " + (*mgrIT)->getName() + ". Will use first."); gotErr = true; } if(grpInq.size()>0){ try{ cfgGrp.write(grpInq[0]); }catch(...){ emit logMessage("STRodCrate::saveDB : error writing config for group " + (*mgrIT)->getName() + " to DB object."); gotErr = true; } } } // save PixController config PixController *myROD = (*mgrIT)->getPixController(); //RodPixController *myROD = dynamic_cast((*mgrIT)->getPixController()); if(myROD!=0 && (*mgrIT)->cfgEdited(41)){ Config &cfgROD = myROD->config(); // have to get decorated name from module... std::string find_name = (*(*mgrIT)->modBegin())->moduleName(); // remove module name find_name.erase(find_name.length()-1,1); int pos = (int)find_name.find_last_of("/"); if(pos!=(int)std::string::npos) find_name.erase(pos+1,find_name.length()-pos); // then add the ROD-specific bits for the full decorated name find_name += (*mgrIT)->getRodName(); // std::cout << "Saving PixController " << find_name << std::endl; find_name += "/PixController;1"; std::vector rodInq; try{ rodInq = myDB->DBFindRecordByName(PixLib::BYDECNAME, find_name); }catch(...){ // dealt with later rodInq.clear(); } if(rodInq.size()==0){ emit logMessage("STRodCrate::saveDB : Could not find PixController " + (*mgrIT)->getName() + " in DB object."); gotErr = true; } if(rodInq.size()>1){ emit logMessage("STRodCrate::saveDB : Got several DB objects for PixController " + (*mgrIT)->getName() + ". Will use first."); gotErr = true; } if(rodInq.size()>0){ try{ cfgROD.write(rodInq[0]); }catch(...){ emit logMessage("STRodCrate::saveDB : error writing config for PixController " + (*mgrIT)->getName() + " to DB object."); gotErr = true; } } } PixBoc* myBOC = dynamic_cast((*mgrIT)->getPixBoc()); if(myBOC!=0 && (*mgrIT)->cfgEdited(42)){ Config &cfgBOC = *(myBOC->getConfig()); // have to get decorated name from module... std::string find_name = (*(*mgrIT)->modBegin())->moduleName(); // remove module name find_name.erase(find_name.length()-1,1); int pos = (int)find_name.find_last_of("/"); if(pos!=(int)std::string::npos) find_name.erase(pos+1,find_name.length()-pos); // the add the BOC-specific bits for the full decorated name find_name += "OpticalBoc"; // std::cout << "Saving BOC " << find_name << std::endl; find_name += "/PixBoc;1"; std::vector bocInq; try{ bocInq = myDB->DBFindRecordByName(PixLib::BYDECNAME, find_name); }catch(...){ // dealt with later bocInq.clear(); } if(bocInq.size()==0){ emit logMessage("STRodCrate::saveDB : Could not find BOC " + (*mgrIT)->getName() + " in DB object."); gotErr = true; } if(bocInq.size()>1){ emit logMessage("STRodCrate::saveDB : Got several DB objects for BOC " + (*mgrIT)->getName() + ". Will use first."); gotErr = true; } if(bocInq.size()>0){ try{ cfgBOC.write(bocInq[0]); }catch(...){ emit logMessage("STRodCrate::saveDB : error writing config for BOC " + (*mgrIT)->getName() + " to DB object."); gotErr = true; } } PixBoc::PixTx* myTx[4]; std::string txnr; char txnumber[3]; for(int i =0; i<4; i++) { myTx[i] = dynamic_cast((*mgrIT)->getPixBoc()->getTx(i)); if(myTx[i]!=0){ Config &cfgTx = *(myTx[i]->getConfigTx()); // have to get decorated name from module... std::string find_name = (*(*mgrIT)->modBegin())->moduleName(); // remove module name find_name.erase(find_name.length()-1,1); int pos = (int)find_name.find_last_of("/"); if(pos!=(int)std::string::npos) find_name.erase(pos+1,find_name.length()-pos); // the add the BOC-specific bits for the full decorated name find_name += "OpticalBoc"; sprintf(txnumber,"%d",i); txnr=txnumber; find_name += "/TxNr"+txnr; find_name += "/PixTx;1"; std::vector txInq; try{ txInq = myDB->DBFindRecordByName(PixLib::BYDECNAME, find_name); }catch(...){ // dealt with later txInq.clear(); } if(txInq.size()==0){ emit logMessage("STRodCrate::saveDB : Could not find Tx board for BOC of group " + (*mgrIT)->getName() + " in DB object."); gotErr = true; } if(txInq.size()>1){ emit logMessage("STRodCrate::saveDB : Got several DB objects for Tx board for BOC of group " + (*mgrIT)->getName() + ". Will use first."); gotErr = true; } if(txInq.size()>0){ try{ cfgTx.write(txInq[0]); }catch(...){ emit logMessage("STRodCrate::saveDB : error writing config for Tx board for BOC " + (*mgrIT)->getName() + " to DB object."); gotErr = true; } } } } PixBoc::PixRx* myRx[4]; std::string rxnr; char rxnumber[3]; for(int i =0; i<4; i++) { myRx[i] = dynamic_cast((*mgrIT)->getPixBoc()->getRx(i)); if(myRx[i]!=0){ Config &cfgRx = *(myRx[i]->getConfigRx()); // have to get decorated name from module... std::string find_name = (*(*mgrIT)->modBegin())->moduleName(); // remove module name find_name.erase(find_name.length()-1,1); int pos = (int)find_name.find_last_of("/"); if(pos!=(int)std::string::npos) find_name.erase(pos+1,find_name.length()-pos); // the add the BOC-specific bits for the full decorated name find_name += "OpticalBoc"; sprintf(rxnumber,"%d",i); rxnr=rxnumber; find_name += "/RxNr"+rxnr; find_name += "/PixRx;1"; std::vector rxInq; try{ rxInq = myDB->DBFindRecordByName(PixLib::BYDECNAME, find_name); }catch(...){ // dealt with later rxInq.clear(); } if(rxInq.size()==0){ emit logMessage("STRodCrate::saveDB : Could not find Rx board for BOC of group " + (*mgrIT)->getName() + " in DB object."); gotErr = true; } if(rxInq.size()>1){ emit logMessage("STRodCrate::saveDB : Got several DB objects for Rx board for BOC of group " + (*mgrIT)->getName() + ". Will use first."); gotErr = true; } if(rxInq.size()>0){ try{ cfgRx.write(rxInq[0]); }catch(...){ emit logMessage("STRodCrate::saveDB : error writing config for Rx board for BOC " + (*mgrIT)->getName() + " to DB object."); gotErr = true; } } } } } for(PixModuleGroup::moduleIterator mi = (*mgrIT)->modBegin(); mi != (*mgrIT)->modEnd(); mi++){ if((*mgrIT)->cfgEdited((*mi)->moduleId())){ // save module config Config &modconf = (*mi)->config(); std::string find_name = (*mi)->moduleName(); // std::cout << "Saving module " << find_name << std::endl; find_name += "PixModule;1"; std::vector modInq; try{ modInq = myDB->DBFindRecordByName(PixLib::BYDECNAME, find_name); }catch(...){ modInq.clear(); } if(modInq.size()==0){ emit logMessage("STRodCrate::saveDB : Could not find module " + (*mi)->moduleName() + " in DB object."); gotErr = true; } if(modInq.size()>1){ emit logMessage("STRodCrate::saveDB : Got several DB objects for module " + (*mi)->moduleName() + ". Will use first."); gotErr = true; } if(modInq.size()>0){ try{ //std::cout << "saving module " << (*mi)->moduleName() << std::endl; modconf.write(modInq[0]); }catch(...){ emit logMessage("STRodCrate::saveDB : error writing config for module " + (*mi)->moduleName() + " to DB object."); gotErr = true; } } } } // clear all edit flags for this group (*mgrIT)->savedCfg(); } // save DCS objects // to do: use edit flag and save only when set, like for PixModule(Group) etc. for(std::vector ::iterator di=m_pixDcs.begin(); di!=m_pixDcs.end(); di++){ Config &dcsconf = (*di)->config(); std::string find_name = (*di)->decName(); // std::cout << "Saving DCS object " << (*di)->name() << " into " << find_name<< std::endl; find_name += "PixDcs;1"; std::vector dcsInq; try{ dcsInq = myDB->DBFindRecordByName(PixLib::BYDECNAME, find_name); }catch(...){ dcsInq.clear(); } if(dcsInq.size()==0){ emit logMessage("STRodCrate::saveDB : Could not find DCS object " + (*di)->name() + " in DB object."); gotErr = true; } if(dcsInq.size()>1){ emit logMessage("STRodCrate::saveDB : Got several DB objects for DCS object " + (*di)->name() + ". Will use first."); gotErr = true; } if(dcsInq.size()>0){ try{ dcsconf.write(dcsInq[0]); }catch(...){ emit logMessage("STRodCrate::saveDB : error writing config for DCS object " + (*di)->name() + " to DB object."); gotErr = true; } } } // close temporary file delete myDB; QApplication::restoreOverrideCursor(); return gotErr; } bool STRodCrate::reloadModCfg(const char *fname){ PixConfDBInterface *myDB=0; QApplication::setOverrideCursor(Qt::waitCursor); try{ myDB = DBEdtEngine::openFile(fname); }catch(SctPixelRod::BaseException& exc){ QApplication::restoreOverrideCursor(); std::stringstream msg; msg << "STRodCrate::reloadModCfg : exception while opening DB file " << std::string(fname) << ": " << exc; emit errorMessage(msg.str()); return false; }catch(...){ QApplication::restoreOverrideCursor(); emit errorMessage("STRodCrate::reloadModCfg : unknown exception while opening DB file " + std::string(fname)); return false; } bool gotErr = false; // get groups in current crate and loop over them for(std::vector::iterator mgrIT = m_pixModuleGroups.begin(); mgrIT != m_pixModuleGroups.end();mgrIT++){ for(PixModuleGroup::moduleIterator mi = (*mgrIT)->modBegin(); mi != (*mgrIT)->modEnd(); mi++){ Config &modconf = (*mi)->config(); std::string find_name = (*mi)->moduleName(); //std::cout << "re-loading cfg. for module " << find_name << std::endl; find_name += "PixModule;1"; std::vector modInq; try{ modInq = myDB->DBFindRecordByName(PixLib::BYDECNAME, find_name); }catch(...){ modInq.clear(); } if(modInq.size()==0){ emit logMessage("STRodCrate::reloadModCfg : Could not find module " + (*mi)->moduleName() + " in DB object."); gotErr = true; } if(modInq.size()>1){ emit logMessage("STRodCrate::reloadModCfg : Got several DB objects for module " + (*mi)->moduleName() + ". Will use first."); gotErr = true; } if(modInq.size()>0){ try{ //std::cout << "loading inquire " << modInq[0]->getDecName() << std::endl; if(!modconf.read(modInq[0])){ emit logMessage("STRodCrate::reloadModCfg : Config::read returns error for module " + (*mi)->moduleName() + "."); gotErr = true; } }catch(...){ emit logMessage("STRodCrate::reloadModCfg : error reading config for module " + (*mi)->moduleName() + " to DB object."); gotErr = true; } } } } delete myDB; QApplication::restoreOverrideCursor(); return gotErr; } void STRodCrate::loadDcs( DBInquire *dcsInq ){ PixDcs *dcs = 0; std::string dcsName; QApplication::setOverrideCursor( Qt::waitCursor ); try{ // Create PixDcs object fieldIterator f = dcsInq->findField("ActualClassName"); dcsInq->getDB()->DBProcess(f,READ, dcsName); void *interface = 0; // check if name of a group with a USB controller was specified // if so, get the pointer and give it to PixDcs constructor f = dcsInq->findField("USBPixController"); std::string ctrlName="???"; if(f!=dcsInq->fieldEnd()){ dcsInq->getDB()->DBProcess(f,READ, ctrlName); for( std::vector::iterator group = m_pixModuleGroups.begin(); group != m_pixModuleGroups.end(); group++ ) { if((*group)->getName()==ctrlName) interface = (void*)(*group)->getPixController(); } } if(interface!=0 || ctrlName=="???") dcs = PixDcs::make(dcsInq, interface, dcsName); else emit errorMessage("STRodCrate::loadDcs : Can't find any USB interface for PixController "+ctrlName); } catch (PixDcsExc & pdexc){ QApplication::restoreOverrideCursor(); std::stringstream msg; msg << "STRodCrate::loadDcs : PixDcs exception: "; pdexc.dump(msg); emit errorMessage(msg.str()); // sends to log container and makes engine open a warning box return; } catch (BaseException & exc){ QApplication::restoreOverrideCursor(); std::stringstream msg; msg << "STRodCrate::loadDcs : Base exception: "<< exc; emit errorMessage(msg.str()); // sends to log container and makes engine open a warning box return; } catch (...){ QApplication::restoreOverrideCursor(); std::stringstream msg; msg << "STRodCrate::loadDcs : Unknown exception."; emit errorMessage(msg.str()); // sends to log container and makes engine open a warning box return; } m_pixDcs.push_back(dcs); QApplication::restoreOverrideCursor(); emit groupListChanged(); return; } void STRodCrate::loadModuleGroup( DBInquire *grpInq ){ std::map geomType; geomType["unknown"] = 0; geomType["Stave"] = 1; geomType["Sector"] = 2; STPixModuleGroup *grp = 0; QApplication::setOverrideCursor( Qt::waitCursor ); try{ grp = new STPixModuleGroup(m_pixModuleGroups.size(), grpInq->getDB(), grpInq, *m_vmeInterface, m_app, m_filebusy, this, "mygrp"+QString::number(m_pixModuleGroups.size())); PixController *pc = grp->getPixController(); USBPixController *upc = dynamic_cast(pc); RodPixController *rpc = dynamic_cast(pc); if(rpc!=0){ if(m_IFtype!=tRCCVME){ // VME hasn been initialised yet m_IFtype=tRCCVME; setupVme(); // now create module group again with proper VME interface delete grp; grp = new STPixModuleGroup(m_pixModuleGroups.size(), grpInq->getDB(), grpInq, *m_vmeInterface, m_app, m_filebusy, this, "mygrp"+QString::number(m_pixModuleGroups.size())); } } else if(upc!=0){ if(m_IFtype != tUSBSys){ m_IFtype = tUSBSys; setupVme(); } } else m_IFtype = tundefIF; } catch (PixFeExc &fExc){ std::stringstream txt; txt << "STRodCrate::loadModuleGroup : PixFe-exception level " << fExc.dumpLevel() << ", type " << fExc.dumpType() << "\n"; emit errorMessage(txt.str()); // sends to log container and makes engine open a warning box return; } catch (ConfigExc & cfExc){ std::stringstream txt; txt << "STRodCrate::loadModuleGroup : Config-exception " << cfExc << "\n"; emit errorMessage(txt.str()); // sends to log container and makes engine open a warning box return; } catch (VmeException &v) { QApplication::restoreOverrideCursor(); std::stringstream msg; msg << "STRodCrate::loadModuleGroup : VmeException:"; msg << " ErrorClass = " << v.getErrorClass(); msg << " ErrorCode = " << v.getErrorCode(); emit errorMessage(msg.str()); // sends to log container and makes engine open a warning box return; } catch (BaseException & exc){ QApplication::restoreOverrideCursor(); std::stringstream msg; msg << "STRodCrate::loadModuleGroup : Base exception: "<< exc; emit errorMessage(msg.str()); // sends to log container and makes engine open a warning box return; } catch (...){ QApplication::restoreOverrideCursor(); std::stringstream msg; msg << "STRodCrate::loadModuleGroup : Unknown exception."; emit errorMessage(msg.str()); // sends to log container and makes engine open a warning box return; } // // forward groupChange signal // connect(grp, SIGNAL(groupChanged()), this, SIGNAL(groupListChanged())); // // forward updateModList signal // connect(grp, SIGNAL(updateModList()), this, SIGNAL(updateModList())); // forward log messages to log container connect(grp,SIGNAL(logMessage(std::string)), this, SIGNAL(logMessage(std::string))); // forward error messages to log container connect(grp,SIGNAL(errorMessage(std::string)), this, SIGNAL(errorMessage(std::string))); // forward error messages to log container connect(grp,SIGNAL(rodMessage(std::string, bool)), this, SIGNAL(rodMessage(std::string, bool))); // forward module test signals connect(grp,SIGNAL(sendRTStatus(const char*)), this, SIGNAL(sendRTStatus(const char*))); connect(grp,SIGNAL(currentModule(PixLib::PixModule *)), this, SLOT(recCurrentModule(PixLib::PixModule *))); connect(grp, SIGNAL(statusChanged()), this, SIGNAL(statusChanged())); // DCS hand shake-communication: // setting from group to crate connect(grp, SIGNAL(setDcs(std::string, double, int, STPixModuleGroup*)), this, SLOT(setDcs(std::string, double, int, STPixModuleGroup*))); // reading from group to crate connect(grp, SIGNAL(getDcs(std::string, PixScan::DcsReadMode, int, STPixModuleGroup*)), this, SLOT(getDcs(std::string, PixScan::DcsReadMode, int, STPixModuleGroup*))); // store group in resp. vector m_pixModuleGroups.push_back( grp ); QApplication::restoreOverrideCursor(); emit groupListChanged(); return; } /** initialises the PixScan objects of all module groups */ int STRodCrate::setPixScan(PixScan &inPixScan){ int error=0; // store raw file name in case it is needed below std::string orgRawFile = inPixScan.getSourceRawFile(); for( std::vector::iterator group = m_pixModuleGroups.begin(); group != m_pixModuleGroups.end(); group++ ) { // source scan: must add group name to raw file uniquely identify it in case several boards are being used // skip if no raw data file name if provided, otherwise this will accidentally be written if(m_pixModuleGroups.size()>1 && orgRawFile!=""){ std::string rawFile = orgRawFile; // strip off extension and insert group name int epos = rawFile.find_last_of(".raw"); if(epos != (int)std::string::npos){ rawFile.erase(epos-3, rawFile.length()-epos+4); } rawFile += "_grp_"+(*group)->getName()+".raw"; ((ConfString&)inPixScan.config()["general"]["sourceRawFile"]).m_value = rawFile; } error = (*group)->setPixScan(inPixScan); if(error) return error; } // restore original raw name ((ConfString&)inPixScan.config()["general"]["sourceRawFile"]).m_value = orgRawFile; return error; } int STRodCrate::CtrlStatusSummary() { if( m_pixModuleGroups.size() == 0 ) { return -1; } else { int nRods = 0; for(std::vector::iterator i=m_pixModuleGroups.begin(); i != m_pixModuleGroups.end(); i++) { if((*i)->getPixCtrlStatus()==tOK) nRods++; } return nRods; } } void STRodCrate::readRodBuff(){ if(m_IFtype!=tRCCVME) return; // not functionality for non-RCC systems if(m_vmeInterface!=0){ // can't work w/o VME interface // Loop over module groups for( std::vector::iterator group = m_pixModuleGroups.begin(); group != m_pixModuleGroups.end(); group++ ) { (*group)->readRodBuff(""); } } else{ emit logMessage("STRodCrate::readRodBuff() : no VME interfaces found for crate "+getName()+ ", can't proceed"); } return; } bool STRodCrate::RodProcessing() { bool processing = false; if( m_pixModuleGroups.size() == 0 || (m_vmeInterface==0 && m_IFtype!=tUSBSys)) { return false; } for(std::vector::iterator i=m_pixModuleGroups.begin(); i != m_pixModuleGroups.end(); i++) { if((*i)->getProcessing()==true) { processing = true; } } return processing; } void STRodCrate::initRods() { // send init command if( m_vmeInterface!=0 && m_IFtype!=tUSBSys) { for( std::vector::iterator group = m_pixModuleGroups.begin(); group != m_pixModuleGroups.end(); group++ ){ if((*group)->getPixCtrlStatus()!=tbusy){ (*group)->ThreadExecute(MTinitrods); } } } if(m_IFtype==tUSBSys){ // stop USB background checking, might interfere with what the driver is doing m_timer->stop(); // make sure that pending calls don't interfere std::map grpState; for( std::vector::iterator group = m_pixModuleGroups.begin(); group != m_pixModuleGroups.end(); group++ ){ if((*group)->getPixCtrlStatus()!=tbusy){ grpState[(*group)->getName()] = (*group)->initrods(); } } // if uC code was loaded, this will scramble the handles, so update them for( std::vector::iterator group = m_pixModuleGroups.begin(); group != m_pixModuleGroups.end(); group++ ){ USBPixController *upc = dynamic_cast((*group)->getPixController()); if(upc!=0){ try{ // only call update if init was successful, otherwise we get a crash if(grpState[(*group)->getName()]) upc->updateDeviceHandle(); }catch(...){ } } } // re-start timer if we're in USBPix mode m_timer->start(50); } return; } void STRodCrate::resetRods() { if( m_vmeInterface!=0 || m_IFtype==tUSBSys) { for( std::vector::iterator group = m_pixModuleGroups.begin(); group != m_pixModuleGroups.end(); group++ ){ if((*group)->getPixCtrlStatus()!=tbusy){ (*group)->ThreadExecute(MTresetrods); } } } return; } void STRodCrate::initBocs() { if( m_vmeInterface!=0 || m_IFtype==tUSBSys) { for( std::vector::iterator group = m_pixModuleGroups.begin(); group != m_pixModuleGroups.end(); group++ ){ if((*group)->getPixCtrlStatus()!=tbusy){ (*group)->ThreadExecute(MTinitbocs); } } } return; } void STRodCrate::configModules(int cfgType, int patternType, int DCs, std::string latch) { std::vector opts; opts.push_back(cfgType); opts.push_back(patternType); opts.push_back(DCs); if( m_vmeInterface!=0 || m_IFtype==tUSBSys) { for( std::vector::iterator group = m_pixModuleGroups.begin(); group != m_pixModuleGroups.end(); group++ ){ if((*group)->getPixCtrlStatus()!=tbusy){ (*group)->ThreadExecute(MTconfig, opts, latch); } } } return; } void STRodCrate::resetModules(int type) { std::vector opts; opts.push_back(type); if( m_vmeInterface!=0 || m_IFtype==tUSBSys) { for( std::vector::iterator group = m_pixModuleGroups.begin(); group != m_pixModuleGroups.end(); group++ ){ if((*group)->getPixCtrlStatus()!=tbusy){ (*group)->ThreadExecute(MTresetmods, opts); } } } return; } void STRodCrate::triggerModules() { if( m_vmeInterface!=0 || m_IFtype==tUSBSys) { for( std::vector::iterator group = m_pixModuleGroups.begin(); group != m_pixModuleGroups.end(); group++ ){ if((*group)->getPixCtrlStatus()!=tbusy){ (*group)->ThreadExecute(MTtrigger); } } } return; } void STRodCrate::getSrvRec(){ if( m_vmeInterface!=0 || m_IFtype==tUSBSys) { for( std::vector::iterator group = m_pixModuleGroups.begin(); group != m_pixModuleGroups.end(); group++ ){ if((*group)->getPixCtrlStatus()!=tbusy){ (*group)->ThreadExecute(MTsrvrec); } } } return; } void STRodCrate::setMcc(int opt) { std::vector opts; opts.push_back(opt); if( m_vmeInterface!=0 || m_IFtype==tUSBSys) { for( std::vector::iterator group = m_pixModuleGroups.begin(); group != m_pixModuleGroups.end(); group++ ){ if((*group)->getPixCtrlStatus()!=tbusy){ (*group)->ThreadExecute(MTsetmcc, opts); } } } return; } void STRodCrate::scan(STControlEngine::pixScanRunOptions scanOpts) { if( m_vmeInterface!=0 || m_IFtype==tUSBSys) { PixScan *cfg = scanOpts.scanConfig; bool anyDcsScanned =false; for(int il=0;il<3;il++){ if(cfg->getLoopActive(il) && cfg->getLoopParam(il)==PixLib::PixScan::DCS_VOLTAGE) anyDcsScanned = true; } // store DCS config before scan for restoring it later if(cfg->getRestoreModuleConfig() && anyDcsScanned){ for(std::vector ::iterator IT=m_pixDcs.begin(); IT!=m_pixDcs.end(); IT++){ m_dcsState.push_back((*IT)->ReadState("xx")); for(std::vector ::iterator ITC=(*IT)->chanBegin(); ITC!=(*IT)->chanEnd(); ITC++){ if((*IT)->getDevType()==PixDcs::SUPPLY){ #ifdef HAVE_GPIB GPIBPixDcsChan *gc = dynamic_cast(*ITC); #endif USBPixDcsChan *uc = dynamic_cast(*ITC); if(uc!=0) m_dcsPrescanCfg.push_back((PixDcsChan*)(new USBPixDcsChan(*uc))); #ifdef HAVE_GPIB else if(gc!=0) m_dcsPrescanCfg.push_back((PixDcsChan*)(new GPIBPixDcsChan(*gc))); #endif else m_dcsPrescanCfg.push_back(0); } else m_dcsPrescanCfg.push_back(0); } } } // start scan over all rods for( std::vector::iterator group = m_pixModuleGroups.begin(); group != m_pixModuleGroups.end(); group++ ){ // load DCS info if needed if(cfg->getDcsChan()!=""){ for(PixModuleGroup::moduleIterator mit=(*group)->modBegin(); mit!=(*group)->modEnd(); mit++){ std::string dcsName = (*mit)->moduleName(); getDecNameCore(dcsName); dcsName = cfg->getDcsChan()+"_"+dcsName; (*group)->setDcsChan((*mit)->moduleId(), 0); // set to NULL-pointer initially for(std::vector ::iterator IT=m_pixDcs.begin(); IT!=m_pixDcs.end(); IT++){ for(std::vector ::iterator ITC=(*IT)->chanBegin(); ITC!=(*IT)->chanEnd(); ITC++){ if((*ITC)->name()==dcsName) (*group)->setDcsChan((*mit)->moduleId(), *ITC); } } } } // actual scan start if((*group)->getPixCtrlStatus()!=tbusy) (*group)->ThreadExecute(MTscan, scanOpts); } } } void STRodCrate::restoreAfterScan() { // restore DCS config - if m_dcsPrescanCfg.size()>0 then DCS config was altered during scan // and org. config stored in STRodCrate::scan if(m_dcsPrescanCfg.size()>0){ std::vector::iterator ITD=m_dcsPrescanCfg.begin(); std::vector::iterator ITS=m_dcsState.begin(); for(std::vector ::iterator IT=m_pixDcs.begin(); IT!=m_pixDcs.end(); IT++){ for(std::vector ::iterator ITC=(*IT)->chanBegin(); ITC!=(*IT)->chanEnd(); ITC++){ if((*ITD)!=0) (*ITC)->config() = (*ITD)->config(); delete (*ITD); *ITD = 0; ITD++; } if((*ITS)=="ON" || (*ITS)=="OFF") (*IT)->SetState(*ITS); ITS++; } m_dcsPrescanCfg.clear(); m_dcsState.clear(); } } void STRodCrate::setGR(std::string GRname, int GRval){ // get groups in this crate and loop over them for(std::vector::iterator mgrIT = m_pixModuleGroups.begin(); mgrIT != m_pixModuleGroups.end();mgrIT++) (*mgrIT)->setGR(GRname, GRval); return; } void STRodCrate::setPR(std::string PRname, int PRval){ // get groups in this crate and loop over them for(std::vector::iterator mgrIT = m_pixModuleGroups.begin(); mgrIT != m_pixModuleGroups.end();mgrIT++) (*mgrIT)->setPR(PRname, PRval); return; } int STRodCrate::setTFDACs(const char *fname, bool isTDAC) { int not_found=0; // get groups in this crate and loop over them for(std::vector::iterator mgrIT = m_pixModuleGroups.begin(); mgrIT != m_pixModuleGroups.end();mgrIT++) not_found += (*mgrIT)->setTFDACs(fname, isTDAC); return not_found; } int STRodCrate::setMasks(std::vector files, std::vector histos, int mask){ //setMasks(const char *fname, const char *hname, int mask){ int not_found=0; // get groups in this crate and loop over them for(std::vector::iterator mgrIT = m_pixModuleGroups.begin(); mgrIT != m_pixModuleGroups.end();mgrIT++) not_found += (*mgrIT)->setMasks(files, histos, mask); return not_found; } void STRodCrate::setVcal(float charge, bool Chigh) { // get groups in this crate and loop over them for(std::vector::iterator mgrIT = m_pixModuleGroups.begin(); mgrIT != m_pixModuleGroups.end();mgrIT++) (*mgrIT)->setVcal(charge,Chigh); return; } void STRodCrate::incrMccDelay(float delay, bool calib) { // get groups in this crate and loop over them for(std::vector::iterator mgrIT = m_pixModuleGroups.begin(); mgrIT != m_pixModuleGroups.end();mgrIT++) (*mgrIT)->incrMccDelay(delay, calib); return; } void STRodCrate::disableFailed() { // get groups in this crate and loop over them for(std::vector::iterator mgrIT = m_pixModuleGroups.begin(); mgrIT != m_pixModuleGroups.end();mgrIT++){ (*mgrIT)->disableFailed(); } return; } void STRodCrate::listRODs(std::vector &rod_slots, std::vector &revs){ rod_slots.clear(); revs.clear(); if(m_vmeInterface==0) return; // can't work w/o VME interface #ifndef NOTDAQ int i, address; for(i=5;i<22;i++){ if (i!=13){ // don't even bother to try the TIM slot address= i <<24 ; try{ SctPixelRod::RodModule rod(address,0x1000000, *m_vmeInterface, 4); rod.hpiLoad(SctPixelRod::HPIC, 0x10001); if( rod.hpiFetch(SctPixelRod::HPIC)==0x90009){ unsigned long rodserial=rod.hpiFetch(FPGA_STATUS_REG_6_REL_ADDR); // ROD Serial Number rod_slots.push_back(i); revs.push_back((rodserial>>16)&0xFF); } } catch(...){ } } } #endif return; } void STRodCrate::clearModuleInfo() { modStatus modS; std::vector tmpGrp = m_pixModuleGroups; for( std::vector::iterator gi = tmpGrp.begin(); gi!=tmpGrp.end(); gi++){ for(PixModuleGroup::moduleIterator mi = (*gi)->modBegin(); mi != (*gi)->modEnd(); mi++){ modS = (*gi)->getPixModuleStatus((*mi)->moduleId()); if(modS.modStat!=tOK) modS.modStat = tunknown; if(modS.mccStat!=tOK) modS.mccStat = tunknown; modS.modMsg = ""; modS.mccMsg = ""; for(int chip=0;chip<16;chip++){ if(modS.feStat[chip]!=tOK) modS.feStat[chip] = tunknown; modS.feMsg[chip] = ""; } (*gi)->setPixModuleStatus((*mi)->moduleId(),modS); } } } void STRodCrate::abortScan() { for( std::vector::iterator group = m_pixModuleGroups.begin(); group != m_pixModuleGroups.end(); group++ ) { (*group)->abortScan(); } } int STRodCrate::getGrpNSteps(int iGrp, int i) { if(iGrp>=0 && iGrp<(int)m_pixModuleGroups.size()) return m_pixModuleGroups[iGrp]->getNSteps(i); else return -1; } int STRodCrate::getGrpNMasks(int iGrp) { if(iGrp>=0 && iGrp<(int)m_pixModuleGroups.size()) return m_pixModuleGroups[iGrp]->getNMasks(); else return -1; } int STRodCrate::getGrpSRAMFillLevel(int iGrp) { if(iGrp>=0 && iGrp<(int)m_pixModuleGroups.size()) return m_pixModuleGroups[iGrp]->getSRAMFillLevel(); else return -1; } int STRodCrate::getGrpTriggerRate(int iGrp) { if(iGrp>=0 && iGrp<(int)m_pixModuleGroups.size()) return m_pixModuleGroups[iGrp]->getTriggerRate(); else return -1; } int STRodCrate::getGrpHitRate(int iGrp) { if(iGrp>=0 && iGrp<(int)m_pixModuleGroups.size()) return m_pixModuleGroups[iGrp]->getHitRate(); else return -1; } int STRodCrate::getGrpCurrFe(int iGrp) { if(iGrp>=0 && iGrp<(int)m_pixModuleGroups.size()) return m_pixModuleGroups[iGrp]->getCurrFe(); else return -1; } int STRodCrate::getGrpScanStatus(int iGrp) { if(iGrp>=0 && iGrp<(int)m_pixModuleGroups.size()) return m_pixModuleGroups[iGrp]->getScanStatus(); else return -1; } std::string STRodCrate::getGrpName(int iGrp) { if(iGrp>=0 && iGrp<(int)m_pixModuleGroups.size()) return m_pixModuleGroups[iGrp]->getName(); else return ""; } std::string STRodCrate::getGrpDecName(int iGrp) { if(iGrp>=0 && iGrp<(int)m_pixModuleGroups.size()) return m_pixModuleGroups[iGrp]->getDecName(); else return ""; } std::string STRodCrate::getModName(int iGrp, int iMod) { if(iGrp>=0 && iGrp<(int)m_pixModuleGroups.size() && m_pixModuleGroups[iGrp]->module(iMod)!=0) return m_pixModuleGroups[iGrp]->module(iMod)->moduleName(); else return ""; } void STRodCrate::getModules(int iGrp, std::vector< std::pair > &list) { if(iGrp>=0 && iGrp<(int)m_pixModuleGroups.size()){ for(PixModuleGroup::moduleIterator mi = m_pixModuleGroups[iGrp]->modBegin(); mi != m_pixModuleGroups[iGrp]->modEnd(); mi++) list.push_back(std::make_pair((*mi)->moduleName(), (*mi)->moduleId())); return; }else return; } void STRodCrate::writeConfig(int iGrp, int iMod) { if(iGrp>=0 && iGrp<(int)m_pixModuleGroups.size() && getPixCtrlStatus(iGrp)==tOK){ PixLib::PixModule *mod = m_pixModuleGroups[iGrp]->module(iMod); if(mod!=0) mod->writeConfig(); } } modStatus STRodCrate::getPixModuleStatus(int iGrp, int modID) { static modStatus modS; if(iGrp>=0 && iGrp<(int)m_pixModuleGroups.size()) return m_pixModuleGroups[iGrp]->getPixModuleStatus(modID); else return modS; } void STRodCrate::setPixModuleStatus(int iGrp, int modID, modStatus newStatus, bool emitSignal) { if(iGrp>=0 && iGrp<(int)m_pixModuleGroups.size()) m_pixModuleGroups[iGrp]->setPixModuleStatus(modID, newStatus, emitSignal); } void STRodCrate::recCurrentModule(PixLib::PixModule *mod) { if(mod==0) return; int grpID = ((STPixModuleGroup*)mod->getPixModGroup())->getID(); emit currentModule(m_ID, grpID, mod->moduleId()); } void STRodCrate::runLinkTest(int iGrp, int modID) { if( m_vmeInterface!=0 || m_IFtype==tUSBSys) { if(iGrp>=0 && iGrp<(int)m_pixModuleGroups.size()) m_pixModuleGroups[iGrp]->runLinkTest(m_pixModuleGroups[iGrp]->module(modID),0); else{ for( std::vector::iterator group = m_pixModuleGroups.begin(); group != m_pixModuleGroups.end(); group++ ){ if((*group)->getPixCtrlStatus()!=tbusy){ (*group)->ThreadExecute(MTlinktest); } } } } } void STRodCrate::runChipTest(ChipTest *ct, bool resetMods, int iGrp, int modID){ if( m_vmeInterface!=0 || m_IFtype==tUSBSys) { if(iGrp>=0 && iGrp<(int)m_pixModuleGroups.size()) m_pixModuleGroups[iGrp]->runChipTest(ct, resetMods, m_pixModuleGroups[iGrp]->module(modID)); else{ for( std::vector::iterator group = m_pixModuleGroups.begin(); group != m_pixModuleGroups.end(); group++ ){ if((*group)->getPixCtrlStatus()!=tbusy){ (*group)->ThreadExecute(MTchiptest, ct, resetMods); } } } } } void STRodCrate::selectFe(int iFE, int grpID, int modID) { int iGrpStart = 0; int iGrpStop = m_pixModuleGroups.size(); if(grpID>=0 && grpID<(int)m_pixModuleGroups.size()){ iGrpStart = grpID; iGrpStop = grpID+1; } for(int iGrp = iGrpStart; iGrpselectFe(iFE, modID); if(m_pixModuleGroups[iGrp]->getPixCtrlStatus()==tOK) m_pixModuleGroups[iGrp]->downloadConfig(); } } void STRodCrate::configSingleMod(int iGrp, int modID, int maskFE) { if(iGrp>=0 && iGrp<(int)m_pixModuleGroups.size()) m_pixModuleGroups[iGrp]->configSingleMod(modID, maskFE); } bool STRodCrate::getModuleActive(int iGrp, int modID) { if(iGrp>=0 && iGrp<(int)m_pixModuleGroups.size()) return m_pixModuleGroups[iGrp]->getModuleActive(modID); else return false; } void STRodCrate::setModuleActive(int iGrp, int modID, bool active) { if(iGrp>=0 && iGrp<(int)m_pixModuleGroups.size()) m_pixModuleGroups[iGrp]->setModuleActive(modID, active); } int STRodCrate::hasCtrl(int iGrp) { if(iGrp>=0 && iGrp<(int)m_pixModuleGroups.size()){ PixController *pc = m_pixModuleGroups[iGrp]->getPixController(); if(pc!=0){ if(dynamic_cast(pc)!=0) return 1; if(dynamic_cast(pc)!=0) return 2; if(dynamic_cast(pc)!=0) return 3; } } return 0; } bool STRodCrate::hasBoc(int iGrp) { if(iGrp>=0 && iGrp<(int)m_pixModuleGroups.size()) return (m_pixModuleGroups[iGrp]->getPixBoc()!=0); else return false; } StatusTag STRodCrate::getPixBocStatus(int iGrp) { if(iGrp>=0 && iGrp<(int)m_pixModuleGroups.size()) return m_pixModuleGroups[iGrp]->getPixBocStatus(); else return tunknown; } StatusTag STRodCrate::getPixCtrlStatus(int iGrp) { if(iGrp>=0 && iGrp<(int)m_pixModuleGroups.size()) return m_pixModuleGroups[iGrp]->getPixCtrlStatus(); else return tunknown; } void STRodCrate::setPixCtrlStatus(int iGrp, StatusTag status) { if(iGrp>=0 && iGrp<(int)m_pixModuleGroups.size()) m_pixModuleGroups[iGrp]->setPixCtrlStatus(status); } bool STRodCrate::getCtrlInputStatus(int iGrp, int input){ if(iGrp>=0 && iGrp<(int)m_pixModuleGroups.size()) return m_pixModuleGroups[iGrp]->getCtrlInputStatus(input); else return false; } PixLib::Config& STRodCrate::getPixModuleConf(int iGrp, int modID) { static Config dummyCfg("dummymod"); if(iGrp>=0 && iGrp<(int)m_pixModuleGroups.size()){ PixLib::PixModule *mod = m_pixModuleGroups[iGrp]->module(modID); if(mod!=0) return mod->config(); return dummyCfg; } return dummyCfg; } PixLib::Config& STRodCrate::getPixModuleChipConf(int iGrp, int modID, int chipID) { static Config dummyCfg("dummychip"); if(iGrp>=0 && iGrp<(int)m_pixModuleGroups.size()){ PixLib::PixModule *mod = m_pixModuleGroups[iGrp]->module(modID); if(mod!=0){ if(chipID>=0 && chipID<16){ if(mod->pixFE(chipID)!=0) return mod->pixFE(chipID)->config(); else return dummyCfg; }else if(chipID==16){ if(mod->pixMCC()!=0) return mod->pixMCC()->config(); else return dummyCfg; }else return dummyCfg; } return dummyCfg; } return dummyCfg; } PixLib::Config& STRodCrate::getPixCtrlConf(int iGrp) { static Config dummyCfg("dummyctrl"); if(iGrp>=0 && iGrp<(int)m_pixModuleGroups.size()){ PixLib::PixController *ctrl = m_pixModuleGroups[iGrp]->getPixController(); if(ctrl!=0) return ctrl->config(); return dummyCfg; } return dummyCfg; } PixLib::Config& STRodCrate::getPixBocConf(int iGrp) { static Config dummyCfg("dummyboc"); if(iGrp>=0 && iGrp<(int)m_pixModuleGroups.size()){ PixLib::PixBoc *boc = m_pixModuleGroups[iGrp]->getPixBoc(); if(boc!=0) return *(boc->getConfig()); return dummyCfg; } return dummyCfg; } PixLib::Config& STRodCrate::getGrpConf(int iGrp) { static Config dummyCfg("dummygrp"); if(iGrp>=0 && iGrp<(int)m_pixModuleGroups.size()) return m_pixModuleGroups[iGrp]->config(); return dummyCfg; } void STRodCrate::editedCfg(int iGrp, int ID) { if(iGrp>=0 && iGrp<(int)m_pixModuleGroups.size()) m_pixModuleGroups[iGrp]->editedCfg(ID); } void STRodCrate::editedCfgAllMods(int iGrp) { if(iGrp>=0 && iGrp<(int)m_pixModuleGroups.size()) m_pixModuleGroups[iGrp]->editedCfgAllMods(); } void STRodCrate::initDcs(){ for(std::vector ::iterator IT=m_pixDcs.begin(); IT!=m_pixDcs.end(); IT++){ try{ (*IT)->initHW(); }catch(PixDcsExc &pde){ std::stringstream msg; pde.dump(msg); emit errorMessage("STRodCrate::initDcs : PixDcs exception while initialising "+(*IT)->name()+": "+msg.str()); }catch(...){ emit errorMessage("STRodCrate::initDcs : unknown exception while initialising " + (*IT)->name()); } } } void STRodCrate::setDcs(std::string chanName, double value, int cmdId, STPixModuleGroup *grp){ bool foundIt=false; for(std::vector ::iterator IT=m_pixDcs.begin(); IT!=m_pixDcs.end(); IT++){ for(std::vector::iterator CIT=(*IT)->chanBegin(); CIT!=(*IT)->chanEnd(); CIT++){ if(chanName==(*CIT)->name()){ foundIt = true; if((*IT)->ReadState("")!="ON" && (*IT)->ReadState("")!="OFF"){ grp->setDcsState(cmdId, 2); }else{ // set voltage to desired value Config &cfg = (*CIT)->config(); if(cfg["settings"].name()!="__TrashConfGroup__" && cfg["settings"]["NomVolts"].name()!="__TrashConfObj__"){ ((ConfFloat&)cfg["settings"]["NomVolts"]).m_value = (float)value; (*IT)->SetState("ON"); // either turns on and ramps up, or if on already just ramps to set voltage grp->setDcsState(cmdId, 1); } else grp->setDcsState(cmdId, 2); } return; } } } if(!foundIt){ grp->setDcsState(cmdId, 2); } return; } void STRodCrate::getDcs(std::string chanName, PixScan::DcsReadMode rtype, int cmdId, STPixModuleGroup *grp){ bool foundIt=false; for(std::vector ::iterator IT=m_pixDcs.begin(); IT!=m_pixDcs.end(); IT++){ for(std::vector::iterator CIT=(*IT)->chanBegin(); CIT!=(*IT)->chanEnd(); CIT++){ if(chanName==(*CIT)->name()){ foundIt = true; double val = 0.; try{ std::string rtypes = "unknown"; switch(rtype){ case PixScan::VOLTAGE: rtypes = "voltage"; break; case PixScan::CURRENT: rtypes = "current"; break; } val = (*CIT)->ReadParam(rtypes); }catch(...){ grp->setDcsRState(cmdId, 2, val); } grp->setDcsRState(cmdId, 1, val); return; } } } // if(!foundIt){ // // std::cout << "STRodCrate: DCS cannel " << chanName << " not found" << std::endl; // grp->setDcsRState(cmdId, 2, ((double)rand())/((double)RAND_MAX)); // } return; } void STRodCrate::checkUsbEvent(){ if(OnDeviceChange()){ //cout << "INFO: STRodCrate::checkUsbEvent: USB update event detected " << endl; for(std::vector::iterator i=m_pixModuleGroups.begin(); i != m_pixModuleGroups.end(); i++) { USBPixController *upc = dynamic_cast((*i)->getPixController()); if(upc!=0){ try{ upc->updateDeviceHandle(); if((*i)->getPixCtrlStatus()==tproblem) (*i)->setPixCtrlStatus(tblocked); }catch (USBPixControllerExc & upcexc){ std::stringstream msg; upcexc.dump(msg); emit logMessage("STRodCrate::checkUsbEvent() : USBPixController-exception (grp. " + (*i)->getName() + "): " + msg.str()); (*i)->setPixCtrlStatus(tproblem); }catch (...){ emit logMessage("STRodCrate::checkUsbEvent() : unknown exception (grp. " + (*i)->getName() + ")"); (*i)->setPixCtrlStatus(tproblem); } } } } } void STRodCrate::getSrvRecRes(int iGrp, std::vector &srvRec){ srvRec.clear(); srvRec.resize(32); // service records have 32 elements if(iGrp>=0 && iGrp<(int)m_pixModuleGroups.size()){ for(unsigned int i=0;(i<(m_pixModuleGroups[iGrp]->m_srvCounts).size()) && (i<32);i++) srvRec[i] = m_pixModuleGroups[iGrp]->m_srvCounts[i]; } return; } void STRodCrate::reloadCtrlCfg(int iGrp){ if(iGrp>=0 && iGrp<(int)m_pixModuleGroups.size()) m_pixModuleGroups[iGrp]->reloadCtrlCfg(); return; } void STRodCrate::setFeMode(int mode){ for(std::vector::iterator i=m_pixModuleGroups.begin(); i != m_pixModuleGroups.end(); i++) { USBPixController *upc = dynamic_cast((*i)->getPixController()); switch(mode){ case 0: default: upc->setFEConfigurationMode(); break; case 1: upc->setFERunMode(); break; } } return; } void STRodCrate::readEPROM(){ for(std::vector::iterator i=m_pixModuleGroups.begin(); i != m_pixModuleGroups.end(); i++) { USBPixController *upc = dynamic_cast((*i)->getPixController()); upc->readEPROM(); } return; } void STRodCrate::burnEPROM(){ for(std::vector::iterator i=m_pixModuleGroups.begin(); i != m_pixModuleGroups.end(); i++) { USBPixController *upc = dynamic_cast((*i)->getPixController()); upc->burnEPROM(); } return; } void STRodCrate::saveScanIfDone(STControlEngine::pixScanRunOptions scanOpts){ #ifdef WIN32 // linux is using a differen storage mechanism, so don't allo wto execute for(std::vector::iterator i=m_pixModuleGroups.begin(); i != m_pixModuleGroups.end(); i++){ if((*i)->getScanStatus()==3){ // grp. is ready for saving; will be set to 1 after call to processPixScanHistos std::stringstream msg; // try to catch any kind of problem - avoids uncontrolled crashes (hopefully) try{ (*i)->processPixScanHistos(scanOpts); } catch (SctPixelRod::VmeException& v) { msg << "VME-exception "; msg << v; } catch(SctPixelRod::BaseException& b){ msg << "Base exception "; msg << b; } catch(std::exception& s){ msg << "Std-lib exception "; msg << s.what(); } catch(...){ msg << "Unknown exception "; } if(msg.str()!=""){ emit logMessage("STRodCrate::saveScanIfDone: Exception " + msg.str() + " not caught during execution with group "+ (*i)->getName()+ " at " + std::string(QDateTime::currentDateTime().toString("hh:mm:ss on MM-dd-yyyy").latin1())+"\n" ); // TFile might still be open - close if gFile is not NULL try{ if(gFile!=0) gFile->Close(); }catch(...){} // nothing else to try, give up... // call to processPixScanHistos failed, set status to 1=finished manually (*i)->setScanStatus(1); } } } #endif } void STRodCrate::readUsbPixDcs(){ bool scanRuns = true; for(int iGrp=0;iGrp::iterator pdIT = m_pixDcs.begin(); pdIT!=m_pixDcs.end(); pdIT++){ USBPixDcs *upd = dynamic_cast(*pdIT); if(upd!=0){ STPixModuleGroup &mgr = (STPixModuleGroup&)(upd->getCtrl()->getModGroup()); for(std::vector::iterator dcsc = (*pdIT)->chanBegin(); dcsc!=(*pdIT)->chanEnd(); dcsc++){ try{ dcsReading readings; readings.chanName = (*dcsc)->name(); readings.volts = (*dcsc)->ReadParam("voltage"); readings.curr = (*dcsc)->ReadParam("current"); mgr.m_scanDcsReadings.push_back(readings); }catch(...){ } } } } } } }