diff --git a/build.gradle.kts b/build.gradle.kts index 08895dd..c3e44b3 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,7 +4,7 @@ plugins { allprojects { group = "ru.inr.mass" - version = "0.1.0-SHAPSHOT" + version = "0.1.0" } val dataforgeVersion by extra("0.3.0-dev-1") diff --git a/numass-data-proto/src/main/kotlin/ru/inr/mass/data/proto/NumassDirectorySet.kt b/numass-data-proto/src/main/kotlin/ru/inr/mass/data/proto/NumassDirectorySet.kt index 38dcc78..ffee513 100644 --- a/numass-data-proto/src/main/kotlin/ru/inr/mass/data/proto/NumassDirectorySet.kt +++ b/numass-data-proto/src/main/kotlin/ru/inr/mass/data/proto/NumassDirectorySet.kt @@ -4,6 +4,7 @@ import hep.dataforge.context.Context import hep.dataforge.context.logger import hep.dataforge.io.io import hep.dataforge.io.readEnvelopeFile +import hep.dataforge.meta.DFExperimental import hep.dataforge.meta.Meta import ru.inr.mass.data.api.NumassPoint import ru.inr.mass.data.api.NumassSet @@ -21,31 +22,43 @@ public class NumassDirectorySet internal constructor( public val path: Path, ) : NumassSet { + @OptIn(DFExperimental::class) override val meta: Meta by lazy { val metaFilePath = path / "meta" if (metaFilePath.exists()) { - val envelope = context.io.readEnvelopeFile(path) ?: error("Envelope could not be read from $path") + val envelope = context.io.readEnvelopeFile(metaFilePath) ?: error("Envelope could not be read from $metaFilePath") envelope.meta } else { + context.logger.warn { "Meta file does not exist for Numass set $metaFilePath" } Meta.EMPTY } } override val points: List by lazy> { - Files.list(path).filter { it.fileName.startsWith("p") }.map { path -> + Files.list(path).filter { it.fileName.startsWith("p") }.map { pointPath -> try { - context.readNumassFile(path) + context.readNumassFile(pointPath) } catch (e: Exception) { - context.logger.error(e) { "Error reading Numass point file $path" } + context.logger.error(e) { "Error reading Numass point file $pointPath" } null } }.toList().filterNotNull() } } +@OptIn(DFExperimental::class) +public fun Context.readNumassFile(path: Path): ProtoNumassPoint? { + val envelope = io.readEnvelopeFile(path) ?: error("Envelope could not be read from $path") + return ProtoNumassPoint.fromEnvelope(envelope) +} + +public fun Context.readNumassFile(path: String): ProtoNumassPoint? = readNumassFile(Path.of(path)) + @OptIn(ExperimentalPathApi::class) public fun Context.readNumassDirectory(path: Path): NumassDirectorySet { if(!path.exists()) error("Path $path does not exist") if(!path.isDirectory()) error("The path $path is not a directory") return NumassDirectorySet(this, path) -} \ No newline at end of file +} + +public fun Context.readNumassDirectory(path: String): NumassDirectorySet = readNumassDirectory(Path.of(path)) \ No newline at end of file diff --git a/numass-data-proto/src/main/kotlin/ru/inr/mass/data/proto/readFiles.kt b/numass-data-proto/src/main/kotlin/ru/inr/mass/data/proto/readFiles.kt deleted file mode 100644 index 446c765..0000000 --- a/numass-data-proto/src/main/kotlin/ru/inr/mass/data/proto/readFiles.kt +++ /dev/null @@ -1,13 +0,0 @@ -package ru.inr.mass.data.proto - -import hep.dataforge.context.Context -import hep.dataforge.io.io -import hep.dataforge.io.readEnvelopeFile -import java.nio.file.Path - -public fun Context.readNumassFile(path: Path): ProtoNumassPoint? { - val envelope = io.readEnvelopeFile(path) ?: error("Envelope could not be read from $path") - return ProtoNumassPoint.fromEnvelope(envelope) -} - -public fun Context.readNumassFile(path: String): ProtoNumassPoint? = readNumassFile(Path.of(path)) \ No newline at end of file