11
11
package cbit .vcell .client ;
12
12
13
13
import java .awt .Dimension ;
14
+ import java .io .BufferedWriter ;
14
15
import java .io .File ;
15
16
import java .io .FileNotFoundException ;
17
+ import java .io .FileWriter ;
16
18
import java .io .IOException ;
17
19
import java .io .InputStream ;
18
20
import java .io .InputStreamReader ;
23
25
import java .util .EventObject ;
24
26
import java .util .Hashtable ;
25
27
import java .util .LinkedHashMap ;
28
+ import java .util .List ;
26
29
import java .util .Vector ;
27
30
28
31
import javax .swing .SwingUtilities ;
54
57
import cbit .vcell .client .desktop .simulation .SimulationWindow .LocalState ;
55
58
import cbit .vcell .client .desktop .simulation .SimulationWorkspace ;
56
59
import cbit .vcell .client .pyvcellproxy .SimulationDataSetRef ;
60
+ import cbit .vcell .client .server .ClientServerManager ;
57
61
import cbit .vcell .client .server .UserPreferences ;
58
62
import cbit .vcell .client .task .AsynchClientTask ;
59
63
import cbit .vcell .client .task .AsynchClientTaskFunction ;
63
67
import cbit .vcell .field .FieldDataIdentifierSpec ;
64
68
import cbit .vcell .mapping .SimulationContext ;
65
69
import cbit .vcell .mapping .SimulationContext .NetworkGenerationRequirements ;
70
+ import cbit .vcell .message .server .bootstrap .client .RemoteProxyVCellConnectionFactory .RemoteProxyException ;
66
71
import cbit .vcell .messaging .server .SimulationTask ;
72
+ import cbit .vcell .parser .ExpressionException ;
67
73
import cbit .vcell .resource .PropertyLoader ;
68
74
import cbit .vcell .resource .ResourceUtil ;
69
75
import cbit .vcell .resource .VCellConfiguration ;
76
+ import cbit .vcell .server .DataSetController ;
70
77
import cbit .vcell .server .SimulationStatus ;
71
78
import cbit .vcell .simdata .DataManager ;
72
79
import cbit .vcell .simdata .DataSetControllerImpl ;
88
95
import cbit .vcell .solver .TempSimulation ;
89
96
import cbit .vcell .solver .VCSimulationDataIdentifier ;
90
97
import cbit .vcell .solver .VCSimulationIdentifier ;
98
+ import cbit .vcell .solver .ode .ODESimData ;
99
+ import cbit .vcell .solver .ode .ODESolverResultSet ;
91
100
import cbit .vcell .solver .server .SimulationMessage ;
92
101
import cbit .vcell .solver .server .Solver ;
93
102
import cbit .vcell .solver .server .SolverEvent ;
94
103
import cbit .vcell .solver .server .SolverFactory ;
95
104
import cbit .vcell .solver .server .SolverListener ;
96
105
import cbit .vcell .solver .server .SolverStatus ;
106
+ import cbit .vcell .util .ColumnDescription ;
97
107
98
108
/**
99
109
* Insert the type's description here.
@@ -287,8 +297,9 @@ private static void saveFailure(Hashtable<String, Object>hashTable,Simulation si
287
297
failures .put (sim , throwable );
288
298
}
289
299
290
- public void importBatchSimulations (OutputContext outputContext , Simulation simulation ) throws java .beans .PropertyVetoException {
300
+ public void getBatchSimulationsResults (OutputContext outputContext , Simulation simulation ) throws java .beans .PropertyVetoException {
291
301
302
+
292
303
293
304
// simulation should be a template simulation
294
305
if (simulation .getName ().contains (SimulationContext .ReservedBatchExtensionString )) {
@@ -305,35 +316,82 @@ public void importBatchSimulations(OutputContext outputContext, Simulation simul
305
316
throw new RuntimeException ("Cannot add simulation, bioModel not set" );
306
317
}
307
318
319
+ File batchResultsDir = ResourceUtil .getLocalBatchDir ();
320
+ // File localSimDir = ResourceUtil.getLocalSimDir(User.tempUser.getName());
321
+
322
+ ArrayList <AsynchClientTask > taskList = new ArrayList <AsynchClientTask >();
323
+ AsynchClientTask retrieveResultsTask = new AsynchClientTask ("Retrieving results" , AsynchClientTask .TASKTYPE_NONSWING_BLOCKING ) {
324
+ public void run (Hashtable <String , Object > hashTable ) throws Exception {
325
+
326
+ // recover the list of batch simulations that belong to this template
327
+ Simulation allSims [] = bioModel .getSimulations ();
328
+ LinkedHashMap <String , String > importsMap = new LinkedHashMap <>();
329
+ LinkedHashMap <String , Boolean > successMap = new LinkedHashMap <>();
330
+ String namePrefix = simulation .getName () + SimulationContext .ReservedBatchExtensionString ;
331
+
332
+ for (Simulation simCandidate : allSims ) {
333
+ if (simCandidate .getName ().startsWith (namePrefix ) && simCandidate .getName ().contains ("_bat_" )) {
334
+
335
+ int pos = simCandidate .getName ().lastIndexOf ("_" );
336
+ String indexName = simCandidate .getName ().substring (pos +1 );
337
+ File currentSimulation = new File (batchResultsDir , indexName + ".txt" );
338
+
339
+ ODESimData simData = null ;
340
+ importsMap .put (simCandidate .getName (), simCandidate .getSimulationID ());
341
+ successMap .put (simCandidate .getName (), true ); // on failure we'll change to false
308
342
309
- // recover the list of batch simulations that belong to this template
310
- Simulation allSims [] = bioModel .getSimulations ();
311
- LinkedHashMap <String , String > importsMap = new LinkedHashMap <>();
312
- String namePrefix = simulation .getName () + SimulationContext .ReservedBatchExtensionString ;
313
- for (Simulation simCandidate : allSims ) {
314
- if (simCandidate .getName ().startsWith (namePrefix )) {
315
- importsMap .put (simCandidate .getName (), simCandidate .getSimulationID ());
316
- System .out .println (simCandidate .getName () + ": " + simCandidate .getSimulationID ());
317
- SwingUtilities .invokeLater (new Runnable () {
318
- public void run () {
319
- // importBatchSimulation(outputContext, simCandidate);
343
+ try {
344
+ simData = importBatchSimulation (outputContext , simCandidate );
345
+ } catch (Exception e ) { // whatever fails, we keep going, this is a batch run
346
+ System .out .println (simCandidate .getName () + ": failed to recover simulation results" );
347
+
348
+ // TODO: also make a report with detailed exception text
349
+ // e.printStackTrace();
350
+ successMap .put (simCandidate .getName (), false );
351
+ }
352
+ if (simData != null ) { // write the file
353
+ // double[] res = osrs.extractColumn(4);
354
+
355
+ StringBuilder sb = new StringBuilder ();
356
+ for (ColumnDescription cd : simData .getDataColumnDescriptions ()) {
357
+ sb .append (cd .getName () + " " );
358
+ }
359
+ sb .append ("\r \n " );
360
+
361
+ for (double [] row : simData .getRows ()) {
362
+ for (double entry : row ) {
363
+ sb .append (entry );
364
+ sb .append (" " );
365
+ }
366
+ sb .append ("\r \n " );
367
+ }
368
+ PrintWriter out = new PrintWriter (currentSimulation );
369
+ out .print (sb .toString ());
370
+ out .flush ();
371
+ out .close ();
372
+ }
320
373
}
321
- });
322
- }
323
- }
324
- // for(String name : importsMap.keySet()) {
325
- // String value = importsMap.get(name);
326
- // SwingUtilities.invokeLater(new Runnable() {
327
- // public void run() {
328
- // // write manifest
374
+ }
375
+
376
+ // for(String name : importsMap.keySet()) {
377
+ // String value = importsMap.get(name);
378
+ // write some manifest?
379
+ // // at least some basic info like the name of the simulation / biomodel / dat file
329
380
// }
330
- // });
331
- // }
381
+ System .out .println ("Done !!!" );
382
+ } // --- end run()
383
+ };
384
+ taskList .add (retrieveResultsTask );
385
+ AsynchClientTask [] taskArray = new AsynchClientTask [taskList .size ()];
386
+ taskList .toArray (taskArray );
387
+ // knowProgress, cancelable, progressDialogListener
388
+ ClientTaskDispatcher .dispatch (documentWindowManager .getComponent (), new Hashtable <String , Object >(), taskArray , false , false , null );
332
389
}
333
- private void importBatchSimulation (OutputContext outputContext , Simulation sim ) {
334
390
335
- File localBatchDir = ResourceUtil .getLocalBatchDir ();
336
- File localSimDir = ResourceUtil .getLocalSimDir (User .tempUser .getName ());
391
+ private ODESimData importBatchSimulation (OutputContext outputContext , Simulation sim ) throws DataAccessException , RemoteProxyException , ExpressionException {
392
+
393
+ boolean success = false ;
394
+ ODESimData simData = null ;
337
395
338
396
if (sim .getVersion () == null ) {
339
397
throw new RuntimeException ("Missing Version." );
@@ -346,10 +404,18 @@ private void importBatchSimulation(OutputContext outputContext, Simulation sim)
346
404
User usr = sim .getVersion ().getOwner ();
347
405
348
406
349
- // VCSimulationIdentifier authoritativeVCSimulationIdentifier = simInfo.getAuthoritativeVCSimulationIdentifier();
350
- // // sim.getScanCount() number of jobs - is 0
351
- // VCSimulationDataIdentifier vcSimulationDataIdentifier = new VCSimulationDataIdentifier(authoritativeVCSimulationIdentifier, 0);
352
- // VCellClientTest.getVCellClient().getClientServerManager().getDataSetController().getODEData(vcSimulationDataIdentifier);
407
+ VCSimulationIdentifier asi = simInfo .getAuthoritativeVCSimulationIdentifier ();
408
+ // sim.getScanCount() number of jobs must be one, so job index is 0
409
+ VCSimulationDataIdentifier vcSimulationDataIdentifier = new VCSimulationDataIdentifier (asi , 0 );
410
+
411
+ ClientServerManager csm = VCellClientTest .getVCellClient ().getClientServerManager ();
412
+ DataSetController dsc = csm .getDataSetController ();
413
+ simData = dsc .getODEData (vcSimulationDataIdentifier );
414
+
415
+ System .out .println (sim .getName () + ": simulation results recovered" );
416
+ return simData ;
417
+
418
+
353
419
354
420
/*
355
421
@@ -393,6 +459,7 @@ private void importBatchSimulation(OutputContext outputContext, Simulation sim)
393
459
}
394
460
395
461
*/
462
+
396
463
}
397
464
398
465
private AsynchClientTask [] showSimulationResults0 (final boolean isLocal , final ViewerType viewerType ) {
0 commit comments