diff --git a/programs/us_xpn_viewer/us_xpn_viewer_gui.cpp b/programs/us_xpn_viewer/us_xpn_viewer_gui.cpp index 48d4e93df..435062dc1 100644 --- a/programs/us_xpn_viewer/us_xpn_viewer_gui.cpp +++ b/programs/us_xpn_viewer/us_xpn_viewer_gui.cpp @@ -270,6 +270,7 @@ US_XpnDataViewer::US_XpnDataViewer(QString auto_mode) : US_Widgets() in_reload_auto = false; finishing_live_update = false; in_reload_all_data = false; + in_reload_all_data_set_gui = false; in_reload_data_init = false; in_reload_check_sysdata = false; in_reload_end_processes = false; @@ -1458,7 +1459,7 @@ bool US_XpnDataViewer::check_sysdata_connection( void ) //Link *link1 = new Link(); bool status_sys_data = link1->connectToServer( xpnhost, xpnmsgPort.toInt() ); - qDebug() << "status_sys_data: " << status_sys_data; + qDebug() << "in [check_sysdata_connection]: status_sys_data: " << status_sys_data; //US_Sleep::msleep( 400 ); @@ -2617,7 +2618,8 @@ void US_XpnDataViewer::check_for_sysdata( void ) qDebug() << "SYS_STAT: After replot(), BEFORE CheExpStat!! "; - int exp_status = CheckExpComplete_auto( RunID_to_retrieve ); + bool o_connection = true; + int exp_status = CheckExpComplete_auto( RunID_to_retrieve, o_connection ); if ( exp_status == 5 || exp_status == 0 ) { @@ -2648,7 +2650,7 @@ void US_XpnDataViewer::check_for_sysdata( void ) return; } - if ( exp_status == 0 ) + if ( exp_status == 0 && o_connection ) experimentAborted = true; if ( !timer_all_data_avail->isActive() ) // Check if reload_data Timer is stopped @@ -2714,7 +2716,8 @@ void US_XpnDataViewer::check_for_data( QMap < QString, QString > & protocol_deta { //Also reset the panel before reattachement //reset_auto(); - + in_reload_all_data_set_gui = false; + opsys_auto.clear(); combinedOptics = false; @@ -2964,22 +2967,31 @@ void US_XpnDataViewer::end_processes( void ) //message informing user before throwing signal! QMessageBox msgBox_sys_data; msgBox_sys_data.setIcon(QMessageBox::Critical); + msgBox_sys_data.setWindowFlags ( Qt::CustomizeWindowHint | Qt::WindowTitleHint); msgBox_sys_data.setWindowTitle(tr("Optima System Data Server Connection Problem!")); - QString msg_sys_text = QString("Attention! UltraScan GMP is not able to communicate with the data acquisition server on the %1. Please check the following: ").arg(xpndesc); - QString msg_sys_text_info = QString("1. %1 is turned on \n2. the data acquisition server on %1 is running \n3. your license key is stored in $HOME/ultrascan/etc/optima and is not expired \n\nUse of the UltraScan GMP in conjunction with the %1 machine is suspended until this condition is resolved. \n\nThe program will return to the Optima Run Manager.").arg(xpndesc); + QString msg_sys_text = QString(tr("Attention! UltraScan GMP is not able to communicate with the data acquisition server on the %1.\n\n ")) + .arg(xpndesc); + QString msg_sys_text_info = QString(tr("The program will Return to \"Manage Optima Runs\" where you can re-attach to this run later " + "by clicking \"Select Optima Run to follow\" once the network " + "issue is resolved. UltraScan will then resume data acquisition.\n\n" + "NOTE: If the network connection cannot be re-established to the ongoing run, " + "you can delete this run from the Run Manager (\"Delete Record\" button). " + "The data will still be collected on the %1, " + "but will need to be imported and processed manually at the end of the experiment.")) + .arg(xpndesc); - QPushButton *Accept_sys = msgBox_sys_data.addButton(tr("OK"), QMessageBox::YesRole); + QPushButton *Accept_sys = msgBox_sys_data.addButton(tr("Return"), QMessageBox::YesRole); msgBox_sys_data.setText( msg_sys_text ); msgBox_sys_data.setInformativeText( msg_sys_text_info ); msgBox_sys_data.exec(); if (msgBox_sys_data.clickedButton() == Accept_sys) - qDebug() << "Closing Program..."; - - emit aborted_back_to_initAutoflow( ); + qDebug() << "Going to Run Manager.."; + emit aborted_back_to_initAutoflow( ); return; + } emit liveupdate_processes_stopped(); @@ -3030,47 +3042,48 @@ void US_XpnDataViewer::retrieve_xpn_raw_auto( void ) in_reload_all_data = true; // Flag in the midst of a reload - //Here, check if connection to Optima possibly broken: - if ( CheckExpComplete_auto( RunID_to_retrieve ) == 0 ) - { - //check connection to Optima: if at this point statusExp=0 due to lost connection - //then, stop everything && return to the Run Manager + + // //Here, check if connection to Optima possibly broken: + // if ( CheckExpComplete_auto( RunID_to_retrieve ) == 0 ) + // { + // //check connection to Optima: if at this point statusExp=0 due to lost connection + // //then, stop everything && return to the Run Manager - /* - Link *link1 = new Link( xpndesc ); // THIS DID NOT WORK... - bool status_sys_data = link1->connectToServer( xpnhost, xpnmsgPort.toInt() ); - qDebug() << "in [retrieve_xpn_raw_auto()]: statusExp == 0; status_sys_data: " << status_sys_data; + // /* + // Link *link1 = new Link( xpndesc ); // THIS DID NOT WORK... + // bool status_sys_data = link1->connectToServer( xpnhost, xpnmsgPort.toInt() ); + // qDebug() << "in [retrieve_xpn_raw_auto()]: statusExp == 0; status_sys_data: " << status_sys_data; - bool combined_check = status_sys_data & link1->connected_itself; - link1->disconnectFromServer(); - qDebug() << "in [retrieve_xpn_raw_auto()]: status_sys_data & connected_itself = ? " - << status_sys_data << " & " << link1->connected_itself << " = " << combined_check; - delete link1; // THIS DID NOT WORK... - */ + // bool combined_check = status_sys_data & link1->connected_itself; + // link1->disconnectFromServer(); + // qDebug() << "in [retrieve_xpn_raw_auto()]: status_sys_data & connected_itself = ? " + // << status_sys_data << " & " << link1->connected_itself << " = " << combined_check; + // delete link1; // THIS DID NOT WORK... + // */ - //alternative -- TO BE tested further - US_XpnData* xpn_data11 = new US_XpnData(); - bool o_connected = xpn_data11->connect_data( xpnhost, xpnport.toInt(), xpnname, xpnuser, xpnpasw ); - xpn_data11->close(); - delete xpn_data11; - //end of checking connection to Optima sys_data server + // //alternative -- TO BE tested further + // US_XpnData* xpn_data11 = new US_XpnData(); + // bool o_connected = xpn_data11->connect_data( xpnhost, xpnport.toInt(), xpnname, xpnuser, xpnpasw ); + // xpn_data11->close(); + // delete xpn_data11; + // //end of checking connection to Optima sys_data server - //if ( !combined_check ) - if ( !o_connected ) - { - timer_all_data_avail->stop(); - disconnect(timer_all_data_avail, SIGNAL(timeout()), 0, 0); //Disconnect timer from anything - qDebug() << "in [retrieve_xpn_raw_auto()]: stop timer_all_data_avail"; - qDebug() << "in [retrieve_xpn_raw_auto()]: statusExp == 0 && NO Coneection to Optima!"; - in_reload_all_data = false; - link-> disconnected_itself = true; // do we need to set it explicitly? - reset_liveupdate_panel(); //assumes link-> disconnected_itself = true!!! - qApp->processEvents(); + // //if ( !combined_check ) + // if ( !o_connected ) + // { + // timer_all_data_avail->stop(); + // disconnect(timer_all_data_avail, SIGNAL(timeout()), 0, 0); //Disconnect timer from anything + // qDebug() << "in [retrieve_xpn_raw_auto()]: stop timer_all_data_avail"; + // qDebug() << "in [retrieve_xpn_raw_auto()]: statusExp == 0 && NO Coneection to Optima!"; + // in_reload_all_data = false; + // link-> disconnected_itself = true; // do we need to set it explicitly? + // reset_liveupdate_panel(); //assumes link-> disconnected_itself = true!!! + // qApp->processEvents(); - return; - } - } - // end checking connection to Optima lost + // return; + // } + // } + // // end checking connection to Optima lost QString drDesc = ""; @@ -3170,11 +3183,40 @@ DbgLv(1) << "RDa: iRId" << iRunId << "sMsks scnmask" << sMasks << scanmask; //ALEXEY: maybe put in_reload_check_sysdata = true; and then false (after xpn_data->import_data( iRunId, scanmask ); ) //in_reload_check_sysdata = true; //ALEXEY - xpn_data->import_data( iRunId, scanmask ); // ALEXEY <-- actual data retreiving +//xpn_data->import_data( iRunId, scanmask ); // ALEXEY <-- actual data retreiving - int ntsrows = xpn_data->countOf( "scan_rows" ); + //MEasure time of xpn_data->import_data_auto: + QElapsedTimer timer_xpn_data_import_data_auto; + timer_xpn_data_import_data_auto.start(); + + bool o_connected = true; + xpn_data->import_data_auto( iRunId, scanmask, o_connected ); // ALEXEY <-- actual data retreiving + + qDebug() << "[TIME] of xpn_data->import_data_auto: " << int( timer_xpn_data_import_data_auto.elapsed() / 1000 ) << " sec"; + + //IF no connection to PostGreSQL //////////////////////////////////////////////////// + if ( !o_connected ) + { + timer_all_data_avail->stop(); + disconnect(timer_all_data_avail, SIGNAL(timeout()), 0, 0); //Disconnect timer from anything + qDebug() << "in [retrieve_xpn_raw_auto()]: stop timer_all_data_avail"; + qDebug() << "in [retrieve_xpn_raw_auto()]: statusExp == 0 && NO Coneection to Optima!"; + in_reload_all_data = false; + link-> disconnected_itself = true; // do we need to set it explicitly? + reset_liveupdate_panel(); //assumes link-> disconnected_itself = true!!! + qApp->processEvents(); + + return; + } + // END check if PostGreSQL connection ////////////////////////////////////////////////// + + + int ntsrows = xpn_data->countOf( "scan_rows" ); // <-- gets 'ntsrow' from xpn_data->import_data_auto( iRunId, scanmask, o_connected ); + // plus scan_xpndata( const int runId, const QChar scantype ) DbgLv(1) << "RDa: ntsrows" << ntsrows; DbgLv(1) << "RDa: knt(triple) " << xpn_data->countOf( "triple" ); + + qDebug() << "RDa: ntsrows" << ntsrows; qApp->processEvents(); if ( ntsrows < 1 ) @@ -3184,8 +3226,9 @@ DbgLv(1) << "RDa: knt(triple) " << xpn_data->countOf( "triple" ); in_reload_all_data = false; - //ALEXEY: rare case when no data but exp. aborted !!!! - if ( CheckExpComplete_auto( RunID_to_retrieve ) == 0 ) //ALEXEY should be == 3 as per documentation + //ALEXEY: rare case when no data but exp. aborted !!!! + bool o_connection = true; + if ( CheckExpComplete_auto( RunID_to_retrieve, o_connection ) == 0 ) //ALEXEY should be == 3 as per documentation { if ( finishing_live_update ) { @@ -3196,8 +3239,9 @@ DbgLv(1) << "RDa: knt(triple) " << xpn_data->countOf( "triple" ); } qDebug() << "ABORTION IN EARLY STAGE..."; - - experimentAborted = true; + + if ( o_connection ) + experimentAborted = true; timer_all_data_avail->stop(); disconnect(timer_all_data_avail, SIGNAL(timeout()), 0, 0); //Disconnect timer from anything @@ -3218,8 +3262,9 @@ DbgLv(1) << "RDa: knt(triple) " << xpn_data->countOf( "triple" ); } } - //ALEXEY: rare case when no data but experiment "finished" !!!! - if ( CheckExpComplete_auto( RunID_to_retrieve ) == 5 ) + //ALEXEY: rare case when no data but experiment "finished" !!!! + bool o_connection_1 = true; + if ( CheckExpComplete_auto( RunID_to_retrieve, o_connection_1 ) == 5 ) { if ( finishing_live_update ) { @@ -3249,7 +3294,9 @@ DbgLv(1) << "RDa: knt(triple) " << xpn_data->countOf( "triple" ); return; } } - + + + qDebug() << "ntsrows < 1, possibly as a result of no Posgresql conneciton!"; return; } @@ -3429,21 +3476,40 @@ DbgLv(1) << "RDa: runType2 scanmask" << runType2 << scanmask << "[ifw]scn_rows qApp->processEvents(); //ALEXEY: maybe this will help DbgLv(1) << "RDa: 1. Crashes HERE!!!!"; + + + //First time setting Optics types counter ////////////////////////////////////////////// + if ( !in_reload_all_data_set_gui ) + { + qDebug() << "[FIRTS TIME] Setting Optics types counter..."; + cb_optsys->disconnect(); + cb_optsys->clear(); + DbgLv(1) << "RDa: 1a. Crashes HERE!!!!"; + + cb_optsys->addItems( opsys_auto ); // ALEXEY fill out Optics listbox + DbgLv(1) << "RDa: 1ab. Crashes HERE!!!! - BEFORE Setting index to cb_optsys: optndx_auto = " << optndx_auto; + cb_optsys->setCurrentIndex( optndx_auto ); + DbgLv(1) << "RDa: 1ac. Crashes HERE!!!! - AFTER Setting index to cb_optsys"; + connect( cb_optsys, SIGNAL( currentIndexChanged( int ) ), + this, SLOT ( changeOptics_auto( ) )); + } + // END of [First time setting Optics types counter] ///////////////////////////////////// + - cb_optsys->disconnect(); - cb_optsys->clear(); - DbgLv(1) << "RDa: 1a. Crashes HERE!!!!"; + // cb_optsys->disconnect(); + // cb_optsys->clear(); + // DbgLv(1) << "RDa: 1a. Crashes HERE!!!!"; - cb_optsys->addItems( opsys_auto ); // ALEXEY fill out Optics listbox - DbgLv(1) << "RDa: 1ab. Crashes HERE!!!! - BEFORE Setting index to cb_optsys: optndx_auto = " << optndx_auto; - cb_optsys->setCurrentIndex( optndx_auto ); - DbgLv(1) << "RDa: 1ac. Crashes HERE!!!! - AFTER Setting index to cb_optsys"; + // cb_optsys->addItems( opsys_auto ); // ALEXEY fill out Optics listbox + // DbgLv(1) << "RDa: 1ab. Crashes HERE!!!! - BEFORE Setting index to cb_optsys: optndx_auto = " << optndx_auto; + // cb_optsys->setCurrentIndex( optndx_auto ); + // DbgLv(1) << "RDa: 1ac. Crashes HERE!!!! - AFTER Setting index to cb_optsys"; - // connect( cb_optsys, SIGNAL( currentIndexChanged( int ) ), - // this, SLOT ( changeOptics( ) ) ); + // // connect( cb_optsys, SIGNAL( currentIndexChanged( int ) ), + // // this, SLOT ( changeOptics( ) ) ); - connect( cb_optsys, SIGNAL( currentIndexChanged( int ) ), - this, SLOT ( changeOptics_auto( ) )); + // connect( cb_optsys, SIGNAL( currentIndexChanged( int ) ), + // this, SLOT ( changeOptics_auto( ) )); DbgLv(1) << "RDa: 1b. Crashes HERE!!!!"; @@ -3483,11 +3549,26 @@ DbgLv(1) << "RDa: mwr ntriple" << ntriple; DbgLv(1) << "RDa: ncellch" << ncellch << cellchans.count(); DbgLv(1) << "RDa: nscan" << nscan << "npoint" << npoint; DbgLv(1) << "RDa: rvS rvE" << r_radii[0] << r_radii[npoint-1]; - cb_cellchn->disconnect(); - cb_cellchn->clear(); - cb_cellchn->addItems( cellchans ); // ALEXEY fill out Cells/Channels listbox - connect( cb_cellchn, SIGNAL( currentIndexChanged( int ) ), - this, SLOT ( changeCellCh( ) ) ); + + + //First time setting Cell/Channs counter ////////////////////////////////////////////////////// + if ( !in_reload_all_data_set_gui ) + { + qDebug() << "[FIRTS TIME] Setting Cell/Channs counter..."; + cb_cellchn->disconnect(); + cb_cellchn->clear(); + cb_cellchn->addItems( cellchans ); // ALEXEY fill out Cells/Channels listbox + connect( cb_cellchn, SIGNAL( currentIndexChanged( int ) ), + this, SLOT ( changeCellCh( ) ) ); + } + //END of [First time setting Cell/Channs counter ] ////////////////////////////////////////////// + + + // cb_cellchn->disconnect(); + // cb_cellchn->clear(); + // cb_cellchn->addItems( cellchans ); // ALEXEY fill out Cells/Channels listbox + // connect( cb_cellchn, SIGNAL( currentIndexChanged( int ) ), + // this, SLOT ( changeCellCh( ) ) ); nlambda = xpn_data->lambdas_raw( lambdas ); // ALEXEY lambdas int wvlo = lambdas[ 0 ]; @@ -3528,7 +3609,17 @@ DbgLv(1) << "RDa: allData size" << allData.size(); in_reload_auto = false; // Ok to enable some buttons now - enableControls(); //ALEXEY ...and actual plotting data + //First time enabling Controls /////////////////////////////////////////////////////// + if ( !in_reload_all_data_set_gui ) + { + qDebug() << "[FIRTS TIME] Enabling Controls..."; + enableControls(); //ALEXEY ...and actual plotting data + in_reload_all_data_set_gui = true; + } + //ENF of [First time enabling Controls ] ////////////////////////////////////////////// + + + // enableControls(); //ALEXEY ...and actual plotting data if ( combinedOptics ) { @@ -3544,8 +3635,9 @@ DbgLv(1) << "RDa: allData size" << allData.size(); qDebug() << "finishing_live_update " << finishing_live_update; - //ALEXEY: Add Exp. Abortion Exception HERE... - if ( CheckExpComplete_auto( RunID_to_retrieve ) == 0 ) //ALEXEY should be == 3 as per documentation + //ALEXEY: Add Exp. Abortion Exception HERE... + bool o_connection = true; + if ( CheckExpComplete_auto( RunID_to_retrieve, o_connection ) == 0 ) //ALEXEY should be == 3 as per documentation { if ( finishing_live_update ) { @@ -3556,8 +3648,9 @@ DbgLv(1) << "RDa: allData size" << allData.size(); } qDebug() << "ABORTION IN EARLY STAGE..."; - - experimentAborted = true; + + if ( o_connection ) + experimentAborted = true; timer_all_data_avail->stop(); disconnect(timer_all_data_avail, SIGNAL(timeout()), 0, 0); //Disconnect timer from anything @@ -5073,11 +5166,11 @@ DbgLv(1) << "RLd: build-raw done: tm1 tm2" << tm1 << tm2 } -int US_XpnDataViewer::CheckExpComplete_auto( QString & runid ) +int US_XpnDataViewer::CheckExpComplete_auto( QString & runid, bool& o_conn ) { // Implement Optima's ExperimentRun query for RunStatus field [enum: 0 - NoRunInfo; 2- InProgress; 5- CompleteOK], look in db_defines.h of Dennis's util // in utils/us_xpn_data.cpp - int exp_status = xpn_data->checkExpStatus( runid ); + int exp_status = xpn_data->checkExpStatus_auto( runid, o_conn ); return exp_status; } @@ -5106,9 +5199,27 @@ QDateTime sttime=QDateTime::currentDateTime(); qApp->processEvents(); // Import any newly added Scan Data records - bool upd_ok = xpn_data->reimport_data( iRunId, scanmask ); + bool o_connected = true; + bool upd_ok = xpn_data->reimport_data_auto( iRunId, scanmask, o_connected ); /* udp_ok -> false when ALSO conneciton to PostgresSql lost !!!********************/ + qDebug() << "in [reloadData_auto()]: o_connected: " << o_connected; + //IF no connection to PostGreSQL + if ( !o_connected ) + { + timer_data_reload->stop(); + disconnect(timer_data_reload, SIGNAL(timeout()), 0, 0); //Disconnect timer from anything + qDebug() << "in [reloadData_auto()]: Stop auto-reload timer: " ; + qDebug() << "in [reloadData_auto()]: statusExp == 0 && NO Coneection to Optima!"; + in_reload_auto = false; + link-> disconnected_itself = true; // do we need to set it explicitly? + reset_liveupdate_panel(); //assumes link-> disconnected_itself = true!!! + qApp->processEvents(); + + return; + } + + //then, proceed as before: check if #scans changed etc. if ( ! upd_ok ) { // No change in data scans: report inability to update @@ -5132,7 +5243,8 @@ QDateTime sttime=QDateTime::currentDateTime(); DbgLv(1) << "RLd: NO CHANGE"; /*** Check Experiement Status: if completed, kill the timer, export the data into AUC format, return, signal to switch panels in US_comproject ***/ - int statusExp = CheckExpComplete_auto( RunID_to_retrieve ); + bool o_connection = true; + int statusExp = CheckExpComplete_auto( RunID_to_retrieve, o_connection ); if ( statusExp == 5 || statusExp == 0 ) { @@ -5143,62 +5255,64 @@ DbgLv(1) << "RLd: NO CHANGE"; in_reload_auto = false; return; } - - if ( statusExp == 0 ) // If there is still connection, then exp. is truly aborted!! - { - //check connection to Optima: if at this point statusExp=0 due to lost connection - //then, stop everything && return to the Run Manager - /* - Link *link1 = new Link( xpndesc ); // --- THIS DID NOT WORK ?? - bool status_sys_data = link1->connectToServer( xpnhost, xpnmsgPort.toInt() ); - qDebug() << "in [reloadData_auto()]: statusExp == 0; status_sys_data: " << status_sys_data; + if ( statusExp == 0 && o_connection ) + experimentAborted = true; + + // if ( statusExp == 0 ) // If there is still connection, then exp. is truly aborted!! + // { + // //check connection to Optima: if at this point statusExp=0 due to lost connection + // //then, stop everything && return to the Run Manager + + // /* + // Link *link1 = new Link( xpndesc ); // --- THIS DID NOT WORK ?? + // bool status_sys_data = link1->connectToServer( xpnhost, xpnmsgPort.toInt() ); + // qDebug() << "in [reloadData_auto()]: statusExp == 0; status_sys_data: " << status_sys_data; - bool combined_check = status_sys_data & link1->connected_itself; - link1->disconnectFromServer(); - qDebug() << "in [reloadData_auto()]: status_sys_data & connected_itself = ? " - << status_sys_data << " & " << link1->connected_itself << " = " << combined_check; - delete link1; // --- THIS DID NOT WORK ?? - */ - - // alternative -- TO BE tested further - QString xpndesc11 = currentInstrument[ "name" ]; - QString xpnhost11 = currentInstrument[ "optimaHost" ]; - QString xpnport11 = currentInstrument[ "optimaPort" ]; - QString xpnname11 = currentInstrument[ "optimaDBname" ]; - QString xpnuser11 = currentInstrument[ "optimaDBusername" ]; - QString xpnpasw11 = currentInstrument[ "optimaDBpassw" ]; - QString xpnmsgPort11 = currentInstrument[ "msgPort" ]; - - qDebug() << "DB parms: " << xpndesc11 << xpnhost11 << xpnport11 << xpnname11 << xpnuser11 << xpnpasw11 << xpnmsgPort11; + // bool combined_check = status_sys_data & link1->connected_itself; + // link1->disconnectFromServer(); + // qDebug() << "in [reloadData_auto()]: status_sys_data & connected_itself = ? " + // << status_sys_data << " & " << link1->connected_itself << " = " << combined_check; + // delete link1; // --- THIS DID NOT WORK ?? + // */ + + // // alternative -- TO BE tested further + // QString xpndesc11 = currentInstrument[ "name" ]; + // QString xpnhost11 = currentInstrument[ "optimaHost" ]; + // QString xpnport11 = currentInstrument[ "optimaPort" ]; + // QString xpnname11 = currentInstrument[ "optimaDBname" ]; + // QString xpnuser11 = currentInstrument[ "optimaDBusername" ]; + // QString xpnpasw11 = currentInstrument[ "optimaDBpassw" ]; + // QString xpnmsgPort11 = currentInstrument[ "msgPort" ]; + + // qDebug() << "DB parms: " << xpndesc11 << xpnhost11 << xpnport11 << xpnname11 << xpnuser11 << xpnpasw11 << xpnmsgPort11; - US_XpnData* xpn_data11 = new US_XpnData(); - bool o_connected = xpn_data11->connect_data( xpnhost11, xpnport11.toInt(), xpnname11, xpnuser11, xpnpasw11 ); - xpn_data11->close(); - delete xpn_data11; - - qDebug() << "DB connection, o_connected ? -- " << o_connected; - //end of checking connection to Optima sys_data server - - //if ( !combined_check ) - if ( !o_connected ) - { - timer_data_reload->stop(); - disconnect(timer_data_reload, SIGNAL(timeout()), 0, 0); //Disconnect timer from anything - qDebug() << "in [reloadData_auto()]: Stop auto-reload timer: " ; - qDebug() << "in [reloadData_auto()]: statusExp == 0 && NO Coneection to Optima!"; - in_reload_auto = false; - link-> disconnected_itself = true; // do we need to set it explicitly? - reset_liveupdate_panel(); //assumes link-> disconnected_itself = true!!! - qApp->processEvents(); + // US_XpnData* xpn_data11 = new US_XpnData(); + // bool o_connected = xpn_data11->connect_data( xpnhost11, xpnport11.toInt(), xpnname11, xpnuser11, xpnpasw11 ); + // xpn_data11->close(); + // delete xpn_data11; + + // qDebug() << "DB connection, o_connected ? -- " << o_connected; + // //end of checking connection to Optima sys_data server + + // //if ( !combined_check ) + // if ( !o_connected ) + // { + // timer_data_reload->stop(); + // disconnect(timer_data_reload, SIGNAL(timeout()), 0, 0); //Disconnect timer from anything + // qDebug() << "in [reloadData_auto()]: Stop auto-reload timer: " ; + // qDebug() << "in [reloadData_auto()]: statusExp == 0 && NO Coneection to Optima!"; + // in_reload_auto = false; + // link-> disconnected_itself = true; // do we need to set it explicitly? + // reset_liveupdate_panel(); //assumes link-> disconnected_itself = true!!! + // qApp->processEvents(); - return; - } - else - experimentAborted = true; - } + // return; + // } + // else + // experimentAborted = true; + // } - timer_data_reload->stop(); disconnect(timer_data_reload, SIGNAL(timeout()), 0, 0); //Disconnect timer from anything @@ -5227,9 +5341,7 @@ DbgLv(1) << "RLd: NO CHANGE"; return; } } - - - + in_reload_auto = false; // Flag no longer in the midst of reload qDebug() << "Exit from reloaData with no change!"; diff --git a/programs/us_xpn_viewer/us_xpn_viewer_gui.h b/programs/us_xpn_viewer/us_xpn_viewer_gui.h index d4a6e01e9..64d940353 100644 --- a/programs/us_xpn_viewer/us_xpn_viewer_gui.h +++ b/programs/us_xpn_viewer/us_xpn_viewer_gui.h @@ -279,6 +279,7 @@ class US_XpnDataViewer : public US_Widgets bool in_reload_data_init; bool in_reload_all_data; + bool in_reload_all_data_set_gui; bool in_reload_check_sysdata; bool in_reload_end_processes; bool in_reload_end_process_all_data_avail; @@ -357,7 +358,7 @@ class US_XpnDataViewer : public US_Widgets void end_process_all_data_avail ( void ); void reloadData_auto ( void ); - int CheckExpComplete_auto( QString & ); + int CheckExpComplete_auto( QString &, bool & ); void update_autoflow_runId_timeStarted( void ); int read_timeElapsed_offset( void ); void delete_autoflow_record( void ); diff --git a/utils/us_xpn_data.cpp b/utils/us_xpn_data.cpp index d735a6280..677e3f3cc 100644 --- a/utils/us_xpn_data.cpp +++ b/utils/us_xpn_data.cpp @@ -113,6 +113,37 @@ int US_XpnData::checkExpStatus( QString runid ) return sqry.value( 0 ).toInt(); } +// Check Experiment status [for autoflow] +int US_XpnData::checkExpStatus_auto( QString runid, bool& o_conn ) +{ + + qDebug() << "in [checkExpStatus_auto]: Init o_conn status: " << o_conn; + + if ( ! dbxpn.open() ) + { + o_conn = false; + qDebug() << "XPN: checkExpStatus_auto: !dbxpn.open() !!! runid, o_conn -- " + << runid << o_conn; + + return false; + } + + QString tabname( "ExperimentRun" ); + QSqlQuery sqry; + QString schname( "AUC_schema" ); + QString sqtab = schname + "." + tabname; + QString qrytab = "\"" + schname + "\".\"" + tabname + "\""; + + QString qrytext = "SELECT \"RunStatus\" from " + qrytab + + " WHERE \"RunId\"=" + runid + ";"; + sqry = dbxpn.exec( qrytext ); + sqry.next(); + + qDebug() << "INSIDE CheckExpSTATUS: status: " << sqry.value( 0 ).toInt(); + return sqry.value( 0 ).toInt(); +} + + void US_XpnData::setEtimOffZero( void ) { //etimoff = 0; @@ -600,6 +631,112 @@ DbgLv(1) << "XpDa:i_d: arows frows irows wrows srows crows" return status; } +// Import XPN data from a selected database server [for autoflow] +bool US_XpnData::import_data_auto( const int runId, const int scanMask, bool& o_conn ) +{ + bool status = true; + ntscan = 0; + ntsrow = 0; + + qDebug() << "in [import_data_auto]: Init o_Conn status: " << o_conn; + + if ( ! dbxpn.open() ) + { + o_conn = false; + qDebug() << "XPN: import_data_auto: !dbxpn.open() !!! runId, scanMask, o_conn -- " + << runId << scanMask << o_conn; + return false; + } + + tAsdata.clear(); // Clear table value vectors + tFsdata.clear(); + tIsdata.clear(); + tWsdata.clear(); + tSydata.clear(); + tCrprof.clear(); + bool ascnf = scanMask & 1; + bool fscnf = scanMask & 2; + bool iscnf = scanMask & 4; + bool wscnf = scanMask & 8; + + arows = 0; + frows = 0; + irows = 0; + wrows = 0; + + //booleans for diff. types + bool srows_bool = true; + bool arows_bool = true; + bool frows_bool = true; + bool irows_bool = true; + bool wrows_bool = true; + bool crows_bool = true; + + // Scan and build data for System Status Data + QElapsedTimer timer_srows; + timer_srows.start(); + int srows = scan_xpndata_auto( runId, 'S', srows_bool, timer_srows ); + qDebug() << "[TIME] of scan_xpndata_auto( runId, 'S', srows_bool ) " << int( timer_srows.elapsed() / 1000 ) << " sec"; + + if ( ascnf ) + { // Scan and build data for Absorbance Scan Data + QElapsedTimer timer_arows; + timer_arows.start(); + arows = scan_xpndata_auto( runId, 'A', arows_bool, timer_arows ); + qDebug() << "[TIME] of scan_xpndata_auto( runId, 'A', arows_bool ) " << int( timer_arows.elapsed() / 1000 ) << " sec"; + } + + if ( fscnf ) + { // Scan and build data for Fluorescence Scan Data + QElapsedTimer timer_frows; + timer_frows.start(); + frows = scan_xpndata_auto( runId, 'F', frows_bool, timer_frows ); + qDebug() << "[TIME] of scan_xpndata_auto( runId, 'F', frows_bool ) " << int( timer_frows.elapsed() / 1000 ) << " sec"; + } + + if ( iscnf ) + { // Scan and build data for Interference Scan Data + QElapsedTimer timer_irows; + timer_irows.start(); + irows = scan_xpndata_auto( runId, 'I', irows_bool, timer_irows ); + qDebug() << "[TIME] of scan_xpndata_auto( runId, 'I', irows_bool ) " << int( timer_irows.elapsed() / 1000 ) << " sec"; + } + + if ( wscnf ) + { // Scan and build data for Wavelength Scan Data + QElapsedTimer timer_wrows; + timer_wrows.start(); + wrows = scan_xpndata_auto( runId, 'W', wrows_bool, timer_wrows ); + qDebug() << "[TIME] of scan_xpndata_auto( runId, 'W', wrows_bool ) " << int( timer_wrows.elapsed() / 1000 ) << " sec"; + } + + // Scan and build data for Centrifuge Run Profile + QElapsedTimer timer_crows; + timer_crows.start(); + int crows = scan_xpndata_auto( runId, 'C', crows_bool, timer_crows ); + qDebug() << "[TIME] of scan_xpndata_auto( runId, 'C', crows_bool ) " << int( timer_crows.elapsed() / 1000 ) << " sec"; + + + qDebug() << "XpDa:i_d: arows frows irows wrows srows crows" + << arows << frows << irows << wrows << srows << crows; + + qDebug() << "XpDa:i_d: [BOOLS] arows_bool frows_bool irows_bool wrows_bool srows_bool crows_bool" + << arows_bool << frows_bool << irows_bool << wrows_bool << srows_bool << crows_bool; + + ntsrow = arows + frows + irows + wrows; + qDebug() << "in [import_data_auto]:ntsrow = " << ntsrow; + + if ( !arows_bool || !frows_bool || !irows_bool || !wrows_bool || !srows_bool || !crows_bool) + { + o_conn = false; + qDebug() << "No connection in one of scan_xpndata_auto()..."; + return false; + } + + return status; +} + + // Re-import XPN data from a selected database server bool US_XpnData::reimport_data( const int runId, const int scanMask ) { @@ -607,8 +744,82 @@ bool US_XpnData::reimport_data( const int runId, const int scanMask ) if ( ! dbxpn.open() ) { - qDebug() << "XPN: reimport_data: !dbxpn.open() !!! runID, scanMask -- " - << runID << scanMask; + qDebug() << "XPN: reimport_data: !dbxpn.open() !!! runId, scanMask -- " + << runId << scanMask; + return false; + } + + int oarows = tAsdata.count(); // Get old row counts + int ofrows = tFsdata.count(); + int oirows = tIsdata.count(); + int owrows = tWsdata.count(); + if ( oarows > 1 && tAsdata[ 0 ].radPath != tAsdata[ 1 ].radPath ) + oarows /= 2; + if ( ofrows > 0 && tFsdata[ 0 ].radPath != tFsdata[ 1 ].radPath ) + ofrows /= 2; + if ( owrows > 0 && tWsdata[ 0 ].radPath != tWsdata[ 1 ].radPath ) + owrows /= 2; + bool ascnf = scanMask & 1; + bool fscnf = scanMask & 2; + bool iscnf = scanMask & 4; + bool wscnf = scanMask & 8; + + int arows = 0; + int frows = 0; + int irows = 0; + int wrows = 0; + + if ( ascnf ) + { // Scan and update data for Absorbance Scan Data + arows = update_xpndata( runId, 'A' ); + status = ( status || arows > oarows ); +DbgLv(1) << "XpDa: rei_dat: arows oarows status" << arows << oarows << status; + qDebug() << "XpDa: rei_dat: arows oarows status" << arows << oarows << status; + } + + if ( fscnf ) + { // Scan and update data for Fluorescence Scan Data + frows = update_xpndata( runId, 'F' ); + status = ( status || frows > ofrows ); + } + + if ( iscnf ) + { // Scan and update data for Interference Scan Data + irows = update_xpndata( runId, 'I' ); + status = ( status || irows > oirows ); + } + + if ( wscnf ) + { // Scan and update data for Wavelength Scan Data + wrows = update_xpndata( runId, 'W' ); + status = ( status || wrows > owrows ); + } + +DbgLv(1) << "XpDa: rei_dat: arows frows irows wrows" + << arows << frows << irows << wrows << "status" << status; + qDebug() << "XpDa: rei_dat: arows frows irows wrows" + << arows << frows << irows << wrows << "status" << status; +//*DEBUG* +//status=true; +//*DEBUG* + + return status; +} + + +// Re-import XPN data from a selected database server [for autoflow] +bool US_XpnData::reimport_data_auto( const int runId, const int scanMask, bool& o_conn ) +{ + bool status = false; + + qDebug() << "in [reimport_data_auto]: Init o_Conn status: " << o_conn; + + if ( ! dbxpn.open() ) + { + o_conn = false; + qDebug() << "XPN: reimport_data_auto: !dbxpn.open() !!! runId, scanMask, o_conn -- " + << runId << scanMask << o_conn; + return false; } @@ -669,6 +880,7 @@ DbgLv(1) << "XpDa: rei_dat: arows frows irows wrows" return status; } + // Query and save data for a [AIFW]ScanData or [SC] table int US_XpnData::scan_xpndata( const int runId, const QChar scantype ) { @@ -700,9 +912,10 @@ int US_XpnData::scan_xpndata( const int runId, const QChar scantype ) sqry.next(); count = sqry.value( 0 ).toInt(); DbgLv(1) << "XpDa:s_x: sRunId" << sRunId << "count" << count; + if ( count < 1 ) { - return count; + return count; } emit status_text( tr( " Scanning %1 rows of %2 table..." ) @@ -994,6 +1207,410 @@ DbgLv(1) << "XpDa:scn: nn=" << nn << " Vals nn-5 to nn-1 --"; return rows; } + +// Query and save data for a [AIFW]ScanData or [SC] table: [for autoflow framework] +int US_XpnData::scan_xpndata_auto( const int runId, const QChar scantype, bool& o_conn, QElapsedTimer elapse_t ) +{ + QSqlQuery sqry; + QSqlRecord qrec; + QString schname( "AUC_schema" ); + QString tabname( "AbsorbanceScanData" ); + tabname = ( scantype == 'F' ) ? "FluorescenceScanData" : tabname; + tabname = ( scantype == 'I' ) ? "InterferenceScanData" : tabname; + tabname = ( scantype == 'W' ) ? "WavelengthScanData" : tabname; + tabname = ( scantype == 'S' ) ? "SystemStatusData" : tabname; + tabname = ( scantype == 'C' ) ? "CentrifugeRunProfile" : tabname; + QString sqtab = schname + "." + tabname; + QString qrytab = "\"" + schname + "\".\"" + tabname + "\""; + QString sRunId = QString::number( runId ); + QStringList cnames; + QList< int > cxs; + + int count = 0; + int rows = 0; + + // Get count of rows matching runId + QString qrytext = "SELECT count(*) from " + qrytab + + " WHERE \"RunId\"=" + sRunId + ";"; + if ( scantype == 'C' ) + qrytext = "SELECT count(*) from " + qrytab + ";"; + + qDebug() << "in [scan_xpndata_auto()]: scantype, qrytext -- " + << scantype << qrytext; + + qDebug() << "[TIME 1] of scan_xpndata_auto(): " << int( elapse_t.elapsed() / 1000 ) << " sec"; + + sqry = dbxpn.exec( qrytext ); + qDebug() << "sqry.isActive() ? " << sqry.isActive(); + + qDebug() << "[TIME 2] of scan_xpndata_auto(): " << int( elapse_t.elapsed() / 1000 ) << " sec"; + + bool scan_xpndata_query_success = sqry.next(); + + qDebug() << "[TIME 3] of scan_xpndata_auto(): " << int( elapse_t.elapsed() / 1000 ) << " sec"; + + count = sqry.value( 0 ).toInt(); +DbgLv(1) << "XpDa:s_x: sRunId" << sRunId << "count" << count; + qDebug() << "XpDa:s_x: sRunId" << sRunId << "scan_xpndata_query_success, count: " << scan_xpndata_query_success << count; + + qDebug() << "[TIME 4] of scan_xpndata_auto(): " << int( elapse_t.elapsed() / 1000 ) << " sec"; + + if( !scan_xpndata_query_success || !sqry.isActive() ) + { + qDebug() << "in [scan_xpndata()], scan_xpndata_query_success, NO CONNECTION? " + << scan_xpndata_query_success << !scan_xpndata_query_success; + qDebug() << "count = 0 ? " << count; + o_conn = false; + + return count; + } + + if ( count < 1 ) + { + qDebug() << "in [scan_xpndata()], count < 1..."; + return count; + } + + emit status_text( tr( " Scanning %1 rows of %2 table..." ) + .arg( count ).arg( tabname ) ); + + qDebug() << "[TIME 5] of scan_xpndata_auto(): " << int( elapse_t.elapsed() / 1000 ) << " sec"; + + // Get columns and determine indecies of fields + qrytext = "SELECT * from " + qrytab + + " WHERE \"RunId\"=" + sRunId + + " ORDER BY \"DataId\" ;"; + if ( scantype == 'C' ) + qrytext = "SELECT * from " + qrytab + ";"; + + int cols = column_indexes( tabname, cnames, cxs ); +DbgLv(1) << "XpDa:s_x: cols" << cols << "cnames" << cnames[0] << "..." + << cnames[cols-1] << "tabname" << tabname; + + qDebug() << "XpDa:s_x: cols" << cols << "cnames" << cnames[0] << "..." + << cnames[cols-1] << "tabname" << tabname; + + sqry = dbxpn.exec( qrytext ); + + qDebug() << "[TIME 6] of scan_xpndata_auto(): " << int( elapse_t.elapsed() / 1000 ) << " sec"; + + int isctyp = ( scantype == 'A' ) ? 1 : 0; + isctyp = ( scantype == 'F' ) ? 2 : isctyp; + isctyp = ( scantype == 'I' ) ? 3 : isctyp; + isctyp = ( scantype == 'W' ) ? 4 : isctyp; + isctyp = ( scantype == 'S' ) ? 5 : isctyp; + isctyp = ( scantype == 'C' ) ? 6 : isctyp; +DbgLv(1) << "XpDa:s_x: isctyp scantype" << isctyp << scantype + << "qrytext" << qrytext; + + qDebug() << "XpDa:s_x: isctyp scantype" << isctyp << scantype + << "qrytext" << qrytext; + + // Loop to read data and store in internal array + + while ( sqry.next() ) + { + rows++; + emit status_text( tr( "Of %1 ScanData(%2) rows, queried row %3" ) + .arg( count ).arg( scantype ).arg( rows ) ); + + switch ( isctyp ) + { + case 1: + { + update_ATable( sqry, cxs ); +//*DEBUG* +if(rows<21 || (rows+21)>count) { +int ldx=tAsdata.count()-1; +tbAsData asdrow = tAsdata[ldx]; +DbgLv(1) << "XpDa:scn: row" << rows << "run" << asdrow.runId + << "dat" << asdrow.dataId << "count" << asdrow.count; +DbgLv(1) << "XpDa:scn: rads0 rads1 vals0 vals1" + << asdrow.rads[0] << asdrow.rads[1] << asdrow.vals[0] << asdrow.vals[1]; +DbgLv(1) << "XpDa:scn: etim scn temp speed omg estr" + << asdrow.exptime << asdrow.scanSeqN << asdrow.tempera << asdrow.speed + << asdrow.omgSqT << asdrow.expstart.toString(); +} +//*DEBUG* + + break; + } + case 2: + { + update_FTable( sqry, cxs ); +//*DEBUG* +if(rows<9 || (rows+9)>count) { +int ldx=tFsdata.count()-1; +tbFsData fsdrow = tFsdata[ldx]; +DbgLv(1) << "XpDa:scn: row" << rows << "run" << fsdrow.runId + << "dat" << fsdrow.dataId; +DbgLv(1) << "XpDa:scn: cnames" << cnames; +} +//*DEBUG* + break; + } + case 3: + { + update_ITable( sqry, cxs ); +//*DEBUG* +if(rows<9 || (rows+9)>count) { +int ldx=tIsdata.count()-1; +tbIsData isdrow = tIsdata[ldx]; +DbgLv(1) << "XpDa:scn: row" << rows << "run" << isdrow.runId + << "dat" << isdrow.dataId; +DbgLv(1) << "XpDa:scn: rads0 rads1 vals0 vals1" + << isdrow.rads[0] << isdrow.rads[1] << isdrow.vals[0] << isdrow.vals[1]; +} +//*DEBUG* + break; + } + case 4: + { + update_WTable( sqry, cxs ); +//*DEBUG* +if(rows<9 || (rows+9)>count) { +int ldx=tWsdata.count()-1; +tbWsData wsdrow = tWsdata[ldx]; +DbgLv(1) << "XpDa:scn: row" << rows << "run dat count" << wsdrow.runId + << wsdrow.dataId << wsdrow.count; +} +//*DEBUG* + break; + } + case 5: + { + tbSyData sydrow; + + sydrow.dataId = sqry.value( cxs[ 0 ] ).toInt(); + sydrow.runId = sqry.value( cxs[ 1 ] ).toInt(); + sydrow.expstart = sqry.value( cxs[ 2 ] ).toDateTime(); + sydrow.exptime = sqry.value( cxs[ 3 ] ).toInt(); + sydrow.tempera = sqry.value( cxs[ 4 ] ).toDouble(); + sydrow.speed = sqry.value( cxs[ 5 ] ).toDouble(); + sydrow.omgSqT = sqry.value( cxs[ 6 ] ).toDouble(); + sydrow.stageNum = sqry.value( cxs[ 7 ] ).toInt(); + + tSydata << sydrow; + + qDebug() << "[TIME 7 'S'] of scan_xpndata_auto(): " << int( elapse_t.elapsed() / 1000 ) << " sec"; +//*DEBUG* +if(rows<21 || (rows+21)>count) { +DbgLv(1) << "XpDa:scn: row" << rows << "run dat" << sydrow.runId << sydrow.dataId + << "time" << sydrow.exptime << "temp" << sydrow.tempera << "speed" << sydrow.speed + << "omg2t" << sydrow.omgSqT; + + qDebug() << "XpDa:scn: row" << rows << "run dat" << sydrow.runId << sydrow.dataId + << "time" << sydrow.exptime << "temp" << sydrow.tempera << "speed" << sydrow.speed + << "omg2t" << sydrow.omgSqT; + + } +//*DEBUG* + break; + } + case 6: + { + tbCrProf crprow; + + crprow.frunId = sqry.value( cxs[ 0 ] ).toInt(); + crprow.tempera = sqry.value( cxs[ 1 ] ).toDouble(); + crprow.sbrake = sqry.value( cxs[ 2 ] ).toInt(); + crprow.brrate = sqry.value( cxs[ 3 ] ).toDouble(); + crprow.holdte = sqry.value( cxs[ 4 ] ).toInt(); + crprow.holdsp = sqry.value( cxs[ 5 ] ).toInt(); + crprow.sette = sqry.value( cxs[ 6 ] ).toInt(); + crprow.sstintv = sqry.value( cxs[ 7 ] ).toDouble(); + crprow.stages = sqry.value( cxs[ 8 ] ).toString(); + crprow.stgrpm = sqry.value( cxs[ 9 ] ).toDouble(); + crprow.stgstart = sqry.value( cxs[ 10 ] ).toDouble(); + crprow.stgdurat = sqry.value( cxs[ 11 ] ).toDouble(); + crprow.stgaccel = sqry.value( cxs[ 12 ] ).toDouble(); + crprow.paramids = sqry.value( cxs[ 13 ] ).toString(); + + tCrprof << crprow; + + qDebug() << "[TIME 7 'C'] of scan_xpndata_auto(): " << int( elapse_t.elapsed() / 1000 ) << " sec"; +//*DEBUG* +if(rows<21 || (rows+21)>count) { +DbgLv(1) << "XpDa:scn: row" << rows << "fugeRunId" << crprow.frunId + << "ssInterval" << crprow.sstintv; + qDebug() << "XpDa:scn: row" << rows << "fugeRunId" << crprow.frunId + << "ssInterval" << crprow.sstintv; + +} +//*DEBUG* + break; + } + } + } + + if ( scantype == 'C' ) + { // Show mapping of RunId to ExperimentId to FugeRunProfileId + QList< int > rExpIds; // ExperimentRun experiment Ids + QList< int > rRunIds; // ExperimentRun run Ids + QList< int > dExpIds; // ExperimentDefinition experiment Ids + QList< int > dFugIds; // ExperimentDefinition fugeProfile Ids +DbgLv(1) << "XpDa:scn: tCrprof count" << tCrprof.count(); + + int iRunId = sRunId.toInt(); + tabname = "ExperimentRun"; + sqtab = schname + "." + tabname; + qrytab = "\"" + schname + "\".\"" + tabname + "\""; + qrytext = "SELECT * from " + qrytab + ";"; + + qDebug() << "[TIME 8 'C'] of scan_xpndata_auto(): " << int( elapse_t.elapsed() / 1000 ) << " sec"; + + sqry = dbxpn.exec( qrytext ); + + qDebug() << "[TIME 9 'C'] of scan_xpndata_auto(): " << int( elapse_t.elapsed() / 1000 ) << " sec"; + + qrec = dbxpn.record( qrytab ); + + qDebug() << "[TIME 10 'C'] of scan_xpndata_auto(): " << int( elapse_t.elapsed() / 1000 ) << " sec"; + + // Get indexes to ExperimentId and RunId + cols = column_indexes( tabname, cnames, cxs ); + int jexpid = cnames.indexOf( "ExperimentId" ); + int jrunid = cnames.indexOf( "RunId" ); + while ( sqry.next() ) + { // Build a list of ExperimentRun expIds and runIds + int rExpId = sqry.value( jexpid ).toInt(); + int rRunId = sqry.value( jrunid ).toInt(); + rExpIds << rExpId; + rRunIds << rRunId; + } + + qDebug() << "[TIME 11 'C'] of scan_xpndata_auto(): " << int( elapse_t.elapsed() / 1000 ) << " sec"; + + tabname = "ExperimentDefinition"; + sqtab = schname + "." + tabname; + qrytab = "\"" + schname + "\".\"" + tabname + "\""; + qrytext = "SELECT * from " + qrytab + ";"; + + qDebug() << "[TIME 12 'C'] of scan_xpndata_auto(): " << int( elapse_t.elapsed() / 1000 ) << " sec"; + + sqry = dbxpn.exec( qrytext ); + + qDebug() << "[TIME 13 'C'] of scan_xpndata_auto(): " << int( elapse_t.elapsed() / 1000 ) << " sec"; + + qrec = dbxpn.record( qrytab ); + + qDebug() << "[TIME 14 'C'] of scan_xpndata_auto(): " << int( elapse_t.elapsed() / 1000 ) << " sec"; + + cols = column_indexes( tabname, cnames, cxs ); + // Get indexes to ExperimentId and FugeRunProfileId + jexpid = cnames.indexOf( "ExperimentId" ); + int jfruid = cnames.indexOf( "FugeRunProfileId" ); + int jexpnm = cnames.indexOf( "Name" ); +//DbgLv(1) << "XpDa:scn: jexpid jfruid" << jexpid << jfruid; + while ( sqry.next() ) + { // Build a list of ExperimentDefinition expIds and fugeIds + int dExpId = sqry.value( jexpid ).toInt(); + int dFugId = sqry.value( jfruid ).toInt(); + dExpIds << dExpId; + dFugIds << dFugId; +DbgLv(1) << "XpDa:scn: dExpId" << dExpId << "dFugId" << dFugId + << "Name" << sqry.value(jexpnm).toString(); + } + + qDebug() << "[TIME 15 'C'] of scan_xpndata_auto(): " << int( elapse_t.elapsed() / 1000 ) << " sec"; + +//DbgLv(1) << "XpDa:scn: dExpIds" << dExpIds; +//DbgLv(1) << "XpDa:scn: dFugIds" << dFugIds; + // Map experimentId to runId, then fugeId to experimentId + int rrndx = rRunIds.indexOf( iRunId ); +DbgLv(1) << "XpDa:scn: iRunId" << iRunId << "rrndx" << rrndx; + int iExpId = rExpIds[ rrndx ]; + int dendx = dExpIds.indexOf( iExpId ); +DbgLv(1) << "XpDa:scn: iExpId" << iExpId << "dendx" << dendx; + int iFugId = ( dendx >= 0 ) ? dFugIds[ dendx ] : iExpId; + sstintv = 0.0; + double sstintl = 1000.0; +DbgLv(1) << "XpDa:scn: RunId" << iRunId << "ExperimentId" << iExpId + << "FugeRunProfileId" << iFugId; + + for ( int ii = 0; ii < tCrprof.count(); ii++ ) + { // Look for matching fuge Id in CentrifugeRunProfile values + sstintl = tCrprof[ ii ].sstintv; + + if ( tCrprof[ ii ].frunId == iFugId ) + { // Match found: save corresponding SystemStatusInterval + sstintv = sstintl; + break; + } + } + + sstintv = ( sstintv > 0.0 ) ? sstintv : sstintl; +DbgLv(1) << "XpDa:scn: FugId" << iFugId << "sstInterval" << sstintv; + } + + if ( scantype == 'S' ) + { // Determine experiment time offset (time at last rms=0 point) + int ntssda = tSydata.count(); + fnzstx = 0; + + qDebug() << "[TIME 8 'S'] of scan_xpndata_auto(): " << int( elapse_t.elapsed() / 1000 ) << " sec"; + + for ( int ii = 0; ii < ntssda; ii++ ) + { // Find the index to the first non-zero speed + int irSpeed = (int)qRound( tSydata[ ii ].speed ); + if ( irSpeed > 0 ) + { + fnzstx = ii; + break; + } + } + + // First non-zero-speed time index + fnzstx = ( fnzstx > 0 ) ? fnzstx : 1; //ALEXEY: if tSydata.count() == 1 (so only tSydata[0] exists), AND fnzstx was 0, THEN + // fnzstx = ( fnzstx > 0 ) ? fnzstx : 1; will lead to fnzstx = 1 !!! + // THEN int etime1 = tSydata[ 1 ].exptime; WILL CRASH + int t2tx = fnzstx + 1; + // Experiment time offset (== negative of first time + interval) + //int etime1 = tSydata[ fnzstx ].exptime; + + //ALEXEY: check additionally if tSydata[fnzstx] exists!!! + int etime1 = 0; + if ( fnzstx < tSydata.count() ) + { + etime1 = tSydata[ fnzstx ].exptime; + } + //////////////// + + int timeintv = sstintv; + if ( t2tx < tSydata.count() ) + { + timeintv = tSydata[ t2tx ].exptime - etime1; + } + timeintv = qMax( timeintv, 1 ); + etimoff = timeintv - etime1; +//*DEBUG* +DbgLv(1) << "XpDa:scn: fnzstx" << fnzstx << "etimoff" << etimoff + << " etime1 timeintv" << etime1 << timeintv << sstintv; +int nn=qMin(tSydata.count(),fnzstx+3); +DbgLv(1) << "XpDa:scn: nn=" << nn << " Vals nn-5 to nn-1 --"; +//if(nn>4) { +// DbgLv(1) << "XpDa:scn: times:" +// << tSydata[nn-5].exptime +// << tSydata[nn-4].exptime +// << tSydata[nn-3].exptime +// << tSydata[nn-2].exptime +// << tSydata[nn-1].exptime; +// DbgLv(1) << "XpDa:scn: speeds:" +// << tSydata[nn-5].speed +// << tSydata[nn-4].speed +// << tSydata[nn-3].speed +// << tSydata[nn-2].speed +// << tSydata[nn-1].speed; } +//*DEBUG* + + qDebug() << "[TIME 9 'S'] of scan_xpndata_auto(): " << int( elapse_t.elapsed() / 1000 ) << " sec"; + } + + return rows; +} + + + // Query and update data for a [AIFW]ScanData table int US_XpnData::update_xpndata( const int runId, const QChar scantype ) { diff --git a/utils/us_xpn_data.h b/utils/us_xpn_data.h index fc4280220..eda797750 100644 --- a/utils/us_xpn_data.h +++ b/utils/us_xpn_data.h @@ -239,6 +239,7 @@ class US_UTIL_EXTERN US_XpnData : public QObject int get_runid( QString ); int checkExpStatus( QString ); + int checkExpStatus_auto( QString, bool& ); //! \brief Filter Runs information to exclude zero-data ones //! \param runInfo Reference for input/updated run info strings @@ -250,6 +251,7 @@ class US_UTIL_EXTERN US_XpnData : public QObject //! \param scantype Scan type ('A','F','I','W','S','C') to match //! \returns Number of rows of match ScanData found int scan_xpndata( const int, const QChar ); + int scan_xpndata_auto( const int, const QChar, bool&, QElapsedTimer ); //! \brief Update the DB [AIFW]ScanData table information //! \param runId Run ID to match @@ -273,12 +275,14 @@ class US_UTIL_EXTERN US_XpnData : public QObject //! \param scanMask Scan mask (AFIW, 1 to 15) of tables //! \returns Status of import (true->imported OK) bool import_data ( const int, const int ); + bool import_data_auto ( const int, const int, bool& ); //! \brief Reimport ScanData from the postgres database //! \param runId Run ID to match //! \param scanMask Scan mask (AFIW, 1 to 15) of tables //! \returns Status of reimport (false->reimport not needed) bool reimport_data ( const int, const int ); + bool reimport_data_auto ( const int, const int, bool& ); //! \brief Load XPN internal variables from loaded rawDatas //! \param allData Vector of loaded rawDatas