From 5465ee579292be430f99c7aaae9d5cbd36b5d813 Mon Sep 17 00:00:00 2001 From: Martin Hierholzer <martin.hierholzer@desy.de> Date: Wed, 4 Jul 2018 15:47:12 +0200 Subject: [PATCH] necessary update for a change in DeviceAccess --- Modules/include/LimitValue.h | 15 +++---- Modules/include/Multiplier.h | 4 +- Modules/include/SplitArray.h | 45 +++++++++++---------- Modules/src/Logging.cc | 2 +- example/demoApp.cc | 2 +- tests/executables_src/testTestFacilities.cc | 2 +- tests/executables_src/testVariableGroup.cc | 20 ++++----- 7 files changed, 46 insertions(+), 44 deletions(-) diff --git a/Modules/include/LimitValue.h b/Modules/include/LimitValue.h index 18ed690b..fb7891b8 100644 --- a/Modules/include/LimitValue.h +++ b/Modules/include/LimitValue.h @@ -1,5 +1,5 @@ /* - * Generic module to restrict a value into a certain range. + * Generic module to restrict a value into a certain range. */ #ifndef CHIMERATK_APPLICATION_CORE_LIMIT_VALUE_H @@ -19,7 +19,7 @@ namespace ChimeraTK { void applyLimit(UserType min, UserType max) { bool wasLimited = isLimited; - + // clamp input value into given range UserType value = input; if(value > max) { @@ -34,12 +34,12 @@ namespace ChimeraTK { output = value; isLimited = false; } - + // write output. isLimited is only written when changed output.write(); if(isLimited != wasLimited) isLimited.write(); wasLimited = isLimited; - + } }; @@ -51,12 +51,13 @@ namespace ChimeraTK { ScalarPushInput<UserType> max{this, "max", "", "The maximum allowed value."}; using LimitValueModuleBase<UserType>::input; using LimitValueModuleBase<UserType>::applyLimit; - + void mainLoop() { + auto readGroup = this->readAnyGroup(); while(true) { applyLimit(min,max); // wait for new input values (at the end, since we want to process the initial values first) - Application::readAny({input, min, max}); + readGroup.readAny(); } } }; @@ -67,7 +68,7 @@ namespace ChimeraTK { using LimitValueModuleBase<UserType>::LimitValueModuleBase; using LimitValueModuleBase<UserType>::input; using LimitValueModuleBase<UserType>::applyLimit; - + void mainLoop() { while(true) { applyLimit(min,max); diff --git a/Modules/include/Multiplier.h b/Modules/include/Multiplier.h index adee629e..54b16d30 100644 --- a/Modules/include/Multiplier.h +++ b/Modules/include/Multiplier.h @@ -75,7 +75,7 @@ namespace ChimeraTK { output.write(); // wait for new input value (at the end, since we want to process the initial values first) - group.waitAny(); + group.readAny(); } } @@ -110,7 +110,7 @@ namespace ChimeraTK { output.write(); // wait for new input value (at the end, since we want to process the initial values first) - group.waitAny(); + group.readAny(); } } diff --git a/Modules/include/SplitArray.h b/Modules/include/SplitArray.h index 72cbd22b..5733cef5 100644 --- a/Modules/include/SplitArray.h +++ b/Modules/include/SplitArray.h @@ -9,16 +9,16 @@ namespace ChimeraTK { - /** + /** * Split an array of the data type TYPE into nGroups with each nElemsPerGroup elements. The splitted array is an * output of this module and will be written everytime any of the inputs is updated. Each input is an array of the * length nElemsPerGroup and there are nGroups inputs. nElemsPerGroup defaults to 1, so the array is split into * its individual elements (and the inputs can be used as scalars). - * + * * The output array is called "output", while each input is called "input#", where # is the index of the input * counting from 0. When using the C++ interface, the inputs are stored in a std::vector and thus can be accessed * e.g. through "input[index]". - * + * * The output array has a size of nGroups*nElementsPerGroup. */ template<typename TYPE> @@ -26,7 +26,7 @@ namespace ChimeraTK { WriteSplitArrayModule(EntityOwner *owner, const std::string &name, const std::string &description, size_t nGroups, size_t nElemsPerGroup=1); - + WriteSplitArrayModule() {} /** Vector of input arrays, each with a length of nElemsPerGroup. If nElemsPerGroup is 1 (default), the inputs @@ -35,14 +35,14 @@ namespace ChimeraTK { * The input with the index "index" corresponds to the elements "index*nElemsPerGroup" to * "(index+1)*nElemsPerGroup-1" of the output array. */ std::vector<ArrayPushInput<TYPE>> input; - + /** Output array. Will be updated each time any input was changed with the corresponding data from the input. */ ArrayOutput<TYPE> output; - + void mainLoop(); - + private: - + size_t _nGroups; size_t _nElemsPerGroup; @@ -50,16 +50,16 @@ namespace ChimeraTK { /*********************************************************************************************************************/ - /** + /** * Split an array of the data type TYPE into nGroups with each nElemsPerGroup elements. The splitted array is an * input to this module and ann outputs will be written to each time the input is updated. Each output is an array of * then length nElemsPerGroup and there are nGroups inputs. nElemsPerGroup defaults to 1, so the array is split into * its individual elements (and the outpus can be used as scalars). - * + * * The input array is called "input", while each output is called "output#", where # is the index of the output * counting from 0. When using the C++ interface, the outputs are stored in a std::vector and thus can be accessed * e.g. through "output[index]". - * + * * The input array has a size of nGroups*nElementsPerGroup. */ template<typename TYPE> @@ -67,7 +67,7 @@ namespace ChimeraTK { ReadSplitArrayModule(EntityOwner *owner, const std::string &name, const std::string &description, size_t nGroups, size_t nElemsPerGroup=1); - + ReadSplitArrayModule() {} /** Vector of output arrays, each with a length of nElemsPerGroup. If nElemsPerGroup is 1 (default), the outputs @@ -76,14 +76,14 @@ namespace ChimeraTK { * The output with the index "index" corresponds to the elements "index*nElemsPerGroup" to * "(index+1)*nElemsPerGroup-1" of the input array. */ std::vector<ArrayOutput<TYPE>> output; - + /** Input array. Each time this input is changed, all outputs will be updated with the corresponding data. */ ArrayPushInput<TYPE> input; - + void mainLoop(); - + private: - + size_t _nGroups; size_t _nElemsPerGroup; @@ -117,8 +117,9 @@ namespace ChimeraTK { template<typename TYPE> void WriteSplitArrayModule<TYPE>::mainLoop() { + auto readGroup = readAnyGroup(); while(true) { - + // write the array from the individual elements for(size_t i=0; i<_nGroups; ++i) { for(size_t k=0; k<_nElemsPerGroup; ++k) { @@ -126,9 +127,9 @@ namespace ChimeraTK { } } output.write(); - + // wait for new input values (at the end, since we want to process the initial values first) - readAny(); + readGroup.readAny(); } } @@ -156,11 +157,11 @@ namespace ChimeraTK { } /*********************************************************************************************************************/ - + template<typename TYPE> void ReadSplitArrayModule<TYPE>::mainLoop() { while(true) { - + // write the array from the individual elements for(size_t i=0; i<_nGroups; ++i) { for(size_t k=0; k<_nElemsPerGroup; ++k) { @@ -168,7 +169,7 @@ namespace ChimeraTK { } } writeAll(); - + // wait for new input values (at the end, since we want to process the initial values first) input.read(); } diff --git a/Modules/src/Logging.cc b/Modules/src/Logging.cc index fd603d5d..a5ecbee5 100644 --- a/Modules/src/Logging.cc +++ b/Modules/src/Logging.cc @@ -99,7 +99,7 @@ void LoggingModule::mainLoop(){ } auto group = readAnyGroup(); while(1){ - auto id = group.waitAny(); + auto id = group.readAny(); auto sender = UpdatePair(id); if(targetStream == 3) continue; diff --git a/example/demoApp.cc b/example/demoApp.cc index ccb28d92..13c6c26b 100644 --- a/example/demoApp.cc +++ b/example/demoApp.cc @@ -49,7 +49,7 @@ struct TableGeneration : public ctk::ApplicationModule { void mainLoop() { ctk::ReadAnyGroup tableParametersReadGroup = tableParameters.readAnyGroup(); while(true) { - tableParametersReadGroup.waitAny(); // block until the any table parameter is changed + tableParametersReadGroup.readAny(); // block until the any table parameter is changed for(size_t i = 0; i < tableLength; ++i) { if(i < tableParameters.pulseLength * samplingFrequency) { diff --git a/tests/executables_src/testTestFacilities.cc b/tests/executables_src/testTestFacilities.cc index 7b5924f5..acba07fa 100644 --- a/tests/executables_src/testTestFacilities.cc +++ b/tests/executables_src/testTestFacilities.cc @@ -112,7 +112,7 @@ struct ReadAnyTestModule : public ctk::ApplicationModule { void mainLoop() { auto group = inputs.readAnyGroup(); while(true) { - auto justRead = group.waitAny(); + auto justRead = group.readAny(); if(inputs.v1.getId() == justRead) { index = 1; value = (T)inputs.v1; diff --git a/tests/executables_src/testVariableGroup.cc b/tests/executables_src/testVariableGroup.cc index aa2862e3..4437c746 100644 --- a/tests/executables_src/testVariableGroup.cc +++ b/tests/executables_src/testVariableGroup.cc @@ -253,7 +253,7 @@ BOOST_AUTO_TEST_CASE( testReadAny ) { BOOST_CHECK(app.testModule.mixedGroup.consumingPoll == 0); BOOST_CHECK(app.testModule.mixedGroup.consumingPoll2 == 0); BOOST_CHECK(app.testModule.mixedGroup.consumingPoll3 == 0); - group.waitAny(); + group.readAny(); BOOST_CHECK(app.testModule.mixedGroup.consumingPush == 0); BOOST_CHECK(app.testModule.mixedGroup.consumingPush2 == 42); BOOST_CHECK(app.testModule.mixedGroup.consumingPush3 == 0); @@ -270,7 +270,7 @@ BOOST_AUTO_TEST_CASE( testReadAny ) { BOOST_CHECK(app.testModule.mixedGroup.consumingPoll == 10); BOOST_CHECK(app.testModule.mixedGroup.consumingPoll2 == 11); BOOST_CHECK(app.testModule.mixedGroup.consumingPoll3 == 12); - group.waitAny(); + group.readAny(); app.testModule.feedingPush3.write(); BOOST_CHECK(app.testModule.mixedGroup.consumingPush == 0); BOOST_CHECK(app.testModule.mixedGroup.consumingPush2 == 666); @@ -278,7 +278,7 @@ BOOST_AUTO_TEST_CASE( testReadAny ) { BOOST_CHECK(app.testModule.mixedGroup.consumingPoll == 10); BOOST_CHECK(app.testModule.mixedGroup.consumingPoll2 == 11); BOOST_CHECK(app.testModule.mixedGroup.consumingPoll3 == 12); - group.waitAny(); + group.readAny(); BOOST_CHECK(app.testModule.mixedGroup.consumingPush == 0); BOOST_CHECK(app.testModule.mixedGroup.consumingPush2 == 666); BOOST_CHECK(app.testModule.mixedGroup.consumingPush3 == 120); @@ -286,8 +286,8 @@ BOOST_AUTO_TEST_CASE( testReadAny ) { BOOST_CHECK(app.testModule.mixedGroup.consumingPoll2 == 11); BOOST_CHECK(app.testModule.mixedGroup.consumingPoll3 == 12); - // launch waitAny() asynchronously and make sure it does not yet receive anything - auto futureRead = std::async(std::launch::async, [&group]{ group.waitAny(); }); + // launch readAny() asynchronously and make sure it does not yet receive anything + auto futureRead = std::async(std::launch::async, [&group]{ group.readAny(); }); BOOST_CHECK(futureRead.wait_for(std::chrono::milliseconds(200)) == std::future_status::timeout); BOOST_CHECK(app.testModule.mixedGroup.consumingPush == 0); BOOST_CHECK(app.testModule.mixedGroup.consumingPush2 == 666); @@ -309,8 +309,8 @@ BOOST_AUTO_TEST_CASE( testReadAny ) { BOOST_CHECK(app.testModule.mixedGroup.consumingPoll2 == 11); BOOST_CHECK(app.testModule.mixedGroup.consumingPoll3 == 12); - // launch another waitAny() asynchronously and make sure it does not yet receive anything - auto futureRead2 = std::async(std::launch::async, [&group]{ group.waitAny(); }); + // launch another readAny() asynchronously and make sure it does not yet receive anything + auto futureRead2 = std::async(std::launch::async, [&group]{ group.readAny(); }); BOOST_CHECK(futureRead2.wait_for(std::chrono::milliseconds(200)) == std::future_status::timeout); BOOST_CHECK(app.testModule.mixedGroup.consumingPush == 3); BOOST_CHECK(app.testModule.mixedGroup.consumingPush2 == 666); @@ -327,7 +327,7 @@ BOOST_AUTO_TEST_CASE( testReadAny ) { app.testModule.feedingPoll3 = 88; app.testModule.feedingPoll3.write(); - // make sure waitAny still does not receive anything + // make sure readAny still does not receive anything BOOST_CHECK(futureRead2.wait_for(std::chrono::milliseconds(200)) == std::future_status::timeout); BOOST_CHECK(app.testModule.mixedGroup.consumingPush == 3); BOOST_CHECK(app.testModule.mixedGroup.consumingPush2 == 666); @@ -350,7 +350,7 @@ BOOST_AUTO_TEST_CASE( testReadAny ) { BOOST_CHECK(app.testModule.mixedGroup.consumingPoll3 == 88); // two changes at a time - auto futureRead3 = std::async(std::launch::async, [&group]{ group.waitAny(); }); + auto futureRead3 = std::async(std::launch::async, [&group]{ group.readAny(); }); BOOST_CHECK(futureRead3.wait_for(std::chrono::milliseconds(200)) == std::future_status::timeout); BOOST_CHECK(app.testModule.mixedGroup.consumingPush == 3); BOOST_CHECK(app.testModule.mixedGroup.consumingPush2 == 123); @@ -365,7 +365,7 @@ BOOST_AUTO_TEST_CASE( testReadAny ) { app.testModule.feedingPush3.write(); BOOST_CHECK(futureRead3.wait_for(std::chrono::milliseconds(2000)) == std::future_status::ready); - auto futureRead4 = std::async(std::launch::async, [&group]{ group.waitAny(); }); + auto futureRead4 = std::async(std::launch::async, [&group]{ group.readAny(); }); BOOST_CHECK(futureRead4.wait_for(std::chrono::milliseconds(2000)) == std::future_status::ready); BOOST_CHECK(app.testModule.mixedGroup.consumingPush == 3); BOOST_CHECK(app.testModule.mixedGroup.consumingPush2 == 234); -- GitLab