@@ -37,7 +37,7 @@ namespace helper
3737
3838// Preparation for map axis -> map with bin labels
3939template <std::size_t NStep, std::size_t NArgLocal, std::size_t NAxis, typename TupleArgs>
40- void getMapBinLabelsPerAxis (std::map<unsigned int , std::map<unsigned int , std::string>>& mapAxisToMapBinLabels, const TupleArgs& tupleArgs)
40+ inline void getMapBinLabelsPerAxis (std::map<unsigned int , std::map<unsigned int , std::string>>& mapAxisToMapBinLabels, const TupleArgs& tupleArgs)
4141{
4242 if constexpr (NStep < std::tuple_size_v<TupleArgs>) {
4343 using ElementType = typename std::tuple_element<NStep, TupleArgs>::type;
@@ -59,7 +59,7 @@ void getMapBinLabelsPerAxis(std::map<unsigned int, std::map<unsigned int, std::s
5959
6060// For unpacking std::map<unsigned int, std::string> into tuple of bin parameters
6161template <typename Arg>
62- auto unpackHistArg (const Arg& arg)
62+ inline auto unpackHistArg (const Arg& arg)
6363{
6464 if constexpr (std::is_same_v<std::decay_t <Arg>, std::map<unsigned int , std::string>>) {
6565 return std::make_tuple (static_cast <int >(arg.size ()), float (0.0 ), static_cast <float >(arg.size ()));
@@ -74,7 +74,7 @@ auto unpackHistArg(const Arg& arg)
7474// auto h2 = makeHist<TH1F>("hist2","hist2",map1)
7575
7676template <typename HistType, typename ... BinArgs>
77- auto makeHist (const std::string& name, const std::string& title, BinArgs&&... binArgs)
77+ inline auto makeHist (const std::string& name, const std::string& title, BinArgs&&... binArgs)
7878{
7979
8080 const auto tupleArgs = std::tuple_cat (std::make_tuple (name, title), unpackHistArg (std::forward<BinArgs>(binArgs))...);
@@ -109,7 +109,7 @@ auto makeHist(const std::string& name, const std::string& title, BinArgs&&... bi
109109}
110110
111111template <typename HistType, typename ManagerType, typename ... BinArgs>
112- auto registerHist (ManagerType manager, const std::string& defaultDrawOption, const std::string& name, const std::string& title, BinArgs&&... binArgs)
112+ inline auto registerHist (ManagerType manager, const std::string& defaultDrawOption, const std::string& name, const std::string& title, BinArgs&&... binArgs)
113113{
114114 auto ptrHist = makeHist<HistType>(name, title, std::forward<BinArgs>(binArgs)...);
115115 manager->startPublishing (ptrHist.get ());
@@ -120,7 +120,7 @@ auto registerHist(ManagerType manager, const std::string& defaultDrawOption, con
120120}
121121
122122template <typename ValueType>
123- ValueType getConfigFromPropertyTree (const boost::property_tree::ptree& config, const char * fieldName, ValueType value = {})
123+ inline ValueType getConfigFromPropertyTree (const boost::property_tree::ptree& config, const char * fieldName, ValueType value = {})
124124{
125125 const auto & node = config.get_child_optional (fieldName);
126126 if (node) {
@@ -134,7 +134,7 @@ ValueType getConfigFromPropertyTree(const boost::property_tree::ptree& config, c
134134
135135// first entry - start BC, second - number of BCs in row
136136template <typename BitSetBC>
137- std::vector<std::pair<int , int >> getMapBCtrains (const BitSetBC& bitsetBC)
137+ inline std::vector<std::pair<int , int >> getMapBCtrains (const BitSetBC& bitsetBC)
138138{
139139 std::vector<std::pair<int , int >> vecTrains{};
140140 int nBCs{ 0 };
@@ -160,6 +160,49 @@ std::vector<std::pair<int, int>> getMapBCtrains(const BitSetBC& bitsetBC)
160160 return vecTrains;
161161}
162162
163+ inline std::map<unsigned int , std::string> multiplyMaps (const std::vector<std::tuple<std::string, std::map<unsigned int , std::string>, std::string>>& vecPreffixMapSuffix, bool useMapSizeAsMultFactor = true )
164+ {
165+
166+ auto multiplyPairMaps = [](bool useMapSizeAsMultFactor, const std::tuple<std::string, std::map<unsigned int , std::string>, std::string>& firstPreffixMapSuffix,
167+ const std::tuple<std::string, std::map<unsigned int , std::string>, std::string>& secondPreffixMapSuffix = {}) -> std::map<unsigned int , std::string> {
168+ std::map<unsigned int , std::string> mapResult{};
169+ const auto & firstPreffix = std::get<0 >(firstPreffixMapSuffix);
170+ const auto & firstSuffix = std::get<2 >(firstPreffixMapSuffix);
171+ const auto & firstMap = std::get<1 >(firstPreffixMapSuffix);
172+
173+ const auto & secondPreffix = std::get<0 >(secondPreffixMapSuffix);
174+ const auto & secondSuffix = std::get<2 >(secondPreffixMapSuffix);
175+ const auto & secondMap = std::get<1 >(secondPreffixMapSuffix);
176+
177+ const unsigned int lastPosSecondMap = secondMap.size () > 0 ? (--secondMap.end ())->first : 0 ;
178+ const unsigned int multFactor = (useMapSizeAsMultFactor && secondMap.size () > 0 ) ? secondMap.size () : lastPosSecondMap + 1 ;
179+
180+ for (const auto & entryFirst : firstMap) {
181+ const std::string newEntrySecond_preffix = firstPreffix + entryFirst.second + firstSuffix;
182+ const unsigned int startIndex = entryFirst.first * multFactor;
183+ for (const auto & entrySecond : secondMap) {
184+ const std::string newEntrySecond = newEntrySecond_preffix + secondPreffix + entrySecond.second + secondSuffix;
185+ const unsigned int newEntryFirst = startIndex + entrySecond.first ;
186+ mapResult.insert ({ newEntryFirst, newEntrySecond });
187+ }
188+ if (secondMap.size () == 0 ) {
189+ // Only add preffix and suffix
190+ mapResult.insert ({ startIndex, newEntrySecond_preffix });
191+ }
192+ }
193+ return mapResult;
194+ };
195+ std::map<unsigned int , std::string> mapResult{};
196+ if (vecPreffixMapSuffix.size () > 0 ) {
197+ mapResult = multiplyPairMaps (useMapSizeAsMultFactor, vecPreffixMapSuffix[0 ]);
198+ for (int iEntry = 1 ; iEntry < vecPreffixMapSuffix.size (); iEntry++) {
199+ const std::string s1{ " " }, s2{ " " };
200+ mapResult = multiplyPairMaps (useMapSizeAsMultFactor, std::tie (s1, mapResult, s2), vecPreffixMapSuffix[iEntry]);
201+ }
202+ }
203+ return mapResult;
204+ }
205+
163206} // namespace helper
164207} // namespace o2::quality_control_modules::fit
165208#endif
0 commit comments