13 rawList( rData ), triples( trips ), workingDir( wdir )
19 setWindowTitle( tr(
"Load AUC Data from Local Disk" ) );
24 setWindowTitle( tr(
"Load AUC Data from DB" ) );
30 QVBoxLayout*
main =
new QVBoxLayout(
this );
31 main->setSpacing ( 2 );
32 main->setContentsMargins( 2, 2, 2, 2 );
40 QHBoxLayout* investigator =
new QHBoxLayout;
47 QString number = (
id > 0 )
55 QHBoxLayout* search =
new QHBoxLayout;
56 QLabel* lb_search =
us_label( tr(
"Search" ) );
57 search->addWidget( lb_search );
60 connect(
le_search, SIGNAL( textChanged(
const QString& ) ),
67 tree =
new QTreeWidget;
68 tree->setFrameStyle ( QFrame::NoFrame );
70 tree->setFont ( tr_font );
71 tree->setIndentation ( 20 );
72 tree->setSelectionBehavior ( QAbstractItemView::SelectRows );
73 tree->setSelectionMode ( QAbstractItemView::ExtendedSelection );
74 tree->setAutoFillBackground (
true );
75 tree->installEventFilter (
this );
79 headers << tr(
"Run|Triple" )
83 tree->setColumnCount( 4 );
84 tree->setHeaderLabels( headers );
85 tree->setSortingEnabled(
false );
88 te_notes->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
90 te_notes->setText( tr(
"Right-mouse-button-click on a list selection"
92 int font_ht = QFontMetrics( tr_font ).lineSpacing();
93 te_notes->setMaximumHeight( font_ht * 2 + 12 );
99 QHBoxLayout* buttons =
new QHBoxLayout;
101 QPushButton* pb_expand =
us_pushbutton( tr(
"Expand All" ) );
102 QPushButton* pb_collapse =
us_pushbutton( tr(
"Collapse All" ) );
105 QPushButton* pb_shedits =
us_pushbutton( tr(
"Show Triples" ) );
108 buttons->addWidget( pb_expand );
109 buttons->addWidget( pb_collapse );
110 buttons->addWidget( pb_help );
111 buttons->addWidget( pb_cancel );
112 buttons->addWidget( pb_shedits );
113 buttons->addWidget( pb_accept );
115 connect( pb_expand, SIGNAL( clicked() ), SLOT(
expand() ) );
116 connect( pb_collapse, SIGNAL( clicked() ), SLOT(
collapse() ) );
117 connect( pb_help, SIGNAL( clicked() ), SLOT(
help() ) );
118 connect( pb_cancel, SIGNAL( clicked() ), SLOT( reject() ) );
119 connect( pb_shedits, SIGNAL( clicked() ), SLOT(
fill_in() ) );
120 connect( pb_accept, SIGNAL( clicked() ), SLOT(
load() ) );
123 main->addLayout( investigator );
124 main->addLayout( search );
125 main->addWidget(
tree );
127 main->addLayout( buttons );
135 QList< QTreeWidgetItem* > items =
tree->selectedItems();
136 int nitems = items.count();
137 QList< DataDesc > sdescs;
141 QMessageBox::warning(
this,
142 tr(
"Invalid Selection" ),
143 tr(
"No selection has been made" ) );
151 QTreeWidgetItem* item = items[ 0 ];
153 while ( item->parent() != NULL )
154 item = item->parent();
159 qDebug() <<
"Ed:Ld: runID_sel" <<
runID_sel;
161 QApplication::setOverrideCursor( QCursor( Qt::WaitCursor ) );
162 te_notes->setText( tr(
"Gathering information on raw triples for"
163 " run ID\n\"%1\"..." ).arg(
runID_sel ) );
164 qApp->processEvents();
165 qApp->processEvents();
172 te_notes->setText( tr(
"Loading data from Database ..." ) );
173 qApp->processEvents();
174 qApp->processEvents();
184 te_notes->setText( tr(
"Loading data from Local Disk ..." ) );
185 qApp->processEvents();
186 qApp->processEvents();
191 QApplication::restoreOverrideCursor();
192 QApplication::restoreOverrideCursor();
198 QTreeWidgetItem* item = items.at( 0 );
199 qDebug() <<
"Ed:Ld: nitems" << items.size();
207 for (
int ii = 0; ii < nitems; ii++ )
209 item = items.at( ii );
210 QString lkey = item->text( 0 );
213 if ( item->parent() != NULL )
215 lkey = item->parent()->text( 0 ) +
"." + lkey;
223 lkey = lkey +
"." + item->child( 0 )->text( 0 );
229 if ( !runIDs.contains( runID ) )
238 qDebug() <<
"Ed:Ld: ntops" << ntops <<
"trips" << tripls.count()
239 <<
"nitems" << nitems <<
"nruns" << nruns;
242 if ( ntops > 1 || nruns > 1 )
244 QMessageBox::warning(
this,
245 tr(
"Invalid Selection" ),
246 tr(
"Only items from one run may be selected." ) );
250 if ( ntops != nitems && tripls.count() != nitems )
252 QMessageBox::warning(
this,
253 tr(
"Invalid Selection" ),
254 tr(
"A single run or items from a single run must be selected." ) );
260 QString runID = sdescs.at( 0 ).runID;
261 item = items .at( 0 );
263 for (
int ii = 1; ii < item->childCount(); ii++ )
265 QString lkey = runID +
"." + item->child( ii )->text( 0 );
271 QApplication::setOverrideCursor( QCursor( Qt::WaitCursor ) );
272 te_notes->setText( tr(
"Loading data from " ) +
281 QApplication::restoreOverrideCursor();
293 connect( inv_dialog, SIGNAL( investigator_accepted(
int ) ),
303 QString number = ( invID > 0 ) ? QString::number( invID ) +
": " :
"";
317 QApplication::setOverrideCursor( QCursor( Qt::WaitCursor ) );
318 qDebug() <<
"Ed:Ptree: sel_run" <<
sel_run;
332 te_notes->setText( tr(
"Right-mouse-button-click on a list selection"
334 "Select triples and click on \"Load\""
335 " to load selected AUC data." ) );
350 te_notes->setText( tr(
"Select a run, then click on \"Show Triples\""
351 " to fill in triples;\n"
352 "or click on \"Load\" to load all triples"
353 " AUC data for the selected run." ) );
356 qApp->processEvents();
357 QApplication::restoreOverrideCursor();
358 QApplication::restoreOverrideCursor();
362 QMessageBox::information(
this,
363 tr(
"No AUC Files" ),
364 tr(
"No AUC files were found." ) );
371 QList< DataDesc > ddescs =
datamap.values();
372 QTreeWidgetItem* top = NULL;
374 headers << (
sel_run ? tr(
"Run|Triple" ) : tr(
"Run" ) )
378 tree->setColumnCount( 4 );
379 tree->setHeaderLabels( headers );
380 tree->setSortingEnabled(
false );
382 for (
int ii = 0; ii < naucf; ii++ )
385 QStringList item( ddesc.
tripID );
387 topItem << ddesc.
runID
388 << QString( ddesc.
date ).section(
" ", 0, 0 )
389 << QString().sprintf(
"%6d", ddesc.
DB_id )
392 if ( ! runIDs.contains( ddesc.
runID ) )
394 top =
new QTreeWidgetItem( topItem );
395 tree->addTopLevelItem( top );
396 runIDs << ddesc.
runID;
401 new QTreeWidgetItem( top, item );
404 tree->resizeColumnToContents( 0 );
405 tree->resizeColumnToContents( 1 );
406 tree->resizeColumnToContents( 2 );
407 tree->setSortingEnabled(
true );
408 tree->sortByColumn( 0, Qt::AscendingOrder );
409 tree->sortByColumn( 1, Qt::DescendingOrder );
410 qDebug() <<
"PopTr: naucf valsize" << naucf <<
datamap.values().size();
417 bool have_search = ! search.isEmpty();
419 for (
int i = 0; i <
tree->topLevelItemCount(); i++ )
421 QTreeWidgetItem* item =
tree->topLevelItem( i );
422 QString lkey = item->text( 0 );
425 item->setHidden( have_search &&
426 ! lkey.contains( search, Qt::CaseInsensitive ) );
433 for (
int i = 0; i <
tree->topLevelItemCount(); i++ )
435 QTreeWidgetItem* item =
tree->topLevelItem( i );
436 item->setExpanded(
true );
443 for (
int i = 0; i <
tree->topLevelItemCount(); i++ )
445 QTreeWidgetItem* item =
tree->topLevelItem( i );
446 item->setExpanded(
false );
453 QList< QTreeWidgetItem* > selitems =
tree->selectedItems();
455 if ( selitems.size() < 1 )
458 te_notes->setText( tr(
"Reading AUC information to fully populate"
459 " the list data tree..." ) );
464 QTreeWidgetItem* twi = selitems[ 0 ];
465 while ( twi->parent() != NULL )
469 te_notes->setText( tr(
"Reading AUC information for run \"%1\",\n"
470 " to populate its list data tree..." )
474 qApp->processEvents();
480 tree->resizeColumnToContents( 0 );
493 setWindowTitle( tr(
"Load AUC Data from " )
494 + ( db ? tr(
"DB" ) : tr(
"Local Disk" ) ) );
502 if ( obj ==
tree && e->type() == QEvent::ContextMenu )
504 QPoint mpos = ((QContextMenuEvent*)e)->pos();
513 return US_WidgetsDialog::eventFilter( obj, e );
520 QList< QTreeWidgetItem* > selitems =
tree->selectedItems();
521 QTreeWidgetItem* item = selitems.size() > 0 ? selitems.at( 0 )
522 :
tree->itemAt( pos );
523 QTreeWidgetItem* pitem = item->parent();
524 QTreeWidgetItem* citem = item->child( 0 );
525 bool toplev = ( pitem == NULL );
526 QString runID = toplev ? item ->text( 0 ) : pitem->text( 0 );
527 runID = runID.section(
"[", 0, 0 ).simplified();
528 QString tripID = toplev ? citem->text( 0 ) : item ->text( 0 );
529 QString lkey = runID +
"." + tripID;
531 QString dtext = tr(
"Data Information for " );
532 dtext += toplev ? tr(
"the first triple of run %1" ).arg( runID )
533 : tr(
"item %1" ).arg( lkey );
535 + tr(
"\n List Item Key: " ) + lkey
536 + tr(
"\n AUC Database ID: " ) + QString::number( ddesc.
DB_id )
537 + tr(
"\n AUC Global ID: " ) + ddesc.
rawGUID
538 + tr(
"\n Filename: " ) + ddesc.
filename
539 + tr(
"\n Last Updated: " ) + ddesc.
date
540 + tr(
"\n Label: " ) + ddesc.
label
541 + tr(
"\n Run ID: " ) + runID
542 + tr(
"\n Triple ID: " ) + tripID
543 + tr(
"\n Triple Index: " ) + QString::number( ddesc.
tripndx )
544 + tr(
"\n Triples per Run: " ) + QString::number( ddesc.
tripknt )
549 eddiag->setWindowTitle( tr(
"Data Information" ) );
550 eddiag->move( this->pos() + pos + QPoint( 500, 100 ) );
551 eddiag->resize( 720, 240 );
554 eddiag->
e->setText( dtext );
570 QMessageBox::warning(
this, tr(
"Connection Problem" ),
571 tr(
"Could not connect to database\n" ) + db.lastError() );
576 QString idInv = QString::number(
personID );
577 QString label = db.value( 1 ).toString();
580 query <<
"get_raw_desc_by_runID" << idInv <<
runID_sel;
582 query <<
"get_rawData_desc" << idInv;
588 QString rawDataID = db.value( 0 ).toString();
589 QString label = db.value( 1 ).toString();
590 QString filename = db.value( 2 ).toString();
591 QString date = db.value( 5 ).toString() +
" UTC";
592 QString rawPers = db.value( 6 ).toString();
593 QString rawGUID = db.value( 7 ).toString();
594 QString runID = filename.section(
".", 0, -6 );
596 QString tripID = filename.section(
".", -4, -2 );
597 QString lkey = runID +
"." + tripID;
598 QString idata = label +
"^" +
626 QStringList aucfilt(
"*.auc" );
629 QStringList aucdirs = QDir( rdir ).entryList(
630 QDir::AllDirs | QDir::NoDotAndDotDot, QDir::Name );
632 for (
int ii = 0; ii < aucdirs.size(); ii++ )
634 QString subdir = rdir +
"/" + aucdirs.at( ii );
636 QStringList aucfiles = QDir( subdir ).entryList(
637 aucfilt, QDir::Files, QDir::Name );
639 if ( aucfiles.size() < 1 )
642 QString aucfbase = aucfiles.at( 0 );
643 QString runID = QString( aucfiles.at( 0 ) ).section(
".", 0, -6 );
648 for (
int jj = 0; jj < aucfiles.size(); jj++ )
650 QString aucfbase = aucfiles.at( jj );
651 QString aucfname = subdir +
"/" + aucfbase;
652 QString runID = aucfbase.section(
".", 0, -6 );
653 QString tripID = aucfbase.section(
".", -4, -2 );
654 QString lkey = runID +
"." + tripID;
655 QString label = runID;
658 QFileInfo( aucfname ).lastModified().toUTC()
659 .toString( Qt::ISODate ),
true );
661 QString xmlfbase = aucfbase.section(
".", 0, -5 ) +
".xml";
662 QString xmlfname = subdir +
"/" + xmlfbase;
663 QFile filei( xmlfname );
666 if ( ! filei.open( QIODevice::ReadOnly | QIODevice::Text ) )
671 QXmlStreamReader xml( &filei );
672 QXmlStreamAttributes atts;
674 while ( ! xml.atEnd() )
683 if ( xml.isStartElement() )
685 if ( xml.name() ==
"dataset" )
687 atts = xml.attributes();
688 QString cell = atts.value(
"cell" ).toString();
689 QString chan = atts.value(
"channel" ).toString();
690 QString wlen = atts.value(
"wavelength" ).toString();
691 QString trip = cell +
"." + chan +
"." + wlen;
693 if ( trip == tripID )
695 rawDataID = atts.value(
"id" ).toString();
696 rawGUID = atts.value(
"guid" ).toString();
700 else if ( xml.name() ==
"label" )
703 label = xml.text().toString();
709 QString idata = label +
"^" +
741 QMessageBox::warning(
this, tr(
"Connection Problem" ),
742 tr(
"Could not connect to database\n" ) + db.lastError() );
746 QString rawGUID =
"(unknown)";
747 QString tripID =
"0.A.999";
748 QString filename =
"(unknown)";
749 QStringList q(
"get_experiment_desc" );
755 QString rawDataID = db.value( 0 ).toString();
756 QString runID = db.value( 1 ).toString();
757 QString label = db.value( 4 ).toString();
758 QString date = db.value( 5 ).toString() +
" UTC";
760 QString lkey = runID +
"." + tripID;
761 QString idata = label +
"^" +
783 QString rawGUID =
"(unknown)";
784 QString tripID =
"0.A.999";
785 QString filename =
"(unknown)";
787 QStringList aucfilt(
"*.auc" );
790 QStringList aucdirs = QDir( rdir ).entryList(
791 QDir::AllDirs | QDir::NoDotAndDotDot, QDir::Name );
793 for (
int ii = 0; ii < aucdirs.size(); ii++ )
795 QString subdir = rdir +
"/" + aucdirs.at( ii );
796 QStringList aucfiles = QDir( subdir ).entryList(
797 aucfilt, QDir::Files, QDir::Name );
799 if ( aucfiles.size() < 1 )
802 QString aucfbase = aucfiles.at( 0 );
803 QString aucfname = subdir +
"/" + aucfbase;
804 QString runID = aucfbase.section(
".", 0, -6 );
805 QString tripID = aucfbase.section(
".", -4, -2 );
806 QString lkey = runID +
"." + tripID;
807 QString label = runID;
810 QFileInfo( aucfname ).lastModified().toUTC()
811 .toString( Qt::ISODate ),
true );
813 QString xmlfbase = aucfbase.section(
".", 0, -5 ) +
".xml";
814 QString xmlfname = subdir +
"/" + xmlfbase;
815 QFile filei( xmlfname );
818 if ( ! filei.open( QIODevice::ReadOnly | QIODevice::Text ) )
823 QXmlStreamReader xml( &filei );
824 QXmlStreamAttributes atts;
826 while ( ! xml.atEnd() )
835 if ( xml.isStartElement() )
837 if ( xml.name() ==
"dataset" )
839 atts = xml.attributes();
840 QString cell = atts.value(
"cell" ).toString();
841 QString chan = atts.value(
"channel" ).toString();
842 QString wlen = atts.value(
"wavelength" ).toString();
843 QString trip = cell +
"." + chan +
"." + wlen;
845 if ( trip == tripID )
847 rawDataID = atts.value(
"id" ).toString();
848 rawGUID = atts.value(
"guid" ).toString();
852 else if ( xml.name() ==
"label" )
855 label = xml.text().toString();
861 QString idata = label +
"^" +
891 for (
int ii = 0; ii < naucf; ii++ )
894 QString idata = infoDs.at( ii );
895 QString label = idata.section(
"^", 0, 0 );
896 QString runID = idata.section(
"^", 1, 1 );
897 QString tripID = idata.section(
"^", 2, 2 );
898 QString filename = idata.section(
"^", 3, 3 );
899 QString rawGUID = idata.section(
"^", 4, 4 );
900 QString rawDataID = idata.section(
"^", 5, 5 );
901 QString date = idata.section(
"^", 6, 6 );
902 QString dcheck = idata.section(
"^", 7, 7 );
903 QString lkey = runID +
"." + tripID;
904 tripndx = ( runID == prunid ) ? ( tripndx + 1 ) : 1;
916 ddesc.
DB_id = rawDataID.toInt();
917 ddesc.
tripknt = runIDs.count( runID );
921 if (
datamap.contains( lkey ) )
923 qDebug() <<
"*** DUPLICATE lkey" << lkey <<
"***";
926 if (
datamap.contains( lkey ) )
928 lkey = lkey.replace(
"(2)",
"(3)" );
943 QString runID = sdescs.count() > 0 ? sdescs.at( 0 ).runID :
"";
957 QMessageBox::warning(
this, tr(
"Connection Problem" ),
958 tr(
"Could not connect to database\n " ) + db.lastError() );
962 for (
int ii = 0; ii < sdescs.count(); ii++ )
966 int idRaw = ddesc.
DB_id;
968 QString filename =
workingDir +
"/" + filebase;
969 QString triple = ddesc.
tripID.replace(
".",
" / " );
970 QString dcheck = ddesc.
dcheck;
971 bool dload_auc =
true;
974 if ( QFile( filename ).exists() )
978 if ( dcheck.isEmpty() )
981 query <<
"get_rawData" << QString::number( idRaw );
984 ddesc.
dcheck = db.value( 8 ).toString() +
" " +
985 db.value( 9 ).toString();
989 dload_auc = ( fcheck != dcheck );
992 emit
progress( tr(
"Loading triple " ) + triple );
993 qApp->processEvents();
998 db.readBlobFromDB( filename,
"download_aucData", idRaw );
999 int stat = db.lastErrno();
1004 emsg += tr(
"Error (%1) downloading to file %2\n" )
1005 .arg( stat ).arg( filebase );
1015 emsg += tr(
"Error (%1) reading file %2\n" )
1016 .arg( stat ).arg( filebase );
1030 QString runID = sdescs.count() > 0 ? sdescs.at( 0 ).runID :
"";
1038 for (
int ii = 0; ii < sdescs.count(); ii++ )
1043 QString filename =
workingDir +
"/" + filebase;
1044 QString triple = ddesc.
tripID.replace(
".",
" / " );
1046 emit
progress( tr(
"Loading triple " ) + triple );
1047 qApp->processEvents();
1055 emsg += tr(
"Error (%1) reading file %2\n" )
1056 .arg( stat ).arg( filebase );
1070 emsg = ( nerr == 1 ) ? tr(
"*** ERROR:\n" )
1071 : tr(
"*** %1 ERRORS:\n" ).arg( nerr ) + emsg;
1072 QMessageBox::critical(
this, tr(
"Data Load Error" ), emsg );