SimpleReader.cpp 1.91 KB
Newer Older
legoc's avatar
legoc committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
/*
 * 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 : lstsimplereader128 <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;
}