23
23
24
24
#if openPMD_HAVE_ADIOS1
25
25
26
+ #include " openPMD/auxiliary/JSON.hpp"
27
+ #include " openPMD/Error.hpp"
26
28
#include " openPMD/IO/ADIOS/ADIOS1IOHandlerImpl.hpp"
27
29
#include " openPMD/IO/ADIOS/ParallelADIOS1IOHandlerImpl.hpp"
28
30
@@ -468,6 +470,33 @@ CommonADIOS1IOHandlerImpl< ChildClass >::createPath(Writable* writable,
468
470
}
469
471
}
470
472
473
+ static auxiliary::Option< std::string > datasetTransform (
474
+ json::TracingJSON config )
475
+ {
476
+ using ret_t = auxiliary::Option< std::string >;
477
+ if ( !config.json ().contains ( " dataset" ) )
478
+ {
479
+ return ret_t {};
480
+ }
481
+ config = config[ " dataset" ];
482
+ if ( !config.json ().contains ( " transform" ) )
483
+ {
484
+ return ret_t {};
485
+ }
486
+ config = config[ " transform" ];
487
+ auto maybeRes = json::asStringDynamic ( config.json () );
488
+ if ( maybeRes.has_value () )
489
+ {
490
+ return std::move ( maybeRes.get () );
491
+ }
492
+ else
493
+ {
494
+ throw error::BackendConfigSchema (
495
+ { " adios1" , " dataset" , " transform" },
496
+ " Key must convertible to type string." );
497
+ }
498
+ }
499
+
471
500
template < typename ChildClass >
472
501
void
473
502
CommonADIOS1IOHandlerImpl< ChildClass >::createDataset(Writable* writable,
@@ -521,7 +550,31 @@ CommonADIOS1IOHandlerImpl< ChildClass >::createDataset(Writable* writable,
521
550
chunkOffsetParam.c_str ());
522
551
VERIFY (id != 0 , " [ADIOS1] Internal error: Failed to define ADIOS variable during Dataset creation" );
523
552
524
- std::string transform = " " ; // @todo read from JSON
553
+ std::string transform = " " ;
554
+ {
555
+ json::TracingJSON options =
556
+ json::parseOptions ( parameters.options );
557
+ auto maybeTransform = datasetTransform ( options );
558
+ if ( maybeTransform.has_value () )
559
+ {
560
+ transform = maybeTransform.get ();
561
+ }
562
+
563
+ auto shadow = options.invertShadow ();
564
+ if ( shadow .size () > 0 )
565
+ {
566
+ std::cerr << " Warning: parts of the JSON configuration for "
567
+ " ADIOS1 dataset '"
568
+ << name << " ' remain unused:\n "
569
+ << shadow << std::endl;
570
+ }
571
+ }
572
+ // Fallback: global option
573
+ if ( transform.empty () )
574
+ {
575
+ transform = m_defaultTransform;
576
+ }
577
+
525
578
if ( !transform.empty () )
526
579
{
527
580
int status;
@@ -1700,9 +1753,24 @@ CommonADIOS1IOHandlerImpl< ChildClass >::listAttributes(Writable* writable,
1700
1753
}
1701
1754
}
1702
1755
1756
+ template < typename ChildClass >
1757
+ void CommonADIOS1IOHandlerImpl< ChildClass >::initJson(
1758
+ json::TracingJSON config )
1759
+ {
1760
+ if ( !config.json ().contains ( " adios1" ) )
1761
+ {
1762
+ return ;
1763
+ }
1764
+ auto maybeTransform = datasetTransform ( config[ " adios1" ] );
1765
+ if ( maybeTransform.has_value () )
1766
+ {
1767
+ m_defaultTransform = std::move ( maybeTransform.get () );
1768
+ }
1769
+ }
1770
+
1703
1771
template class CommonADIOS1IOHandlerImpl < ADIOS1IOHandlerImpl >;
1704
1772
#if openPMD_HAVE_MPI
1705
1773
template class CommonADIOS1IOHandlerImpl < ParallelADIOS1IOHandlerImpl >;
1706
1774
#endif // opepnPMD_HAVE_MPI
1707
1775
#endif // openPMD_HAVE_ADIOS1
1708
- }
1776
+ }
0 commit comments