#/*************************************************************************** STcontrolEngine.cxx - description ------------------- begin : Fri Apr 16 2004 copyright : (C) 2004 by jschumac email : jschumac@silabsbc modifications : 2005 by rottlaen ***************************************************************************/ /*************************************************************************** * * * 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 #include #include #include #include #include #include #include #include #include #include #include "STCLogContainer.h" #include "STCLog.h" #include "STControlEngine.h" #include "STRodCrate.h" #include "ChipTest.h" #include #include #include #include #include #include #include #include #include #ifdef WIN32 #include #else #include #endif STControlEngine::STControlEngine( QApplication *app, STCLogContainer& log_in, QObject * parent, const char * name , bool singleCrateMode) : QObject( parent, name ), m_app(app), m_log(log_in), m_singleCrateMode(singleCrateMode), m_PixConfDBFname("") { m_PixConfDBFname = ""; m_IFtype = tundefIF; m_lastPixScanOpts.scanConfig=0; m_lastPixScanOpts.loadToAna=0; m_lastPixScanOpts.anaLabel=""; m_lastPixScanOpts.writeToFile=false; m_lastPixScanOpts.fileName=""; m_lastPixScanOpts.timestampStart=""; m_lastPixScanOpts.stdTestID = -1; m_scanTimer = new QTimer(this); m_scanTimer2 = new QTimer(this); m_cfgEdited=false; m_scanPtsPtr[0] = 0; m_scanPtsPtr[1] = 0; m_checkScanCount = 0; //m_finishScanRunning = false; // m_observedGroup = 0; m_obsCrate = -1; m_obsGrp = -1; // chip test option classes m_ctCfg = new Config("ChipTest"); m_ctCfg->addGroup("general"); (*m_ctCfg)["general"].addBool("resetAfterTest", m_resetAfterTest, false, "Reset Module/FEs after any of the tests", true); m_ctCfg->reset(); ChipTest ctdummy(ChipTest::CTDUMMY); std::map types = ctdummy.getTypeList(); for(std::map::iterator it=types.begin(); it!=types.end(); it++){ ChipTest *ct = ChipTest::make((ChipTest::chipTestType) it->second); m_chipTests[it->first] = ct; m_ctCfg->addConfig(&(ct->config())); } // need $PIX_LIB to find base config files m_plPath = gSystem->Getenv("PIX_LIB"); // set up options m_options = new Config("STControlConfig"); Config &conf = *m_options; // Group layout conf.addGroup("layout"); conf["layout"].addBool("RoDcsSamePanel", m_RoDcsSamePanel, true, "Show read-out and monitoring/regulator config on same panel", true); // Group paths conf.addGroup("paths"); conf["paths"].addString("defCfgPath", m_cfgPath, ".", "default config file path", true, 2); conf["paths"].addString("defLogPath", m_logPath, QDir::homeDirPath().latin1(), "default logfile file path", true, 2); conf["paths"].addString("defDataPath", m_dataPath, ".", "default data file path", true, 2); conf["paths"].addString("defDataName", m_dataName, "", "default data file name", true); conf["paths"].addBool("addDatetoDataFile", m_addDatetoDataFile, true, "append current date to default data file name", true); // Group module tests conf.addGroup("autoload"); conf["autoload"].addString("defCfgName", m_cfgName, "", "start-up loading of cfg.-file", true, 3); conf["autoload"].addBool("initRods", m_initRods, false, "init all PixControllers after auto-config loading", true); conf["autoload"].addBool("initDcs", m_initDcs, false, "init all PixDcs objects after auto-config loading", true); conf["autoload"].addBool("dcsOn", m_dcsOn, false, "turn on all supply-type PixDcs objects after auto-DCS-init", true); conf["autoload"].addString("defPixScanName", m_psName, "", "start-up loading of PixScan-file", true); conf["autoload"].addBool("doPixScanAutoLabel", m_psAutoLabel, true, "automatic setting of scan label from PixScan name", true); conf.addGroup("errors"); conf["errors"].addBool("showRodWin", m_showRodWin, true, "Show warning panel in case of ROD error buffer messages", true); conf.addGroup("modtest"); conf["modtest"].addString("defPath", m_modPath, ".", "default path for module testing", true, 2); // conf["modtest"].addVector("testTypes", m_testTypes, types, // "default path for module testing", true); conf["modtest"].addBool("resetAfterTest", m_resetAfterTest, false, "Reset Module/FEs after any of the tests", true); conf.addGroup("PDB"); conf["PDB"].addString("user", m_userPDB, "", "PDB user-ID, needed for retrieving assembly info", true); conf["PDB"].addString("password", m_passwdPDB, "", "PDB password, needed for retrieving assembly info", true); conf["PDB"].addBool("getAssyInfo", m_getAssyInfo, false, "automatically retrieve disk/half-shell assy info from PDB", false); // initialise options m_options->reset(); try{ loadOptions(); }catch(...){ m_options->reset(); } } STControlEngine::~STControlEngine(){ m_singleCrateMode=false; // make sure crates are deleted this time clear(); // remove user PixScan configs m_lastPixScanOpts.scanConfig=0; for(std::vector::iterator scfgIter=m_knownPixScanCfgs.begin(); scfgIter!=m_knownPixScanCfgs.end();scfgIter++) delete (*scfgIter); delete m_options; for(std::map::iterator it=m_chipTests.begin(); it!=m_chipTests.end(); it++) delete (it->second); } /** Read property of vector m_sTRodCrate. */ std::vector & STControlEngine::getSTRodCrates(){ return m_sTRodCrates; } /** open DB file and remember its name */ void STControlEngine::setPixConfDBFname(const char *in_path){ m_PixConfDBFname = in_path; emit cfgLabelChanged(); PixConfDBInterface *myDB=0; if(m_PixConfDBFname!=""){ // open new file try{ myDB = DBEdtEngine::openFile(m_PixConfDBFname.c_str(), false); }catch(SctPixelRod::BaseException& exc){ std::stringstream msg; msg << "STControlEngine::setPixConfDBFname : exception while opening DB file " << m_PixConfDBFname << ": " << exc; toErrLog(msg.str().c_str()); }catch(...){ toErrLog(("STControlEngine::setPixConfDBFname : unknown exception while opening DB file " + m_PixConfDBFname).c_str()); } delete myDB; } } std::string STControlEngine::getPixScanCfgDBName(PixScan *cfg){ std::string defVal = "unknown"; if(m_knownPSDBcfgs.lower_bound((long int)cfg)==m_knownPSDBcfgs.end()) return defVal; return (*m_knownPSDBcfgs.lower_bound((long int)cfg)).second; } void STControlEngine::setPixScanCfgDBName(PixScan *cfg, const char *name){ if(m_knownPSDBcfgs.lower_bound((long int)cfg)!=m_knownPSDBcfgs.end()) (*m_knownPSDBcfgs.lower_bound((long int)cfg)).second = name; } /** Adds a STRodCrate */ STRodCrate& STControlEngine::addCrate(const char *SBCaddress){ if(m_singleCrateMode && m_sTRodCrates.size()!=0){ toErrLog("STControlEngine::addCrate : a crate already exists and we are in special single-crate mode -> not creating new crate."); static STRodCrate tmpCrate; return tmpCrate; } int crID = m_sTRodCrates.size(); m_sTRodCrates.push_back( new STRodCrate(crID, m_app, this,SBCaddress,SBCaddress) ); // forward signals from STRodCrate connect(m_sTRodCrates[crID],SIGNAL(groupListChanged()), this, SIGNAL(crateListChanged())); // connect(m_sTRodCrates[crID],SIGNAL(updateModList()), this, SIGNAL(updateModList())); // forward uncritical messages to log container connect(m_sTRodCrates[crID],SIGNAL(logMessage(std::string)), this, SLOT(toLog(std::string))); // forward error messages to log container connect(m_sTRodCrates[crID],SIGNAL(errorMessage(std::string)), this, SLOT(toErrLog(std::string))); // forward ROD messages to log container connect(m_sTRodCrates[crID],SIGNAL(rodMessage(std::string, bool)), this, SLOT(toRodBuff(std::string, bool))); // forward module test signals connect(m_sTRodCrates[crID],SIGNAL(sendRTStatus(const char*)), this, SIGNAL(sendRTStatus(const char*))); connect(m_sTRodCrates[crID],SIGNAL(currentModule(int, int, int)), this, SIGNAL(currentModule(int, int, int))); connect(m_sTRodCrates[crID],SIGNAL(statusChanged()), this, SIGNAL(statusChanged())); // get it working and add to list view m_sTRodCrates[crID]->setupVme(); emit crateListChanged(); return *(m_sTRodCrates[crID]); } /** Deletes all STRodCrates */ void STControlEngine::clear(){ m_cfgEdited=false; if(!m_singleCrateMode){ // must not delete single crate if in single-crate mode! for(std::vector::iterator i=m_sTRodCrates.begin(); i != m_sTRodCrates.end(); i++) { // disable these signals, after deletion the crate list is not sane any more disconnect((*i),SIGNAL(groupListChanged()), this, SIGNAL(crateListChanged())); // disconnect((*i),SIGNAL(updateModList()), this, SIGNAL(updateModList())); disconnect((*i),SIGNAL(statusChanged()), this, SIGNAL(statusChanged())); delete *i; *i = 0; } m_sTRodCrates.clear(); emit crateListChanged(); // call this only once for all crates } else if ( m_sTRodCrates.size() == 1 ) // in single-crate mode, just clear that crate m_sTRodCrates[0]->clear(); else toErrLog("STControlEngine::clear: can't clear because we don't have any crates but we're supposed to have exactly one."); } void STControlEngine::addCrateToDB(const char *crateName, std::vector inGrpData, const char *DBfilename, IFtypes crtIFtype, bool addUsbDcs) { PixConfDBInterface *myDB = 0; QApplication::setOverrideCursor(Qt::waitCursor); try{ // open file, create app myDB = PixLib::addAppInq(DBfilename, crateName); }catch(PixDBException &dbexc){ std::stringstream txt, exmsg; dbexc.what(exmsg); txt << "STControlEngine::addCrateToDB : PixDB-exception " <::iterator IT=inGrpData.begin(); IT!=inGrpData.end(); IT++){ addGrouptoDB(startInq, *IT, crtIFtype); if(crtIFtype==tUSBSys && addUsbDcs){ // copy USBPixDcs entries, too - one per new group with ref. to USBPixController if(IT->myMods.size()>0 && IT->myMods[0].fname!=""){ PixConfDBInterface *dcsDB = DBEdtEngine::openFile(IT->myMods[0].fname.c_str()); DBInquire *dcsRoot = dcsDB->readRootRecord(1); DBInquire *dcsAppInq = *(dcsRoot->recordBegin()); for(recordIterator dcsit=dcsAppInq->recordBegin();dcsit!=dcsAppInq->recordEnd();dcsit++){ if((*dcsit)->getName()=="PixDcs"){ fieldIterator fit = (*dcsit)->findField("ActualClassName"); if(fit!=(*dcsit)->fieldEnd()){ std::string clname; dcsDB->DBProcess(*fit,READ, clname); if(clname=="USBPixDcs"){ std::stringstream a; a << usbInd; usbInd++; DBInquire *new_inq = myDB->makeInquire("PixDcs","USBPixDcs_"+a.str()); startInq->pushRecord(new_inq); myDB->DBProcess(startInq,COMMITREPLACE); myDB->DBProcess(new_inq,COMMIT); // call copy function for all depending fields for(fit=(*dcsit)->fieldBegin(); fit!=(*dcsit)->fieldEnd(); fit++){ if((*fit)->getName()=="USBPixController"){ DBField *fld = myDB->makeField("USBPixController"); std::string ctrlName="USB-board_"; std::stringstream b; b << IT->myROD.slot; ctrlName += b.str(); myDB->DBProcess(fld,COMMIT,ctrlName); new_inq->pushField(fld); delete fld; myDB->DBProcess(new_inq,COMMITREPLACE); }else if((*fit)->getName()=="general_Index"){ DBField *fld = myDB->makeField("general_Index"); int myind = usbInd-1; myDB->DBProcess(fld,COMMIT,myind); new_inq->pushField(fld); delete fld; myDB->DBProcess(new_inq,COMMITREPLACE); }else if((*fit)->getName()=="general_DeviceName"){ std::string ctrlName; myDB->DBProcess(*fit,READ,ctrlName); std::stringstream b; b << IT->myROD.slot; ctrlName += " - board "+b.str(); DBField *fld = myDB->makeField("general_DeviceName"); myDB->DBProcess(fld,COMMIT,ctrlName); new_inq->pushField(fld); delete fld; myDB->DBProcess(new_inq,COMMITREPLACE); } else insertDBField(*fit, new_inq); } // call copy function for all depending inquires for(recordIterator rit=(*dcsit)->recordBegin();rit!=(*dcsit)->recordEnd();rit++) insertDBInquire(*rit, new_inq); } } } } delete dcsDB; } else if(IT->myMods.size()>0 && (IT->myMods[0].assyType==1 || IT->myMods[0].assyType==2)){ // USBPix regulators std::stringstream a; a << usbInd; DBInquire *new_inq = myDB->makeInquire("PixDcs","USBPixDcs_"+a.str()); startInq->pushRecord(new_inq); myDB->DBProcess(startInq,COMMITREPLACE); myDB->DBProcess(new_inq,COMMIT); DBField *fld = myDB->makeField("USBPixController"); std::string ctrlName="USB-board_"; std::stringstream b; b << IT->myROD.slot; ctrlName += b.str(); myDB->DBProcess(fld,COMMIT,ctrlName); new_inq->pushField(fld); delete fld; myDB->DBProcess(new_inq,COMMITREPLACE); fld = myDB->makeField("general_Index"); myDB->DBProcess(fld,COMMIT,usbInd); new_inq->pushField(fld); delete fld; myDB->DBProcess(new_inq,COMMITREPLACE); ctrlName = "USB-regulators"; fld = myDB->makeField("general_DeviceName"); myDB->DBProcess(fld,COMMIT,ctrlName); new_inq->pushField(fld); delete fld; myDB->DBProcess(new_inq,COMMITREPLACE); ctrlName = "SUPPLY"; fld = myDB->makeField("general_DeviceType"); myDB->DBProcess(fld,COMMIT,ctrlName); new_inq->pushField(fld); delete fld; myDB->DBProcess(new_inq,COMMITREPLACE); ctrlName = "USBPixDcs"; fld = myDB->makeField("ActualClassName"); myDB->DBProcess(fld,COMMIT,ctrlName); new_inq->pushField(fld); delete fld; myDB->DBProcess(new_inq,COMMITREPLACE); // DCS channels std::string descr[4]={"VDDD1", "VDDA1", "VDDD2", "VDDA2"}; float nomvolts[4]={1.2f,1.5f,1.2f,1.5f}; for(int iCh=0;iCh<4;iCh++){ std::stringstream c; c<makeInquire("PixDcsChan","USBPixDcsChan_"+c.str()); new_inq->pushRecord(ch_inq); myDB->DBProcess(new_inq,COMMITREPLACE); myDB->DBProcess(ch_inq,COMMIT); fld = myDB->makeField("general_ChannelDescr"); myDB->DBProcess(fld,COMMIT,descr[iCh]); ch_inq->pushField(fld); delete fld; myDB->DBProcess(ch_inq,COMMITREPLACE); fld = myDB->makeField("general_ChannelName"); myDB->DBProcess(fld,COMMIT,descr[iCh]); ch_inq->pushField(fld); delete fld; myDB->DBProcess(ch_inq,COMMITREPLACE); fld = myDB->makeField("settings_NomVolts"); myDB->DBProcess(fld,COMMIT,nomvolts[iCh]); ch_inq->pushField(fld); delete fld; myDB->DBProcess(ch_inq,COMMITREPLACE); } usbInd++; // USBPix NTC ADC std::stringstream d; d << usbInd; new_inq = myDB->makeInquire("PixDcs","USBPixDcs_"+d.str()); startInq->pushRecord(new_inq); myDB->DBProcess(startInq,COMMITREPLACE); myDB->DBProcess(new_inq,COMMIT); fld = myDB->makeField("USBPixController"); ctrlName="USB-board_"; ctrlName += b.str(); myDB->DBProcess(fld,COMMIT,ctrlName); new_inq->pushField(fld); delete fld; myDB->DBProcess(new_inq,COMMITREPLACE); fld = myDB->makeField("general_Index"); myDB->DBProcess(fld,COMMIT,usbInd); new_inq->pushField(fld); delete fld; myDB->DBProcess(new_inq,COMMITREPLACE); ctrlName = "USB-ADC"; fld = myDB->makeField("general_DeviceName"); myDB->DBProcess(fld,COMMIT,ctrlName); new_inq->pushField(fld); delete fld; myDB->DBProcess(new_inq,COMMITREPLACE); ctrlName = "ADC-METER"; fld = myDB->makeField("general_DeviceType"); myDB->DBProcess(fld,COMMIT,ctrlName); new_inq->pushField(fld); delete fld; myDB->DBProcess(new_inq,COMMITREPLACE); ctrlName = "USBPixDcs"; fld = myDB->makeField("ActualClassName"); myDB->DBProcess(fld,COMMIT,ctrlName); new_inq->pushField(fld); delete fld; myDB->DBProcess(new_inq,COMMITREPLACE); // DCS channel DBInquire *ch_inq = myDB->makeInquire("PixDcsChan","USBPixDcsChan_0"); new_inq->pushRecord(ch_inq); myDB->DBProcess(new_inq,COMMITREPLACE); myDB->DBProcess(ch_inq,COMMIT); fld = myDB->makeField("general_ChannelDescr"); descr[0] = "Temp"; myDB->DBProcess(fld,COMMIT,descr[0]); ch_inq->pushField(fld); delete fld; myDB->DBProcess(ch_inq,COMMITREPLACE); fld = myDB->makeField("general_ChannelName"); descr[0] = "FE on-board NTC"; myDB->DBProcess(fld,COMMIT,descr[0]); ch_inq->pushField(fld); delete fld; myDB->DBProcess(ch_inq,COMMITREPLACE); usbInd++; } } } // get rid of temporary file delete myDB; }catch(PixDBException &dbexc){ std::stringstream txt, exmsg; dbexc.what(exmsg); txt << "STControlEngine::addCrateToDB : PixDB-exception " < inModData){ std::string fname = getPixConfDBFname(); if(fname==""){ toErrLog("STControlEngine::addModulesCurrDB : Can't find existing DB file in memory, so can't save."); return; } STRodCrate *crate = getSTRodCrates()[crateID]; // get name/decorated name of group std::string org_name = crate->getGrpName(grpID); std::string find_name = crate->getGrpDecName(grpID); if(org_name==""|| find_name==""){ toErrLog("STControlEngine::addModulesCurrDB : error retrieving DB names for group"); return; } // remove module name int pos = (int)find_name.find_last_of("/"); // remove trailing "/" if(pos!=(int)std::string::npos){ // extract group name from "path" find_name.erase(pos,find_name.length()-pos); pos = find_name.find_last_of("/"); if(pos!=(int)std::string::npos) find_name.erase(0,pos+1); } // must re-open in rw mode PixConfDBInterface *myDB = reopenDBforEdit(); if(myDB==0){ toErrLog("STControlEngine::addModulesCurrDB : error reopening existing DB file, so can't edit."); reloadDBafterEdit(false); return; } QApplication::setOverrideCursor(Qt::waitCursor); DBInquire *startInq=0, *grpInq=0; try{ if(m_singleCrateMode) startInq = PixLib::findAppInq(myDB); else{ // get inquire for this crate std::string name = "TestApp"; if(crate!=0) name = crate->getName(); startInq = PixLib::findAppInq(myDB, name.c_str()); } grpInq = *(startInq->findRecord(find_name+"/PixModuleGroup;1")); }catch(SctPixelRod::BaseException& exc){ QApplication::restoreOverrideCursor(); std::stringstream msg; msg << "STControlEngine::addModulesCurrDB : exception while searching for inquire for group " << org_name << " from DB file " << fname << ": " << exc; toErrLog(msg.str().c_str()); delete myDB; reloadDBafterEdit(false); return; }catch(...){ QApplication::restoreOverrideCursor(); toErrLog(("STControlEngine::addModulesCurrDB : unknown exception while searching for inquire for group " + org_name + " from DB file "+ fname).c_str()); delete myDB; reloadDBafterEdit(false); return; } QApplication::restoreOverrideCursor(); if(grpInq==0){ QApplication::restoreOverrideCursor(); toErrLog(("STControlEngine::addModulesCurrDB : can't find inquire for group " + org_name + " in DB file " + fname).c_str()); delete myDB; reloadDBafterEdit(false); return; } // add modules try{ newModWiz(inModData, grpInq, m_plPath.latin1()); }catch(SctPixelRod::BaseException& exc){ QApplication::restoreOverrideCursor(); std::stringstream msg; msg << "STControlEngine::addModulesCurrDB : exception while creating modules in module group DB entry: " << exc; toErrLog(msg.str().c_str()); delete myDB; reloadDBafterEdit(false); return; }catch(...){ QApplication::restoreOverrideCursor(); toErrLog("STControlEngine::addModulesCurrDB : unknown exception while creating modules in module group DB entry"); delete myDB; reloadDBafterEdit(false); return; } QApplication::restoreOverrideCursor(); // close and remove old file and load new one delete myDB; reloadDBafterEdit(true); return; } /** adds a PixModuleGroup to a loaded DB file */ void STControlEngine::addGrouptoDB(DBInquire *startInq, grpData inGrpData, IFtypes crtIFtype){ // create group inquire with ROD entries QApplication::setOverrideCursor(Qt::waitCursor); PixLib::DBInquire *grpInq=0; try{ if(crtIFtype==tRCCVME) grpInq = PixLib::newGroupWiz(inGrpData.myROD,startInq); else if(crtIFtype==tUSBSys){ QString grpName="USB-board_"; grpName += QString::number(inGrpData.myROD.slot); grpInq = PixLib::newGroupWiz("USBPixController", grpName.latin1(), startInq); recordIterator r=grpInq->recordBegin(); for( ; (r!=grpInq->recordEnd()) && ((*r)->getName()!="PixController"); r++) {} if(r!=grpInq->recordEnd()) { if(inGrpData.cfgType==1){ // >1 USB board, must specify ID DBField *ctrlField = grpInq->getDB()->makeField("general_BoardID"); grpInq->getDB()->DBProcess(ctrlField,COMMIT,inGrpData.myROD.slot); (*r)->pushField(ctrlField); delete ctrlField; grpInq->getDB()->DBProcess(*r,COMMITREPLACE); } if(inGrpData.myMods[0].assyType>1){ // 2-FE-module: 2nd board must be declared DBField *ctrlField = grpInq->getDB()->makeField("general_Board2ID"); int tmpID = 0; grpInq->getDB()->DBProcess(ctrlField,COMMIT,tmpID); (*r)->pushField(ctrlField); delete ctrlField; grpInq->getDB()->DBProcess(*r,COMMITREPLACE); } if(inGrpData.myROD.IPfile!=""){ DBField *ctrlField = grpInq->getDB()->makeField("general_FirmwareFile"); grpInq->getDB()->DBProcess(ctrlField,COMMIT,inGrpData.myROD.IPfile); (*r)->pushField(ctrlField); delete ctrlField; grpInq->getDB()->DBProcess(*r,COMMITREPLACE); } if(inGrpData.myROD.IDfile!=""){ DBField *ctrlField = grpInq->getDB()->makeField("general_uCFirmwareFile"); grpInq->getDB()->DBProcess(ctrlField,COMMIT,inGrpData.myROD.IDfile); (*r)->pushField(ctrlField); delete ctrlField; grpInq->getDB()->DBProcess(*r,COMMITREPLACE); } } }else{ QApplication::restoreOverrideCursor(); std::stringstream msg; msg << "STControlEngine::addGrouptoDB : unknown interface tpye encountered while creating module group DB entry. "; toErrLog(msg.str().c_str()); return; } }catch(PixDBException &dbexc){ std::stringstream txt, exmsg; dbexc.what(exmsg); txt << "STControlEngine::addGrouptoDB : PixDB-exception " <getDB(); if(inGrpData.cfgType<0 || (inGrpData.cfgType==1 && inGrpData.myMods[i].connName=="")){ // default, empty config std::string decName; decName = grpInq->getDecName() + inGrpData.myMods[i].modname; DBInquire *modInq = myDB->makeInquire("PixModule",decName); grpInq->pushRecord(modInq); myDB->DBProcess(grpInq,COMMITREPLACE); myDB->DBProcess(modInq,COMMIT); // define FE flavour and set PP0-type to USB DBField *newField = myDB->makeField("general_FE_Flavour"); std::string name, cname; switch(inGrpData.myMods[i].assyID){ case 0: name = "FE_I2"; cname= "PixFeI2"; break; case 1: name = "FE_I4A"; cname= "PixFeI4A"; break; case 2: name = "FE_I4B"; cname= "PixFeI4B"; break; default: name = "???"; cname= "PixFeI1"; break; } myDB->DBProcess(newField,COMMIT,name); modInq->pushField(newField); delete newField; myDB->DBProcess(modInq,COMMITREPLACE); //PixModule::USB; newField = myDB->makeField("pp0_Type"); name="USB"; myDB->DBProcess(newField,COMMIT,name); modInq->pushField(newField); delete newField; myDB->DBProcess(modInq,COMMITREPLACE); // add FE inquire(s) and label its/their type for(int iFe=0; iFegetDecName() + "PixFe_"+a.str(); DBInquire *feInq = myDB->makeInquire("PixFe",decName); modInq->pushRecord(feInq); myDB->DBProcess(modInq,COMMITREPLACE); myDB->DBProcess(feInq,COMMIT); newField = myDB->makeField("ClassInfo_ClassName"); myDB->DBProcess(newField,COMMIT,cname); feInq->pushField(newField); delete newField; myDB->DBProcess(feInq,COMMITREPLACE); newField = myDB->makeField("Misc_Address"); myDB->DBProcess(newField,COMMIT,iFe); feInq->pushField(newField); delete newField; myDB->DBProcess(feInq,COMMITREPLACE); // add inquires for global, pixel and trim registers decName = feInq->getDecName() + "GlobalRegister_0"; DBInquire *regInq = myDB->makeInquire("GlobalRegister",decName); feInq->pushRecord(regInq); myDB->DBProcess(feInq,COMMITREPLACE); myDB->DBProcess(regInq,COMMIT); decName = feInq->getDecName() + "PixelRegister_0"; regInq = myDB->makeInquire("PixelRegister",decName); feInq->pushRecord(regInq); myDB->DBProcess(feInq,COMMITREPLACE); myDB->DBProcess(regInq,COMMIT); decName = feInq->getDecName() + "Trim_0"; regInq = myDB->makeInquire("Trim",decName); feInq->pushRecord(regInq); myDB->DBProcess(feInq,COMMITREPLACE); myDB->DBProcess(regInq,COMMIT); } } else if(inGrpData.cfgType==0){ // create config from TurboDAQ file std::vector modInq = newModWiz(inGrpData.myMods, grpInq, m_plPath.latin1()); for(std::vector::iterator IT = modInq.begin(); IT!=modInq.end();IT++){ fieldIterator f; f = (*IT)->findField("pp0_Type"); std::string new_value = "USB"; if(f!=(*IT)->fieldEnd()) myDB->DBProcess(*f,COMMIT,new_value); // final commit myDB->DBProcess((*IT),COMMITREPLACE); } } else if(inGrpData.cfgType==1){ // copy config from RootDB file std::string decName; decName = grpInq->getDecName() + inGrpData.myMods[i].modname; DBInquire *modInq = myDB->makeInquire("PixModule",decName); grpInq->pushRecord(modInq); myDB->DBProcess(grpInq,COMMITREPLACE); myDB->DBProcess(modInq,COMMIT); // open file from which to copy and get module inquire DBInquire *cpModInq=0; PixConfDBInterface *modDB = DBEdtEngine::openFile(inGrpData.myMods[i].fname.c_str()); std::vector ti = modDB->DBFindRecordByName(PixLib::BYDECNAME,inGrpData.myMods[i].connName+"PixModule"); if(ti.size()==1) cpModInq=ti[0]; if(cpModInq!=0){ // copy all inquires and fields into new module inquire for(fieldIterator fit=cpModInq->fieldBegin(); fit!=cpModInq->fieldEnd(); fit++) insertDBField(*fit, modInq); for(recordIterator rit=cpModInq->recordBegin();rit!=cpModInq->recordEnd();rit++) insertDBInquire(*rit, modInq); } delete modDB; } else{ std::stringstream txt; txt << inGrpData.cfgType; toErrLog("STControlEngine::addGrouptoDB : unknown config type in USBPix mode: "+txt.str()); } }catch(PixDBException &dbexc){ std::stringstream txt; txt << "STControlEngine::addGrouptoDB : PixDB-exception " << dbexc.message << " while handling file " + inGrpData.myMods[i].fname + ", adding module group DB entry."; toErrLog(txt.str()); }catch(SctPixelRod::BaseException& exc){ QApplication::restoreOverrideCursor(); std::stringstream msg; msg << "STControlEngine::addGrouptoDB : exception while handling file " + inGrpData.myMods[i].fname + ", adding module group DB entry: " << exc; toErrLog(msg.str()); return; }catch(...){ QApplication::restoreOverrideCursor(); toErrLog("STControlEngine::addGrouptoDB : unknown exception handling file " + inGrpData.myMods[i].fname + ", adding module group DB entry"); return; } } }else{ if(inGrpData.cfgType){ // RootDB type input for(unsigned int i=0;igetDB(); DBInquire *root = modDB->readRootRecord(1); DBInquire *appInq = *(root->recordBegin()); DBInquire *grpInq2 = *(appInq->recordBegin()); DBInquire *modInq = *(grpInq2->recordBegin()); std::string decName; decName = grpInq->getDecName() + inGrpData.myMods[i].modname; DBInquire *modInq2 = myDB->makeInquire("PixModule",decName); grpInq->pushRecord(modInq2); myDB->DBProcess(grpInq,COMMITREPLACE); myDB->DBProcess(modInq2,COMMIT); // call resp. function for all depending fields for(fieldIterator fit=modInq->fieldBegin(); fit!=modInq->fieldEnd(); fit++) insertDBField(*fit, modInq2); // call this function for all depending inquires for(recordIterator rit=modInq->recordBegin();rit!=modInq->recordEnd();rit++) insertDBInquire(*rit, modInq2); fixModule(modInq2, inGrpData.myMods[i]); delete modDB; }catch(SctPixelRod::BaseException& exc){ QApplication::restoreOverrideCursor(); std::stringstream msg; msg << "STControlEngine::addGrouptoDB : exception while handling file " + inGrpData.myMods[i].fname + " while adding module group DB entry: " << exc; toErrLog(msg.str().c_str()); return; }catch(...){ QApplication::restoreOverrideCursor(); toErrLog("STControlEngine::addGrouptoDB : unknown exception handling file " + inGrpData.myMods[i].fname + " while adding module group DB entry"); return; } } } else{ // TurboDAQ input try{ newModWiz(inGrpData.myMods, grpInq, m_plPath.latin1()); }catch(SctPixelRod::BaseException& exc){ QApplication::restoreOverrideCursor(); std::stringstream msg; msg << "STControlEngine::addGrouptoDB : exception while creating modules in module group DB entry: " << exc; toErrLog(msg.str().c_str()); return; }catch(...){ QApplication::restoreOverrideCursor(); toErrLog("STControlEngine::addGrouptoDB : unknown exception while creating modules in module group DB entry"); return; } } } QApplication::restoreOverrideCursor(); } /** loads objects according to entries in DB file */ void STControlEngine::loadDB(const char *DBfilename){ QString my_path = DBfilename; QApplication::setOverrideCursor(Qt::waitCursor); // load DB object try{ PixConfDBInterface *tmp_DB = 0; if(my_path.right(8)!="cfg.root"){ //clumsy way to identify a root file, but OK for a start // assume this is an ascii DB file (TurboDaqDB), so must convert to RootDB std::string openopt = "CREATE"; FILE *testf = fopen((my_path+".root").latin1(),"r"); if(testf!=0){ fclose(testf); openopt = "RECREATE"; } tmp_DB = new RootDB(my_path.latin1(),openopt); // re-open in read-only mode to avoid corrupting the file delete tmp_DB; my_path += ".root"; } // store file name QApplication::restoreOverrideCursor(); setPixConfDBFname(my_path.latin1()); } catch(SctPixelRod::BaseException& exc){ QApplication::restoreOverrideCursor(); std::stringstream msg; msg << "STControlEngine::loadDB : exception while converting TurboDaqDB file to RootDB file: " << exc; toErrLog(msg.str().c_str()); setPixConfDBFname(""); return; } catch(...){ QApplication::restoreOverrideCursor(); toErrLog("STControlEngine::loadDB : unknown exception while converting TurboDaqDB file to RootDB file."); setPixConfDBFname(""); return; } QApplication::restoreOverrideCursor(); // load the crates, module group(s) etc loadCrates(); // for backward compatibility, load san config, too // don't support any longer, out of use for way too long // loadScanCfg(); } PixConfDBInterface * STControlEngine::reopenDBforEdit(){ QString fname = getPixConfDBFname(); if(fname==""){ toErrLog("STControlEngine::reopenDBforEdit : Can't find existing DB file in memory, so can't save."); return 0; } fname = getPixConfDBFname(); setPixConfDBFname(""); // close current (read-only) file QString cp_cmd; #ifdef WIN32 cp_cmd = "copy " + fname + " " + fname + ".temp.cfg.root"; cp_cmd.replace("/","\\"); #else cp_cmd = "cp " + fname + " " + fname + ".temp.cfg.root"; #endif system(cp_cmd.latin1()); QApplication::setOverrideCursor(Qt::waitCursor); PixConfDBInterface *myDB; try{ myDB = DBEdtEngine::openFile((fname + ".temp.cfg.root").latin1(),true); }catch(SctPixelRod::BaseException& exc){ QApplication::restoreOverrideCursor(); std::stringstream msg; msg << "STControlEngine::reopenDBforEdit : exception while re-opening DB file " << std::string(fname.latin1()) << ": " << exc; toErrLog(msg.str().c_str()); remove((fname + ".temp.cfg.root").latin1()); return 0; }catch(...){ QApplication::restoreOverrideCursor(); toErrLog(("STControlEngine::reopenDBforEdit : unknown exception while re-opening DB file "+fname ).latin1()); remove((fname + ".temp.cfg.root").latin1()); return 0; } QApplication::restoreOverrideCursor(); m_PixConfDBFname = (fname + ".temp.cfg.root").latin1(); return myDB; } void STControlEngine::reloadDBafterEdit(bool getNew){ // retrieve original filename and check if current name has ".temp" extension (mandatory in editing mode) QString fname = getPixConfDBFname(); int pos = (int)fname.find(".temp.cfg.root"); if(pos>=0){ fname.remove(pos, 14); } else { toErrLog("STControlEngine::reloadDBafterEdit : we are not in DB-file editing mode, no action performed."); return; } if(getNew){ // remove old file, rename new(.temp) to old name QString cp_cmd; #ifdef WIN32 cp_cmd = fname; cp_cmd.replace("/","\\"); cp_cmd = "del /f " + cp_cmd; #else cp_cmd = "rm -f " + fname; #endif system(cp_cmd.latin1()); rename((fname + ".temp.cfg.root").latin1(), fname.latin1()); //remove((fname+".temp.cfg.root").c_str()); } else{ // remove .temp file, not needed any longer remove((fname+".temp.cfg.root").latin1()); } setPixConfDBFname(fname.latin1()); // reload DB file clear(); loadDB(fname.latin1()); } void STControlEngine::saveDB(const char *DBfilename){ QString fname = getPixConfDBFname(); QString cp_cmd, path=fname + ".temp.cfg.root"; if(DBfilename!=0) path=DBfilename; else if(fname==""){ toErrLog("STControlEngine::saveDB : Can't find name of existing DB file in memory, so can't save."); return; } #ifdef WIN32 cp_cmd = "copy " + fname + " " + path; cp_cmd.replace("/","\\"); #else cp_cmd = "cp " + fname + " " + path; #endif system(cp_cmd.latin1()); PixConfDBInterface *myDB=0; QApplication::setOverrideCursor(Qt::waitCursor); try{ myDB = DBEdtEngine::openFile(path.latin1(),true); }catch(SctPixelRod::BaseException& exc){ QApplication::restoreOverrideCursor(); std::stringstream msg; msg << "STControlEngine::saveDB : exception while re-opening DB file " << std::string(path.latin1()) << ": " << exc; toErrLog(msg.str().c_str()); return; }catch(...){ QApplication::restoreOverrideCursor(); toErrLog(("STControlEngine::saveDB : unknown exception while re-opening DB file " + std::string(path.latin1())).c_str()); return; } delete myDB; myDB = 0; // retrieve inquires and save configs bool gotErr = false; // loop over crates std::vector myCrates = getSTRodCrates(); for(std::vector::iterator crIT = myCrates.begin(); crIT != myCrates.end(); crIT++) gotErr |= (*crIT)->saveDB(path.latin1()); QApplication::restoreOverrideCursor(); if(gotErr) toErrLog("Errors occured while saving, please check log for details."); else{ // clear edit flag savedCfg(); if(DBfilename==0){ // remove old file, and rename temp. file to old file name #ifdef WIN32 cp_cmd = fname; cp_cmd.replace("/","\\"); cp_cmd = "del /f " + cp_cmd; #else cp_cmd = "rm -f " + fname; #endif system(cp_cmd.latin1()); rename(path.latin1(),fname.latin1()); } else{ // we're actually in "save as..." mode, so just change the filename used here fname = path; } m_PixConfDBFname = fname.latin1(); emit cfgLabelChanged(); } return; } void STControlEngine::savePixScan(const char *DBfilename){ if(DBfilename==0) return; std::string cp_cmd, path=DBfilename; PixConfDBInterface *myDB=0; QApplication::setOverrideCursor(Qt::waitCursor); // create file if necessary - function will throw an exception when file exists, so just ignore that try{ DBEdtEngine::createFile(path.c_str()); }catch(...){ } // open file try{ myDB = DBEdtEngine::openFile(path.c_str(),true); }catch(SctPixelRod::BaseException& exc){ QApplication::restoreOverrideCursor(); std::stringstream msg; msg << "STControlEngine::savePixScan : exception while opening DB file " << path << ": " << exc; toErrLog(msg.str().c_str()); return; }catch(...){ QApplication::restoreOverrideCursor(); toErrLog(("STControlEngine::savePixScan : unknown exception while opening DB file " + path).c_str()); return; } // Save PixScan config - loop over what the engine has got for(std::vector::const_iterator it = getPixScanCfg().begin(); it != getPixScanCfg().end(); it++) { std::string find_name = getPixScanCfgDBName(*it); if( (*it) != 0 && find_name!="unknown" ){ find_name += "/PixScan;1"; std::vector scanInq; try{ scanInq = myDB->DBFindRecordByName(PixLib::BYDECNAME, find_name); }catch(...){ // everything is caught by the statement below scanInq.clear(); } if(scanInq.size()==0){ // add new inquire for this config std::string name="PixScan"; try{ PixLib::DBInquire *root = myDB->readRootRecord(1); std::string decName = root->getDecName() + getPixScanCfgDBName(*it); scanInq.push_back(myDB->makeInquire(name, decName)); root->pushRecord(scanInq[0]); myDB->DBProcess(root,COMMITREPLACE); myDB->DBProcess(scanInq[0],COMMIT); setPixScanCfgDBName(*it, decName.c_str()); } catch(...){ QApplication::restoreOverrideCursor(); toErrLog(("STControlEngine::savePixScan : could not find nor create DB object for PixScan " +find_name+" -> can't save.").c_str()); } try{ scanInq.clear(); // must close and re-open file to make this work delete myDB; myDB = DBEdtEngine::openFile(path.c_str(),true); find_name = getPixScanCfgDBName(*it); if( (*it) != 0 && find_name!="unknown" ){ find_name += "/PixScan;1"; scanInq = myDB->DBFindRecordByName(PixLib::BYDECNAME, find_name); } } catch(SctPixelRod::BaseException& exc){ QApplication::restoreOverrideCursor(); std::stringstream msg; msg << "STControlEngine::savePixScan : exception while re-opening DB file " << path << " after PixScan config creation: " << exc; toErrLog(msg.str().c_str()); } catch(...){ QApplication::restoreOverrideCursor(); toErrLog(("STControlEngine::savePixScan : unknown exception while re-opening DB file " +path+" after PixScan config creation.").c_str()); } } else{ if(scanInq.size()!=1) toLog(("STControlEngine::savePixScan : got several PixScan configs for " +find_name+".Will use first.").c_str()); } if(scanInq.size()>0){ try{ (*it)->writeConfig( scanInq[0] ); } catch(SctPixelRod::BaseException& exc){ QApplication::restoreOverrideCursor(); std::stringstream msg; msg << "STControlEngine::savePixScan : exception while saving PixScan config: " << exc; toErrLog(msg.str().c_str()); return; } catch(...){ QApplication::restoreOverrideCursor(); toErrLog("STControlEngine::savePixScan : unknown exception while saving PixScan config."); return; } } } } // close temporary file delete myDB; QApplication::restoreOverrideCursor(); } /** Loads PixModuleGroup */ void STControlEngine::loadCrates() { // if in single crate mode, we only have one crate for now, but need to make sure it is initialized if( m_singleCrateMode && m_sTRodCrates.size() < 1 ) { toErrLog("STControlEngine::loadModuleGroup : can't load module group because we don't have any crates."); return; } QApplication::setOverrideCursor(Qt::waitCursor); PixConfDBInterface * confDBInterface = DBEdtEngine::openFile(getPixConfDBFname(), false); DBInquire* root=0; try{ root = confDBInterface->readRootRecord(1); }catch(SctPixelRod::BaseException& exc){ QApplication::restoreOverrideCursor(); std::stringstream msg; msg << exc; toErrLog(("STControlEngine::loadModuleGroup : can't get root record: "+msg.str()).c_str()); return; }catch(...){ QApplication::restoreOverrideCursor(); toErrLog("STControlEngine::loadModuleGroup : can't get root record"); return; } if( root == 0 ){ QApplication::restoreOverrideCursor(); toErrLog("STControlEngine::loadModuleGroup: can't find root record in DB" ); return; } QApplication::restoreOverrideCursor(); // loop over DB entries and create a PixModuleGroup when an according entry is found for(recordIterator appIter = root->recordBegin();appIter!=root->recordEnd();appIter++){ if((int)(*appIter)->getName().find("application")!=(int)std::string::npos){ if(m_singleCrateMode){ m_sTRodCrates[0]->loadDB(getPixConfDBFname(), (*appIter)->getDecName().c_str());// gets all module groups from *appIter m_IFtype = m_sTRodCrates[0]->getIFtype(); }else{ // create crate according to DB name std::string cname = (*appIter)->getDecName(); // remove heading and trailing "/" cname.erase(0,1); cname.erase(cname.length()-1,1); // addCrate(cname.c_str()).loadDB(*appIter);// gets all module groups from *appIter addCrate(cname.c_str()).loadDB(getPixConfDBFname(), (*appIter)->getDecName().c_str());// gets all module groups from *appIter } } } emit configChanged(); // close file delete confDBInterface; return; } void STControlEngine::readRodBuff(std::string msg){ // user message if(msg!="") m_log.buffers() << (msg+"\n").c_str(); // Loop over crates for( std::vector::iterator crate = m_sTRodCrates.begin(); crate != m_sTRodCrates.end(); crate++ ) (*crate)->readRodBuff(); return; } void STControlEngine::toRodBuff(std::string msg, bool error){ if(error && m_showRodWin) m_log.errBuffers() << (msg+"\n").c_str(); else m_log.buffers() << (msg+"\n").c_str(); } void STControlEngine::toLog(std::string msg){ // write to log container m_log.log() << (msg+"\n").c_str(); } void STControlEngine::toErrLog(std::string msg){ // write to log container as error m_log.errLog() << (msg+"\n").c_str(); //stopping toolpanel-loop. emit breakloop(); } void STControlEngine::loadScanCfg(const char *fname){ PixConfDBInterface *tmpDB = 0; QString file_name; if(fname==0) file_name = getPixConfDBFname(); else{ file_name = fname; } tmpDB = DBEdtEngine::openFile(file_name.latin1()); if( tmpDB == 0 ) { toLog("[WARNING] STControlEngine::loadScanCfg() :\n" "[WARNING] No PixConfDBInterface present. Returning. \n"); return; } // clear existing PixScan records for(std::vector::const_iterator pcfgIT = m_knownPixScanCfgs.begin(); pcfgIT!=m_knownPixScanCfgs.end();pcfgIT++) delete (*pcfgIT); m_knownPixScanCfgs.clear(); m_knownPSDBcfgs.clear(); // get root record DBInquire* root=0; try{ root = tmpDB->readRootRecord(1); }catch(SctPixelRod::BaseException& exc){ std::stringstream msg; msg << exc; toErrLog("STControlEngine::loadScanCfg() : Can't get root record: "+msg.str()); if(fname!=0) delete tmpDB; return; }catch(...){ toErrLog("STControlEngine::loadScanCfg() : Can't get root record"); if(fname!=0) delete tmpDB; return; } std::stringstream msg; if( root == 0 ){ toLog("[WARNING] STControlEngine::loadScanCfg() :\n" "[WARNING] Can not find root record in database. Returning. \n"); if(fname!=0) delete tmpDB; return; } // get a record iterator recordIterator it = root->recordBegin(); if( *it == 0 ){ toLog("[WARNING] STControlEngine::loadScanCfg() :\n" "[WARNING] Can not find any records in database. Returning. \n"); if(fname!=0) delete tmpDB; return; } // load the scan config items into vetor containers recordIterator itEnd = root->recordEnd(); for( it = root->recordBegin(); it != itEnd; it++) { if( (*it)->getName() == "PixScan" ) { PixScan *scanCfg = new PixScan(*it); m_knownPixScanCfgs.push_back(scanCfg); m_knownPSDBcfgs.insert(std::make_pair((long int)scanCfg,(*it)->getDecName())); } } delete tmpDB; //emit scanConfigChanged(); return; } void STControlEngine::newPixScanCfg(const char *cfgName, PixScan *copy_from_this){ std::string name = cfgName; PixScan *scanCfg = new PixScan(); if(copy_from_this!=0) scanCfg->config() = copy_from_this->config(); m_knownPixScanCfgs.push_back(scanCfg); m_knownPSDBcfgs.insert(std::make_pair((long int)scanCfg,name)); m_cfgEdited=true; emit configChanged(); return; } void STControlEngine::clearModuleInfo(){ for( std::vector::iterator crate = getSTRodCrates().begin(); crate != getSTRodCrates().end(); crate++ ) (*crate)->clearModuleInfo(); return; } void STControlEngine::processExecute() { PixLib::sleep(20); do{ PixLib::sleep(10); m_app->processEvents(); } while (RodProcessing()); m_app->processEvents(); } void STControlEngine::initRods() { // Loop over crates for( std::vector::iterator crate = getSTRodCrates().begin(); crate != getSTRodCrates().end(); crate++ ) { if((*crate)->vmeOK()){ (*crate)->initRods(); } else{ toLog("STControlEngine::initRods() : no VME interfaces found for crate "+(*crate)->getName()+ ", can't proceed"); } } processExecute(); readRodBuff("Post-ROD/BOC-init info:"); return; } void STControlEngine::resetRods() { // Loop over crates for( std::vector::iterator crate = getSTRodCrates().begin(); crate != getSTRodCrates().end(); crate++ ) { if((*crate)->vmeOK()){ (*crate)->initRods(); } else{ toLog("STControlEngine::resetRods() : no VME interfaces found for crate "+(*crate)->getName()+ ", can't proceed"); } } processExecute(); return; } void STControlEngine::initBocs() { // Loop over crates for( std::vector::iterator crate = getSTRodCrates().begin(); crate != getSTRodCrates().end(); crate++ ) { if((*crate)->vmeOK()){ (*crate)->initBocs(); } else{ toLog("STControlEngine::initBocs() : no VME interfaces found for crate "+(*crate)->getName()+ ", can't proceed"); } } processExecute(); readRodBuff("Post-BOC-init info:"); return; } void STControlEngine::initDcs(){ // Loop over crates for( std::vector::iterator crate = getSTRodCrates().begin(); crate != getSTRodCrates().end(); crate++ ) { (*crate)->initDcs(); } emit statusChanged(); processExecute(); // readRodBuff("Post-DCS-init info:"); return; } void STControlEngine::configModules(int cfgType, int patternType, int DCs, std::string latch){ // Loop over crates for( std::vector::iterator crate = getSTRodCrates().begin(); crate != getSTRodCrates().end(); crate++ ) { if((*crate)->vmeOK()){ (*crate)->configModules(cfgType, patternType, DCs, latch); } else{ toLog("STControlEngine::configModules() : no VME interfaces found for crate "+(*crate)->getName()+ ", can't proceed"); } } processExecute(); //readRodBuff("Post-module-cfg info:"); return; } void STControlEngine::resetModules(int type) { // Loop over crates for( std::vector::iterator crate = getSTRodCrates().begin(); crate != getSTRodCrates().end(); crate++ ) { if((*crate)->vmeOK()){ (*crate)->resetModules(type); } else{ toLog("STControlEngine::resetModules() : no VME interfaces found for crate "+(*crate)->getName()+ ", can't proceed"); } } processExecute(); return; } void STControlEngine::triggerModules() { // Loop over crates for( std::vector::iterator crate = getSTRodCrates().begin(); crate != getSTRodCrates().end(); crate++ ) { if((*crate)->vmeOK()){ (*crate)->triggerModules(); } else{ toLog("STControlEngine::triggerModules() : no VME interfaces found for crate "+(*crate)->getName()+ ", can't proceed"); } } processExecute(); return; } void STControlEngine::getSrvRec(){ // Loop over crates for( std::vector::iterator crate = getSTRodCrates().begin(); crate != getSTRodCrates().end(); crate++ ) { if((*crate)->vmeOK()){ (*crate)->getSrvRec(); } else{ toLog("STControlEngine::getSrvRec() : no VME interfaces found for crate "+(*crate)->getName()+ ", can't proceed"); } } processExecute(); return; } void STControlEngine::readEPROM(){ // Loop over crates for( std::vector::iterator crate = getSTRodCrates().begin(); crate != getSTRodCrates().end(); crate++ ) { if((*crate)->vmeOK()){ (*crate)->readEPROM(); } else{ toLog("STControlEngine::readEPROM() : no VME interfaces found for crate "+(*crate)->getName()+ ", can't proceed"); } } processExecute(); return; } void STControlEngine::setMcc(int opt) { // Loop over crates for( std::vector::iterator crate = getSTRodCrates().begin(); crate != getSTRodCrates().end(); crate++ ) { if((*crate)->vmeOK()){ (*crate)->setMcc(opt); } else{ toLog("STControlEngine::setMcc(int) : no VME interfaces found for crate "+(*crate)->getName()+ ", can't proceed"); } } processExecute(); return; } void STControlEngine::updateGUI(){ if(m_app!=0) m_app->processEvents(); } /** Start a scan using the configuration in the function argument. */ int STControlEngine::pixScan(pixScanRunOptions scanOpts, bool start_monitor){ emit sendPixScanStatus(0,0,0,0,-1,0,0,0,10); m_app->processEvents(); m_checkScanCount = 0; for(int ic=0;ic<(int)m_sTRodCrates.size();ic++) m_sTRodCrates[ic]->m_readyForDcs=0; if(scanOpts.scanConfig==0) return -1; // can't work without config m_app->processEvents(); // make sure GUI really updates // set wait cursor QApplication::setOverrideCursor(Qt::waitCursor); // if in source scan mode and auto-indexing of raw file is requested, // check for existing file std::string orgRawName = scanOpts.scanConfig->getSourceRawFile().c_str();; if(scanOpts.indexRawFile && scanOpts.scanConfig->getSourceScanFlag()){ QString newRname = scanOpts.fileName.c_str(); // strip off extension QString rExt=""; int spos = newRname.lastIndexOf("."); if(spos){ rExt = newRname.right(newRname.length()-spos); newRname = newRname.left(spos); } // assemble all parts and save in scan config QString appName = scanOpts.anaLabel.c_str(); appName.replace(" ","_"); newRname += "_"+appName+".raw"; ((ConfString&)scanOpts.scanConfig->config()["general"]["sourceRawFile"]).m_value = std::string(newRname.latin1()); } // store scan options m_lastPixScanOpts = scanOpts; // copy config into all module groups for( std::vector::iterator crate = m_sTRodCrates.begin(); crate != m_sTRodCrates.end(); crate++ ) if((*crate)->setPixScan(*(scanOpts.scanConfig))) return -2; // then tell the ROD about it // ROD text buffer dump readRodBuff("Pre-scan-init info:"); // set ToolPanel inactive emit beganScanning(); // save starting time for logfiles later m_lastPixScanOpts.timestampStart = ("Scan commenced at "+ QDateTime::currentDateTime().toString("hh:mm:ss on MM-dd-yyyy")).latin1(); // TurboDAQ format: Scan commenced at 11:58:45 on 05-28-2004 // if scan modifies and does *not* restore module config, // set edited flag accordingly if(!(scanOpts.scanConfig->getRestoreModuleConfig())) editedCfg(); //m_log.buffers() << "Post-scan-init info:\n"; for( std::vector::iterator crate = m_sTRodCrates.begin(); crate != m_sTRodCrates.end(); crate++ ) (*crate)->scan(m_lastPixScanOpts); PixLib::sleep(10); // restore original raw name - important for iterative calls from prim. list ((ConfString&)scanOpts.scanConfig->config()["general"]["sourceRawFile"]).m_value = orgRawName; if(start_monitor){ connect( m_scanTimer2, SIGNAL(timeout()), this, SLOT(FinishScan()) ); m_scanTimer2->start( 500, FALSE ); } QApplication::restoreOverrideCursor(); m_app->processEvents(); return 0; } void STControlEngine::FinishScan() { //m_finishScanRunning = true; disconnect( m_scanTimer2, SIGNAL(timeout()), this, SLOT(FinishScan()) ); m_scanTimer2->stop(); m_app->processEvents(); // ensure all Rods have finished. if (RodProcessing()) // some scanning still in progress, wait till finished { // update GUI if(m_obsCrate>=0 && m_obsGrp>=0 && m_obsCrate<(int)m_sTRodCrates.size() && m_obsGrpnGroups()){ if (m_sTRodCrates[m_obsCrate]->getGrpScanStatus(m_obsGrp) == 1) // set Status: waiting for other Rods emit sendPixScanStatus(m_sTRodCrates[m_obsCrate]->getGrpNSteps(m_obsGrp,0),m_sTRodCrates[m_obsCrate]->getGrpNSteps(m_obsGrp,1), m_sTRodCrates[m_obsCrate]->getGrpNSteps(m_obsGrp,2),m_sTRodCrates[m_obsCrate]->getGrpNMasks(m_obsGrp), m_sTRodCrates[m_obsCrate]->getGrpCurrFe(m_obsGrp),m_sTRodCrates[m_obsCrate]->getGrpSRAMFillLevel(m_obsGrp), m_sTRodCrates[m_obsCrate]->getGrpTriggerRate(m_obsGrp),m_sTRodCrates[m_obsCrate]->getGrpHitRate(m_obsGrp),8); else // update ScanPanel according to Status of observed Rod emit sendPixScanStatus(m_sTRodCrates[m_obsCrate]->getGrpNSteps(m_obsGrp,0),m_sTRodCrates[m_obsCrate]->getGrpNSteps(m_obsGrp,1), m_sTRodCrates[m_obsCrate]->getGrpNSteps(m_obsGrp,2),m_sTRodCrates[m_obsCrate]->getGrpNMasks(m_obsGrp), m_sTRodCrates[m_obsCrate]->getGrpCurrFe(m_obsGrp),m_sTRodCrates[m_obsCrate]->getGrpSRAMFillLevel(m_obsGrp), m_sTRodCrates[m_obsCrate]->getGrpTriggerRate(m_obsGrp),m_sTRodCrates[m_obsCrate]->getGrpHitRate(m_obsGrp), m_sTRodCrates[m_obsCrate]->getGrpScanStatus(m_obsGrp)); } else emit sendPixScanStatus(0,0,0,0,-1,0,0,0,9); // read DCS if requested if(m_lastPixScanOpts.readDcs>0) for(std::vector::iterator crIT = getSTRodCrates().begin(); crIT != getSTRodCrates().end(); crIT++) (*crIT)->readUsbPixDcs(); // process scan to file writing from here for windows due to problems with ROOT file writing from threads #ifdef WIN32 for(std::vector::iterator i=m_sTRodCrates.begin(); i != m_sTRodCrates.end(); i++) (*i)->saveScanIfDone(m_lastPixScanOpts); #endif connect( m_scanTimer2, SIGNAL(timeout()), this, SLOT(FinishScan()) ); m_scanTimer2->start( 500, FALSE ); return; } else{ // all scanning done QApplication::setOverrideCursor(Qt::waitCursor); //send status "post-scan actions" emit sendPixScanStatus(0,0,0,2147483647,-1,0,0,0,4); m_app->processEvents(); // restore DCS settings if they were altered for(std::vector::iterator i=m_sTRodCrates.begin(); i != m_sTRodCrates.end(); i++) (*i)->restoreAfterScan(); QApplication::restoreOverrideCursor(); //load data from file to DataPanel if requested if(m_lastPixScanOpts.writeToFile==true && m_lastPixScanOpts.fileName!=""){// && m_lastPixScanOpts.loadToAna){ QApplication::setOverrideCursor(Qt::waitCursor); FILE *testDB = fopen(m_lastPixScanOpts.fileName.c_str(),"r"); if(testDB!=0){ fclose(testDB); // tell the data viewer to re-load display emit gotPixScanData(m_lastPixScanOpts.fileName.c_str()); m_app->processEvents(); } else{ m_log.errLog() << ("STControlEngine::FinishScan() : ERROR loading file " + m_lastPixScanOpts.fileName + " to Data Panel \n").c_str(); } QApplication::restoreOverrideCursor(); } //send status "finished" emit sendPixScanStatus(0,0,0,2147483647,-1,0,0,0,1); m_app->processEvents(); // #ifndef WIN32 // system("export currmem=`ps lx | grep STcontrol | awk '{print $7}'`; echo curr. memory consumed $currmem"); // #endif readRodBuff("Post-scan info:"); // m_finishScanRunning = false; m_app->processEvents(); // set ToolPanel active again emit finishedScanning(); m_app->processEvents(); return; } } void STControlEngine::saveOptions(){ QString openOpt, file = QDir::homeDirPath() + "/.stcrc"; FILE *f = fopen(file.latin1(),"r"); if(f!=0){ openOpt = "UPDATE"; fclose(f); }else openOpt = "NEW"; PixLib::RootDB *optf = new RootDB(file.latin1(),openOpt.latin1()); m_options->write(optf->readRootRecord(1)); delete optf; } void STControlEngine::loadOptions(){ QString file = QDir::homeDirPath() + "/.stcrc"; FILE *f = fopen(file.latin1(),"r"); if(f!=0) fclose(f); else return; PixLib::RootDB *optf = new RootDB(file.latin1()); m_options->read(optf->readRootRecord(1)); delete optf; } void STControlEngine::changedConfigs() { emit crateListChanged(); m_app->processEvents(); // make sure GUI really updates } int STControlEngine::CtrlStatusSummary() { bool existflag = false; int nRods = 0; for( std::vector::iterator crate = m_sTRodCrates.begin(); crate != m_sTRodCrates.end(); crate++ ) { if((*crate)->CtrlStatusSummary()!=-1) { nRods+=(*crate)->CtrlStatusSummary(); // number of initialised Rods existflag = true; // at least one Rod existing } } if (!existflag) return -1; else return nRods; } bool STControlEngine::RodProcessing() { for( std::vector::iterator crate = getSTRodCrates().begin(); crate != getSTRodCrates().end(); crate++ ) { if( (*crate)->RodProcessing()==true) return true; } return false; } void STControlEngine::init(const char *cfg_file, bool initRODs, const char *ps_file) { m_app->processEvents(); // make sure GUI really updates std::string cfname="", pfname=""; if(cfg_file!=0) cfname = cfg_file; if(ps_file!=0) pfname = ps_file; Config &my_cfg = getOptions(); if(cfg_file==0 && ((ConfString&)my_cfg["paths"]["defCfgPath"]).value()!="." && ((ConfString&)my_cfg["autoload"]["defCfgName"]).value()!="") cfname = ((ConfString&)my_cfg["paths"]["defCfgPath"]).value() + "/" + ((ConfString&)my_cfg["autoload"]["defCfgName"]).value(); if(ps_file==0 && ((ConfString&)my_cfg["paths"]["defCfgPath"]).value()!="." && ((ConfString&)my_cfg["autoload"]["defPixScanName"]).value()!="") pfname = ((ConfString&)my_cfg["paths"]["defCfgPath"]).value() + "/" + ((ConfString&)my_cfg["autoload"]["defPixScanName"]).value(); if(cfname!=""){ QApplication::setOverrideCursor(Qt::waitCursor); loadDB(cfname.c_str()); QApplication::restoreOverrideCursor(); m_app->processEvents(); // make sure GUI really updates if(initRODs || m_initRods){ QApplication::setOverrideCursor(Qt::waitCursor); initRods(); QApplication::restoreOverrideCursor(); } if(m_initDcs){ QApplication::setOverrideCursor(Qt::waitCursor); initDcs(); if(m_dcsOn){ std::vector myCrates = getSTRodCrates(); for(std::vector::iterator crIT = myCrates.begin(); crIT != myCrates.end(); crIT++){ std::vector pd = (*crIT)->getPixDcs(); for(std::vector ::iterator pdIT = pd.begin(); pdIT!=pd.end(); pdIT++) (*pdIT)->SetState("ON"); } emit statusChanged(); } QApplication::restoreOverrideCursor(); } m_app->processEvents(); // make sure GUI really updates } if(pfname!=""){ QApplication::setOverrideCursor(Qt::waitCursor); loadScanCfg(pfname.c_str()); QApplication::restoreOverrideCursor(); m_app->processEvents(); // make sure GUI really updates } return; } int STControlEngine::setTFDACs(const char *fname, bool isTDAC) { int not_found=0; // loop over crates std::vector myCrates = getSTRodCrates(); for(std::vector::iterator crIT = myCrates.begin(); crIT != myCrates.end(); crIT++) not_found += (*crIT)->setTFDACs(fname, isTDAC); if(not_found>0) editedCfg(); return not_found; } int STControlEngine::setMasks(std::vector files, std::vector histos, int mask){ //setMasks(const char *fname, const char *hname, int mask){ int not_found=0; // loop over crates std::vector myCrates = getSTRodCrates(); for(std::vector::iterator crIT = myCrates.begin(); crIT != myCrates.end(); crIT++) not_found += (*crIT)->setMasks(files, histos, mask); if(not_found>0) editedCfg(); return not_found; } void STControlEngine::setVcal(float charge, bool Chigh) { // loop over crates std::vector myCrates = getSTRodCrates(); for(std::vector::iterator crIT = myCrates.begin(); crIT != myCrates.end(); crIT++) (*crIT)->setVcal(charge, Chigh); editedCfg(); return; } void STControlEngine::incrMccDelay(float delay, bool calib) { // loop over crates std::vector myCrates = getSTRodCrates(); for(std::vector::iterator crIT = myCrates.begin(); crIT != myCrates.end(); crIT++) (*crIT)->incrMccDelay(delay, calib); editedCfg(); return; } void STControlEngine::disableFailed() { // loop over crates std::vector myCrates = getSTRodCrates(); for(std::vector::iterator crIT = myCrates.begin(); crIT != myCrates.end(); crIT++) (*crIT)->disableFailed(); emit statusChanged(); m_app->processEvents(); return; } void STControlEngine::launchPrimList(std::vector list, const char *outname, int labelIndex, bool modTest) { if(outname==0){ toErrLog("STControlEngine::launchPrimList : no output file name specified"); return; } m_prlOutname = outname; m_prlModTestType = ""; // temporary solution, needs fix for cfg. with >1 module std::string mname = "123456"; if(modTest){ m_prlModTestType = outname; if(getSTRodCrates().size()>0 && getSTRodCrates()[0]->nGroups()>0) mname = getSTRodCrates()[0]->getModName(0,0); getDecNameCore(mname); // make sure all needed dir's exist QDir mainDir(m_modPath.c_str()); mainDir.mkpath(("M"+mname+"/data").c_str()); mainDir.mkpath(("M"+mname+"/configs").c_str()); mainDir.cd(("M"+mname+"/data").c_str()); // determine lowest unused index and save into file name and test type int itest; char sitest[3]; for(itest=99;itest>0;itest--){ sprintf(sitest,"%02d", itest); m_prlOutname = mname + "_" + m_prlModTestType + std::string(sitest) + ".root"; if(mainDir.exists(m_prlOutname.c_str())){ int myind = itest+1; // previous index is the last unused sprintf(sitest,"%02d", myind); m_prlModTestType += std::string(sitest); m_prlOutname = m_modPath + "/M" + mname + "/data/" + mname + "_" + m_prlModTestType + ".root"; break; } } if(itest==0){ int myind = itest+1; // previous index is the last unused sprintf(sitest,"%02d", myind); m_prlModTestType += std::string(sitest); m_prlOutname = m_modPath + "/M" + mname + "/data/" + mname + "_" + m_prlModTestType + ".root"; } } m_prlList.clear(); m_prlList = list; m_prlIndex = -1; m_prlLabelIndex = labelIndex; // set ToolPanel inactive emit beganScanning(); // set BOC and PixScan panel inactive emit prlScanStarted(0); // check if file exists, and append new data if so // only do first time if we're in a repeating loop if(m_prlLabelIndex<2 && m_prlOutname!=""){ FILE *testDB = fopen(m_prlOutname.c_str(),"r"); if(testDB!=0){ fclose(testDB); } else{ // need new file try{ RootDB *myData = new RootDB(m_prlOutname.c_str(),"NEW"); delete myData; }catch(...){ toErrLog("STControlEngine::launchPrimList : ERROR creating file " + m_prlOutname + "\n"); // re-set scan panel emit sendPixScanStatus(0,0,0,0,-1,0,0,0,1); // re-activate tool panel emit finishedScanning(); m_app->processEvents(); emit prlDone(); return; } } if(modTest){ // save test type and index in case of module test mode RootDB *myDB = new RootDB(m_prlOutname.c_str(),"UPDATE"); PixLib::DBInquire *root = 0; root = myDB->readRootRecord(1); fieldIterator f; f = root->findField("ModuleTestType"); DBField *fi=0; if (f==root->fieldEnd()) { fi = myDB->makeField("ModuleTestType"); f.pointsTo(fi); f = root->pushField(*f); } myDB->DBProcess(f,COMMIT,m_prlModTestType); delete fi; myDB->DBProcess(root,COMMITREPLACE); delete myDB; } } m_prlSkipToEnd = false; m_stopProcessing = false; connect( m_scanTimer, SIGNAL(timeout()), this, SLOT(processPrimList()) ); m_scanTimer->start( 500, true ); return; } void STControlEngine::processPrimList() { // only needed for start-up, stop for the rest of this list disconnect( m_scanTimer, SIGNAL(timeout()), this, SLOT(processPrimList()) ); //m_scanTimer->stop(); // remove connection of this functuion to scanning end (will be restored if nec.) disconnect(this, SIGNAL(finishedScanning()), this, SLOT(processPrimList())); // go to next item m_prlIndex++; // at end of list? -> finish if(m_prlIndex>=(int)m_prlList.size() || m_stopProcessing){ // re-set scan panel emit sendPixScanStatus(0,0,0,0,-1,0,0,0,1); // re-activate tool panel emit finishedScanning(); m_app->processEvents(); emit prlDone(); return; } if(m_prlList[m_prlIndex]==0){ toLog("STControlEngine::processPrimList : PrimListItem-pointer is NULL, can't process."); processPrimList(); // needed to keep going return; } // keep BOC and PixScan panels inactive - might have been set to idle by FinishScan routine m_app->processEvents(); // make sure GUI really updates emit prlScanStarted(0); m_app->processEvents(); // make sure GUI really updates emit sendPixScanStatus(0,0,0,0,-1,0,0,0,11); m_app->processEvents(); // make sure GUI really updates // send current index to prim. list panel emit prlInProgress(m_prlIndex); m_app->processEvents(); // make sure GUI really updates // load data or update in data viewer emit scanFileChanged(m_prlOutname.c_str()); m_app->processEvents(); // make sure GUI really updates // skip flag raised? then process item only if explicitly set so if(m_prlSkipToEnd && !m_prlList[m_prlIndex]->getSkipFlag()){ processPrimList(); // needed to keep going return; } bool error = false; std::stringstream a; a << m_prlLabelIndex; switch(m_prlList[m_prlIndex]->getType()){ case PrimListItem::DEF_SCAN: error = launchPrlScans((m_prlList[m_prlIndex]->getScanLabel()+((m_prlLabelIndex>0)?(" "+a.str()):"")).c_str(),m_prlOutname.c_str(), 0, m_prlList[m_prlIndex]->getSubType(), m_prlList[m_prlIndex]->getReadDcs()); break; case PrimListItem::CUST_SCAN: error = launchPrlScans((m_prlList[m_prlIndex]->getScanLabel()+((m_prlLabelIndex>0)?(" "+a.str()):"")).c_str(),m_prlOutname.c_str(), m_prlList[m_prlIndex]->getPS(),0, m_prlList[m_prlIndex]->getReadDcs()); break; case PrimListItem::TOOL:{ error = launchPrlTools(); break;} case PrimListItem::CHIP_TEST:{ clearModuleInfo(); runChipTest(m_prlList[m_prlIndex]->getCT(), -1,-1,-1); // save result to file PixConfDBInterface *myData=0; DBInquire *root=0, *testInq=0, *grpInq=0, *modInq=0; if(m_prlOutname!=""){ // open data file myData = new RootDB(m_prlOutname.c_str(),"UPDATE"); root = myData->readRootRecord(1); // check if this scan already has an inquire, and create one if not testInq = *(root->findRecord(m_prlList[m_prlIndex]->getLabel()+ ((m_prlLabelIndex>0)?(" "+a.str()):"") + "/ChipTestResult")); if(testInq==0){ std::string name, decName, myDecName; name="ChipTestResult"; decName = root->getDecName() + m_prlList[m_prlIndex]->getLabel()+ ((m_prlLabelIndex>0)?(" "+a.str()):""); testInq = myData->makeInquire(name, decName); root->pushRecord(testInq); // process myData->DBProcess(root,COMMITREPLACE); myData->DBProcess(testInq,COMMIT); delete myData; myData = new RootDB(m_prlOutname.c_str(),"UPDATE"); root = myData->readRootRecord(1); testInq = *(root->findRecord(m_prlList[m_prlIndex]->getLabel() + ((m_prlLabelIndex>0)?(" "+a.str()):"") + "/ChipTestResult")); } // loop over crates std::vector myCrates = getSTRodCrates(); for(std::vector::iterator crIT = myCrates.begin(); crIT != myCrates.end(); crIT++){ // loop over groups for(int iGrp=0;iGrp<(*crIT)->nGroups();iGrp++){ // create inquire for this group std::string name, decName, myDecName; name="PixModuleGroup"; decName = testInq->getDecName() + (*crIT)->getGrpName(iGrp); grpInq = myData->makeInquire(name, decName); testInq->pushRecord(grpInq); // process myData->DBProcess(testInq,COMMITREPLACE); myData->DBProcess(grpInq,COMMIT); delete myData; myData = new RootDB(m_prlOutname.c_str(),"UPDATE"); root = myData->readRootRecord(1); testInq = *(root->findRecord(m_prlList[m_prlIndex]->getLabel() + ((m_prlLabelIndex>0)?(" "+a.str()):"") + "/ChipTestResult")); grpInq = *(testInq->findRecord((*crIT)->getGrpName(iGrp)+"/PixModuleGroup")); // loop over modules std::vector< std::pair > modList; (*crIT)->getModules(iGrp, modList); for(std::vector< std::pair >::iterator modIT=modList.begin(); modIT!=modList.end();modIT++){ // create inquire for this module std::stringstream b; b << modIT->second; name="Mod"+b.str(); decName = testInq->getDecName() + name; modInq = myData->makeInquire(name, decName); grpInq->pushRecord(modInq); // process myData->DBProcess(grpInq,COMMITREPLACE); myData->DBProcess(modInq,COMMIT); delete myData; myData = new RootDB(m_prlOutname.c_str(),"UPDATE"); root = myData->readRootRecord(1); testInq = *(root->findRecord(m_prlList[m_prlIndex]->getLabel() + ((m_prlLabelIndex>0)?(" "+a.str()):"") + "/ChipTestResult")); grpInq = *(testInq->findRecord((*crIT)->getGrpName(iGrp)+"/PixModuleGroup")); modInq = *(grpInq->findRecord(name+"/"+name)); // get chip test info modStatus ms = (*crIT)->getPixModuleStatus(iGrp, modIT->second); // dump info and pass/fail flag to DB file RootDBField *infoField = new RootDBField("Result",myData); myData->DBProcess(infoField,COMMIT,ms.feMsg[0]); modInq->pushField(infoField); delete infoField; myData->DBProcess(modInq,COMMITREPLACE); bool modPass = (ms.feStat[0]==tOK); if(!modPass && ((ConfBool&)m_prlList[m_prlIndex]->config()["specific"]["raiseSkipIfFailed"]).value()) m_prlSkipToEnd = true; RootDBField *passField = new RootDBField("PassFlag",myData); myData->DBProcess(passField,COMMIT,modPass); modInq->pushField(passField); delete passField; myData->DBProcess(modInq,COMMITREPLACE); delete myData; myData = new RootDB(m_prlOutname.c_str(),"UPDATE"); root = myData->readRootRecord(1); testInq = *(root->findRecord(m_prlList[m_prlIndex]->getLabel() + ((m_prlLabelIndex>0)?(" "+a.str()):"") + "/ChipTestResult")); grpInq = *(testInq->findRecord((*crIT)->getGrpName(iGrp)+"/PixModuleGroup")); } } } delete myData; } // done, process next prl item processPrimList(); break;} default: toLog("STControlEngine::processPrimList : unknown/unhandled type for item "+m_prlList[m_prlIndex]->getLabel()+"."); processPrimList(); // needed to keep going return; } // handle errors if(error && m_prlList[m_prlIndex]->getAbort()){ toErrLog("STControlEngine::processPrimList : error while starting item \""+ m_prlList[m_prlIndex]->getLabel() + "\" - aborting prim. list execution."); // re-set scan panel emit sendPixScanStatus(0,0,0,0,-1,0,0,0,1); // re-activate tool panel emit finishedScanning(); m_app->processEvents(); emit prlDone(); return; } else if(error){ toLog("STControlEngine::processPrimList : error while starting item \""+m_prlList[m_prlIndex]->getLabel()+"\"."); processPrimList(); // needed to keep going } return; } bool STControlEngine::launchPrlScans(const char *label, const char *fname, PixScan *cfg, int type, int readDcs) { std::string scan_label = label; if(fname==0 || (fname!=0 && std::string(fname)=="")){ toLog("STControlEngine::processPrlScans : no output file name specified, won't start scan "+scan_label); return true; } PixScan *myCfg = cfg; if(cfg==0) myCfg = new PixScan((PixLib::PixScan::ScanType)type); if(CtrlStatusSummary()==0){ toLog("STControlEngine::processPrlScans : can't find any initialised RODs, won't start scan "+scan_label); if(cfg==0) delete myCfg; return true; } // set PixScanPanel view correctly int sctype = 2*(int)myCfg->getSourceScanFlag(); if(sctype==2) sctype += (int)myCfg->getLoopActive(0); // type = 4 foreseen for TB in scanRunning - where do we get that info from? - why was this never implemented? if(sctype==0 && !myCfg->getDspMaskStaging()) sctype = 1; emit prlScanStarted(sctype); // simple stuff to start with - needs to take care of a few more options pixScanRunOptions myscopt; myscopt.scanConfig = myCfg; myscopt.loadToAna = false; myscopt.anaLabel = scan_label; myscopt.writeToFile = (fname!=0); if(myscopt.writeToFile) myscopt.fileName = fname; else myscopt.fileName = ""; myscopt.determineSDSPcfg = true; myscopt.stdTestID = -1; if(cfg==0) myscopt.stdTestID = type; myscopt.runFEbyFE = false; myscopt.indexRawFile = myCfg->getSourceScanFlag() && (myCfg->getSrcTriggerType()!=PixScan::STROBE_SCAN || myCfg->getSourceRawFile()=="generate"); myscopt.readDcs = readDcs; // start scan - in monitoring pixScan(myscopt); if(cfg==0) delete myCfg; // after scan: go to next prl item connect(this, SIGNAL(finishedScanning()), this, SLOT(processPrimList())); return false; } bool STControlEngine::launchPrlTools() { PrimListItem::PrimListTools type = (PrimListItem::PrimListTools) m_prlList[m_prlIndex]->getSubType(); std::string fileName = m_prlOutname; Config &argCfg = m_prlList[m_prlIndex]->config(); switch(type){ case PrimListItem::INIT_ROD: initRods(); break; case PrimListItem::INIT_DCS: initDcs(); break; case PrimListItem::RESET_MODS:{ int type = ((ConfInt&)argCfg["arguments"]["resetType"]).getValue(); resetModules(type); break;} case PrimListItem::CFG_MODS:{ int cfgType = ((ConfInt&)argCfg["arguments"]["cfgtype"]).getValue(); int DCs = ((ConfInt&)argCfg["arguments"]["DCtoWrite"]).getValue(); int patType = ((ConfInt&)argCfg["arguments"]["patternType"]).getValue(); std::string latch = ((ConfList&)argCfg["arguments"]["latch"]).sValue(); configModules(cfgType, patType, DCs, latch); break;} case PrimListItem::SET_VCAL: if(argCfg.name()!="__TrashConfig__" && argCfg["arguments"].name()!="__TrashConfGroup__" && argCfg["arguments"]["charge"].name()!="__TrashConfObj__" && argCfg["arguments"]["useChigh"].name()!="__TrashConfObj__") setVcal(((ConfFloat&)argCfg["arguments"]["charge"]).value(), ((ConfBool&)argCfg["arguments"]["useChigh"]).value()); else return true; // arguments not available somehow, return an error break; case PrimListItem::LINK_CHECK: runLinkCheck(); break; case PrimListItem::DISABLE_FAILED: disableFailed(); break; case PrimListItem::RELOAD_CFG: clear(); loadDB(m_PixConfDBFname.c_str()); break; case PrimListItem::LOAD_NEW_CFG: if(argCfg.name()!="__TrashConfig__" && argCfg["arguments"].name()!="__TrashConfGroup__" && argCfg["arguments"]["fileName"].name()!="__TrashConfObj__"){ std::string cfgName = ((ConfString&)argCfg["arguments"]["fileName"]).value(); clear(); loadDB(cfgName.c_str()); } else return true; // arguments not available somehow, return an error break; case PrimListItem::GET_SRVREC:{ getSrvRec(); std::stringstream a; a << m_prlLabelIndex; std::vector srvRec; std::vector myCrates = getSTRodCrates(); // save result to file PixConfDBInterface *myData=0; DBInquire *root=0, *testInq=0, *grpInq=0, *modInq=0; if(m_prlOutname!=""){ myData = new RootDB(m_prlOutname.c_str(),"UPDATE"); root = myData->readRootRecord(1); // check if this scan already has an inquire, and create one if not testInq = *(root->findRecord(m_prlList[m_prlIndex]->getLabel()+ ((m_prlLabelIndex>0)?(" "+a.str()):"") + ((m_prlLabelIndex>0)?(" "+a.str()):"") + "/ServiceRecord")); if(testInq==0){ std::string name, decName, myDecName; name="ServiceRecord"; decName = root->getDecName() + m_prlList[m_prlIndex]->getLabel() + ((m_prlLabelIndex>0)?(" "+a.str()):""); testInq = myData->makeInquire(name, decName); root->pushRecord(testInq); // process myData->DBProcess(root,COMMITREPLACE); myData->DBProcess(testInq,COMMIT); delete myData; myData = new RootDB(m_prlOutname.c_str(),"UPDATE"); root = myData->readRootRecord(1); testInq = *(root->findRecord(m_prlList[m_prlIndex]->getLabel() + ((m_prlLabelIndex>0)?(" "+a.str()):"") + "/ServiceRecord")); } // loop over crates std::vector myCrates = getSTRodCrates(); for(std::vector::iterator crIT = myCrates.begin(); crIT != myCrates.end(); crIT++){ // loop over groups for(int iGrp=0;iGrp<(*crIT)->nGroups();iGrp++){ (*crIT)->getSrvRecRes(iGrp, srvRec); // cout << "Srv.Rec. for group " << iGrp << endl; // for(unsigned int k=0;kgetDecName() + (*crIT)->getGrpName(iGrp); grpInq = myData->makeInquire(name, decName); testInq->pushRecord(grpInq); // process myData->DBProcess(testInq,COMMITREPLACE); myData->DBProcess(grpInq,COMMIT); delete myData; myData = new RootDB(m_prlOutname.c_str(),"UPDATE"); root = myData->readRootRecord(1); testInq = *(root->findRecord(m_prlList[m_prlIndex]->getLabel() + ((m_prlLabelIndex>0)?(" "+a.str()):"") + "/ServiceRecord")); grpInq = *(testInq->findRecord((*crIT)->getGrpName(iGrp)+"/PixModuleGroup")); // temporary: have only one module per group (needs to be fixed?) // loop over modules // std::vector< std::pair > modList; // (*crIT)->getModules(iGrp, modList); // for(std::vector< std::pair >::iterator modIT=modList.begin(); modIT!=modList.end();modIT++){ // create inquire for this module std::stringstream b; b << 0;//modIT->second; name="Mod"+b.str(); decName = testInq->getDecName() + name; modInq = myData->makeInquire(name, decName); grpInq->pushRecord(modInq); // process myData->DBProcess(grpInq,COMMITREPLACE); myData->DBProcess(modInq,COMMIT); delete myData; myData = new RootDB(m_prlOutname.c_str(),"UPDATE"); root = myData->readRootRecord(1); testInq = *(root->findRecord(m_prlList[m_prlIndex]->getLabel() + ((m_prlLabelIndex>0)?(" "+a.str()):"") + "/ServiceRecord")); grpInq = *(testInq->findRecord((*crIT)->getGrpName(iGrp)+"/PixModuleGroup")); modInq = *(grpInq->findRecord(name+"/"+name)); // dump service record vector DB file RootDBField *infoField = new RootDBField("Result",myData); myData->DBProcess(infoField,COMMIT,srvRec); modInq->pushField(infoField); delete infoField; myData->DBProcess(modInq,COMMITREPLACE); delete myData; myData = new RootDB(m_prlOutname.c_str(),"UPDATE"); root = myData->readRootRecord(1); testInq = *(root->findRecord(m_prlList[m_prlIndex]->getLabel() + ((m_prlLabelIndex>0)?(" "+a.str()):"") + "/ServiceRecord")); // grpInq = *(testInq->findRecord((*crIT)->getGrpName(iGrp)+"/PixModuleGroup")); // } } } delete myData; } break;} case PrimListItem::SET_FE_GR:{ if(argCfg.name()!="__TrashConfig__" && argCfg["arguments"].name()!="__TrashConfGroup__" && argCfg["arguments"]["RegName"].name()!="__TrashConfObj__" && argCfg["arguments"]["RegVal"].name()!="__TrashConfObj__"){ // loop over crates std::vector myCrates = getSTRodCrates(); for(std::vector::iterator crIT = myCrates.begin(); crIT != myCrates.end(); crIT++){ (*crIT)->setGR(((ConfList&)argCfg["arguments"]["RegName"]).sValue(),((ConfInt&)argCfg["arguments"]["RegVal"]).getValue()); for(int iG=0;iG<(*crIT)->nGroups();iG++){ std::vector< std::pair > mlist; (*crIT)->getModules(iG, mlist); for(std::vector< std::pair >::iterator mIT=mlist.begin(); mIT!=mlist.end();mIT++) (*crIT)->writeConfig(iG, mIT->second); } } editedCfg(); } else return true; // arguments not available somehow, return an error break;} case PrimListItem::SET_FE_PR:{ if(argCfg.name()!="__TrashConfig__" && argCfg["arguments"].name()!="__TrashConfGroup__" && argCfg["arguments"]["RegName"].name()!="__TrashConfObj__" && argCfg["arguments"]["RegVal"].name()!="__TrashConfObj__"){ // loop over crates std::vector myCrates = getSTRodCrates(); for(std::vector::iterator crIT = myCrates.begin(); crIT != myCrates.end(); crIT++) (*crIT)->setPR(((ConfList&)argCfg["arguments"]["RegName"]).sValue(),((ConfInt&)argCfg["arguments"]["RegVal"]).getValue()); editedCfg(); } else return true; // arguments not available somehow, return an error break;} case PrimListItem::SEND_DCS_CMD:{ if(argCfg.name()!="__TrashConfig__" && argCfg["arguments"].name()!="__TrashConfGroup__" && argCfg["arguments"]["dcsName"].name()!="__TrashConfObj__" && argCfg["arguments"]["dcsCmd"].name()!="__TrashConfObj__" && argCfg["arguments"]["readResponse"].name()!="__TrashConfObj__"){ std::string dcsName = ((ConfString&)argCfg["arguments"]["dcsName"]).value(); std::string dcsCmd = ((ConfString&)argCfg["arguments"]["dcsCmd"]).value(); bool readResp = ((ConfBool&)argCfg["arguments"]["readResponse"]).value(); bool devFound=false; // loop over crates std::vector myCrates = getSTRodCrates(); for(std::vector::iterator crIT = myCrates.begin(); crIT != myCrates.end(); crIT++){ std::vector pd = (*crIT)->getPixDcs(); for(std::vector ::iterator pdIT = pd.begin(); pdIT!=pd.end(); pdIT++) if((*pdIT)->name()==dcsName){ devFound = true; if((*pdIT)->sendCommand(dcsCmd, readResp)){ toLog(("STControlEngine::launchPrlTools : DCS device "+dcsName+ " returned error on cmd; return string: " + dcsCmd ).c_str()); return true; } break; } } if(!devFound){ toLog(("STControlEngine::launchPrlTools : DCS device which should have been turned on/off wasn't found: "+dcsName ).c_str()); return true; } }else return true; // arguments not available somehow, return an error break; } case PrimListItem::DCS_PWR: if(argCfg.name()!="__TrashConfig__" && argCfg["arguments"].name()!="__TrashConfGroup__" && argCfg["arguments"]["dcsName"].name()!="__TrashConfObj__" && argCfg["arguments"]["on_or_off"].name()!="__TrashConfObj__"){ std::string dcsName = ((ConfString&)argCfg["arguments"]["dcsName"]).value(); bool on_or_off = ((ConfBool&)argCfg["arguments"]["on_or_off"]).value(); bool devFound=false; // loop over crates std::vector myCrates = getSTRodCrates(); for(std::vector::iterator crIT = myCrates.begin(); crIT != myCrates.end(); crIT++){ std::vector pd = (*crIT)->getPixDcs(); for(std::vector ::iterator pdIT = pd.begin(); pdIT!=pd.end(); pdIT++) if((*pdIT)->name()==dcsName){ devFound = true; (*pdIT)->SetState(on_or_off?"ON":"OFF"); break; } } if(!devFound){ toLog(("STControlEngine::launchPrlTools : DCS device which should have been turned on/off wasn't found: "+dcsName ).c_str()); return true; } emit statusChanged(); } else return true; // arguments not available somehow, return an error break; case PrimListItem::DCS_SET: if(argCfg.name()!="__TrashConfig__" && argCfg["arguments"].name()!="__TrashConfGroup__" && argCfg["arguments"]["dcsName"].name()!="__TrashConfObj__" && argCfg["arguments"]["dcsSetType"].name()!="__TrashConfObj__" && argCfg["arguments"]["setVal"].name()!="__TrashConfObj__"){ std::string dcsName = ((ConfString&)argCfg["arguments"]["dcsName"]).value(); std::string setType = ((ConfList&)argCfg["arguments"]["dcsSetType"]).sValue(); float setVal = ((ConfFloat&)argCfg["arguments"]["setVal"]).value(); // loop over crates bool chanFound = false; std::vector myCrates = getSTRodCrates(); for(std::vector::iterator crIT = myCrates.begin(); crIT != myCrates.end(); crIT++){ std::vector pd = (*crIT)->getPixDcs(); for(std::vector ::iterator pdIT = pd.begin(); pdIT!=pd.end(); pdIT++){ for(std::vector::iterator dcsc = (*pdIT)->chanBegin(); dcsc!=(*pdIT)->chanEnd(); dcsc++){ if((*dcsc)->name()==dcsName){ chanFound = true; Config &cfg = (*dcsc)->config(); std::string cfgStype = "unknown"; if(setType=="voltage") cfgStype = "NomVolts"; else if(setType=="currentlim") cfgStype = "CurrLim"; if(cfg["settings"].name()!="__TrashConfGroup__" && cfg["settings"][cfgStype].name()!="__TrashConfObj__"){ ((ConfFloat&)cfg["settings"][cfgStype]).m_value = setVal; (*dcsc)->SetParam(setType, setVal); if((*pdIT)->ReadState("")=="ON") (*pdIT)->SetState("ON"); // if device is already on, update settings on supply } else{ toLog(("STControlEngine::launchPrlTools : can't find ConfObj for setting type "+setType+" in DCS channel "+dcsName ).c_str()); return true; } } } } } if(!chanFound){ toLog(("STControlEngine::launchPrlTools : DCS channel from which should have been read wasn't found: "+dcsName ).c_str()); return true; } emit statusChanged(); } else return true; // arguments not available somehow, return an error break; case PrimListItem::DCS_GET: if(argCfg.name()!="__TrashConfig__" && argCfg["arguments"].name()!="__TrashConfGroup__" && argCfg["arguments"]["dcsName"].name()!="__TrashConfObj__" && argCfg["arguments"]["dcsGetType"].name()!="__TrashConfObj__" && argCfg["arguments"]["storeName"].name()!="__TrashConfObj__" && argCfg["arguments"]["minCut"].name()!="__TrashConfObj__" && argCfg["arguments"]["maxCut"].name()!="__TrashConfObj__"){ std::stringstream a; a << m_prlLabelIndex; std::string dcsName = ((ConfString&)argCfg["arguments"]["dcsName"]).value(); std::string getType = ((ConfList&)argCfg["arguments"]["dcsGetType"]).sValue(); std::string storeName = ((ConfString&)argCfg["arguments"]["storeName"]).value()+ ((m_prlLabelIndex>0)?(" "+a.str()):""); float minCut = ((ConfFloat&)argCfg["arguments"]["minCut"]).value(); float maxCut = ((ConfFloat&)argCfg["arguments"]["maxCut"]).value(); PixConfDBInterface *myDB = 0; PixLib::DBInquire *dcsRec= 0; if(storeName!="" && fileName!=""){ try{ myDB = new RootDB(fileName.c_str(),"UPDATE"); }catch(SctPixelRod::BaseException& exc){ std::stringstream msg; msg << "STControlEngine::launchPrlTools : exception while opening DB file " << fileName << ": " << exc; toLog(msg.str().c_str()); return true; }catch(...){ toLog(("STControlEngine::launchPrlTools : unknown exception while opening DB file "+fileName ).c_str()); return true; } std::string rname = "DCS_readings/DCS_readings"; PixLib::DBInquire *root = myDB->readRootRecord(1); if(root->findRecord(rname)==root->recordEnd()){ try{ dcsRec = myDB->makeInquire("DCS_readings", "DCS_readings"); root->pushRecord(dcsRec); myDB->DBProcess(root,COMMITREPLACE); myDB->DBProcess(dcsRec,COMMIT); delete myDB; myDB = new RootDB(fileName.c_str(),"UPDATE"); root = myDB->readRootRecord(1); dcsRec = *(root->findRecord(rname)); }catch(...){ toLog("STControlEngine::launchPrlTools : exception while creating a record for DCS reading in DB file"); delete myDB; return true; } } else dcsRec = *(root->findRecord(rname)); } // loop over crates bool chanFound = false; std::vector myCrates = getSTRodCrates(); for(std::vector::iterator crIT = myCrates.begin(); crIT != myCrates.end(); crIT++){ std::vector pd = (*crIT)->getPixDcs(); for(std::vector ::iterator pdIT = pd.begin(); pdIT!=pd.end(); pdIT++){ for(std::vector::iterator dcsc = (*pdIT)->chanBegin(); dcsc!=(*pdIT)->chanEnd(); dcsc++){ if((*dcsc)->name()==dcsName){ chanFound = true; float readVal = (*dcsc)->ReadParam(getType); // apply cut to value and write into m_prlSkipToEnd if(readVal < minCut || readVal > maxCut) m_prlSkipToEnd = true; if(dcsRec!=0){ if(dcsRec->findField(storeName)==dcsRec->fieldEnd()){ try{ DBField * newField = myDB->makeField(storeName); myDB->DBProcess(newField,COMMIT,readVal); dcsRec->pushField(newField); delete newField; myDB->DBProcess(dcsRec,COMMITREPLACE); }catch(...){ toLog("STControlEngine::launchPrlTools : exception while creating a field for DCS reading in DB file"); delete myDB; return true; } } else{ toLog(("STControlEngine::launchPrlTools : field to which should be written already exists: "+storeName ).c_str()); delete myDB; return true; } } break; } } } } if(!chanFound){ toLog(("STControlEngine::launchPrlTools : DCS channel from which should have been read wasn't found: "+dcsName ).c_str()); delete myDB; return true; } delete myDB; } else return true; // arguments not available somehow, return an error break; case PrimListItem::GET_TIME:{ std::stringstream a; a << m_prlLabelIndex; std::string storeName = m_prlList[m_prlIndex]->getLabel() + ((m_prlLabelIndex>0)?(" "+a.str()):""); PixConfDBInterface *myDB = 0; PixLib::DBInquire *dcsRec= 0; if(storeName!="" && fileName!=""){ try{ myDB = new RootDB(fileName.c_str(),"UPDATE"); }catch(SctPixelRod::BaseException& exc){ std::stringstream msg; msg << "STControlEngine::launchPrlTools : exception while opening DB file " << fileName << ": " << exc; toLog(msg.str().c_str()); return true; }catch(...){ toLog(("STControlEngine::launchPrlTools : unknown exception while opening DB file "+fileName ).c_str()); return true; } std::string rname = "Timestamps/DCS_readings"; PixLib::DBInquire *root = myDB->readRootRecord(1); if(root->findRecord(rname)==root->recordEnd()){ try{ dcsRec = myDB->makeInquire("DCS_readings", "Timestamps"); root->pushRecord(dcsRec); myDB->DBProcess(root,COMMITREPLACE); myDB->DBProcess(dcsRec,COMMIT); delete myDB; myDB = new RootDB(fileName.c_str(),"UPDATE"); root = myDB->readRootRecord(1); dcsRec = *(root->findRecord(rname)); }catch(...){ toLog("STControlEngine::launchPrlTools : exception while creating a record for DCS reading in DB file"); delete myDB; return true; } } else dcsRec = *(root->findRecord(rname)); if(dcsRec->findField(storeName)==dcsRec->fieldEnd()){ try{ std::string ts = (QDateTime::currentDateTime().toString("hh:mm:ss on MM-dd-yyyy")).latin1(); DBField * newField = myDB->makeField(storeName); myDB->DBProcess(newField,COMMIT,ts); dcsRec->pushField(newField); delete newField; myDB->DBProcess(dcsRec,COMMITREPLACE); delete myDB; }catch(...){ toLog("STControlEngine::launchPrlTools : exception while creating a field for DCS reading in DB file"); delete myDB; return true; } } else{ toLog(("STControlEngine::launchPrlTools : field to which should be written already exists: "+storeName ).c_str()); delete myDB; return true; } } break;} case PrimListItem::FIT_SCAN: if(argCfg.name()!="__TrashConfig__" && argCfg["arguments"].name()!="__TrashConfGroup__" && argCfg["arguments"]["scanName"].name()!="__TrashConfObj__" && argCfg["arguments"]["histoType"].name()!="__TrashConfObj__" && argCfg["arguments"]["funcType"].name()!="__TrashConfObj__" && argCfg["arguments"]["storeType"].name()!="__TrashConfObj__" && argCfg["arguments"]["fitParPreset"].name()!="__TrashConfObj__" && argCfg["arguments"]["conversion"].name()!="__TrashConfObj__" && argCfg["arguments"]["offset"].name()!="__TrashConfObj__" && argCfg["arguments"]["fitRangeMin"].name()!="__TrashConfObj__" && argCfg["arguments"]["fitRangeMax"].name()!="__TrashConfObj__"){ std::string scanName = ((ConfString&)argCfg["arguments"]["scanName"]).value(); std::string storeType = ((ConfList&)argCfg["arguments"]["storeType"]).sValue(); int histoType = ((ConfList&)argCfg["arguments"]["histoType"]).getValue(); int funcType = ((ConfList&)argCfg["arguments"]["funcType"]).getValue(); float offset = ((ConfFloat&)argCfg["arguments"]["offset"]).value(); float conversion = ((ConfFloat&)argCfg["arguments"]["conversion"]).value(); float fitRgMin = ((ConfFloat&)argCfg["arguments"]["fitRangeMin"]).value(); float fitRgMax = ((ConfFloat&)argCfg["arguments"]["fitRangeMax"]).value(); // loop over modules for fitting for( std::vector::iterator crate = m_sTRodCrates.begin(); crate != m_sTRodCrates.end(); crate++ ){ for(int iGrp=0; iGrp<(*crate)->nGroups(); iGrp++){ std::vector< std::pair > list; (*crate)->getModules(iGrp, list); for(std::vector< std::pair >::iterator it=list.begin(); it!=list.end(); it++){ if((*crate)->getModuleActive(iGrp, it->second)){ // ignore inactive modules PixDBData *data = 0; try{ data = new PixDBData("fitting", (fileName+":/"+scanName+"/"+(*crate)->getGrpName(iGrp)).c_str(), TLogFile::GetNameFromPath(it->first.c_str()).c_str()); if(histoType == (int)PixScan::DCS_DATA){ std::vector fitPars; float chi2; if(((ConfList&)argCfg["arguments"]["funcType"]).sValue()=="FEI3 CapMeasure"){ fitPars = ((ConfVector&)argCfg["arguments"]["fitParPreset"]).valueVFloat(); double Uload = 2.0; if(fitPars.size()>0) Uload = (double)fitPars[0]; std::vector intermedFitPars; fitPars.clear(); data->fitFEI3CapMeasure(fitPars, intermedFitPars, Uload); } else{ fitPars = ((ConfVector&)argCfg["arguments"]["fitParPreset"]).valueVFloat(); data->fitGraph(fitPars, chi2, funcType, fitRgMin, fitRgMax,false); } if(storeType=="VCAL parameters"){ // get cfg. of FE 0 - won't work for multi-FE-modules since alwas FE index 0 is assumed Config &cfg = (*crate)->getPixModuleChipConf(iGrp, it->second, 0); for(unsigned int ip=0;ipgetPixModuleChipConf(iGrp, it->second, 0); if(fitPars.size()==3){ // must return 3 cap. values, otherwise undef. result if(cfg["Misc"].name()!="__TrashConfGroup__" && cfg["Misc"]["CInjLo"].name()!="__TrashConfObj__") ((ConfFloat&)cfg["Misc"]["CInjLo"]).m_value = fitPars[0]; if(cfg["Misc"].name()!="__TrashConfGroup__" && cfg["Misc"]["CInjHi"].name()!="__TrashConfObj__") ((ConfFloat&)cfg["Misc"]["CInjHi"]).m_value = fitPars[2]; } else{ delete data; return true; } } else if(storeType=="CAP0" || storeType=="CAP1" || storeType=="CAP0+CAP1" || storeType=="all CAPx"){ float cap_res = 5.7f; if(fitPars.size()>1) // must have used linear fit, so ar least 2 scan par's cap_res = fitPars[1]*conversion+offset; else{ delete data; return true; } // get cfg. of FE 0 - won't work for multi-FE-modules since alwas FE index 0 is assumed Config &cfg = (*crate)->getPixModuleChipConf(iGrp, it->second, 0); if(storeType=="all CAPx"){ // CAP0+CAP1 was measured, scale result to all CAP's if(cfg["Misc"].name()!="__TrashConfGroup__" && cfg["Misc"]["CInjHi"].name()!="__TrashConfObj__") ((ConfFloat&)cfg["Misc"]["CInjHi"]).m_value = cap_res; if(cfg["Misc"].name()!="__TrashConfGroup__" && cfg["Misc"]["CInjMed"].name()!="__TrashConfObj__") ((ConfFloat&)cfg["Misc"]["CInjMed"]).m_value = cap_res/5.7*3.9; if(cfg["Misc"].name()!="__TrashConfGroup__" && cfg["Misc"]["CInjLo"].name()!="__TrashConfObj__") ((ConfFloat&)cfg["Misc"]["CInjLo"]).m_value = cap_res/5.7*1.9; } else{ std::string cfgName="none"; if(storeType=="CAP0") cfgName="CInjMed"; if(storeType=="CAP1") cfgName="CInjLo"; if(storeType=="CAP0+CAP1") cfgName="CInjHi"; if(cfg["Misc"].name()!="__TrashConfGroup__" && cfg["Misc"][cfgName].name()!="__TrashConfObj__") ((ConfFloat&)cfg["Misc"][cfgName]).m_value = cap_res; } } // else: not stored or unknown } else{ // not yet implemented } }catch(...){ data = 0; } delete data; } } } } } else return true; // arguments not available somehow, return an error break; case PrimListItem::ANA_GRAPH:{ if(argCfg.name()!="__TrashConfig__" && argCfg["arguments"].name()!="__TrashConfGroup__" && argCfg["arguments"]["scanName"].name()!="__TrashConfObj__" && argCfg["arguments"]["anaAction"].name()!="__TrashConfObj__" && argCfg["arguments"]["anaArgs"].name()!="__TrashConfObj__" && argCfg["arguments"]["storeType"].name()!="__TrashConfObj__"){ std::string scanName = ((ConfString&)argCfg["arguments"]["scanName"]).value(); int storeType = ((ConfList&)argCfg["arguments"]["storeType"]).getValue(); int anaAction = ((ConfList&)argCfg["arguments"]["anaAction"]).getValue(); std::vector anaArgs = ((ConfVector&)argCfg["arguments"]["anaArgs"]).valueVFloat(); // loop over modules for analysis for( std::vector::iterator crate = m_sTRodCrates.begin(); crate != m_sTRodCrates.end(); crate++ ){ for(int iGrp=0; iGrp<(*crate)->nGroups(); iGrp++){ std::vector< std::pair > list; (*crate)->getModules(iGrp, list); for(std::vector< std::pair >::iterator it=list.begin(); it!=list.end(); it++){ if((*crate)->getModuleActive(iGrp, it->second)){ // ignore inactive modules PixDBData *data = 0; try{ data = new PixDBData("anagraph", (fileName+":/"+scanName+"/"+(*crate)->getGrpName(iGrp)).c_str(), TLogFile::GetNameFromPath(it->first.c_str()).c_str()); TGraph *gr = data->GetGraph(); int npts = gr->GetN(); double *x = gr->GetX(), *y = gr->GetY(); double result = 0.; switch(anaAction){ default: case 1: // find best match if(anaArgs.size()!=1){ // wrong # of arg's, can't proceed toLog("STControlEngine::launchPrlTools : wrong number of arguments given to best match analysis, should have been 1."); delete data; return true; } int ibest = -1; double target = (double)anaArgs[0], dbest=1.e10; for(int ip=0;ipfabs(y[ip]-target)){ ibest = ip; dbest = y[ip]; } } if(ibest>=0) result = x[ibest]; else{ toLog("STControlEngine::launchPrlTools : can't match target value in best match analysis."); delete data; return true; } break; } // store result switch(storeType){ default: case 1:{ std::string objN; if(data->getScanPar(0)=="FEI4_GR"){ objN = ((ConfString&)(data->getScanConfig())["loops"]["feGlobRegNameLoop_0"]).value(); // can only do this for 1 FE? FE-index is hard-coded to 0 for now Config &feconf = (*crate)->getPixModuleChipConf(iGrp, it->second, 0).subConfig("GlobalRegister_0/GlobalRegister"); if(feconf["GlobalRegister"].name()!="__TrashConfGroup__" && feconf["GlobalRegister"][objN].name()!="__TrashConfObj__"){ WriteIntConf(((ConfInt&) feconf["GlobalRegister"][objN]), (int)result); } else{ toLog("STControlEngine::launchPrlTools : can't find FE global register "+objN); delete data; return true; } }else if(data->getScanPar(0)=="IREF_PAD"){ Config &cfgUSB = (*crate)->getPixCtrlConf(iGrp); if(cfgUSB["general"].name()!="__TrashConfGroup__" && cfgUSB["general"]["IrefPads"].name()!="__TrashConfObj__"){ WriteIntConf((ConfInt&) cfgUSB["general"]["IrefPads"], (int)result); (*crate)->reloadCtrlCfg(iGrp); } else{ toLog("STControlEngine::launchPrlTools : can't find USBPixController cfg. item IrefPads"); delete data; return true; } }else{ // other scan var's not yet implemented toLog("STControlEngine::launchPrlTools : saving of scan variabled "+data->getScanPar(0)+" not yet implemented, sorry"); delete data; return true; } // do not break, saving to file should always be executed } case 2:{ // store in file std::string storeName = scanName+"_ana"; PixConfDBInterface *myDB = 0; PixLib::DBInquire *anaRec= 0; try{ myDB = new RootDB(fileName.c_str(),"UPDATE"); }catch(SctPixelRod::BaseException& exc){ std::stringstream msg; msg << "STControlEngine::launchPrlTools : exception while opening DB file " << fileName << ": " << exc; toLog(msg.str().c_str()); delete data; return true; }catch(...){ toLog(("STControlEngine::launchPrlTools : unknown exception while opening DB file "+fileName ).c_str()); delete data; return true; } std::string rname = "Graph_ana/DCS_readings"; PixLib::DBInquire *root = myDB->readRootRecord(1); if(root->findRecord(rname)==root->recordEnd()){ try{ anaRec = myDB->makeInquire("DCS_readings", "Graph_ana"); root->pushRecord(anaRec); myDB->DBProcess(root,COMMITREPLACE); myDB->DBProcess(anaRec,COMMIT); delete myDB; myDB = new RootDB(fileName.c_str(),"UPDATE"); root = myDB->readRootRecord(1); anaRec = *(root->findRecord(rname)); }catch(...){ toLog("STControlEngine::launchPrlTools : exception while creating a record for graph analysis result in DB file"); delete myDB; delete data; return true; } } else anaRec = *(root->findRecord(rname)); if(anaRec->findField(storeName)==anaRec->fieldEnd()){ try{ DBField * newField = myDB->makeField(storeName); myDB->DBProcess(newField,COMMIT, result); anaRec->pushField(newField); delete newField; myDB->DBProcess(anaRec,COMMITREPLACE); delete myDB; }catch(...){ toLog("STControlEngine::launchPrlTools : exception while creating a field for graph analysis result in DB file"); delete myDB; delete data; return true; } } else{ toLog(("STControlEngine::launchPrlTools : field to which should be written already exists: "+storeName ).c_str()); delete myDB; return true; } break;} } }catch(...){ data = 0; } delete data; } } } } } else return true; // arguments not available somehow, return an error break;} case PrimListItem::GEN_WAIT:{ int wt = ((ConfInt&)argCfg["arguments"]["waitTime"]).getValue(); for(int iw = 0; iw myCrates = getSTRodCrates(); for(std::vector::iterator crIT = myCrates.begin(); crIT != myCrates.end(); crIT++){ // loop over module groups for(int iGrp=0; iGrp < (*crIT)->nGroups(); iGrp++){ bool retval = (*crIT)->getCtrlInputStatus(iGrp, wt); if(!waitForHigh) retval = !retval; if(lc==0) // OR doWait |= retval; else if(lc==1) // AND doWait &= retval; else // not implemented return true; } } updateGUI(); } break;} case PrimListItem::SAVE_CFG:{ std::string fnExt = ((ConfString&)argCfg["arguments"]["extString"]).value(); std::string cfgFname = fileName; if(m_prlModTestType==""){ int pos = cfgFname.find(".root"); if(pos!=(int)std::string::npos){ cfgFname.erase(pos,cfgFname.length()-pos); cfgFname += fnExt+".cfg.root"; } } else{ // temporary, need to re-write once cfg. can be saved module by module std::string mname = "123456"; if(getSTRodCrates().size()>0 && getSTRodCrates()[0]->nGroups()>0) mname = getSTRodCrates()[0]->getModName(0,0); getDecNameCore(mname); if(fnExt=="") cfgFname = m_modPath + "/M" + mname + "/configs/" + mname + "_" + m_prlModTestType + ".cfg.root"; else cfgFname = m_modPath + "/M" + mname + "/configs/" + mname + "_" + fnExt + "_" + m_prlModTestType + ".cfg.root"; } if(fileName.length()>0){ std::string orgName = getPixConfDBFname(); remove(cfgFname.c_str()); saveDB(cfgFname.c_str()); m_PixConfDBFname = orgName; emit cfgLabelChanged(); } break;} case PrimListItem::LOAD_MOD_CFG:{ bool loadSN = ((ConfBool&)argCfg["arguments"]["SetChipSN"]).value(); int ChipSN = ((ConfInt&)argCfg["arguments"]["Chip_SN"]).getValue(); // loop over crates bool gotErr = false; for(std::vector::iterator crIT = getSTRodCrates().begin(); crIT != getSTRodCrates().end(); crIT++){ gotErr |= (*crIT)->reloadModCfg(getPixConfDBFname()); if(loadSN) (*crIT)->setGR("GlobalRegister_Chip_SN", ChipSN); } if(gotErr){ toErrLog("STControlEngine::launchPrlTools : error loading config for at least one module"); return true; } break;} case PrimListItem::SET_FE_MODE:{ int mode = ((ConfInt&)argCfg["arguments"]["mode"]).getValue(); for(std::vector::iterator crIT = getSTRodCrates().begin(); crIT != getSTRodCrates().end(); crIT++) (*crIT)->setFeMode(mode); break;} case PrimListItem::RD_EPROM:{ // M.B.: implemented new PrlTool for read EPROM. Implementation correct? cout << "DEBUG M.B.: PrlItem RD_EPROM executed in STcontrolEngine ;-) \n"; for(std::vector::iterator crIT = getSTRodCrates().begin(); crIT != getSTRodCrates().end(); crIT++){ (*crIT)->readEPROM(); } break;} case PrimListItem::BURN_EPROM:{ // M.B.: implemented new PrlTool for burn EPROM. Implementation correct? cout << "DEBUG M.B.: PrlItem BURN_EPROM executed in STcontrolEngine ;-) \n"; for(std::vector::iterator crIT = getSTRodCrates().begin(); crIT != getSTRodCrates().end(); crIT++){ (*crIT)->burnEPROM(); } break;} default: // not implemented, return an error return true; } // done, process next prl item processPrimList(); return false; } void STControlEngine::runLinkCheck(int crateID, int grpID, int modID) { if(CtrlStatusSummary()<=0){ sendRTStatus("can't find any initialised RODs, not testing"); return; } // in some cases, it seems to be necessary to reset FEs and MCC before starting... sendRTStatus("resetting modules"); m_app->processEvents(); // make sure GUI really updates resetModules(true); resetModules(false); // set ToolPanel inactive emit beganScanning(); sendRTStatus("running link check"); m_app->processEvents(); // make sure GUI really updates QApplication::setOverrideCursor(Qt::waitCursor); if(crateID<0){ // run link test on all crates std::vector myCrates = getSTRodCrates(); for(std::vector::iterator crIT = myCrates.begin(); crIT != myCrates.end(); crIT++) (*crIT)->runLinkTest(-1,-1); processExecute(); }else if(crateID<(int)m_sTRodCrates.size()){ // just test one module, no need to run multi-threaded m_sTRodCrates[crateID]->runLinkTest(grpID, modID); } QApplication::restoreOverrideCursor(); emit sendPixScanStatus(0,0,0,0,-1,0,0,0,1); emit finishedScanning(); m_app->processEvents(); // make sure GUI really updates QApplication::setOverrideCursor(Qt::waitCursor); m_app->processEvents(); // make sure GUI really updates sendRTStatus("re-initialising RODs"); m_app->processEvents(); // make sure GUI really updates // temporary "fix": ROD doesn't scan properly after this excercise -> reset initRods(); sendRTStatus("Done."); QApplication::restoreOverrideCursor(); return; } void STControlEngine::runChipTest(const char *label, int crateID, int grpID, int modID){ // check if we have a ChipTest object with the requested name ChipTest *ct = m_chipTests[std::string(label)]; if(ct==0){ sendRTStatus(("STControlEngine: can't find ChipTest object with name "+std::string(label)).c_str()); return; } runChipTest(ct, crateID, grpID, modID); } void STControlEngine::runChipTest(ChipTest *ct_in, int crateID, int grpID, int modID){ QApplication::setOverrideCursor(Qt::waitCursor); // set ToolPanel inactive emit beganScanning(); if(crateID<0){ // run scan on all crates std::vector myCrates = getSTRodCrates(); for(std::vector::iterator crIT = myCrates.begin(); crIT != myCrates.end(); crIT++) (*crIT)->runChipTest(ct_in, m_resetAfterTest, -1,-1); processExecute(); }else if(crateID<(int)m_sTRodCrates.size()){ // just test one module, no need to run multi-threaded m_sTRodCrates[crateID]->runChipTest(ct_in, m_resetAfterTest, grpID, modID); } sendRTStatus("Done."); // re-activate tool panel emit finishedScanning(); m_app->processEvents(); QApplication::restoreOverrideCursor(); return; } void STControlEngine::stopPixScan() { if(!m_lastPixScanOpts.scanConfig->getSourceScanFlag()){ // aborted data don't need saving - unless in source mode, then "abort" actually means "stop" m_lastPixScanOpts.writeToFile = false; m_lastPixScanOpts.loadToAna = false; } // stop scan over all crates and rods for( std::vector::iterator crate = m_sTRodCrates.begin(); crate != m_sTRodCrates.end(); crate++ ) (*crate)->abortScan(); } float STControlEngine::readCurrent(float cutval){ // dummy routine float retval = 1.1*cutval; retval += (float)rand()/(float)RAND_MAX*.2*cutval; for(int i=0;i<5;i++){ PixLib::sleep(10); m_app->processEvents(); } return retval; } void STControlEngine::selectFe(int iFE, int crateID, int grpID, int modID) { int iStart = 0; int iStop = m_sTRodCrates.size(); if(crateID>=0 && crateID<(int)m_sTRodCrates.size()){ iStart = crateID; iStop = crateID+1; } for(int ci=iStart; ciselectFe(iFE, grpID, modID); } void STControlEngine::addDcsToCurrDB(const char *objName, int classType, int devType, int nChan, const char *ctrlName, const char *crateName){ std::string fname = getPixConfDBFname(); if(fname==""){ toErrLog("STControlEngine::addGrouptoCurrDB : Can't find existing DB file in memory, so can't edit."); return; } PixConfDBInterface *myDB = reopenDBforEdit(); if(myDB==0){ toErrLog("STControlEngine::addGrouptoCurrDB : error reopening existing DB file, so can't edit."); reloadDBafterEdit(false); return; } QApplication::setOverrideCursor(Qt::waitCursor); DBInquire *startInq=0; try{ if(m_singleCrateMode) startInq = PixLib::findAppInq(myDB); else startInq = PixLib::findAppInq(myDB,crateName); }catch(SctPixelRod::BaseException& exc){ QApplication::restoreOverrideCursor(); std::stringstream msg; msg << "STControlEngine::addDcstoCurrDB : exception while re-reading new DB file " << fname << ": " << exc; toErrLog(msg.str().c_str()); delete myDB; reloadDBafterEdit(false); return; }catch(...){ QApplication::restoreOverrideCursor(); toErrLog(("STControlEngine::addDcstoCurrDB : unknown exception while re-reading new DB file" + fname).c_str()); delete myDB; reloadDBafterEdit(false); return; } QApplication::restoreOverrideCursor(); addDcsToDB(startInq, objName, classType, devType, nChan, ctrlName); // close and remove old file and open new one delete myDB; reloadDBafterEdit(true); return; } void STControlEngine::addDcsToDB(DBInquire *baseInq, const char *objName, int classType, int devType, int nChan, const char *ctrlName){ QApplication::setOverrideCursor(Qt::waitCursor); try{ PixConfDBInterface *myDB = baseInq->getDB(); // count existing PixDcs objects int nDcs=0; for(recordIterator recIter = baseInq->recordBegin();recIter!=baseInq->recordEnd();recIter++){ if((*recIter)->getName().find("PixDcs")!=std::string::npos) nDcs++; } std::stringstream a; a << nDcs; // create main inquire std::string decName, className; decName = baseInq->getDecName(); switch(classType){ case 3: className += "GoeUSB"; break; case 2: className += "GPIB"; break; case 1: className += "RS232"; break; case 0: default: className += "USB"; } className += "PixDcs"; decName += className + "_" + a.str(); DBInquire *dcsInq = myDB->makeInquire("PixDcs",decName); baseInq->pushRecord(dcsInq); myDB->DBProcess(baseInq,COMMITREPLACE); myDB->DBProcess(dcsInq,COMMIT); // define class, device type and name DBField *newField = myDB->makeField("general_DeviceName"); std::string name=objName; myDB->DBProcess(newField,COMMIT,name); dcsInq->pushField(newField); delete newField; myDB->DBProcess(dcsInq,COMMITREPLACE); newField = myDB->makeField("general_DeviceType"); name = "SUPPLY"; DummyPixDcs *pd = new DummyPixDcs(); Config &conf = pd->config(); std::map typeMap = ((ConfList&)conf["general"]["DeviceType"]).symbols(); for(std::map::iterator tit=typeMap.begin(); tit!=typeMap.end(); tit++) if(tit->second==devType) name = tit->first; delete pd; myDB->DBProcess(newField,COMMIT,name); dcsInq->pushField(newField); delete newField; myDB->DBProcess(dcsInq,COMMITREPLACE); newField = myDB->makeField("ActualClassName"); myDB->DBProcess(newField,COMMIT,className); dcsInq->pushField(newField); delete newField; myDB->DBProcess(dcsInq,COMMITREPLACE); // add name of USBPixController if this is a USBPixDcs object if(classType==0){ newField = myDB->makeField("USBPixController"); name =ctrlName; myDB->DBProcess(newField,COMMIT,name); dcsInq->pushField(newField); delete newField; myDB->DBProcess(dcsInq,COMMITREPLACE); } // add channel inquire(s) for(int iCh=0;iChgetDecName() + className+"Chan_"+b.str(); DBInquire *chanInq = myDB->makeInquire("PixDcsChan",decName); dcsInq->pushRecord(chanInq); myDB->DBProcess(dcsInq,COMMITREPLACE); myDB->DBProcess(chanInq,COMMIT); } }catch(SctPixelRod::BaseException& exc){ QApplication::restoreOverrideCursor(); std::stringstream msg; msg << "STControlEngine::addDcsToDB : exception while creating DCS inquire: " << exc; toErrLog(msg.str().c_str()); return; }catch(...){ QApplication::restoreOverrideCursor(); toErrLog("STControlEngine::addDcsToDB : unknown exception while creating DCS inquire." ); return; } QApplication::restoreOverrideCursor(); return; } bool STControlEngine::checkScanLabel(std::vector existingLabels, QString newLabel, QString &suggLabel, QString compExpr){ bool is_dupl = false; QString test_txt = newLabel; suggLabel = newLabel; // if user appended a number to scan label, strip it off int lind=1, tind = test_txt.lastIndexOf(compExpr); // the following avoids stripping off more than just an index at the end if(tind>test_txt.length()-5) test_txt = test_txt.left(tind); for(std::vector::iterator it=existingLabels.begin(); it!=existingLabels.end();it++){ if(newLabel==(*it)) is_dupl = true; if((*it).left(test_txt.length())==test_txt){ // found a label similar to ours - check if it has an index bool isOK; tind = (*it).right((*it).length()-test_txt.length()-1).toInt(&isOK); if(isOK && tind>=lind) lind = tind+1; } } test_txt += compExpr + QString::number(lind); if(is_dupl) suggLabel = test_txt; return is_dupl; } int STControlEngine::currFEFlavour(){ int retval = 0; for( std::vector::iterator crate = m_sTRodCrates.begin(); crate != m_sTRodCrates.end(); crate++ ) { for(int i=0; i<(*crate)->nGroups(); i++){ Config &cfg = (*crate)->getPixModuleConf(i, 0); if(cfg.name()!="__TrashConfig__" && cfg["general"].name()!="__TrashConfGroup__" && cfg["general"]["FE_Flavour"].name()!="__TrashConfObj__"){ std::string feflv = ((ConfList&)cfg["general"]["FE_Flavour"]).sValue(); if(feflv=="FE_I4A"){ if(retval==0) retval = 1; else if(retval!=1) retval = 10; } else if(feflv=="FE_I4B"){ if(retval==0) retval = 2; else if(retval!=2) retval = 10; } } } } return retval; }