20concept FileNameMap = std::same_as<std::remove_cvref_t<typename T::key_type>, std::string>;
23concept IsOptional = std::same_as<std::remove_cvref_t<T>, std::optional<typename T::value_type>>;
39 for (
auto const& [annotationType, annotationMap] : umbModel.
index.
annotations.value()) {
40 for (
auto const& [annotationName, annotationIndex] : annotationMap) {
41 umbModel.
annotations[annotationType][annotationName];
50template<
typename VecT>
51 requires std::same_as<VecT, std::vector<typename VecT::value_type>>
53 return src.template toVector<typename VecT::value_type>();
56template<
typename VecT>
57 requires std::same_as<VecT, storm::storage::BitVector>
59 return src.template toVector<bool>();
62template<
typename VecT>
67template<
typename VecT>
68 requires(!IsOptional<VecT>)
73template<
typename ValueType>
75 target.template set<ValueType>(
importVector<
typename GenericVector::template Vec<ValueType>>(src));
105 "Type " << type.
toString() <<
" for vector located in '" <<
getFilePath(src) <<
"' is not handled");
112 std::vector<std::string> srcPathVec(srcPath.begin(), srcPath.end());
113 if (srcPath ==
"branch-to-probability.bin") {
115 "Found branch probabilities but no type specified.");
117 }
else if (srcPath ==
"state-to-exit-rate.bin") {
120 }
else if (srcPathVec.size() == 3 && srcPathVec[0] ==
"observations" && srcPathVec[2] ==
"probabilities.bin") {
122 "Found observation probabilities but no type specified.");
128 srcPathVec.size() == 5 && srcPathVec[0] ==
"annotations" && (srcPathVec[4] ==
"values.bin" || srcPathVec[4] ==
"probabilities.bin"),
129 storm::exceptions::WrongFormatException,
130 "Unexpected file path '" << srcPath <<
"'. Expected 'annotations/<annotationType>/<annotationId>/<entity>/[values|probabilities].bin'.");
131 auto annotationMap = index.
annotation(srcPathVec[1]);
132 STORM_LOG_THROW(annotationMap.has_value(), storm::exceptions::WrongFormatException,
133 "Annotation type '" << srcPathVec[1] <<
"' referenced in files but not found in index.");
134 auto annotationIt = annotationMap->find(srcPathVec[2]);
135 STORM_LOG_THROW(annotationIt != annotationMap->end(), storm::exceptions::WrongFormatException,
136 "Annotation id '" << srcPathVec[2] <<
"' for type '" << srcPathVec[1] <<
"' referenced in files but not found in index.");
137 auto const& annotation = annotationIt->second;
138 if (srcPathVec[4] ==
"values.bin") {
142 annotation.probabilityType.has_value(), storm::exceptions::WrongFormatException,
143 "Found probabilities for annotation '" << srcPathVec[2] <<
"' of type '" << srcPathVec[1] <<
"' but no probability type specified.");
150template<
typename UmbStructure>
151 requires HasFileNames<UmbStructure>
153 std::filesystem::path
const& context);
156 std::filesystem::path
const& context) {
158 for (
auto& [key, value] : umbStructure) {
166template<
typename UmbStructure>
167 requires HasFileNames<UmbStructure>
169 std::filesystem::path
const& context) {
170 static_assert(UmbStructure::FileNames.size() == boost::pfr::tuple_size_v<UmbStructure>,
"Number of file names does not match number of fields in struct.");
173 auto containsSrc = [&src](
auto const& other) {
175 auto srcIt = srcPath.begin();
176 for (
auto const& o : other) {
177 if (srcIt == srcPath.end() || (*srcIt != o && !o.empty())) {
186 if (!containsSrc(context)) {
190 boost::pfr::for_each_field(umbStructure, [&](
auto& field, std::size_t fieldIndex) {
191 auto fieldPath = context / std::data(UmbStructure::FileNames)[fieldIndex];
193 if (found || !containsSrc(fieldPath)) {
198 using FieldType = std::remove_cvref_t<
decltype(field)>;
202 if (!field.has_value()) {
205 found =
importVector(src, index, field.value(), fieldPath);
210 STORM_LOG_ASSERT(fieldIndex + 1 == UmbStructure::FileNames.size(),
"The field for non-standard files must be the last field in the struct.");
216 "Unexpected file paths: " << fieldPath <<
" != " <<
getFilePath(src));
218 if constexpr (std::is_same_v<FieldType, GenericVector>) {
220 }
else if constexpr (!std::is_same_v<FieldType, storm::umb::ModelIndex>) {
231 bool indexFound =
false;
233 if (entry.name() ==
"index.json") {
239 STORM_LOG_THROW(indexFound, storm::exceptions::FileIoException,
"File 'index.json' not found in UMB archive.");
244 if (entry.name() ==
"index.json" || entry.isDir()) {
251 "File " <<
getFilePath(entry) <<
" in UMB archive " << umbArchive <<
" could not be matched to any UMB field.");
259 STORM_LOG_THROW(std::filesystem::exists(umbLocation), storm::exceptions::FileIoException,
"The given path '" << umbLocation <<
"' does not exist.");
Object that reads the archive entry.
std::filesystem::path name() const
Get the current entry’s path (filename) inside the archive.
Represents a model in the UMB format.
std::map< std::filesystem::path, std::vector< char > > nonStandardFiles
std::map< std::string, Annotation > annotations
#define STORM_LOG_TRACE(message)
#define STORM_LOG_ASSERT(cond, message)
#define STORM_LOG_THROW(cond, exception, message)
ArchiveReader openArchive(std::filesystem::path const &file)
Reads an archive file.
void prepareAnnotations(storm::umb::UmbModel &umbModel)
Prepares annotations so that all fields are available according to the index.
storm::umb::UmbModel fromArchive(std::filesystem::path const &umbArchive, ImportOptions const &)
VecT importVector(typename storm::io::ArchiveReader::ArchiveReadEntry &src)
void importGenericVector(typename storm::io::ArchiveReader::ArchiveReadEntry &src, GenericVector &target)
void parseIndexFromString(std::string const &indexFileString, storm::umb::ModelIndex &index)
std::filesystem::path getFilePath(typename storm::io::ArchiveReader::ArchiveReadEntry const &src)
storm::umb::UmbModel importUmb(std::filesystem::path const &umbLocation, ImportOptions const &options)
carl::Interval< storm::RationalNumber > RationalInterval
nlohmann::basic_json< std::map, std::vector, std::string, bool, int64_t, uint64_t, ValueType > json
std::string dumpJson(storm::json< ValueType > const &j, bool compact)
Dumps the given json object, producing a String.
std::optional< SizedType > exitRateType
std::optional< SizedType > branchProbabilityType
std::optional< SizedType > observationProbabilityType
struct storm::umb::ModelIndex::TransitionSystem transitionSystem
std::optional< std::map< std::string, AnnotationMap > > annotations
storm::OptionalRef< AnnotationMap > annotation(std::string const &annotationsType, bool createIfMissing=false)
std::string toString() const
storm::SerializedEnum< storm::umb::TypeDeclaration > type