Commit 3ca93c96 authored by legoc's avatar legoc

Added simple reader.

parent 98adf744
Pipeline #333 skipped
......@@ -14,8 +14,8 @@ First of all, you have to open a file.
// The classes are defined in the namespace lstdpp128.
using namespace lstdpp128;
// Initialize a reader with a buffer of size 4096.
Reader reader(4096);
// Initialize a reader with a buffer of size 1024.
Reader reader(1024);
// Open the file.
bool success = reader.open(fileName);
......@@ -81,8 +81,14 @@ crateBoard | CrateBoard
The _version_ member represents the version of the format of the file. The _timeBase_ is the unit of time of the events. The value 9 means that the time base is 10^-9.
Read and Process the File
-------------------------
There are two methods to read and process a file:
* Use a simple reader event by event
* Use a more advanced algorithm configured with a method of reading the events.
An example of a simple reader is provided [here] ../src/lstdpp128/apps/common/SimpleReader.cpp .
......
bin_PROGRAMS = \
lstcalibrateinsert128 \
lstsimplereader128 \
lstreader128 \
lstinsertset128 \
lstinsert128 \
......@@ -18,6 +19,12 @@ lstcalibrateinsert128_CPPFLAGS = $(LST_CXXFLAGS)
lstcalibrateinsert128_LDFLAGS = $(LST_LDFLAGS)
lstcalibrateinsert128_LDADD = $(libs) $(LST_LIBS)
lstsimplereader128_SOURCES = \
SimpleReader.cpp
lstsimplereader128_CPPFLAGS = $(LST_CXXFLAGS)
lstsimplereader128_LDFLAGS = $(LST_LDFLAGS)
lstsimplereader128_LDADD = $(libs) $(LST_LIBS)
lstreader128_SOURCES = \
EventReader.cpp
......
/*
* Nomad Instrument Control Software
*
* Copyright 2011 Institut Laue-Langevin
*
* Licensed under the EUPL, Version 1.1 only (the "License");
* You may not use this work except in compliance with the Licence.
* You may obtain a copy of the Licence at:
*
* http://www.osor.eu/eupl
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" basis,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Licence for the specific language governing permissions and
* limitations under the Licence.
*/
#include <iostream>
#include <cstdlib>
#include "../../Event.h"
#include "../../Reader.h"
using namespace std;
using namespace lstdpp128;
void process(int32_t * buffer, int32_t size) {
// The argument size is in words of 32bits.
// Iterate the buffer by 4 words of 32bits.
int32_t index = 0;
int32_t nbIndex = size;
int32_t * bufferPtr = buffer;
// Loop until all the words are read.
while (index < nbIndex) {
// Read an event.
Event event;
if (readEvent(event, bufferPtr + index)) {
// Print the event.
cout << event << endl;
}
// Advance by 4 because the words are 32bits (4 x 32 = 128bits, the size of an event).
index += 4;
}
}
int main(int argc, char * argv[]) {
if (argc < 2) {
cerr << "usage : lstsimplereader <file>" << endl;
return EXIT_FAILURE;
}
// Initialize a reader with a buffer of size 1024.
Reader reader(1024);
// Open the file.
bool success = reader.open(argv[1]);
// Exit in case of error.
if (!success) {
return EXIT_FAILURE;
}
// Print the context.
cout << listModeContext << endl;
// Read the blocks until we read nothing.
while (true) {
// Read the next block.
int32_t size = reader.read();
// Exit if the block is empty.
if (size == 0) {
break;
}
// Process the buffer.
process(reader.buffer(), size);
}
return EXIT_SUCCESS;
}
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