1919#include < Framework/Logger.h>
2020#include < ReconstructionDataFormats/Track.h>
2121
22- #include < TEnv.h>
23- #include < THashList.h>
24- #include < TObject.h>
25- #include < TSystem.h>
26-
2722#include < map>
2823#include < string>
2924#include < vector>
@@ -44,66 +39,30 @@ class GeometryContainer
4439 /* *
4540 * @brief Parses a TEnv configuration file and returns the key-value pairs split per entry
4641 * @param filename Path to the TEnv configuration file
42+ * @param layers Vector to store the order of the layers as they appear in the file
4743 * @return A map where each key is a layer name and the value is another map of key-value pairs for that layer
4844 */
49- static std::map<std::string, std::map<std::string, std::string>> parseTEnvConfiguration (std::string filename)
50- {
51- std::map<std::string, std::map<std::string, std::string>> configMap;
52- filename = gSystem ->ExpandPathName (filename.c_str ());
53- TEnv env (filename.c_str ());
54- THashList* table = env.GetTable ();
55- std::vector<std::string> layers;
56- for (int i = 0 ; i < table->GetEntries (); ++i) {
57- const std::string key = table->At (i)->GetName ();
58- // key should contain exactly one dot
59- if (key.find (' .' ) == std::string::npos || key.find (' .' ) != key.rfind (' .' )) {
60- LOG (fatal) << " Key " << key << " does not contain exactly one dot" ;
61- continue ;
62- }
63- const std::string firstPart = key.substr (0 , key.find (' .' ));
64- if (std::find (layers.begin (), layers.end (), firstPart) == layers.end ()) {
65- layers.push_back (firstPart);
66- }
67- }
68- env.Print ();
69- // Layers
70- for (const auto & layer : layers) {
71- LOG (info) << " Reading layer " << layer;
72- for (int i = 0 ; i < table->GetEntries (); ++i) {
73- const std::string key = table->At (i)->GetName ();
74- if (key.find (layer + " ." ) == 0 ) {
75- const std::string paramName = key.substr (key.find (' .' ) + 1 );
76- const std::string value = env.GetValue (key.c_str (), " " );
77- configMap[layer][paramName] = value;
78- }
79- }
80- }
81- return configMap;
82- }
45+ static std::map<std::string, std::map<std::string, std::string>> parseTEnvConfiguration (std::string filename, std::vector<std::string>& layers);
46+
47+ // A container for the geometry info
8348 struct GeometryEntry {
8449 // Default constructor
8550 GeometryEntry () = default ;
8651 explicit GeometryEntry (std::string filename) : name(filename)
8752 {
88- mConfigurations = GeometryContainer::parseTEnvConfiguration (filename);
53+ mConfigurations = GeometryContainer::parseTEnvConfiguration (filename, layerNames );
8954 }
9055 std::map<std::string, std::map<std::string, std::string>> getConfigurations () const { return mConfigurations ; }
9156 std::map<std::string, std::string> getConfiguration (const std::string& layerName) const ;
92- std::vector<std::string> getLayerNames () const
93- {
94- std::vector<std::string> layerNames;
95- for (const auto & layer : mConfigurations ) {
96- layerNames.push_back (layer.first );
97- }
98- return layerNames;
99- }
57+ std::vector<std::string> getLayerNames () const { return layerNames; }
10058 std::string getValue (const std::string& layerName, const std::string& key, bool require = true ) const ;
10159 float getFloatValue (const std::string& layerName, const std::string& key) const { return std::stof (getValue (layerName, key)); }
10260 int getIntValue (const std::string& layerName, const std::string& key) const { return std::stoi (getValue (layerName, key)); }
10361
10462 private:
10563 std::string name; // Filename of the geometry
10664 std::map<std::string, std::map<std::string, std::string>> mConfigurations ;
65+ std::vector<std::string> layerNames; // Ordered names of the layers
10766 };
10867
10968 void addEntry (const std::string& filename) { entries.emplace_back (filename); }
0 commit comments