| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "na64calib/evType.hh" | ||
| 2 | #include "na64event/data/event.hh" | ||
| 3 | #include "na64util/str-fmt.hh" | ||
| 4 | #include <log4cpp/Category.hh> | ||
| 5 | #include <log4cpp/Priority.hh> | ||
| 6 | #include <sstream> | ||
| 7 | |||
| 8 | namespace na64dp { | ||
| 9 | |||
| 10 | std::string | ||
| 11 | ✗ | EventBitTags::EventSemanticBits::bitflags_to_str(uint16_t flags) const { | |
| 12 | ✗ | if(!flags) return "0x0"; | |
| 13 | // create sorted dict | ||
| 14 | ✗ | std::map<std::string, uint16_t> sortedDict(begin(), end()); | |
| 15 | ✗ | std::ostringstream oss; | |
| 16 | ✗ | bool isFirst = true; | |
| 17 | ✗ | for(const auto & e : sortedDict) { | |
| 18 | ✗ | if(!(e.second & flags)) continue; | |
| 19 | ✗ | if(isFirst) { | |
| 20 | ✗ | isFirst = false; | |
| 21 | } else { | ||
| 22 | ✗ | oss << ", "; | |
| 23 | } | ||
| 24 | ✗ | oss << e.first; | |
| 25 | ✗ | flags &= ~e.second; | |
| 26 | } | ||
| 27 | ✗ | if(!flags) return oss.str(); | |
| 28 | // otherwise, some unknown numeric codes remained; append it in hex form: | ||
| 29 | char strbf[32]; | ||
| 30 | ✗ | snprintf(strbf, sizeof(strbf), "%#x", flags); | |
| 31 | ✗ | if(!isFirst) oss << ", "; | |
| 32 | ✗ | oss << strbf; | |
| 33 | ✗ | return oss.str(); | |
| 34 | } | ||
| 35 | |||
| 36 | ✗ | EventBitTags::EventBitTags(const YAML::Node & cfg) { | |
| 37 | ✗ | if(cfg.IsNull()) | |
| 38 | ✗ | return; | |
| 39 | |||
| 40 | ✗ | if(cfg["triggerBits"]) { | |
| 41 | ✗ | const YAML::Node & ttNode = cfg["triggerBits"]; | |
| 42 | ✗ | for(auto nodeIt = ttNode.begin(); nodeIt != ttNode.end(); ++nodeIt) { | |
| 43 | ✗ | std::string bitMeaning = nodeIt->first.as<std::string>(); | |
| 44 | ✗ | unsigned int bitPosition = nodeIt->second.as<unsigned int>(); | |
| 45 | ✗ | if(bitPosition > 8*sizeof(na64dp::event::Event::trigger)) { | |
| 46 | ✗ | NA64DP_RUNTIME_ERROR("Can not set %u-th bit of Event::trigger" | |
| 47 | " field (too large value).", bitPosition); | ||
| 48 | } | ||
| 49 | ✗ | triggers.emplace(bitMeaning, 0x1 << bitPosition); | |
| 50 | } | ||
| 51 | ✗ | } else { | |
| 52 | ✗ | log4cpp::Category::getInstance("calib") << log4cpp::Priority::WARN | |
| 53 | ✗ | << "No \"triggerBits\" in event semantical bits object."; | |
| 54 | } | ||
| 55 | |||
| 56 | ✗ | if(cfg["eventTypes"]) { | |
| 57 | ✗ | const YAML::Node & etNode = cfg["eventTypes"]; | |
| 58 | ✗ | for(auto nodeIt = etNode.begin(); nodeIt != etNode.end(); ++nodeIt) { | |
| 59 | ✗ | std::string bitMeaning = nodeIt->first.as<std::string>(); | |
| 60 | ✗ | unsigned int bitPosition = nodeIt->second.as<unsigned int>(); | |
| 61 | ✗ | if(bitPosition > 8*sizeof(na64dp::event::Event::evType)) { | |
| 62 | ✗ | NA64DP_RUNTIME_ERROR("Can not set %u-th bit of Event::evType" | |
| 63 | " field (too large value).", bitPosition); | ||
| 64 | } | ||
| 65 | ✗ | types.emplace(bitMeaning, 0x1 << bitPosition); | |
| 66 | } | ||
| 67 | ✗ | } else { | |
| 68 | ✗ | log4cpp::Category::getInstance("calib") << log4cpp::Priority::WARN | |
| 69 | ✗ | << "No \"eventTypes\" in event semantical bits object."; | |
| 70 | } | ||
| 71 | } | ||
| 72 | |||
| 73 | } | ||
| 74 | |||
| 75 |