Directory and file accessors
This commit is contained in:
parent
e52924a5e2
commit
7658f65bd3
@ -4,7 +4,7 @@ plugins {
|
|||||||
|
|
||||||
allprojects {
|
allprojects {
|
||||||
group = "ru.inr.mass"
|
group = "ru.inr.mass"
|
||||||
version = "0.1.0-SHAPSHOT"
|
version = "0.1.0"
|
||||||
}
|
}
|
||||||
|
|
||||||
val dataforgeVersion by extra("0.3.0-dev-1")
|
val dataforgeVersion by extra("0.3.0-dev-1")
|
||||||
|
@ -4,6 +4,7 @@ import hep.dataforge.context.Context
|
|||||||
import hep.dataforge.context.logger
|
import hep.dataforge.context.logger
|
||||||
import hep.dataforge.io.io
|
import hep.dataforge.io.io
|
||||||
import hep.dataforge.io.readEnvelopeFile
|
import hep.dataforge.io.readEnvelopeFile
|
||||||
|
import hep.dataforge.meta.DFExperimental
|
||||||
import hep.dataforge.meta.Meta
|
import hep.dataforge.meta.Meta
|
||||||
import ru.inr.mass.data.api.NumassPoint
|
import ru.inr.mass.data.api.NumassPoint
|
||||||
import ru.inr.mass.data.api.NumassSet
|
import ru.inr.mass.data.api.NumassSet
|
||||||
@ -21,31 +22,43 @@ public class NumassDirectorySet internal constructor(
|
|||||||
public val path: Path,
|
public val path: Path,
|
||||||
) : NumassSet {
|
) : NumassSet {
|
||||||
|
|
||||||
|
@OptIn(DFExperimental::class)
|
||||||
override val meta: Meta by lazy {
|
override val meta: Meta by lazy {
|
||||||
val metaFilePath = path / "meta"
|
val metaFilePath = path / "meta"
|
||||||
if (metaFilePath.exists()) {
|
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
|
envelope.meta
|
||||||
} else {
|
} else {
|
||||||
|
context.logger.warn { "Meta file does not exist for Numass set $metaFilePath" }
|
||||||
Meta.EMPTY
|
Meta.EMPTY
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override val points: List<NumassPoint> by lazy<List<NumassPoint>> {
|
override val points: List<NumassPoint> by lazy<List<NumassPoint>> {
|
||||||
Files.list(path).filter { it.fileName.startsWith("p") }.map { path ->
|
Files.list(path).filter { it.fileName.startsWith("p") }.map { pointPath ->
|
||||||
try {
|
try {
|
||||||
context.readNumassFile(path)
|
context.readNumassFile(pointPath)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
context.logger.error(e) { "Error reading Numass point file $path" }
|
context.logger.error(e) { "Error reading Numass point file $pointPath" }
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
}.toList().filterNotNull()
|
}.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)
|
@OptIn(ExperimentalPathApi::class)
|
||||||
public fun Context.readNumassDirectory(path: Path): NumassDirectorySet {
|
public fun Context.readNumassDirectory(path: Path): NumassDirectorySet {
|
||||||
if(!path.exists()) error("Path $path does not exist")
|
if(!path.exists()) error("Path $path does not exist")
|
||||||
if(!path.isDirectory()) error("The path $path is not a directory")
|
if(!path.isDirectory()) error("The path $path is not a directory")
|
||||||
return NumassDirectorySet(this, path)
|
return NumassDirectorySet(this, path)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public fun Context.readNumassDirectory(path: String): NumassDirectorySet = readNumassDirectory(Path.of(path))
|
@ -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))
|
|
Loading…
Reference in New Issue
Block a user