Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

YadaRunnableDocument.tcl

00001 # Copyright (C) 1997-2004 The CDG Team <cdg@nats.informatik.uni-hamburg.de> 00002 # 00003 # This file is free software; as a special exception the author gives 00004 # unlimited permission to copy and/or distribute it, with or without 00005 # modifications, as long as this notice is preserved. 00006 # 00007 # This program is distributed in the hope that it will be useful, but 00008 # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the 00009 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00010 00011 ## ---------------------------------------------------------------------------- 00012 ## YadaRunnableDocument - abstract document able to launch YadaJobs. 00013 ## This document offers all functionality to launch one or a whole bunch of 00014 ## YadaJobs. Most notably YadaRunner inherits this abstract class and implements 00015 ## the left virtual methods. 00016 ## \ingroup YadauRunnableDocuments 00017 ## 00018 ## \author Michael Daum 00019 ## 00020 ## $Id: YadaRunnableDocument.tcl,v 1.17 2004/05/11 14:30:48 ddreyer Exp $ 00021 ## ---------------------------------------------------------------------------- 00022 class YadaRunnableDocument { 00023 inherit YadaDocument 00024 00025 # variables ---------------------------------------------------------------- 00026 00027 ## Needed for instantiations without view 00028 public variable selectedExperiment "" 00029 00030 ## flag to indicate a received break signal 00031 protected variable _gotBreak 0 00032 00033 ## flag to indicate that the document is currently busy 00034 protected variable _isRunning 0 00035 00036 ## results of _analyseDocument(). 00037 ## This variable is modified by _analyseDocument() in a sideeffect. 00038 ## Outside this method we only read _analyseResult. 00039 ## The filled values are: 00040 ## - wordgraph: the name of the wordgraph in the DomDocument 00041 ## - noValues: the number of levelvalues in a computed constraintnet 00042 ## - score: the score of a found parse 00043 ## - totalTime: the total amount of time needed to terminate the solution method 00044 ## - solutionTime: the time to find the parse 00045 ## - softTime: the time to find the first parse without any hard violations 00046 ## - tries: the number of tried items in the solution parse 00047 ## - structHits: the number of structural correct items in the solution parse 00048 ## - labelledHits: the number of structural correct and correctly labelled items 00049 ## - lexicalHits: the number of structural, labelled and lexically correct items 00050 ## - strictHits: the number of identical dependency edges 00051 protected variable _analyseResult; ## \type TclArray 00052 00053 00054 ## the wordgraph selected by a right mouse click on the table. 00055 protected variable _selectedContextWordgraph "" 00056 00057 ## hash mapping wordgraph ids to 0 or 1. 00058 ## This indicates whether a wordgraph has been computed or not. 00059 protected variable _doneWordgraph; ## \type TclArray 00060 00061 ## hash of registered YadaJobs. 00062 ## This structure hashes a YadaExperiment to all YadaJobs that have been constructed 00063 ## for it and therefor holds all jobs scheduled by this document. 00064 ## \see _registerJob(). 00065 private variable _currentJobs; ## \type TclArray 00066 00067 ## profiler for job execution time. 00068 private variable _timer 0 00069 00070 ## flag indicating whether the display should focus on new data. 00071 private variable _followDataFlag 1 00072 00073 ## current sorting state. 00074 ## This variable stores the column number allong which the table is sorted. 00075 private variable _lastSorting 0 00076 00077 ## traced process. 00078 ## This variable stores the YadaProcess that we currently trace. 00079 private variable _progressProcess "" 00080 00081 ## flag indicating whether we clear the log window on each new computation. 00082 private variable _clearLogFlag 0 00083 00084 ## flag indicating whether we display the table 00085 private variable _tableFlag 1 00086 00087 ## flag indicating whether we display the log window 00088 private variable _consoleFlag 1 00089 00090 ## flag indicating the orientation of the splitted window. 00091 ## Possible values are horizontal and vertical 00092 private variable _orientFlag "horizontal" 00093 00094 # methods ------------------------------------------------------------------ 00095 public method init {}; ## \virtual 00096 public method print {message} ; ## \type TclString 00097 public method sortRows {colNo args} ;## \type TclNumber, TclList 00098 public method resortRows {} 00099 public method selectExperiment {{experimentName ""}} ;## \type TclString 00100 00101 public method step {{wordgraph ""}} ;## \type TclString 00102 public method run {{experiment ""}}; ## \type YadaExperiment 00103 public method runall {} 00104 public method askRunall {} 00105 public method clear {} 00106 public method reload {} 00107 public method save {} 00108 00109 public method breakJob {} 00110 public method unbreakJob {} 00111 public method interruptJobs {} 00112 public method termJob {} 00113 public method killJob {} 00114 00115 constructor {args} {}; ## \type TclList 00116 00117 public method markWordgraph {wordgraph}; ## \type TclString 00118 public method unmarkWordgraph {wordgraph}; ## \type TclString 00119 public method setToggle {name {value ""}}; ## \type TclString, TclRef 00120 00121 00122 protected method loadUpdatedWordgraphs {args} ; ## \type TclList 00123 protected method _getWordgraphs {} 00124 protected method _getActiveWordgraphs {} 00125 protected method _getSelectedWork {} 00126 protected method _getUndoneWork {} 00127 protected method _getDoneWork {} 00128 protected method _getSelectedExperiment {} 00129 00130 protected method _getRowOfWordgraph {wordgraph}; ## \type TclString 00131 protected method _computeSpeedup {time1 time2}; ## \type TclNumber, TclNumber 00132 protected method _insertData {wordgraph args}; ## \type TclString, TclList 00133 protected method _getTypeOfColumn {colNo} ;## \purevirtual \type TclNumber 00134 protected method _analyseDocument {document experiment}; ## \type DomDocument, TclExperiment 00135 protected method _computeStatistics {} 00136 protected method _jobConsumer {job}; ## \type YadaJob 00137 protected method _registerJob {job}; ## \type YadaJob 00138 protected method _unregisterJob {job}; ## \type YadaJob 00139 protected method _showContextMenu {x y xroot yroot}; ## \type TclNumber, TclNumber, TclNumber, TclNumber 00140 protected method _viewLogfile {{experiments ""}}; ## \type TclList 00141 protected method _viewXmlfile {{experiments ""}}; ## \type TclList 00142 protected method _clearRow {} 00143 protected method _deleteData {} 00144 protected method _traceProcess {} 00145 protected method _resetDataOf {wordgraphs}; ## \type TclList 00146 protected method _getXMLFileName { wordgraph }; ## \type TclString 00147 00148 private method _computeETA {machine noJobs}; ## \type YadaMachine, TclNumber 00149 private method _escapeCommand {} 00150 private method _returnCommand {} 00151 private method _leaveTableCommand {} 00152 private method _breakButtonAction {} 00153 private method _runButtonAction {} 00154 }; 00155 00156 00157 ## ---------------------------------------------------------------------------- 00158 ## constructor 00159 ## ---------------------------------------------------------------------------- 00160 body YadaRunnableDocument::constructor {args} { 00161 00162 # 00163 # edit menu 00164 # 00165 $itk_component(editMenu) add command \ 00166 -label "Clear" \ 00167 -underline 0 \ 00168 -command [code $this clear] 00169 $itk_component(editMenu) add command \ 00170 -label "Run" \ 00171 -underline 0 \ 00172 -command [code $this run] 00173 $itk_component(editMenu) add command \ 00174 -label "Run All" \ 00175 -underline 0 \ 00176 -command [code $this runall] 00177 $itk_component(editMenu) add command \ 00178 -label "Step" \ 00179 -underline 0 \ 00180 -command [code $this step] 00181 $itk_component(editMenu) add command \ 00182 -label "Break" \ 00183 -underline 0 \ 00184 -command [code $this breakProcess] 00185 $itk_component(editMenu) add command \ 00186 -label "Unbreak" \ 00187 -underline 0 \ 00188 -command [code $this unbreakProcess] 00189 $itk_component(editMenu) add command \ 00190 -label "Interrupt" \ 00191 -underline 0 \ 00192 -command [code $this interruptProcess] 00193 $itk_component(editMenu) add command \ 00194 -label "Terminate" \ 00195 -underline 0 \ 00196 -command [code $this termProcess] 00197 $itk_component(editMenu) add command \ 00198 -label "Kill" \ 00199 -underline 0 \ 00200 -command [code $this killProcess] 00201 00202 # 00203 # view menu 00204 # 00205 itk_component add sortIncMenu { 00206 menu $itk_component(viewMenu).sortIncMenu 00207 } { 00208 keep -background -cursor 00209 rename -borderwidth -menuborderwidth menuBorderwidth Borderwidth 00210 } 00211 00212 itk_component add sortDecMenu { 00213 menu $itk_component(viewMenu).sortDecMenu 00214 } { 00215 keep -background -cursor 00216 rename -borderwidth -menuborderwidth menuBorderwidth Borderwidth 00217 } 00218 00219 $itk_component(viewMenu) add checkbutton \ 00220 -label "Table" \ 00221 -variable [scope _tableFlag] \ 00222 -command [code $this setToggle "table"] 00223 $itk_component(viewMenu) add checkbutton \ 00224 -label "Console" \ 00225 -variable [scope _consoleFlag] \ 00226 -command [code $this setToggle "console"] 00227 $itk_component(viewMenu) add separator 00228 $itk_component(viewMenu) add radiobutton \ 00229 -label "Horizontal" \ 00230 -variable [scope _orientFlag] \ 00231 -value "horizontal" \ 00232 -command [code $this setToggle "orientation"] 00233 $itk_component(viewMenu) add radiobutton \ 00234 -label "Vertical" \ 00235 -variable [scope _orientFlag] \ 00236 -value "vertical" \ 00237 -command [code $this setToggle "orientation"] 00238 $itk_component(viewMenu) add separator 00239 $itk_component(viewMenu) add checkbutton \ 00240 -label "Follow new data" \ 00241 -variable [scope _followDataFlag] \ 00242 -command [code $this setToggle "follow"] 00243 $itk_component(viewMenu) add checkbutton \ 00244 -label "Clear new log" \ 00245 -variable [scope _clearLogFlag] \ 00246 -command [code $this setToggle "clear"] 00247 $itk_component(viewMenu) add separator 00248 $itk_component(viewMenu) add cascade \ 00249 -label "Sort inc. by" \ 00250 -underline 0 \ 00251 -menu $itk_component(sortIncMenu) 00252 $itk_component(viewMenu) add cascade \ 00253 -label "Sort dec. by" \ 00254 -underline 0 \ 00255 -menu $itk_component(sortDecMenu) 00256 00257 # 00258 # toolbar 00259 # 00260 $itk_component(toolbar) add FlatButton reloadButton \ 00261 -image [YadaImages::get reload] \ 00262 -balloonstr "reload" \ 00263 -command [code $this reload] 00264 00265 $itk_component(toolbar) add FlatButton clearButton \ 00266 -image [YadaImages::get erase] \ 00267 -command [code $this clear] \ 00268 -balloonstr "clear" 00269 00270 $itk_component(toolbar) add FlatButton runButton \ 00271 -image [YadaImages::get run] \ 00272 -command [code $this _runButtonAction] \ 00273 -balloonstr "run" 00274 00275 $itk_component(toolbar) add FlatButton runAllButton \ 00276 -image [YadaImages::get runall] \ 00277 -command [code $this runall] \ 00278 -balloonstr "run all" 00279 00280 $itk_component(toolbar) add FlatButton stepButton \ 00281 -image [YadaImages::get step] \ 00282 -command [code $this step] \ 00283 -balloonstr "step" 00284 00285 $itk_component(toolbar) add FlatButton breakButton \ 00286 -image [YadaImages::get giveup] \ 00287 -command [code $this _breakButtonAction] \ 00288 -balloonstr "break" 00289 00290 $itk_component(toolbar) add FlatButton interruptButton \ 00291 -image [YadaImages::get finish] \ 00292 -command [code $this interruptJobs] \ 00293 -balloonstr "interrupt" 00294 00295 $itk_component(toolbar) add FlatButton termButton \ 00296 -image [YadaImages::get stop] \ 00297 -command [code $this termJob] \ 00298 -balloonstr "terminate" 00299 00300 $itk_component(toolbar) add FlatButton killButton \ 00301 -image [YadaImages::get bomb] \ 00302 -command [code $this killJob] \ 00303 -balloonstr "kill" 00304 00305 # 00306 # overview heading 00307 # 00308 itk_component add heading { 00309 frame $itk_component(childsite).heading 00310 } 00311 00312 00313 # 00314 # the pane 00315 # 00316 itk_component add pane { 00317 iwidgets::panedwindow $itk_component(childsite).pane \ 00318 -orient horizontal \ 00319 -sashindent -8 \ 00320 -thickness 2 \ 00321 -sashheight 8 \ 00322 -sashwidth 18 00323 } { 00324 keep -background -cursor 00325 } 00326 $itk_component(pane) add top -margin 0 00327 $itk_component(pane) add bottom -margin 0 00328 set top [$itk_component(pane) childsite top] 00329 set bottom [$itk_component(pane) childsite bottom] 00330 $itk_component(pane) fraction 74 26 00331 00332 # 00333 # the logwindow 00334 # 00335 itk_component add log { 00336 YadaLog $bottom.log \ 00337 -hscrollmode dynamic \ 00338 -wrap none \ 00339 -borderwidth 2 \ 00340 -sbwidth 12 \ 00341 -troughcolor gray \ 00342 -textbackground gray90 \ 00343 -textfont {-misc-fixed-medium-normal-semicondensed-*-13-*-*-*-*-*-*-*} 00344 } { } 00345 00346 $itk_component(log) autotag INFO \ 00347 -foreground black \ 00348 -background green3 00349 $itk_component(log) autotag WARNING \ 00350 -foreground black \ 00351 -background yellow2 00352 $itk_component(log) autotag ERROR \ 00353 -foreground white \ 00354 -background red3 00355 $itk_component(log) autotag DEBUG \ 00356 -foreground white \ 00357 -background blue3 00358 $itk_component(log) autotag PROFILE \ 00359 -foreground black \ 00360 -background lightblue 00361 00362 # 00363 # table 00364 # 00365 itk_component add table { 00366 MyTable $top.table \ 00367 -exportselection 1 \ 00368 -selecttitles 1 \ 00369 -rowseparator "\n" \ 00370 -colseparator "\t" \ 00371 -rows 300 \ 00372 -cols 6 \ 00373 -state normal \ 00374 -cellanchor c \ 00375 -colstretchmode last \ 00376 -rowstretchmode none \ 00377 -selectmode extended \ 00378 -selecttype row \ 00379 -titlerows 1 \ 00380 -titlecols 1 \ 00381 -borderwidth 3 \ 00382 -outerborderwidth 2 \ 00383 -outerrelief sunk \ 00384 -selforeground "" \ 00385 -selbackground "" \ 00386 -font {-adobe-helvetica-medium-r-normal--12-*-*-*-*-*-*-*} \ 00387 -troughcolor gray \ 00388 -hscrollmode dynamic 00389 } { 00390 keep -background -cursor 00391 } 00392 00393 00394 # 00395 # the context menu 00396 # 00397 itk_component add contextMenu { 00398 menu $itk_interior.contextMenu 00399 } { 00400 keep -background -cursor 00401 rename -borderwidth -menuborderwidth menuBorderwidth Borderwidth 00402 } 00403 $itk_component(contextMenu) add command \ 00404 -label "View Log" \ 00405 -underline 0 \ 00406 -command [code $this _viewLogfile] 00407 $itk_component(contextMenu) add command \ 00408 -label "View Xml" \ 00409 -underline 5 \ 00410 -command [code $this _viewXmlfile] 00411 $itk_component(contextMenu) add command \ 00412 -label "Trace" \ 00413 -underline 0 \ 00414 -command [code $this _traceProcess] 00415 $itk_component(contextMenu) add command \ 00416 -label "Clear" \ 00417 -underline 0 \ 00418 -command [code $this _clearRow] 00419 $itk_component(contextMenu) add command \ 00420 -label "Delete" \ 00421 -underline 0 \ 00422 -command [code $this _deleteData] 00423 00424 # bindings 00425 set hull $itk_component(hull) 00426 set tableInTable [$itk_component(table) component table] 00427 bind $hull <Leave> [code $this _leaveTableCommand] 00428 bind $hull <FocusOut> [code $this _leaveTableCommand] 00429 bind $tableInTable <KeyPress-Escape> [code "$this _escapeCommand; break"] 00430 bind $tableInTable <KeyPress-Return> [code "$this _returnCommand; break"] 00431 bind $tableInTable <Button-3> [code "$this _showContextMenu %x %y %X %Y; break"] 00432 00433 # packing 00434 pack $itk_component(heading) -fill x -anchor n 00435 pack $itk_component(pane) -fill both -expand 1 -side top 00436 pack $itk_component(table) -fill both -expand 1 -padx 2 -pady 5 00437 pack $itk_component(log) -side top -expand 1 -fill both -padx 2 -pady 5 00438 00439 } 00440 00441 ## ---------------------------------------------------------------------------- 00442 ## _getRowOfWordgraph 00443 ## ---------------------------------------------------------------------------- 00444 body YadaRunnableDocument::_getRowOfWordgraph {wordgraph} { 00445 00446 set table $itk_component(table) 00447 00448 set rmax [$table cget -rows] 00449 set ids [$table getCell 1,0 $rmax,0] 00450 set row [lsearch -exact $ids $wordgraph] 00451 incr row 00452 00453 return $row 00454 } 00455 00456 ## ---------------------------------------------------------------------------- 00457 ## _runButtonAction 00458 ## ---------------------------------------------------------------------------- 00459 body YadaRunnableDocument::_runButtonAction {} { 00460 set _timer [clock seconds] 00461 set _isRunning 1 00462 run 00463 while {$_isRunning} { 00464 vwait [scope _isRunning] 00465 } 00466 if {$_gotBreak} { 00467 printMessage "interrupted job(s)" 00468 unbreakJob 00469 } else { 00470 printMessage "finished job(s)" 00471 } 00472 } 00473 00474 ## ---------------------------------------------------------------------------- 00475 ## _breakButtonAction 00476 ## ---------------------------------------------------------------------------- 00477 body YadaRunnableDocument::_breakButtonAction {} { 00478 if {$_gotBreak} { 00479 unbreakJob 00480 } else { 00481 breakJob 00482 } 00483 } 00484 00485 ## ---------------------------------------------------------------------------- 00486 ## breakJob 00487 ## ---------------------------------------------------------------------------- 00488 body YadaRunnableDocument::breakJob {} { 00489 print "INFO: break received\n" 00490 if {$_isRunning} { 00491 set _gotBreak 1 00492 $itk_component(toolbar) itemconfigure breakButton -background red3 00493 } 00494 00495 # remove all queued and waiting jobs, let the running once finish 00496 after idle { printMessage "Please wait on step completion." } 00497 foreach experiment [array names _currentJobs] { 00498 foreach job $_currentJobs($experiment) { 00499 set experiment [$job cget -experiment] 00500 set machine [.main getMachine [$experiment cget -machineName]] 00501 if {![$job hasPassedState "dequeuing"]} { 00502 _unregisterJob $job 00503 $machine stopJob $job 00504 } 00505 update 00506 } 00507 } 00508 _computeStatistics 00509 } 00510 00511 ## ---------------------------------------------------------------------------- 00512 ## interruptJobs 00513 ## ---------------------------------------------------------------------------- 00514 body YadaRunnableDocument::interruptJobs {} { 00515 breakJob 00516 foreach experiment [array names _currentJobs] { 00517 foreach job $_currentJobs($experiment) { 00518 set process [$job cget -process] 00519 if {$process != ""} { 00520 $process interrupt 00521 } 00522 update 00523 } 00524 } 00525 } 00526 00527 ## ---------------------------------------------------------------------------- 00528 ## termJob 00529 ## ---------------------------------------------------------------------------- 00530 body YadaRunnableDocument::termJob {} { 00531 breakJob 00532 foreach experiment [array names _currentJobs] { 00533 foreach job $_currentJobs($experiment) { 00534 set process [$job cget -process] 00535 if {$process != ""} { 00536 $process term 00537 } 00538 update 00539 } 00540 } 00541 } 00542 00543 ## ---------------------------------------------------------------------------- 00544 ## killJob 00545 ## ---------------------------------------------------------------------------- 00546 body YadaRunnableDocument::killJob {} { 00547 breakJob 00548 foreach experiment [array names _currentJobs] { 00549 foreach job $_currentJobs($experiment) { 00550 set process [$job cget -process] 00551 if {$process != ""} { 00552 $process killJob 00553 } 00554 update 00555 } 00556 } 00557 } 00558 00559 ## ---------------------------------------------------------------------------- 00560 ## reload 00561 ## ---------------------------------------------------------------------------- 00562 body YadaRunnableDocument::reload {} { 00563 set selection [$itk_component(table) curselection] 00564 clear 00565 if {$selection != ""} { 00566 $itk_component(table) selection set [lindex $selection 0] [lindex $selection end] 00567 } 00568 loadUpdatedWordgraphs 00569 _computeStatistics 00570 } 00571 00572 00573 ## ---------------------------------------------------------------------------- 00574 ## clear 00575 ## ---------------------------------------------------------------------------- 00576 body YadaRunnableDocument::clear {} { 00577 set table $itk_component(table) 00578 set selection [$table curselection] 00579 set cmax [$table cget -cols] 00580 00581 setModified 00582 00583 # only delete the seleted rows 00584 if {$selection != ""} { 00585 set minRow 9999 00586 set maxRow 0 00587 foreach index $selection { 00588 scan $index "%d,%d" row col 00589 $table erase $row,1 $row,$cmax 00590 $table clear tags $row,0 $row,$cmax 00591 set wordgraph [$table getCell $row,0] 00592 _resetDataOf $wordgraph 00593 } 00594 } else { 00595 00596 # reset the whole statistics 00597 $table clear tags 00598 $table delete rows -holddimensions 1 [$table cget -rows] 00599 00600 # insert the wordgraphs 00601 set wordgraphs [_getWordgraphs] 00602 set rmax [llength $wordgraphs] 00603 set table $itk_component(table) 00604 if {$rmax < 20} { 00605 set rmax 20 00606 } else { 00607 incr rmax 00608 } 00609 $table configure -rows $rmax 00610 set row 1 00611 foreach wordgraph $wordgraphs { 00612 $table setCell $row,0 $wordgraph 00613 incr row 00614 } 00615 00616 _resetDataOf "$wordgraphs" 00617 _getActiveWordgraphs 00618 } 00619 00620 unbreakJob 00621 $itk_component(log) clear 00622 .main printStatus "" 00623 } 00624 00625 ## ---------------------------------------------------------------------------- 00626 ## unbreakJob 00627 ## ---------------------------------------------------------------------------- 00628 body YadaRunnableDocument::unbreakJob {} { 00629 set _gotBreak 0 00630 $itk_component(toolbar) itemconfigure breakButton -background gray90 00631 } 00632 00633 ## ---------------------------------------------------------------------------- 00634 ## _escapeCommand 00635 ## ---------------------------------------------------------------------------- 00636 body YadaRunnableDocument::_escapeCommand {} { 00637 set table $itk_component(table) 00638 set lastActiveCell [$table tag cell active] 00639 scan $lastActiveCell "%d,%d" row col 00640 00641 if {$col == 0} { 00642 $table selection clear all 00643 } else { 00644 $table activate -1,-1 00645 } 00646 } 00647 00648 ## ---------------------------------------------------------------------------- 00649 ## _leaveTableCommand 00650 ## ---------------------------------------------------------------------------- 00651 body YadaRunnableDocument::_leaveTableCommand {} { 00652 set table $itk_component(table) 00653 set lastActiveCell [$table tag cell active] 00654 if {$lastActiveCell == ""} { 00655 return 00656 } 00657 00658 scan $lastActiveCell "%d,%d" row col 00659 $table activate -1,-1 00660 } 00661 00662 ## ---------------------------------------------------------------------------- 00663 ## _returnCommand 00664 ## ---------------------------------------------------------------------------- 00665 body YadaRunnableDocument::_returnCommand {} { 00666 set table $itk_component(table) 00667 set lastActiveCell [$table tag cell active] 00668 scan $lastActiveCell "%d,%d" row col 00669 set colMax [expr [$table cget -cols] -1] 00670 if {$col == $colMax} { 00671 incr row 00672 set col 1 00673 } else { 00674 incr col 00675 } 00676 00677 $table activate $row,$col 00678 $table see $row,$col 00679 } 00680 00681 ## ---------------------------------------------------------------------------- 00682 ## init 00683 ## ---------------------------------------------------------------------------- 00684 body YadaRunnableDocument::init {} { 00685 if {$_isInitialized} { 00686 return 00687 } 00688 chain 00689 clear 00690 00691 $itk_component(sortIncMenu) delete 0 end 00692 $itk_component(sortDecMenu) delete 0 end 00693 00694 set cmax [$itk_component(table) cget -cols] 00695 set headings [$itk_component(table) getCell 0,0 0,$cmax] 00696 set colNo 0 00697 foreach heading $headings { 00698 if {$heading != ""} { 00699 $itk_component(sortIncMenu) add command \ 00700 -label "$heading" \ 00701 -command [code $this sortRows $colNo -increasing] 00702 $itk_component(sortDecMenu) add command \ 00703 -label "$heading" \ 00704 -command [code $this sortRows $colNo -decreasing] 00705 } 00706 incr colNo 00707 } 00708 } 00709 00710 ## ---------------------------------------------------------------------------- 00711 ## _computeSpeedup 00712 ## ---------------------------------------------------------------------------- 00713 body YadaRunnableDocument::_computeSpeedup {time1 time2} { 00714 00715 set timeTolerance [.main getTimeTolerance] 00716 00717 if {[expr abs ($time1 - $time2) > $timeTolerance]} { 00718 return [expr (1.0 + $time2) / (1.0 + $time1)] 00719 } else { 00720 return 1.0 00721 } 00722 } 00723 00724 ## ---------------------------------------------------------------------------- 00725 ## _computeStatistics 00726 ## ---------------------------------------------------------------------------- 00727 body YadaRunnableDocument::_computeStatistics {} { 00728 00729 set noJobs 0 00730 foreach experiment [array names _currentJobs] { 00731 incr noJobs [llength $_currentJobs($experiment)] 00732 } 00733 00734 set experiments [array names _currentJobs] 00735 set noExperiments [expr [llength $experiments] -1] 00736 # if {$noExperiments < 0} { 00737 # return 00738 # } 00739 00740 set timeStamp [clock seconds] 00741 set elapsedString [timeToString [expr ($timeStamp - $_timer) * 1000]] 00742 00743 set experiment [lindex $experiments 0] 00744 if {$experiment != ""} { 00745 set machine [.main getMachine [$experiment cget -machineName]] 00746 set avgString [timeToString [$machine getTimePerJob]] 00747 set etaString [timeToString [_computeETA $machine $noJobs]] 00748 set noRunning [expr int([$machine getLoad] * [$machine cget -cpus])] 00749 incr noJobs -$noRunning 00750 .main printStatus "duration = $elapsedString : eta = $etaString : avg = $avgString : remaining experiments = $noExperiments : running jobs = $noRunning : remaining jobs = $noJobs" 00751 } else { 00752 .main printStatus "duration = $elapsedString" 00753 } 00754 } 00755 00756 ## ---------------------------------------------------------------------------- 00757 ## _getWordgraphs: get all wordgraphs of a experiments grammar 00758 ## ---------------------------------------------------------------------------- 00759 body YadaRunnableDocument::_getWordgraphs {} { 00760 ## handle the case that only the 'data model' of the document is being used 00761 if { $hasView == "true" } { 00762 set experiment [_getSelectedExperiment] 00763 } else { ## use document as combined model-view 00764 set experiment $selectedExperiment 00765 } 00766 00767 if {$experiment == ""} { 00768 return "" 00769 } 00770 00771 set grammar [.main getGrammar [$experiment cget -grammarName]] 00772 return [$grammar getSelection] 00773 } 00774 00775 00776 ## ---------------------------------------------------------------------------- 00777 ## _getSelectedExperiment 00778 ## ---------------------------------------------------------------------------- 00779 body YadaRunnableDocument::_getSelectedExperiment {} { 00780 set experimentName [$itk_component(experimentBox) get] 00781 if {$experimentName == "" || $experimentName == "<none>"} { 00782 return "" 00783 } 00784 return [.main getExperiment $experimentName] 00785 } 00786 00787 ## ---------------------------------------------------------------------------- 00788 ## _getSelectedWork 00789 ## ---------------------------------------------------------------------------- 00790 body YadaRunnableDocument::_getSelectedWork {} { 00791 set table $itk_component(table) 00792 00793 set cells [$table curselection] 00794 00795 foreach index $cells { 00796 scan $index "%d,%d" row col 00797 set wordgraph [$table getCell $row,0] 00798 if {$wordgraph != ""} { 00799 set id($row,0) $wordgraph 00800 } 00801 } 00802 00803 set selectedWordgraphs "" 00804 foreach index [array names id] { 00805 lappend selectedWordgraphs $id($index) 00806 } 00807 00808 return $selectedWordgraphs 00809 } 00810 00811 ## ---------------------------------------------------------------------------- 00812 ## _getDoneWork 00813 ## ---------------------------------------------------------------------------- 00814 body YadaRunnableDocument::_getDoneWork {} { 00815 00816 set result "" 00817 00818 foreach wordgraph [array names _doneWordgraph] { 00819 if {$_doneWordgraph($wordgraph) != 0} { 00820 lappend result $wordgraph 00821 } 00822 } 00823 00824 return $result 00825 } 00826 00827 ## ---------------------------------------------------------------------------- 00828 ## _getUndoneWork 00829 ## ---------------------------------------------------------------------------- 00830 body YadaRunnableDocument::_getUndoneWork {} { 00831 set result "" 00832 00833 foreach wordgraph [array names _doneWordgraph] { 00834 if {$_doneWordgraph($wordgraph) == 0} { 00835 lappend result $wordgraph 00836 } 00837 } 00838 00839 return $result 00840 } 00841 00842 ## ---------------------------------------------------------------------------- 00843 ## unmarkWordgraph 00844 ## ---------------------------------------------------------------------------- 00845 body YadaRunnableDocument::unmarkWordgraph {wordgraph} { 00846 _computeStatistics 00847 set table $itk_component(table) 00848 set cmax [$table cget -cols] 00849 set rmax [$table cget -rows] 00850 00851 set row [_getRowOfWordgraph $wordgraph] 00852 $table clear tags $row,0 00853 } 00854 00855 ## ---------------------------------------------------------------------------- 00856 ## markWordgraph 00857 ## ---------------------------------------------------------------------------- 00858 body YadaRunnableDocument::markWordgraph {wordgraph} { 00859 _computeStatistics 00860 if {$wordgraph == ""} { 00861 return 00862 } 00863 00864 set table $itk_component(table) 00865 set cmax [$table cget -cols] 00866 set rmax [$table cget -rows] 00867 00868 # indicate running wordgraph 00869 set row [_getRowOfWordgraph $wordgraph] 00870 $table tag cell runner $row,0 00871 00872 # clear the log window 00873 if {$_clearLogFlag} { 00874 $itk_component(log) clear 00875 } 00876 00877 # scroll to the current wordgraph 00878 if {$_followDataFlag} { 00879 $table see $row,1 00880 } 00881 00882 # possibly remove the given wordgraph from the selection 00883 $table selection clear $row,0 $row,$cmax 00884 } 00885 00886 00887 ## ---------------------------------------------------------------------------- 00888 ## print 00889 ## ---------------------------------------------------------------------------- 00890 body YadaRunnableDocument::print {message} { 00891 $itk_component(log) print $message 00892 } 00893 00894 ## ---------------------------------------------------------------------------- 00895 ## loadUpdatedWordgraphs 00896 ## 00897 ## ---------------------------------------------------------------------------- 00898 body YadaRunnableDocument::loadUpdatedWordgraphs {args} { 00899 set experimentName [$selectedExperiment cget -name] ;#[$itk_component(experimentBox) get] 00900 set experiment [.main getExperiment $experimentName] 00901 00902 # reset scores of selected wordgraphs 00903 if {[llength $args] == 0} { 00904 set activeWordgraphs [_getActiveWordgraphs] 00905 } else { 00906 set activeWordgraphs $args 00907 } 00908 _resetDataOf "$activeWordgraphs" 00909 00910 # load all xml files 00911 set noLoadedFiles 0 00912 foreach wordgraph $activeWordgraphs { 00913 00914 # check if the file is present 00915 set file [$experiment getXmlFileName $wordgraph] 00916 if {![file exists $file]} { 00917 set _doneWordgraph($wordgraph) 0 00918 continue 00919 } 00920 #puts "** Load wordgraph $wordgraph from $wordgraph.xml.gz **" 00921 set _doneWordgraph($wordgraph) 1 00922 00923 # say what we do 00924 print "INFO: loading `$file'\n" 00925 00926 # analyse the file 00927 set fd [open "|zcat $file" r] 00928 set data [read $fd] 00929 close $fd 00930 if {[catch { 00931 set document [dom parse $data] 00932 _analyseDocument $document $experiment 00933 } errMsg]} { 00934 print "ERROR: invalid xml file\n" 00935 print "$errMsg\n$::errorInfo" 00936 } 00937 catch { 00938 $document delete 00939 set document "" 00940 } 00941 00942 incr noLoadedFiles 00943 update 00944 } 00945 00946 print "INFO: loaded $noLoadedFiles files\n" 00947 resortRows 00948 #_computeStatistics 00949 .main printStatus "" 00950 } 00951 00952 ## ---------------------------------------------------------------------------- 00953 ## _getActiveWordgraphs 00954 ## ---------------------------------------------------------------------------- 00955 body YadaRunnableDocument::_getActiveWordgraphs {} { 00956 00957 set wordgraphs [lsort -dictionary [_getSelectedWork]] 00958 if {$wordgraphs == ""} { 00959 set wordgraphs [lsort -dictionary [_getUndoneWork]] 00960 if {$wordgraphs == ""} { 00961 set wordgraphs [lsort -dictionary [_getWordgraphs]] 00962 } else { 00963 } 00964 } 00965 00966 return $wordgraphs 00967 } 00968 00969 ## ---------------------------------------------------------------------------- 00970 ## _insertData 00971 ## ---------------------------------------------------------------------------- 00972 body YadaRunnableDocument::_insertData {wordgraph args} { 00973 set table $itk_component(table) 00974 set cmax [$table cget -cols] 00975 00976 # get place where we belong to 00977 set row [_getRowOfWordgraph $wordgraph] 00978 00979 # fill it 00980 $table clear tags $row,1 $row,$cmax 00981 $table erase $row,1 $row,$cmax 00982 $table setCell row $row,1 $args 00983 00984 00985 # show it 00986 if {$_followDataFlag} { 00987 $table see $row,1 00988 } 00989 } 00990 00991 ## ---------------------------------------------------------------------------- 00992 ## resortRows 00993 ## ---------------------------------------------------------------------------- 00994 body YadaRunnableDocument::resortRows {} { 00995 if {$_lastSorting != ""} { 00996 eval sortRows $_lastSorting 00997 } 00998 } 00999 01000 ## ---------------------------------------------------------------------------- 01001 ## sortRows 01002 ## ---------------------------------------------------------------------------- 01003 body YadaRunnableDocument::sortRows {colNo args} { 01004 set type [_getTypeOfColumn $colNo] 01005 eval $itk_component(table) sortRows $colNo -$type $args 01006 set _lastSorting $colNo 01007 eval lappend _lastSorting $args 01008 } 01009 01010 ## ---------------------------------------------------------------------------- 01011 ## compute the estimated time of arrival. 01012 ## This method tries to compute the left duration of given number of jobs 01013 ## that might run on a YadaMachine. This is done by querying the time-per-job 01014 ## statistics via YadaMachine::getTimePerJob(). This figure is being tracked 01015 ## by the YadaMachine itself and might change the more YadaJobs are executed 01016 ## by that machine. 01017 ## \param machine the YadaMachine which we are interested in 01018 ## \param noJobs the number of jobs that we still need to do 01019 ## \returns the estimation 01020 ## ---------------------------------------------------------------------------- 01021 body YadaRunnableDocument::_computeETA {machine noJobs} { 01022 01023 set timePerJob [$machine getTimePerJob] 01024 set noCpus [$machine cget -cpus] 01025 01026 return [expr round($noJobs * $timePerJob / (0.0 + $noCpus))] 01027 } 01028 01029 01030 ## ---------------------------------------------------------------------------- 01031 ## analyse a given DomDocument produced with the help of a YadaExperiment. 01032 ## This method extracts all the information that we normaly are interested in 01033 ## in runnable documents. Classes (like YadaGlsStats) overload this function and 01034 ## extract extra information not analysed here. So as a sideeffect the resulting 01035 ## data is stored into the protected variable _analyseResult as documented 01036 ## above. In some cases where the DomDocument is illformed we still try to 01037 ## extract as many information as possible. In case of any error you will notice 01038 ## that by a return code of 0. Error messages are give by print(). 01039 ## The \a experiment is consulted especialy when no evaluation data is contained in 01040 ## the \a document in order to get the number of tries in the statistics correctly 01041 ## an which is only provided by the used CDG grammar, especialy the contained 01042 ## annotation of the lattice. 01043 ## \param document the DomDocument resulting from a dom parse 01044 ## \param experiment the experiment with which we produced this document 01045 ## ---------------------------------------------------------------------------- 01046 body YadaRunnableDocument::_analyseDocument {document experiment} { 01047 01048 # initialize the _analyseResult 01049 if {[info exists _analyseResult]} { 01050 unset _analyseResult 01051 } 01052 array set _analyseResult { 01053 wordgraph "" 01054 noValues 0 01055 score 0.0 01056 totalTime 0 01057 solutionTime 0 01058 softTime 0 01059 tries 0 01060 structHits 0 01061 labelledHits 0 01062 lexicalHits 0 01063 strictHits 0 01064 } 01065 01066 set isOk 1 01067 01068 # get the root element 01069 set cdgpNode [$document documentElement] 01070 if {$cdgpNode == ""} { 01071 print "ERROR: no cdgp logfile\n" 01072 return 0 01073 } 01074 01075 # xpath analysis 01076 01077 # get number of values 01078 set _analyseResult(noValues) [[$cdgpNode selectNodes \ 01079 {descendant::netInfo[1]/number[@name="noValues"]}] @value ] 01080 01081 # get name of wordgraph 01082 set _analyseResult(wordgraph) [[$cdgpNode selectNodes \ 01083 {descendant::netInfo[1]/ref[@type="Lattice"]}] @name ] 01084 if {$_analyseResult(wordgraph) == ""} { 01085 print "ERROR: no net information found => newnet failed" 01086 return 0 01087 } 01088 01089 # get the score 01090 set _analyseResult(score) [[$cdgpNode selectNodes \ 01091 {descendant::parse[1]/number[@name="score"]}] @value] 01092 if {$_analyseResult(score) == ""} { 01093 set _analyseResult(score) 0.0 01094 } 01095 01096 # get the parse verification node 01097 set parseVerificationNode [$cdgpNode descendant 1 "parseverification"] 01098 if {$parseVerificationNode != ""} { 01099 foreach aspect {tries structHits labelledHits lexicalHits strictHits} { 01100 set _analyseResult($aspect) [[$parseVerificationNode selectNodes \ 01101 descendant::[string tolower $aspect]/number\[@name="SYN"\]] @value] 01102 } 01103 } else { 01104 # verification fallback: compute tries from annotation 01105 set isOk 0 01106 print "ERROR: no parse verification found\n" 01107 print "INFO: consulting annotation\n" 01108 set grammar [.main getGrammarOfExperiment [$experiment cget -name]] 01109 $grammar scan; # CAUTION: might be costy 01110 set yadaWordgraph [$grammar getWordgraph $_analyseResult(wordgraph)] 01111 set _analyseResult(tries) [$yadaWordgraph cget -noAnnoEdges] 01112 if {$_analyseResult(tries) == 0} { 01113 print "ERROR: no correct annotation for wordgraph '$_analyseResult(wordgraph)'" 01114 } 01115 } 01116 01117 # parse the statistics 01118 foreach aspect {totalTime solutionTime softTime} { 01119 catch {set _analyseResult($aspect) [[$cdgpNode selectNodes \ 01120 descendant::statistics/number\[@name="$aspect"\]] @value ]} 01121 if {$_analyseResult($aspect) == ""} { 01122 set _analyseResult($aspect) 0 01123 } 01124 } 01125 01126 # end of xpath analysis 01127 01128 # fix solution and soft time in case of no score 01129 if {$_analyseResult(softTime) == 0} { 01130 set _analyseResult(softTime) $_analyseResult(solutionTime) 01131 } 01132 if {$_analyseResult(solutionTime) == 0} { 01133 set _analyseResult(softTime) $_analyseResult(totalTime) 01134 set _analyseResult(solutionTime) $_analyseResult(totalTime) 01135 } 01136 01137 return $isOk 01138 } 01139 01140 01141 ## ---------------------------------------------------------------------------- 01142 ## step 01143 ## ---------------------------------------------------------------------------- 01144 body YadaRunnableDocument::step {{wordgraph ""}} { 01145 01146 if {$wordgraph == ""} { 01147 set wordgraph [lindex [_getActiveWordgraphs] 0] 01148 if {$wordgraph == ""} { 01149 return 0 01150 } 01151 } 01152 01153 # get the current experiment 01154 set experiment [_getSelectedExperiment] 01155 if {$experiment == ""} { 01156 return 1 01157 } 01158 01159 # check if the job was already done 01160 set file [$experiment getXmlFileName $wordgraph] 01161 if {[file exists $file]} { 01162 loadUpdatedWordgraphs $wordgraph 01163 _computeStatistics 01164 return 01165 } 01166 01167 # construct a job 01168 set machine [.main getMachine [$experiment cget -machineName]] 01169 set job [YadaJob ::#auto \ 01170 -wordgraphName $wordgraph \ 01171 -experiment $experiment \ 01172 -runner $this \ 01173 -machine $machine \ 01174 -consumerCommand [code $this _jobConsumer]] 01175 _registerJob $job 01176 $machine queueJob $job 01177 01178 # start the job 01179 $machine startJob 01180 01181 # wait 01182 set _isRunning 1 01183 while {$_isRunning} { 01184 vwait [scope _isRunning] 01185 } 01186 01187 # finish message 01188 if {$_gotBreak} { 01189 printMessage "interrupted job(s)" 01190 unbreakJob 01191 } else { 01192 printMessage "finished job(s)" 01193 } 01194 01195 return 1 01196 } 01197 01198 ## ---------------------------------------------------------------------------- 01199 ## run 01200 ## ---------------------------------------------------------------------------- 01201 body YadaRunnableDocument::run {{experiment ""}} { 01202 01203 # get the current experiment 01204 if {$experiment == ""} { 01205 set experiment [_getSelectedExperiment] 01206 if {$experiment == ""} { 01207 return 1 01208 } 01209 } else { 01210 selectExperiment [$experiment cget -name] 01211 } 01212 01213 # check and load 01214 .main printStatus "... checking experiment '[$experiment cget -name]'" 01215 $experiment check 01216 loadUpdatedWordgraphs 01217 _computeStatistics 01218 if {[$experiment cget -isComplete]} { 01219 return 01220 } 01221 01222 # construct all jobs 01223 set machine [.main getMachine [$experiment cget -machineName]] 01224 foreach wordgraph [_getActiveWordgraphs] { 01225 set job [YadaJob ::#auto \ 01226 -wordgraphName $wordgraph \ 01227 -experiment $experiment \ 01228 -runner $this \ 01229 -machine $machine \ 01230 -consumerCommand [code $this _jobConsumer]] 01231 $machine queueJob $job 01232 _registerJob $job 01233 } 01234 01235 $machine startJob 01236 01237 # wait 01238 set _isRunning 1 01239 while {$_isRunning} { 01240 vwait [scope _isRunning] 01241 } 01242 01243 # finish message 01244 if {$_gotBreak} { 01245 printMessage "interrupted job(s)" 01246 unbreakJob 01247 } else { 01248 printMessage "finished job(s)" 01249 } 01250 } 01251 01252 ## ---------------------------------------------------------------------------- 01253 ## runall 01254 ## ---------------------------------------------------------------------------- 01255 body YadaRunnableDocument::runall {} { 01256 set experimentNames [[$itk_component(experimentBox) component list] get 0 end] 01257 01258 # construct possible jobs 01259 set experiments "" 01260 foreach experimentName $experimentNames { 01261 set experiment [.main getExperiment $experimentName] 01262 if {$experimentName == "<none>" || 01263 $experimentName == "" || 01264 ![$experiment cget -isActive]} { 01265 continue 01266 } 01267 01268 # force experiment checking 01269 .main printStatus "... checking experiment `$experimentName'" 01270 if {[$experiment check]} { 01271 continue ;# is complete 01272 } 01273 01274 # construct jobs 01275 set noJobs 0 01276 set grammar [.main getGrammar [$experiment cget -grammarName]] 01277 set machine [.main getMachine [$experiment cget -machineName]] 01278 foreach wordgraph [$grammar getSelection] { 01279 set xmlFile [$experiment getXmlFileName $wordgraph] 01280 # dont recompute existing data 01281 if {[file exists $xmlFile]} { 01282 continue 01283 } 01284 01285 set job [YadaJob ::#auto \ 01286 -wordgraphName $wordgraph \ 01287 -experiment $experiment \ 01288 -runner $this \ 01289 -machine $machine \ 01290 -consumerCommand [code $this _jobConsumer]] 01291 _registerJob $job 01292 incr noJobs 01293 } 01294 if {$noJobs > 0} { 01295 lappend experiments $experiment 01296 print "INFO: $experimentName needs $noJobs jobs\n" 01297 } 01298 } 01299 01300 if {[llength $experiments] == 0} { 01301 printMessage "no jobs need to be done" 01302 return 01303 } 01304 01305 01306 # confirm batch of jobs 01307 if {![askRunall]} { 01308 foreach experiment [array names _currentJobs] { 01309 catch { 01310 foreach job $_currentJobs($experiment) { 01311 _unregisterJob $job 01312 itcl::delete object $job 01313 update ;# this loop could be time consuming 01314 } 01315 } 01316 } 01317 _computeStatistics 01318 return 01319 } 01320 01321 # do it 01322 set _timer [clock seconds] 01323 foreach experiment $experiments { 01324 01325 # select experiment 01326 selectExperiment [$experiment cget -name] 01327 loadUpdatedWordgraphs 01328 _computeStatistics 01329 if {[$experiment cget -isComplete]} { 01330 foreach job $_currentJobs($experiment) { 01331 _unregisterJob $job 01332 itcl::delete object $job 01333 } 01334 _computeStatistics 01335 continue 01336 } 01337 01338 # queue jobs of the current experiment 01339 foreach job $_currentJobs($experiment) { 01340 set machine [$job cget -machine] 01341 $machine queueJob $job 01342 } 01343 01344 # start 01345 $machine startJob 01346 01347 # wait 01348 set _isRunning 1 01349 while {$_isRunning} { 01350 vwait [scope _isRunning] 01351 } 01352 01353 # escape 01354 if {$_gotBreak} { 01355 break 01356 } 01357 } 01358 01359 # finish message 01360 if {$_gotBreak} { 01361 printMessage "interrupted job(s)" 01362 unbreakJob 01363 } else { 01364 printMessage "finished job(s)" 01365 } 01366 01367 } 01368 01369 01370 ## ---------------------------------------------------------------------------- 01371 ## _jobConsumer 01372 ## ---------------------------------------------------------------------------- 01373 body YadaRunnableDocument::_jobConsumer {job} { 01374 $job setState "consuming" 01375 set wordgraph [$job cget -wordgraphName] 01376 set experiment [$job cget -experiment] 01377 set machine [$job cget -machine] 01378 01379 # analyse the new data 01380 set xmlFile [$experiment getXmlFileName $wordgraph] 01381 print "INFO: loading `$xmlFile'\n" 01382 set fd [open "|zcat $xmlFile" r] 01383 set data [read $fd] 01384 close $fd 01385 01386 if {[catch { 01387 set document [dom parse $data] 01388 _analyseDocument $document $experiment 01389 } errMsg ]} { 01390 print "ERROR: invalid xml file\n" 01391 print "$errMsg\n$::errorInfo" 01392 } 01393 catch { 01394 $document delete 01395 set document "" 01396 } 01397 01398 # remove the job from the list of current once 01399 _unregisterJob $job 01400 $machine stopJob $job 01401 01402 # refresh the statistics 01403 unmarkWordgraph $wordgraph 01404 set _doneWordgraph($wordgraph) 1 01405 01406 # start a new job 01407 if {!$_gotBreak} { 01408 if {[$machine startJob]} { 01409 return 01410 } 01411 } 01412 01413 # detect finish 01414 if {$_isRunning} { 01415 if {![info exists _currentJobs($experiment)] || 01416 [llength $_currentJobs($experiment)] == 0} { 01417 set _isRunning 0 ;# signal vwait 01418 } 01419 } 01420 } 01421 01422 ## ---------------------------------------------------------------------------- 01423 ## _registerJob 01424 ## ---------------------------------------------------------------------------- 01425 body YadaRunnableDocument::_registerJob {job} { 01426 set experiment [$job cget -experiment] 01427 lappend _currentJobs($experiment) $job 01428 } 01429 01430 ## ---------------------------------------------------------------------------- 01431 ## _unregisterJob 01432 ## ---------------------------------------------------------------------------- 01433 body YadaRunnableDocument::_unregisterJob {job} { 01434 01435 set experiment [$job cget -experiment] 01436 if {![info exists _currentJobs($experiment)]} { 01437 return 01438 } 01439 set index [lsearch -exact $_currentJobs($experiment) $job] 01440 if {$index >= 0} { 01441 set _currentJobs($experiment) "[lreplace $_currentJobs($experiment) $index $index]" 01442 if {$_currentJobs($experiment) == ""} { 01443 unset _currentJobs($experiment) 01444 } 01445 } 01446 } 01447 01448 ## ---------------------------------------------------------------------------- 01449 ## askRunall 01450 ## ---------------------------------------------------------------------------- 01451 body YadaRunnableDocument::askRunall {} { 01452 set experiments [array names _currentJobs] 01453 set noExperiments [llength $experiments] 01454 if {$noExperiments == 0} { 01455 return 0 01456 } 01457 01458 # estimate job 01459 set eta 0 01460 set noJobs 0 01461 foreach experiment $experiments { 01462 set machine [.main getMachine [$experiment cget -machineName]] 01463 set noExperimentJobs [llength $_currentJobs($experiment)] 01464 incr noJobs $noExperimentJobs 01465 set eta [expr $eta + [_computeETA $machine $noExperimentJobs]] 01466 } 01467 set etaString [timeToString $eta] 01468 01469 # display dialog 01470 set msg [iwidgets::messagedialog .msg \ 01471 -text \ 01472 "Are you sure that you want to compute 01473 $noJobs jobs in $noExperiments experiments(s)? 01474 This will be a job of ca. $etaString!" \ 01475 -title "Yada - Question" \ 01476 -image [YadaImages::get question] \ 01477 -modality application \ 01478 -master $itk_interior] 01479 01480 $msg buttonconfigure OK -text "Yes" 01481 $msg buttonconfigure Cancel -text "No" 01482 $msg center . 01483 01484 set result [$msg activate] 01485 01486 destroy $msg 01487 if {!$result} { 01488 return 0 01489 } 01490 01491 return 1 01492 } 01493 01494 ## ---------------------------------------------------------------------------- 01495 ## selectExperiment 01496 ## ---------------------------------------------------------------------------- 01497 body YadaRunnableDocument::selectExperiment {{experimentName ""}} { 01498 set box $itk_component(experimentBox) 01499 if {$experimentName == ""} { 01500 set experimentName [$box get] 01501 if {$experimentName == ""} { 01502 set experimentName "<none>" 01503 } 01504 } 01505 01506 set listOfEntries [[$box component list] get 0 end] 01507 set index [lsearch $listOfEntries $experimentName] 01508 01509 if {$index < 0} { 01510 selectExperiment "<none>" 01511 } else { 01512 $box clear entry 01513 $box insert entry 0 "$experimentName" 01514 $box selection set $index $index 01515 foreach wordgraph [array names _doneWordgraph] { 01516 unset _doneWordgraph($wordgraph) 01517 } 01518 clear 01519 } 01520 01521 set selectedExperiment [_getSelectedExperiment] 01522 01523 ## Set initial modification time to react to concurrent file changes 01524 if { [hasSavedState] } { 01525 updateModificationTime 01526 } 01527 displayTitle 01528 } 01529 01530 ## ---------------------------------------------------------------------------- 01531 ## _showContextMenu 01532 ## ---------------------------------------------------------------------------- 01533 body YadaRunnableDocument::_showContextMenu {x y xroot yroot} { 01534 set _selectedContextWordgraph [$itk_component(table) getCell @0,$y] 01535 if {$_selectedContextWordgraph == ""} { 01536 return 01537 } 01538 01539 tk_popup $itk_component(contextMenu) $xroot $yroot 01540 } 01541 01542 ## ---------------------------------------------------------------------------- 01543 ## display logfile of a experiment. 01544 ## This method reads the logfiles of one or more experiments given a selected wordgraph 01545 ## in _selectedContextWordgraph. 01546 ## \param experiments the optional list of experiments that we want to display. if the 01547 ## list is empty the we fetch the currently selected experiments via _getSelectedExperiment(). 01548 ## ---------------------------------------------------------------------------- 01549 body YadaRunnableDocument::_viewLogfile {{experiments ""}} { 01550 01551 if {$_selectedContextWordgraph == ""} { 01552 return 01553 } 01554 01555 if {[llength $experiments] == 0} { 01556 lappend experiments [_getSelectedExperiment] 01557 if {[llength $experiments] == 0} { 01558 return 01559 } 01560 } 01561 01562 if {!$_consoleFlag} { 01563 setToggle "console" 1 01564 } 01565 01566 # read computed data of all experiments 01567 $itk_component(log) clear 01568 foreach experiment $experiments { 01569 set fileName [$experiment getLogFileName $_selectedContextWordgraph] 01570 print "INFO: reading $fileName\n" 01571 if {![file exists $fileName]} { 01572 printMessage "File not found!" "error" 01573 return 01574 } 01575 01576 # read 01577 set fd [open "|zcat $fileName" r] 01578 set data [read $fd] 01579 close $fd 01580 01581 # print 01582 print $data 01583 } 01584 $itk_component(log) see end 01585 01586 set _selectedContextWordgraph "" 01587 } 01588 01589 ## ---------------------------------------------------------------------------- 01590 ## _viewXmlfile 01591 ## ---------------------------------------------------------------------------- 01592 body YadaRunnableDocument::_viewXmlfile {{experiments ""}} { 01593 01594 if {$_selectedContextWordgraph == ""} { 01595 return 01596 } 01597 01598 if {[llength $experiments] == 0} { 01599 lappend experiments [_getSelectedExperiment] 01600 if {[llength $experiments] == 0} { 01601 return 01602 } 01603 } 01604 01605 if {!$_consoleFlag} { 01606 setToggle "console" 1 01607 } 01608 01609 # read computed data of all experiments 01610 $itk_component(log) clear 01611 foreach experiment $experiments { 01612 set fileName [$experiment getXmlFileName $_selectedContextWordgraph] 01613 print "INFO: reading $fileName\n" 01614 if {![file exists $fileName]} { 01615 printMessage "File not found!" "error" 01616 return 01617 } 01618 01619 # read 01620 set fd [open "|zcat $fileName" r] 01621 set data [read $fd] 01622 close $fd 01623 01624 # print 01625 print $data 01626 } 01627 $itk_component(log) see end 01628 01629 set _selectedContextWordgraph "" 01630 } 01631 01632 01633 ## ---------------------------------------------------------------------------- 01634 ## _clearRow 01635 ## ---------------------------------------------------------------------------- 01636 body YadaRunnableDocument::_clearRow {} { 01637 01638 set row [_getRowOfWordgraph $_selectedContextWordgraph] 01639 set table $itk_component(table) 01640 set cmax [$table cget -cols] 01641 $table clear tags $row,1 $row,$cmax 01642 $table erase $row,1 $row,$cmax 01643 01644 set _selectedContextWordgraph "" 01645 } 01646 01647 ## ---------------------------------------------------------------------------- 01648 ## _traceProcess 01649 ## ---------------------------------------------------------------------------- 01650 body YadaRunnableDocument::_traceProcess {} { 01651 01652 # check for activity 01653 set row [_getRowOfWordgraph $_selectedContextWordgraph] 01654 if {![$itk_component(table) tag includes runner $row,0]} { 01655 _viewLogfile 01656 return 01657 } 01658 01659 # search job of selected wordgraph 01660 set found 0 01661 set experiment [_getSelectedExperiment] 01662 foreach job $_currentJobs($experiment) { 01663 if {[$job cget -wordgraphName] == $_selectedContextWordgraph} { 01664 set found 1 01665 break; 01666 } 01667 } 01668 if {!$found} { 01669 print "ERROR: wordgraph $wordgraphName not found for [$experiment cget -name]\n" 01670 return 01671 } 01672 01673 # get the corresponding process 01674 set process [$job cget -process] 01675 01676 if {$process != ""} { 01677 01678 # switch off the last progess 01679 if {$_progressProcess != ""} { 01680 if {[info commands $_progressProcess] != ""} { 01681 set oldJob [$_progressProcess cget -job] 01682 print "INFO: switching off trace of [$oldJob cget -wordgraphName]\n" 01683 $_progressProcess configure -showProgress 0 01684 } else { 01685 } 01686 } 01687 01688 # switch on new trace 01689 if {$_progressProcess != $process} { 01690 set _progressProcess $process 01691 set experiment [$job cget -experiment] 01692 set logFile [$experiment getLogFileName $_selectedContextWordgraph] 01693 regsub {^(.*)\.gz$} $logFile {\1} clearLogFile 01694 set fd [open "$clearLogFile" r] 01695 set buffer [read $fd] 01696 close $fd 01697 $itk_component(log) clear 01698 print "$buffer\n" 01699 $process configure -showProgress 1 01700 print "INFO: switching on trace of [$job cget -wordgraphName]\n" 01701 } else { 01702 set _progressProcess "" 01703 } 01704 } 01705 01706 set _selectedContextWordgraph "" 01707 } 01708 01709 ## ---------------------------------------------------------------------------- 01710 ## _deleteData 01711 ## ---------------------------------------------------------------------------- 01712 body YadaRunnableDocument::_deleteData {} { 01713 01714 # check 01715 set experiment [_getSelectedExperiment] 01716 if {$experiment == ""} { 01717 return 01718 } 01719 01720 # are there files available 01721 set fileNames "" 01722 set fileName [$experiment getLogFileName $_selectedContextWordgraph] 01723 if {[file exists $fileName]} { 01724 lappend fileNames $fileName 01725 } 01726 set fileName [$experiment getXmlFileName $_selectedContextWordgraph] 01727 if {[file exists $fileName]} { 01728 lappend fileNames $fileName 01729 } 01730 01731 if {[llength $fileNames] == 0} { 01732 printMessage "File not found, nothing to delete!" "error" 01733 return 01734 } 01735 01736 # ask for confirmation 01737 set msg [iwidgets::messagedialog .msg \ 01738 -text \ 01739 "Are you sure that you want to delete 01740 [join $fileNames \ and\ \n] ?" \ 01741 -title "Yada - Question" \ 01742 -image [YadaImages::get question] \ 01743 -modality application \ 01744 -master $itk_interior] 01745 01746 $msg buttonconfigure OK -text "Yes" 01747 $msg buttonconfigure Cancel -text "No" 01748 $msg center . 01749 01750 set result [$msg activate] 01751 01752 destroy $msg 01753 if {!$result} { 01754 return 0 01755 } 01756 01757 foreach fileName $fileNames { 01758 file delete $fileName 01759 } 01760 } 01761 01762 ## ---------------------------------------------------------------------------- 01763 ## setToggle 01764 ## ---------------------------------------------------------------------------- 01765 body YadaRunnableDocument::setToggle {name {value ""}} { 01766 switch $name { 01767 "table" { 01768 if {$value == 0 || $value == 1} { 01769 set _tableFlag $value 01770 } 01771 if {$_tableFlag} { 01772 $itk_component(pane) show 0 01773 if {$_consoleFlag} { 01774 $itk_component(pane) fraction 80 20 01775 } 01776 } else { 01777 $itk_component(pane) hide 0 01778 } 01779 return $_tableFlag 01780 } 01781 "console" { 01782 if {$value == 0 || $value == 1} { 01783 set _consoleFlag $value 01784 } 01785 if {$_consoleFlag} { 01786 $itk_component(pane) show 1 01787 if {$_tableFlag} { 01788 $itk_component(pane) fraction 80 20 01789 } 01790 } else { 01791 $itk_component(pane) hide 1 01792 } 01793 return $_consoleFlag 01794 } 01795 "follow" { 01796 if {$value == 0 || $value == 1} { 01797 set _followDataFlag $value 01798 } 01799 $itk_component(log) configure -followData $_followDataFlag 01800 return $_followDataFlag 01801 } 01802 "clear" { 01803 if {$value == 0 || $value == 1} { 01804 set _clearLogFlag $value 01805 } 01806 } 01807 "orientation" { 01808 if {$value == "horizontal" || $value == "vertical"} { 01809 set _orientFlag $value 01810 } 01811 if {$_orientFlag == "horizontal"} { 01812 $itk_component(pane) configure \ 01813 -orient $_orientFlag \ 01814 -sashheight 8 -sashwidth 18 01815 } else { 01816 $itk_component(pane) configure \ 01817 -orient $_orientFlag \ 01818 -sashheight 18 -sashwidth 8 01819 } 01820 } 01821 default { 01822 return [chain $name $value] 01823 } 01824 } 01825 } 01826 01827 ## ---------------------------------------------------------------------------- 01828 ## _resetDataOf 01829 ## ---------------------------------------------------------------------------- 01830 body YadaRunnableDocument::_resetDataOf {wordgraphs} { 01831 foreach wordgraph $wordgraphs { 01832 set _doneWordgraph($wordgraph) 0 01833 } 01834 } 01835 01836 01837 ## ---------------------------------------------------------------------------- 01838 ## Returns wordgraph file name for selected experiment 01839 ## ---------------------------------------------------------------------------- 01840 body YadaRunnableDocument::_getXMLFileName { wordgraph } { 01841 01842 set experimentName [$itk_component(experimentBox) get] 01843 set experiment [.main getExperiment $experimentName] 01844 01845 return [$experiment getXmlFileName $wordgraph] 01846 01847 } 01848 01849 01850 ## ---------------------------------------------------------------------------- 01851 ## Overridden method 01852 ## ---------------------------------------------------------------------------- 01853 body YadaRunnableDocument::save {} { 01854 chain 01855 print "INFO: Save document to `[getPersistanceFileName]'\n" 01856 }

YADA 2.0-alpha (20 Oct 2004)