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 93e6c046287ba6d7dc63ce510fe96a06cea5367c..c78a1317916da9524294aeb7b0a8dba7418970fc 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 cb4f399da043aa9715aa4ec9630cf3695332acb6..3fb9ca124314c5452b102291c9a3569497c9cc45 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 21b05f77021beb321d22eefe5e5f8d25802c6512..aee002881980fdb2c602eb68115e2181afd1968e 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 */