Skip to content

Commit

Permalink
addign options handling and hard null type remove pass
Browse files Browse the repository at this point in the history
  • Loading branch information
vkhristenko committed Oct 20, 2017
1 parent 5e4c0d8 commit 43de15a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ package object core

// when you have an array of something simple kOffsetL by ROOT convention
def iterateArray(dimsToGo: Int): core.SRType = {
logger.info(s"dimsToGo = ${dimsToGo} for name = ${streamerElement.getName} type = ${streamerElement.getType} typeName = ${streamerElement.getTypeName}")
if (dimsToGo==1) core.SRArray(streamerElement.getName, b,
if (b==null) null
else b.getLeaves.get(0).asInstanceOf[TLeafElement],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,38 @@ package object optimizations {
trait OptimizationPass {
def run(x: SRRoot, roptions: ROptions): SRRoot

val name: String = this.getClass.getSimpleName.filterNot(_=='$')
val name: String = this.getClass.getSimpleName.filterNot(_=='$').toLowerCase

val default = false

def shouldRun(roptions: ROptions): Boolean = roptions.get(name) match {
case Some(x) =>
case Some(x) => {
logger.info(s"Optimization ${name} is ${x}")
// if the option is provided use that!
if (x.toLowerCase=="off" || x.toLowerCase=="false")
false
else if (x.toLowerCase=="on" || x.toLowerCase=="true")
true
else
throw UnknownOptionException(x)
case None => default
}
case None => { logger.info(s"Optimization ${name} is defaulted to ${default}"); default }
}
}

case object HardRemoveNullTypePass extends OptimizationPass {
override val default = true
private def iterate(t: SRType): SRType = t match {
// type t occupies a branch that either splittable or that is not splittable
// but does not contain null
case x: SRComposite =>
if (x.split)
SRComposite(x.name, x.b, x.members.filterNot({case m =>
occupiesNonSplittableBranchWithNull(m)}).map(iterate(_)), x.split, x.isTop, x.isBase, x._shouldDrop)
// filter out:
// 1. members that are null
// 2. members that are colelction(recursive of null)
// 3. members that occupy a non-splitted branch with a null as a field
occupiesNonSplittableBranchWithNull(m) || isNull(m) || collectionWithNull(m)}).map(iterate(_)), x.split, x.isTop, x.isBase, x._shouldDrop)
else
x
case x: SRVector =>
Expand All @@ -59,6 +66,21 @@ package object optimizations {
x
case _ => t
}
private def isNull(t: SRType): Boolean = t match {
case x: SRNull => true
case x: SRUnknown => true
case _ => false
}
private def collectionWithNull(t: SRType): Boolean = t match {
case x: SRVector => collectionWithNull(x.t)
case x: SRMap => collectionWithNull(x.valueType) || collectionWithNull(x.keyType)
case x: SRMultiMap => collectionWithNull(x.valueType) ||
collectionWithNull(x.keyType)
case x: SRArray => collectionWithNull(x.t)
case x: SRNull => true
case x: SRUnknown => true
case _ => false
}

private def containsNull(t: SRType): Boolean = t match {
// check if valid type t contains null inside
Expand Down Expand Up @@ -104,7 +126,7 @@ package object optimizations {
// to the members down the line.
// (nested as well) e.g. array<array<array<NULL>>>
case object SoftRemoveNullTypePass extends OptimizationPass {
override val default = true
override val default = false

private def notNull(t: SRType): Boolean =
!(t.isInstanceOf[SRNull] || t.isInstanceOf[SRUnknown])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ package experimental {
val treeName = roptions.get("tree")

// some logging
logger.info(s"options: ${options}")
logger.info(s"Building the Abstractly Typed Tree... for treeName=$treeName")
files.map(_.getPath.toString).foreach({x: String => logger.info(s"pathname = $x")})

Expand Down

0 comments on commit 43de15a

Please sign in to comment.