| 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 "na64calib/index.hh" | ||
| 20 | |||
| 21 | namespace na64dp { | ||
| 22 | namespace calib { | ||
| 23 | |||
| 24 | /**\brief Calibration data loader interface | ||
| 25 | * | ||
| 26 | * This is type-agnostic generalization for calibration data loaders. Pointers | ||
| 27 | * for this class may be used to generally treat (iterate, invoke, delete) a | ||
| 28 | * collections of loaders. | ||
| 29 | * | ||
| 30 | * Loader subclasses incapsulates details of how the certain data type has to | ||
| 31 | * be loaded using dispatcher isntance. `iLoader` subclasses implement the | ||
| 32 | * concrete protocol of data retrieval. | ||
| 33 | * | ||
| 34 | * For instance performing a database request for certain data type and | ||
| 35 | * certain event is the subject of loader instance. Retrieving data from a | ||
| 36 | * file or fetching RESTful data are the other important examples. | ||
| 37 | * | ||
| 38 | * User may want to inherit this class for loader that supports conversion into | ||
| 39 | * multiple types, like: | ||
| 40 | * 1. Support for a source providing calibration data of multiple types | ||
| 41 | * 2. Generalized codec (e.g. CSV) file loader converting string into the tuple. | ||
| 42 | */ | ||
| 43 | struct iLoader { | ||
| 44 | ///\brief Type of the aliases dictionary provided by loader. | ||
| 45 | /// | ||
| 46 | /// Maps calibration data type string identifier (like "SADCPedestals" or | ||
| 47 | /// "names" into internal ID). | ||
| 48 | //typedef std::unordered_map<std::string, Dispatcher::CIDataID> CITypeAliases; | ||
| 49 | |||
| 50 | ✗ | virtual ~iLoader() {} | |
| 51 | /// Loads calibration data into given dispatcher instance | ||
| 52 | virtual void load( const iUpdate &, Dispatcher & ) = 0; | ||
| 53 | /// Shall return whether the loader is capable to load data by given update | ||
| 54 | ✗ | virtual bool can_handle( const iUpdate & ) { return false; } | |
| 55 | /// Shall dump general information about loader for debugging inspection | ||
| 56 | virtual void to_yaml_as_loader(YAML::Node &) const = 0; | ||
| 57 | protected: | ||
| 58 | /// \brief This method will be invoked by manager on adding the loader to | ||
| 59 | /// the list of loaders to gather type aliases. | ||
| 60 | /// | ||
| 61 | /// The loader should either update this map immediately | ||
| 62 | /// or cache reference to this map for later update (makes sense for | ||
| 63 | /// generic loaders which can register additional types during their | ||
| 64 | /// lifetime). The lifetime of the provided reference is guaranteed to | ||
| 65 | /// excess the loader's lifetime. | ||
| 66 | //virtual void put_provided_types( CITypeAliases & ) = 0; | ||
| 67 | |||
| 68 | friend class Manager; | ||
| 69 | }; | ||
| 70 | |||
| 71 | #if 0 | ||
| 72 | /// Concrete calibration data type loader | ||
| 73 | template<typename T, typename UpdateT> | ||
| 74 | struct iSpecializedLoader : public iLoader<UpdateT> { | ||
| 75 | virtual ~iSpecializedLoader(){} | ||
| 76 | |||
| 77 | /// Forwards call to `load()` function, specialized on certain calibration | ||
| 78 | /// data type, then uses dispatcher to deliver the loaded update. | ||
| 79 | virtual void load_data( const UpdateT & updRecipe | ||
| 80 | , Dispatcher::CIDataID id | ||
| 81 | , Dispatcher & dsp ) override { | ||
| 82 | dsp.set<T>(id.second, load(updRecipe, id.second)); | ||
| 83 | } | ||
| 84 | |||
| 85 | /// Uses recipe to load the data of certain type; | ||
| 86 | virtual T load( const UpdateT & updRecipe | ||
| 87 | , const std::string & type | ||
| 88 | ) = 0; | ||
| 89 | }; | ||
| 90 | #endif | ||
| 91 | |||
| 92 | } // namespace ::na64dp::calib | ||
| 93 | } // namespace na64dp | ||
| 94 | |||
| 95 |