Skip to content

Commit

Permalink
#3 Finished implementing dataLayer switch
Browse files Browse the repository at this point in the history
  • Loading branch information
Johannes Frohnhofen committed Jan 18, 2014
1 parent 683ab2d commit 814cee0
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 13 deletions.
2 changes: 2 additions & 0 deletions src/main/scala/braingames/binary/DataCache.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ case class CachedBlock(
dataSetName: String,
dataLayerId: String,
dataLayerTyp: String,
dataLayerBaseDir: String,
resolution: Int,
x: Int,
y: Int,
Expand All @@ -25,6 +26,7 @@ object CachedBlock {
b.dataSet.name,
b.dataLayerSection.sectionId,
b.dataLayer.typ,
b.dataLayer.baseDir,
b.resolution,
b.block.x,
b.block.y,
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/braingames/binary/DataRequestActor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ class DataRequestActor(

def loadFromLayer(loadBlock: LoadBlock): Future[Box[Array[Byte]]] = {
if (loadBlock.dataLayerSection.doesContainBlock(loadBlock.block, loadBlock.dataSet.blockLength)) {

def loadFromStore(dataStores: List[ActorRef]): Future[Box[Array[Byte]]] = dataStores match {
case a :: tail =>
(a ? loadBlock)
Expand Down Expand Up @@ -137,7 +136,7 @@ class DataRequestActor(

def loadFromSomewhere(dataSet: DataSet, layer: DataLayer, requestedSection: Option[String], resolution: Int, block: Point3D): Future[Array[Byte]] = {

def loadFromSections(sections: Stream[DataLayerSection]): Future[Array[Byte]] = sections match {
def loadFromSections(sections: Stream[(DataLayerSection, DataLayer)]): Future[Array[Byte]] = sections match {
case (section, layer) #:: tail =>
val loadBlock = LoadBlock(dataSet, layer, section, resolution, block)
loadFromLayer(loadBlock).flatMap {
Expand Down Expand Up @@ -170,6 +169,7 @@ class DataRequestActor(
}
}.getOrElse(Nil)), 5 seconds)
}

loadFromSections(sections)
}

Expand Down
1 change: 1 addition & 0 deletions src/main/scala/braingames/binary/LoadBlock.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import braingames.binary.models.DataLayerSection

case class LoadBlock(
dataSet: DataSet,
dataLayer: DataLayer,
dataLayerSection: DataLayerSection,
resolution: Int,
block: Point3D)
8 changes: 5 additions & 3 deletions src/main/scala/braingames/binary/api/DataSetService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,16 @@ trait DataSetService {

def createUserDataLayer(baseDataSet: DataSet): UserDataLayer = {
val name = userDataSetName()
val baseFolder = new File(userDataSetFolder(name))
val sections = baseDataSet.dataLayer(DataLayer.SEGMENTATION.name).map(_.sections).getOrElse(Nil)
val dataLayer = DataLayer(
DataLayer.SEGMENTATION.name,
userDataSetFolder(name),
baseFolder.getAbsolutePath(),
None,
DataLayer.SEGMENTATION.defaultElementClass,
fallback = Some(baseDataSet.name))
Some(baseDataSet.name),
sections)

val baseFolder = new File(dataLayer.baseDir)
baseFolder.mkdirs()
UserDataLayer(name, baseDataSet.name, dataLayer)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ import java.io.File
*/
case class DataLayerSettings(
typ: String,
baseDir: String,
`class`: String,
flags: Option[List[String]],
fallback: Option[String])

object DataLayerSettings extends SettingsFile with Function5[String, String, String, Option[List[String]], Option[String], DataLayerSettings]{
object DataLayerSettings extends SettingsFile with Function4[String, String, Option[List[String]], Option[String], DataLayerSettings]{
val dataLayerSettingsReads = Json.reads[DataLayerSettings]

def fromFile(f: File): Option[DataLayerSettings] = {
Expand Down
5 changes: 4 additions & 1 deletion src/main/scala/braingames/binary/models/DataLayers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,14 @@ trait DataLayerLike {

case class DataLayer(
typ: String,
baseDir: String,
flags: Option[List[String]],
elementClass: String = "uint8",
fallback: Option[String] = None,
sections: List[DataLayerSection] = Nil) extends DataLayerLike {

def relativeBaseDir(binaryBase: String) = baseDir.replace(binaryBase, "")

val interpolator = DataLayer.interpolationFromString(typ)

val resolutions = sections.flatMap(_.resolutions).distinct
Expand All @@ -46,7 +49,7 @@ case class DataLayer(

case class DataLayerType(name: String, interpolation: Interpolation, defaultElementClass: String = "uint8")

object DataLayer extends Function5[String, Option[List[String]], String, Option[String], List[DataLayerSection], DataLayer]{
object DataLayer extends Function6[String, String, Option[List[String]], String, Option[String], List[DataLayerSection], DataLayer]{
val COLOR =
DataLayerType("color", TrilerpInterpolation)
val SEGMENTATION =
Expand Down
3 changes: 3 additions & 0 deletions src/main/scala/braingames/binary/models/DataSet.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ case class DataSetSettings(

case class DataSet(
name: String,
baseDir: String,
priority: Int = 0,
scale: Scale,
dataLayers: List[DataLayer] = Nil,
Expand All @@ -26,6 +27,8 @@ case class DataSet(
def dataLayer(typ: String) =
dataLayers.find(_.typ == typ)

def relativeBaseDir(binaryBase: String) = baseDir.replace(binaryBase, "")

val blockLength = 128

val blockSize = blockLength * blockLength * blockLength
Expand Down
3 changes: 2 additions & 1 deletion src/main/scala/braingames/binary/store/DataStore.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ abstract class DataStore extends Actor {
object DataStore {

def createFilename(dataInfo: LoadBlock) =
"%s/%d/x%04d/y%04d/z%04d/%s_mag%d_x%04d_y%04d_z%04d.raw".format(
"%s/%s/%d/x%04d/y%04d/z%04d/%s_mag%d_x%04d_y%04d_z%04d.raw".format(
dataInfo.dataLayer.baseDir,
dataInfo.dataLayerSection.baseDir,
dataInfo.resolution,
dataInfo.block.x, dataInfo.block.y, dataInfo.block.z,
Expand Down
10 changes: 6 additions & 4 deletions src/main/scala/braingames/io/DataSetChangeHandler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ class DataSetChangeHandler(dataSetRepository: DataSetRepository)
}
}

def extractSections(base: File): Iterable[DataLayerSection] = {
def extractSections(base: File, basePath: String): Iterable[DataLayerSection] = {
val sectionSettingsMap = extractSectionSettings(base)
sectionSettingsMap.map {
case (path, settings) =>
DataLayerSection(
path.getAbsolutePath(),
path.getAbsolutePath().replace(basePath, ""),
settings.sectionId getOrElse path.getName,
settings.resolutions,
BoundingBox.createFrom(settings.bboxSmall),
Expand Down Expand Up @@ -119,8 +119,8 @@ class DataSetChangeHandler(dataSetRepository: DataSetRepository)
} yield {
println("Found Layer: " + settings)
val dataLayerPath = layer.getAbsolutePath()
val sections = extractSections(layer).toList
DataLayer(settings.typ, settings.flags, settings.`class`, settings.fallback, sections)
val sections = extractSections(layer, dataLayerPath).toList
DataLayer(settings.typ, dataLayerPath, settings.flags, settings.`class`, settings.fallback, sections)
}
}

Expand All @@ -130,6 +130,7 @@ class DataSetChangeHandler(dataSetRepository: DataSetRepository)
case Some(settings) =>
DataSet(
settings.name,
folder.getAbsolutePath,
settings.priority getOrElse 0,
settings.scale,
Nil,
Expand All @@ -138,6 +139,7 @@ class DataSetChangeHandler(dataSetRepository: DataSetRepository)
case _ =>
DataSet(
folder.getName,
folder.getAbsolutePath,
0,
Scale.default,
Nil,
Expand Down

0 comments on commit 814cee0

Please sign in to comment.