ATLAS Offline Software
Loading...
Searching...
No Matches
ElRecomFileHelpers.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4
6
7#include <fstream>
8#include <map>
9
10namespace {
11// Reads the provided file with the mappings
12// and construct the std::map
13std::map<std::string, std::string>
14read(const std::string& strFile)
15{
16 std::ifstream is(strFile.c_str());
17 if (!is.is_open()) {
18 return {};
19 }
20 std::map<std::string, std::string> result;
21 while (!is.eof()) {
22 std::string strLine;
23 getline(is, strLine);
24 int nPos = strLine.find('=');
25 if ((signed int)std::string::npos == nPos)
26 continue; // no '=', invalid line;
27 std::string strKey = strLine.substr(0, nPos);
28 std::string strVal = strLine.substr(nPos + 1, strLine.length() - nPos + 1);
29 result.insert({ strKey, strVal });
30 }
31 return result;
32};
33}
34
35// Convert reco, ID, iso and trigger key values into a
36// single key according to the map file key format
37std::string
38ElRecomFileHelpers::convertToOneKey(const std::string& recokey,
39 const std::string& idkey,
40 const std::string& isokey,
41 const std::string& trigkey)
42{
43
44 std::string key;
45 // Reconstruction Key
46 if (!recokey.empty()) {
47 key = recokey;
48 }
49 // Identification Key
50 if (!idkey.empty() &&
51 (recokey.empty() && isokey.empty() && trigkey.empty())) {
52 key = idkey;
53 }
54 // Isolation Key
55 if ((!idkey.empty() && !isokey.empty()) && recokey.empty() &&
56 trigkey.empty()) {
57 key = std::string(idkey + "_" + isokey);
58 }
59 // Trigger Key
60 if (!trigkey.empty() && !idkey.empty()) {
61 // Trigger SF file with isolation
62 if (!isokey.empty()) {
63 key = std::string(trigkey + "_" + idkey + "_" + isokey);
64 } else {
65 // Trigger SF file without isolation
66 key = std::string(trigkey + "_" + idkey);
67 }
68 }
69 return key;
70}
71
72// Retrieves the value from the provided map file
73// that is associated with the provided key
74std::string
76 const std::string& key)
77{
78 std::map<std::string, std::string> fileTomap = read(file);
79 if (fileTomap.empty()) {
80 return {};
81 }
82
83 auto i = fileTomap.find(key);
84 if (i != fileTomap.end()) {
85 return i->second;
86 }
87 return {};
88}
89
std::string getValueByKey(const std::string &mapFile, const std::string &key)
std::string convertToOneKey(const std::string &recokey, const std::string &idkey, const std::string &isokey, const std::string &trigkey)
IovVectorMap_t read(const Folder &theFolder, const SelectionCriterion &choice, const unsigned int limit=10)
TFile * file