File indexing completed on 2024-04-06 12:05:24
0001 #ifndef DetectorDescription_Core_DDValue_h
0002 #define DetectorDescription_Core_DDValue_h
0003
0004 #include <atomic>
0005 #include <iostream>
0006 #include <memory>
0007 #include <string>
0008 #include <utility>
0009 #include <vector>
0010
0011 #include "DetectorDescription/Core/interface/DDValuePair.h"
0012 #include "oneapi/tbb/concurrent_unordered_map.h"
0013 #include "oneapi/tbb/concurrent_vector.h"
0014 #include "FWCore/Utilities/interface/zero_allocator.h"
0015
0016
0017
0018
0019
0020
0021
0022 class DDValue {
0023 public:
0024
0025 DDValue(void) : id_(0), vecPair_() {}
0026
0027
0028 explicit DDValue(const std::string&);
0029
0030
0031 explicit DDValue(const char*);
0032
0033
0034 explicit DDValue(const std::string&, const std::vector<DDValuePair>&);
0035
0036
0037 explicit DDValue(const std::string&, double);
0038
0039
0040 explicit DDValue(const std::string&, const std::string&, double);
0041
0042
0043 explicit DDValue(const std::string& name, const std::string& val);
0044
0045 explicit DDValue(unsigned int);
0046
0047
0048 unsigned int id(void) const { return id_; }
0049
0050
0051 operator unsigned int(void) const { return id_; }
0052
0053
0054 const std::string& name(void) const { return *(names()[id_].string_); }
0055
0056
0057
0058 DDValuePair operator[](unsigned int i) const;
0059
0060
0061 const std::vector<std::string>& strings() const { return vecPair_->second.first; }
0062
0063
0064 const std::vector<double>& doubles() const;
0065
0066
0067
0068 unsigned int size() const { return vecPair_ ? vecPair_->second.first.size() : 0; }
0069
0070
0071 void setEvalState(bool newState);
0072
0073
0074
0075
0076 bool isEvaluated(void) const;
0077
0078
0079
0080
0081 bool operator==(const DDValue& v) const;
0082
0083
0084 bool operator<(const DDValue&) const;
0085
0086 private:
0087
0088 struct StringHolder {
0089 StringHolder() {}
0090 explicit StringHolder(std::string iString) : string_(new std::string{std::move(iString)}) {}
0091 explicit StringHolder(StringHolder const& iOther) : string_(new std::string{*(iOther.string_)}) {}
0092 StringHolder& operator=(const StringHolder&) = delete;
0093 ~StringHolder() { delete string_.load(); }
0094
0095 std::atomic<std::string*> string_;
0096 };
0097 struct AtomicUInt {
0098 AtomicUInt(unsigned int iValue) : value_(iValue) {}
0099 AtomicUInt() {}
0100 AtomicUInt(const AtomicUInt& iOther) : value_(iOther.value_.load()) {}
0101 AtomicUInt& operator=(const AtomicUInt& iOther) {
0102 value_ = iOther.value_.load();
0103 return *this;
0104 }
0105
0106 std::atomic<unsigned int> value_;
0107 };
0108
0109 void init(const std::string&);
0110
0111 using Names = tbb::concurrent_vector<StringHolder, edm::zero_allocator<StringHolder>>;
0112 static Names& names();
0113 static Names initializeNames();
0114
0115 using NamesToIndicies = tbb::concurrent_unordered_map<std::string, AtomicUInt>;
0116 static NamesToIndicies& indexer();
0117
0118 unsigned int id_;
0119 using vecpair_type = std::pair<bool, std::pair<std::vector<std::string>, std::vector<double>>>;
0120 std::shared_ptr<vecpair_type> vecPair_;
0121 };
0122
0123 std::ostream& operator<<(std::ostream& o, const DDValue& v);
0124
0125 #endif