Skip to content

Commit 99b8e3c

Browse files
committed
Improve order
1 parent 4f90d65 commit 99b8e3c

File tree

2 files changed

+45
-48
lines changed

2 files changed

+45
-48
lines changed

ALICE3/Core/FastTracker.cxx

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@
1515

1616
#include "ReconstructionDataFormats/TrackParametrization.h"
1717

18+
#include <TEnv.h>
19+
#include <THashList.h>
1820
#include <TMath.h>
1921
#include <TMatrixD.h>
2022
#include <TMatrixDSymEigen.h>
2123
#include <TObject.h>
2224
#include <TRandom.h>
25+
#include <TSystem.h>
2326

2427
#include <fstream>
2528
#include <map>
@@ -31,6 +34,41 @@ namespace o2
3134
namespace fastsim
3235
{
3336

37+
std::map<std::string, std::map<std::string, std::string>> GeometryContainer::parseTEnvConfiguration(std::string filename, std::vector<std::string>& layers)
38+
{
39+
std::map<std::string, std::map<std::string, std::string>> configMap;
40+
filename = gSystem->ExpandPathName(filename.c_str());
41+
TEnv env(filename.c_str());
42+
THashList* table = env.GetTable();
43+
layers.clear();
44+
for (int i = 0; i < table->GetEntries(); ++i) {
45+
const std::string key = table->At(i)->GetName();
46+
// key should contain exactly one dot
47+
if (key.find('.') == std::string::npos || key.find('.') != key.rfind('.')) {
48+
LOG(fatal) << "Key " << key << " does not contain exactly one dot";
49+
continue;
50+
}
51+
const std::string firstPart = key.substr(0, key.find('.'));
52+
if (std::find(layers.begin(), layers.end(), firstPart) == layers.end()) {
53+
layers.push_back(firstPart);
54+
}
55+
}
56+
env.Print();
57+
// Layers
58+
for (const auto& layer : layers) {
59+
LOG(info) << " Reading layer " << layer;
60+
for (int i = 0; i < table->GetEntries(); ++i) {
61+
const std::string key = table->At(i)->GetName();
62+
if (key.find(layer + ".") == 0) {
63+
const std::string paramName = key.substr(key.find('.') + 1);
64+
const std::string value = env.GetValue(key.c_str(), "");
65+
configMap[layer][paramName] = value;
66+
}
67+
}
68+
}
69+
return configMap;
70+
}
71+
3472
void GeometryContainer::init(o2::framework::InitContext& initContext)
3573
{
3674
std::vector<std::string> detectorConfiguration;

ALICE3/Core/FastTracker.h

Lines changed: 7 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@
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

Comments
 (0)