File indexing completed on 2024-04-06 12:05:35
0001 #include <iostream>
0002 #include <map>
0003 #include <string>
0004 #include <utility>
0005 #include <vector>
0006
0007 #include "DetectorDescription/Core/interface/DDConstant.h"
0008 #include "DetectorDescription/Core/interface/DDMap.h"
0009 #include "DetectorDescription/Core/interface/DDName.h"
0010 #include "DetectorDescription/Core/interface/DDString.h"
0011 #include "DetectorDescription/Core/interface/DDVector.h"
0012 #include "FWCore/Utilities/interface/Exception.h"
0013
0014 using namespace std;
0015
0016 double get_value(const DDMap& m, const string& k) { return m[k]; }
0017
0018 int main() {
0019 cout << "DDD Named Types, Test" << endl;
0020
0021 DDName numeric_name("Numeric", "Namespace"), string_name("String", "Namespace"), vector_name("Vector", "Namespace"),
0022 map_name("Map", "Namespace");
0023
0024 cout << "DDNumeric:" << endl;
0025 DDNumeric dd_numeric(numeric_name, std::make_unique<double>(1.1));
0026 cout << dd_numeric << endl;
0027
0028 DDString dd_string(string_name, std::make_unique<string>("foo-bar"));
0029 cout << dd_string << endl;
0030
0031 dd_map_type m;
0032 m["first"] = 1.1;
0033 m["second"] = 0.9;
0034 m["third"] = 0.001;
0035 dd_map_type::iterator it(m.begin()), ed(m.end());
0036 for (; it != ed; ++it) {
0037 cout << it->first << ':' << it->second << ' ';
0038 }
0039 cout << endl;
0040 DDMap dd_map(map_name, std::make_unique<dd_map_type>(m));
0041 cout << dd_map << endl;
0042 try {
0043 cout << "dd_map['second']=" << get_value(dd_map, "second") << endl;
0044 cout << "dd_map['xyz']=" << get_value(dd_map, "xyz") << endl;
0045 } catch (const cms::Exception& e) {
0046 cout << "EXCEPTION: " << e.what() << endl;
0047 }
0048
0049 vector<double> vec;
0050 vec.emplace_back(1.);
0051 vec.emplace_back(2.);
0052 vec.emplace_back(3.);
0053 DDVector dd_vector(vector_name, std::make_unique<vector<double>>(vec));
0054 cout << dd_vector << endl;
0055 cout << dd_vector[0] << ' ' << dd_vector[2] << endl;
0056
0057 return 0;
0058 }