Commit 4074db16 authored by Mohamed, Fawzi Roberto (fawzi)'s avatar Mohamed, Fawzi Roberto (fawzi)
Browse files

ArchiveH5: adding calculations.length/lengthL

(calculate efficiently the number of calculations)
parent b4bd6cec
......@@ -17,6 +17,8 @@ package eu.nomad_lab.h5
import eu.nomad_lab.{ IteratorH5, H5Lib, RefCount }
import eu.nomad_lab.ref._
import com.typesafe.scalalogging.StrictLogging
import scala.util.control.NonFatal
object ArchiveH5 {
def unapply(arch: ArchiveH5): Option[Tuple3[FileH5, String, Long]] = {
......@@ -34,9 +36,29 @@ object ArchiveH5 {
*/
class CalculationTraverser(
archive: ArchiveH5
) extends Traversable[CalculationH5] {
) extends Traversable[CalculationH5] with StrictLogging {
private val subGroups = H5Lib.GroupContent(baseGroup = archive.archiveGroup)
def lengthL: Long = {
var len: Long = 0L
try {
for (gInfo <- subGroups) {
if (gInfo.otype == H5Lib.GroupContent.ObjectType.Group) {
gInfo.oname match {
case realCalculationRe() => len += 1L
case _ => ()
}
}
}
} catch {
case NonFatal(e) =>
logger.error(s"failure to calculate number of calculations in $archive", e)
}
len
}
def length: Long = lengthL
/** loops on the real calculations, be careful you need to retain the object if you want to build a collection */
def foreach[U](f: CalculationH5 => U): Unit = {
var current: Option[CalculationH5] = None
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment