ChimeraTK-DeviceAccess 03.25.00
Loading...
Searching...
No Matches
ExperimentalFeatures.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK, ChimeraTK Project <chimeratk-support@desy.de>
2// SPDX-License-Identifier: LGPL-3.0-or-later
3#pragma once
4
5#include <atomic>
6#include <iostream>
7#include <map>
8#include <mutex>
9#include <string>
10
11namespace ChimeraTK {
12
17 public:
22 static void enable() {
23 if(isEnabled) return;
24 std::cerr << "*******************************************************************************" << std::endl;
25 std::cerr << " Experimental features are now enabled in ChimeraTK DeviceAccess" << std::endl;
26 std::cerr << "*******************************************************************************" << std::endl;
27 isEnabled = true;
28 }
29
35 static void check(const std::string& featureName) {
36 if(!isEnabled) {
37 std::cerr << "You are using the experimental feature '" << featureName
38 << "' but do not have experimental features enabled!" << std::endl;
39 std::terminate();
40 }
41 std::lock_guard<std::mutex> guard(reminder.lock_useCount);
42 reminder.useCount[featureName]++;
43 }
44
45 private:
46 static std::atomic<bool> isEnabled;
47
48 class Reminder {
49 friend class ExperimentalFeatures;
50 Reminder() = default;
51 ~Reminder() {
52 if(ExperimentalFeatures::isEnabled) {
53 std::cerr << "*******************************************************************************" << std::endl;
54 std::cerr << " Experimental features were enabled in ChimeraTK DeviceAccess" << std::endl;
55 std::cerr << " The following features were used (use count):" << std::endl;
56 for(auto& uc : useCount) {
57 std::cerr << " - " << uc.first << " (" << uc.second << ")" << std::endl;
58 }
59 std::cerr << "*******************************************************************************" << std::endl;
60 }
61 }
62 std::map<std::string, uint64_t> useCount;
63 std::mutex lock_useCount;
64 };
65 static Reminder reminder;
66 };
67} // namespace ChimeraTK
Class for handling the experimental feature enable flag.
static void check(const std::string &featureName)
Check if experimental features are enabled.
static void enable()
Enable experimental features.