| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* This file is a part of NA64SW software. | ||
| 2 | * Copyright (C) 2015-2022 NA64 Collaboration, CERN | ||
| 3 | * | ||
| 4 | * NA64SW is free software: you can redistribute it and/or modify | ||
| 5 | * it under the terms of the GNU General Public License as published by | ||
| 6 | * the Free Software Foundation, either version 3 of the License, or | ||
| 7 | * (at your option) any later version. | ||
| 8 | * | ||
| 9 | * This program is distributed in the hope that it will be useful, | ||
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | * GNU General Public License for more details. | ||
| 13 | * | ||
| 14 | * You should have received a copy of the GNU General Public License | ||
| 15 | * along with this program. If not, see <https://www.gnu.org/licenses/>. */ | ||
| 16 | |||
| 17 | #pragma once | ||
| 18 | |||
| 19 | #include "na64sw-config.h" | ||
| 20 | #include "na64detID/detectorID.hh" | ||
| 21 | |||
| 22 | #include <map> | ||
| 23 | #include <string> | ||
| 24 | |||
| 25 | namespace na64dp { | ||
| 26 | namespace nameutils { | ||
| 27 | |||
| 28 | /**\brief Table of chip's features | ||
| 29 | * | ||
| 30 | * Represents runtime configuration of detector chips features. Although we | ||
| 31 | * generally do not expect have much types of detector chips in NA64, this | ||
| 32 | * helper class is intended to be extensible container for multiple chip types. | ||
| 33 | * | ||
| 34 | * The key feature of the chip, according to the way NA64 DAQ is implemented is | ||
| 35 | * to define how the corresponding detector's hit shall be interpreted. | ||
| 36 | * Although the hit interpretation itself is somewhat we can not define at the | ||
| 37 | * runtime in C++ (it is, therefore, a subject of type traits technique), the | ||
| 38 | * dynamic naming-relevant part is configured via various string templates. | ||
| 39 | * | ||
| 40 | * The purpose of this auxiliary class is to provide some shortcuts over chip | ||
| 41 | * traits index. | ||
| 42 | * | ||
| 43 | * See docs for nested `ChipFeaturesTable::Features` structure documentation | ||
| 44 | * for further insights. | ||
| 45 | * */ | ||
| 46 | class ChipFeaturesTable { | ||
| 47 | public: | ||
| 48 | /// Represents general chip features, relevant for detector naming | ||
| 49 | struct Features { | ||
| 50 | /// Chip name | ||
| 51 | const std::string name; | ||
| 52 | std::string description ///< Chip description | ||
| 53 | , pathFormat ///< Generic format for objects path | ||
| 54 | , dddNameFormat ///< Format of DDD detector name | ||
| 55 | , nameFormat ///< Common detector entity name format | ||
| 56 | ; | ||
| 57 | /// Interprets the payload part of detector ID and appends the | ||
| 58 | /// string substitution dictionary | ||
| 59 | void (*append_completion_context)( DetID, std::map<std::string, std::string> & ); | ||
| 60 | /// Produces human- and machine-readable suffix according to payload, | ||
| 61 | /// uniquely identifying the detector entity | ||
| 62 | void (*to_string)( DetIDPayload_t, char *, size_t available ); | ||
| 63 | /// Parses the human- and machine-readable suffix into payload number | ||
| 64 | DetIDPayload_t (*from_string)( const char * ); | ||
| 65 | |||
| 66 | /// Constructs empty features entry | ||
| 67 | 23 | Features( const std::string & name_ ) : name(name_) | |
| 68 | 23 | , append_completion_context(nullptr) | |
| 69 | 23 | , to_string(nullptr) | |
| 70 | 23 | , from_string(nullptr) | |
| 71 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 23 times.
|
23 | { assert(!name.empty()); } |
| 72 | }; | ||
| 73 | /// Chips table storage type | ||
| 74 | typedef std::map<DetChip_t, Features> ChipsTable; | ||
| 75 | private: | ||
| 76 | /// Chip entries table, indexed by ID | ||
| 77 | ChipsTable _chipFeatures; | ||
| 78 | /// Chip IDs by name | ||
| 79 | std::map<std::string, DetChip_t> _chipIDs; | ||
| 80 | public: | ||
| 81 | /// Returns chip ID by its string name. Raises runtime error if not found. | ||
| 82 | DetChip_t chip_id( const std::string & ) const; | ||
| 83 | /// Returns chip features entry (by ID) | ||
| 84 | const Features & chip_features( DetChip_t ) const; | ||
| 85 | /// Returns chip features entry (by name) | ||
| 86 | const Features & chip_features( const std::string & ) const; | ||
| 87 | /// Defines new detector chip entry returning new entry for subsequent | ||
| 88 | /// initialization | ||
| 89 | Features & chip_add( const std::string & chipName | ||
| 90 | , DetChip_t chipID | ||
| 91 | , const std::string & chipDescription="" | ||
| 92 | , const std::string & histsTPath="" | ||
| 93 | ); | ||
| 94 | /// Returns true if chip with such name is defined | ||
| 95 | 44 | bool has_chip( const std::string & nm ) const | |
| 96 |
1/1✓ Branch 2 taken 44 times.
|
44 | { return _chipIDs.find(nm) != _chipIDs.end(); } |
| 97 | /// Wipes out all chip features | ||
| 98 | void clear(); | ||
| 99 | }; | ||
| 100 | |||
| 101 | |||
| 102 | } | ||
| 103 | } | ||
| 104 | |||
| 105 |