Skip to content
Snippets Groups Projects
Commit 063a82e3 authored by Martin Christoph Hierholzer's avatar Martin Christoph Hierholzer
Browse files

added constructor for ReadBitMask which allows specifying all meta data for inputs and outputs

parent c264277b
No related branches found
No related tags found
No related merge requests found
...@@ -24,16 +24,16 @@ namespace ChimeraTK { ...@@ -24,16 +24,16 @@ namespace ChimeraTK {
bit[i].replace(ScalarPushInput<int>(this, "bit"+std::to_string(i), "", "The bit "+std::to_string(i)+" of the bit mask")); bit[i].replace(ScalarPushInput<int>(this, "bit"+std::to_string(i), "", "The bit "+std::to_string(i)+" of the bit mask"));
} }
} }
ScalarPushInput<int> bit[NBITS]; ScalarPushInput<int> bit[NBITS];
}; };
Input input{this, "input", "The input bits"}; Input input{this, "input", "The input bits"};
ScalarOutput<int32_t> bitmask{this, "bitmask", "", "Output bit mask."}; ScalarOutput<int32_t> bitmask{this, "bitmask", "", "Output bit mask."};
void mainLoop() { void mainLoop() {
while(true) { while(true) {
// create bit mask // create bit mask
bitmask = 0; bitmask = 0;
for(size_t i=0; i<NBITS; ++i) { for(size_t i=0; i<NBITS; ++i) {
...@@ -42,7 +42,7 @@ namespace ChimeraTK { ...@@ -42,7 +42,7 @@ namespace ChimeraTK {
} }
} }
bitmask.write(); bitmask.write();
// wait for new input values (at the end, since we want to process the initial values first) // wait for new input values (at the end, since we want to process the initial values first)
input.readAny(); input.readAny();
} }
...@@ -54,7 +54,23 @@ namespace ChimeraTK { ...@@ -54,7 +54,23 @@ namespace ChimeraTK {
template<size_t NBITS> template<size_t NBITS>
struct ReadBitMask : public ApplicationModule { struct ReadBitMask : public ApplicationModule {
using ApplicationModule::ApplicationModule; ReadBitMask(EntityOwner *owner, const std::string &name, const std::string &description,
bool eliminateHierarchy=false, const std::unordered_set<std::string> &tags={})
: ApplicationModule(owner, name, description, eliminateHierarchy, tags) {}
ReadBitMask() {}
ReadBitMask( EntityOwner *owner, const std::string &inputName, const std::string &inputDescription,
const std::unordered_set<std::string> &inputTags, const std::array<std::string, NBITS> &outputNames,
const std::array<std::string, NBITS> &outputDescriptions, const std::unordered_set<std::string> &outputTags )
: ApplicationModule(owner, inputName, inputDescription, true)
{
bitmask.setMetaData(inputName, "", inputDescription, inputTags);
output.setEliminateHierarchy();
for(size_t i=0; i<NBITS; ++i) {
output.bit[i].setMetaData(outputNames[i], "", outputDescriptions[i], outputTags);
}
}
/// individual outputs for each bit /// individual outputs for each bit
struct Output : public VariableGroup { struct Output : public VariableGroup {
...@@ -67,22 +83,22 @@ namespace ChimeraTK { ...@@ -67,22 +83,22 @@ namespace ChimeraTK {
bit[i].replace(ScalarOutput<int>(this, "bit"+std::to_string(i), "", "The bit "+std::to_string(i)+" of the bit mask")); bit[i].replace(ScalarOutput<int>(this, "bit"+std::to_string(i), "", "The bit "+std::to_string(i)+" of the bit mask"));
} }
} }
ScalarOutput<int> bit[NBITS]; ScalarOutput<int> bit[NBITS];
}; };
Output output{this, "output", "The extracted output bits"}; Output output{this, "output", "The extracted output bits"};
ScalarPushInput<int32_t> bitmask{this, "bitmask", "", "Input bit mask."}; ScalarPushInput<int32_t> bitmask{this, "bitmask", "", "Input bit mask."};
void mainLoop() { void mainLoop() {
while(true) { while(true) {
// decode bit mask // decode bit mask
for(size_t i=0; i<NBITS; ++i) { for(size_t i=0; i<NBITS; ++i) {
output.bit[i] = (bitmask & (1 << i)) != 0; output.bit[i] = (bitmask & (1 << i)) != 0;
output.bit[i].write(); /// @todo TODO better make a writeAll() for VariableGroups output.bit[i].write(); /// @todo TODO better make a writeAll() for VariableGroups
} }
// wait for new input values (at the end, since we want to process the initial values first) // wait for new input values (at the end, since we want to process the initial values first)
bitmask.read(); bitmask.read();
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment