From 768196c18bb5b39eb3c14bbfd0bf98f0effee52b Mon Sep 17 00:00:00 2001
From: guille <guillermopolito@gmail.com>
Date: Fri, 28 Oct 2016 14:24:27 +0200
Subject: [PATCH] Adding Scaladocs to AER files

---
 .../features/io/input/AERFileReader.scala     | 19 +++++----
 .../features/io/input/AERFileWriter.scala     |  6 +++
 .../features/io/input/AERInputStream.scala    | 39 ++-----------------
 3 files changed, 22 insertions(+), 42 deletions(-)

diff --git a/n2s3/src/main/scala/fr/univ_lille/cristal/emeraude/n2s3/features/io/input/AERFileReader.scala b/n2s3/src/main/scala/fr/univ_lille/cristal/emeraude/n2s3/features/io/input/AERFileReader.scala
index 93e6c046..c78a1317 100644
--- a/n2s3/src/main/scala/fr/univ_lille/cristal/emeraude/n2s3/features/io/input/AERFileReader.scala
+++ b/n2s3/src/main/scala/fr/univ_lille/cristal/emeraude/n2s3/features/io/input/AERFileReader.scala
@@ -4,26 +4,31 @@ package fr.univ_lille.cristal.emeraude.n2s3.features.io.input
   * Created by falezp on 26/07/16.
   */
 
-import java.io.File
-import java.io.FileInputStream
-import java.io.EOFException
-import java.io.FileOutputStream
+import java.io.{EOFException, File, FileInputStream}
 import java.nio.ByteBuffer
 
-
+/**
+  * Represents an event of an AER input (e.g., a camera).
+  * An AER event possess the address where the event occurred (e.g., which pixel in the image) and the timestamp when this happened.
+  */
 case class AEREvent(address : Short, Timestamp : Int)
 
+/**
+  * Reader of files in AER format.
+  * This reader assumes that events inside the file are 6 bytes long.
+  * Events are read in a buffered way in chunks of 64 events.
+  *
+  * Read events are returned as [[AEREvent]] objects with the address of the event in the file and the timestamp where it occurred.
+  */
 class AERFileReader(filename : String) {
 
   private val eventSize = 6
   private val chunkSize = 64
 
   private val file = new File(filename)
-  private val eventNumber = file.length()/eventSize.toLong
 
   private val reader = new FileInputStream(file).getChannel
 
-  private var cursor : Long = 0L
   private val currentChunk = ByteBuffer.allocate(chunkSize*eventSize)
   private var currentChunkSize = 0
 
diff --git a/n2s3/src/main/scala/fr/univ_lille/cristal/emeraude/n2s3/features/io/input/AERFileWriter.scala b/n2s3/src/main/scala/fr/univ_lille/cristal/emeraude/n2s3/features/io/input/AERFileWriter.scala
index cb4f399d..3fb9ca12 100644
--- a/n2s3/src/main/scala/fr/univ_lille/cristal/emeraude/n2s3/features/io/input/AERFileWriter.scala
+++ b/n2s3/src/main/scala/fr/univ_lille/cristal/emeraude/n2s3/features/io/input/AERFileWriter.scala
@@ -8,11 +8,17 @@ import java.io.File
 import java.io.FileOutputStream
 import java.nio.ByteBuffer
 
+/**
+  * Writes [[AEREvent]]-like information to a file.
+  * @param filename
+  */
 class AERFileWriter(filename : String) {
 
   private val file = new File(filename)
   private val writer = new FileOutputStream(file, false).getChannel
 
+  def appendEvent(aEREvent: AEREvent) : Unit = this.appendEvent(aEREvent.address, aEREvent.Timestamp)
+
   def appendEvent(address : Short, timestamp : Int) : Unit = {
     val buffer = ByteBuffer.allocate(6)
     buffer.putShort(address)
diff --git a/n2s3/src/main/scala/fr/univ_lille/cristal/emeraude/n2s3/features/io/input/AERInputStream.scala b/n2s3/src/main/scala/fr/univ_lille/cristal/emeraude/n2s3/features/io/input/AERInputStream.scala
index 21b05f77..aee00288 100644
--- a/n2s3/src/main/scala/fr/univ_lille/cristal/emeraude/n2s3/features/io/input/AERInputStream.scala
+++ b/n2s3/src/main/scala/fr/univ_lille/cristal/emeraude/n2s3/features/io/input/AERInputStream.scala
@@ -71,6 +71,9 @@ class AERCochlea extends AERFormat {
   }
 }
 
+/**
+  * Represents the input of an AER file to send to the simulation.
+  */
 case class AERInput(timestamp: Timestamp, address : Int) extends Input {
   override def prefixTimestamp(prefix: Timestamp): this.type = {
     AERInput(prefix+timestamp, address).asInstanceOf[this.type]
@@ -80,16 +83,6 @@ case class AERInput(timestamp: Timestamp, address : Int) extends Input {
 
 }
 
-
-/*object FreeWay {
-  def input(filename: String, enableSpikeSign: Boolean = false) = {
-    new AERInputStream("data/aerdata/freeway.mat.dat")
-      .groupBy(x => x.timestamp)
-      .map(events => events.map{ event => Input(ShapelessSpike, event.timestamp, AERRetinaInputTransformation.transformAddress(event.destinationIndex, enableSpikeSign)) })
-      .repeat(8)
-  }
-}*/
-
 /**
  * Reads AER files using jAER (jar file in lib directory).
  * All the methods return an IndexedSeq[Event]. The timestamps are
@@ -98,8 +91,7 @@ case class AERInput(timestamp: Timestamp, address : Int) extends Input {
  * @author boulet
  * @param filename: String, the name of the file to read from
  */
-//TODO expliquer la relation entre AERInputStream AERInput
-
+//TODO: expliquer la relation entre AERInputStream AERInput
 class AERInputStream(filename: String, s : Shape, chunkSize : Int = 64) extends N2S3InputStream[InputSeq[AERInput]] with StreamTimestampsManager {
 
   val aeis = new AEFileInputStream(new File(filename))
@@ -137,15 +129,6 @@ class AERInputStream(filename: String, s : Shape, chunkSize : Int = 64) extends
     }
   }
 
-
-  /**
-   * @param n, the number of events to read
-   * @return sequence of events
-   */
-  private def readEventsByNumber(n: Int) = {
-    eventsFromAEPacket(aeis.readPacketByNumber(n))
-  }
-
   /**
    * @param dt, the time interval in µs to read events from the last read event
    * @return sequence of events
@@ -206,20 +189,6 @@ class AERInputStream(filename: String, s : Shape, chunkSize : Int = 64) extends
     }
   }
 
-  private def peek() = {
-    if (this.peekEvent.isEmpty && aeis.position() < aeis.size() - 1 ){
-      try{
-        val read = eventsFromAEPacket(aeis.readPacketByNumber(1))
-        if (read.nonEmpty){
-          this.peekEvent = Some(read)
-        }
-      } catch {
-        case e: EOFException =>
-      }
-    }
-    this.peekEvent
-  }
-
   /**
     * return if we reach the end of the file
     */
-- 
GitLab