diff --git a/a.out b/a.out new file mode 100755 index 0000000..2c9b36b Binary files /dev/null and b/a.out differ diff --git a/core b/core new file mode 100644 index 0000000..c5a5dc1 Binary files /dev/null and b/core differ diff --git a/prova.cpp b/prova.cpp new file mode 100644 index 0000000..8d79f0f --- /dev/null +++ b/prova.cpp @@ -0,0 +1,5 @@ +#include + +int main() { + return 0; +} \ No newline at end of file diff --git a/provider.cxx b/provider.cxx new file mode 100644 index 0000000..7eac361 --- /dev/null +++ b/provider.cxx @@ -0,0 +1,135 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +#define START_OF_HEADER_MARKER 0xee1234ee + +#define MIN_FRAGMENTS 0 +#define MAX_FRAGMENTS 100 + +typedef struct Header { + uint32_t startOfHeaderMarker; + uint32_t headerSize; + uint32_t fragmentSize; + uint32_t runNumber; + uint32_t detectorEventNumber; + uint32_t numberOfStatusElements; + uint32_t *statusElementsArray; + friend std::ostream& operator <<(std::ostream& os, Header const& header) + { + return os << std::setw(8) << std::setfill('0') << header.startOfHeaderMarker << '\n' + << std::setw(8) << std::setfill('0') << header.headerSize << '\n' + << std::setw(8) << std::setfill('0') << header.fragmentSize << '\n' + << std::setw(8) << std::setfill('0') << header.runNumber << '\n' + << std::setw(8) << std::setfill('0') << header.detectorEventNumber << '\n' + << std::setw(8) << std::setfill('0') << header.numberOfStatusElements << '\n'; + } +} Header; + +typedef struct Fragment { + Header header; + uint32_t *payloadElements; +} Fragment; + +enum ERROR_CODES { + INCORRECT_ERROR = (1 << 0), + CORRUPTED_ERROR = (1 << 1), + MISSING_DATA_ERROR = (1 << 2), + TIMEOUT_ERROR = (1 << 3) +}; + +/* +int rndError(float p){ + float rndFloat = static_cast(rand()) / static_cast(RAND_MAX); + return rndFloat < p; +}*/ + + + + +int main(int argc, char* argv[]) { + //will use it later to obtain random number from hardware + std::random_device rd; + std::mt19937 generator(42); + std::discrete_distribution discrete_distr({0.9, 0.1}); + std::normal_distribution normal_distr(25., 10.); + std::uniform_int_distribution unif_int_distib; + std::uniform_real_distribution unif_float_distrib(0.5, 2); + + //commenting all old_style generation + //srand (static_cast (42)); + + bool out_condition = true; + uint32_t event_number = 0; + + uint32_t run_number = 0; + if (argc > 1) { + run_number = atoi(argv[1]); + } + + while (true) { + Header header; + header.startOfHeaderMarker = START_OF_HEADER_MARKER; + header.runNumber = run_number; + header.detectorEventNumber = event_number; + event_number++; + header.numberOfStatusElements = 0; + //if swap to old style just change with function above and prob 0.1 for 1 + uint8_t incorrectError = discrete_distr(generator); + uint8_t corruptedError = discrete_distr(generator); + uint8_t missingDataError = discrete_distr(generator); + uint8_t timeoutError = discrete_distr(generator); + + uint32_t firstStatusElement = 0x0; + + if (incorrectError) firstStatusElement |= INCORRECT_ERROR; + if (corruptedError) firstStatusElement |= CORRUPTED_ERROR; + if (missingDataError) firstStatusElement |= MISSING_DATA_ERROR; + if (timeoutError) firstStatusElement |= TIMEOUT_ERROR; + + if (firstStatusElement != 0x0) { + header.numberOfStatusElements = 1; + header.statusElementsArray = new uint32_t[header.numberOfStatusElements]; + header.statusElementsArray[0] = firstStatusElement; + } + + uint32_t payload_size = std::max(std::min(static_cast(std::round(normal_distr(generator))), MAX_FRAGMENTS), MIN_FRAGMENTS); + header.headerSize = 6 + header.numberOfStatusElements; + header.fragmentSize = header.headerSize + payload_size; + + Fragment fragment; + fragment.header = header; + fragment.payloadElements = new uint32_t[payload_size]; + for (uint32_t i = 0; i < payload_size; i++) { + fragment.payloadElements[i] = unif_int_distib(generator); + } + + std::cout << std::hex << std::setw(8) << std::setfill('0'); + std::cout << fragment.header; + for (uint8_t i = 0; i < fragment.header.numberOfStatusElements; i++) { + std::cout << "status element " << std::setw(8) << std::setfill('0') << fragment.header.statusElementsArray[i] << std::endl; + } + for (uint32_t i = 0; i < payload_size; i++) { + std::cout << "payload element " << std::setw(8) << std::setfill('0') << fragment.payloadElements[i] << std::endl; + } + std::cout << std::endl; + + if (header.numberOfStatusElements > 0){ + delete [] fragment.header.statusElementsArray; + } + delete [] fragment.payloadElements; + + + sleep(unif_float_distrib(generator)); + } + + return 0; +} \ No newline at end of file