ATLAS Offline Software
DecodeVersionKey.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
8 #include "GaudiKernel/ISvcLocator.h"
9 #include "GaudiKernel/Bootstrap.h"
10 #include <string>
11 #include <iostream>
12 
13 DecodeVersionKey::DecodeVersionKey(const IGeoModelSvc * geoModel, const std::string & node)
14 {
15  defineTag<IGeoModelSvc>(geoModel,node);
16 }
17 
18 DecodeVersionKey::DecodeVersionKey(const IGeoDbTagSvc * geoDbTag, const std::string & node)
19 {
20  defineTag<IGeoDbTagSvc>(geoDbTag,node);
21 }
22 
24 {
25  SmartIF<IGeoDbTagSvc> geoDbTag{Gaudi::svcLocator()->service("GeoDbTagSvc")};
26  if(!geoDbTag.isValid()) throw std::runtime_error("DecodeVersionKey constructor: cannot access GeoDbTagSvc");
27  defineTag<IGeoDbTagSvc>(geoDbTag,node);
28 }
29 
30 template <class T>
31 void DecodeVersionKey::defineTag(const T* svc, const std::string & node)
32 {
33  std::string nodeOverrideTag;
34  std::string indetOverrideTag; // Indet has two levels.
35  if (node == "ATLAS") {
36  nodeOverrideTag = "";
37  } else if (node == "InnerDetector") {
38  nodeOverrideTag = svc->inDetVersionOverride();
39  } else if (node == "Pixel") {
40  indetOverrideTag = svc->inDetVersionOverride();
41  nodeOverrideTag = svc->pixelVersionOverride();
42  } else if (node == "SCT") {
43  indetOverrideTag = svc->inDetVersionOverride();
44  nodeOverrideTag = svc->SCT_VersionOverride();
45  } else if (node == "TRT") {
46  indetOverrideTag = svc->inDetVersionOverride();
47  nodeOverrideTag = svc->TRT_VersionOverride();
48  } else if (node == "LAr") {
49  nodeOverrideTag = svc->LAr_VersionOverride();
50  } else if (node == "TileCal") {
51  nodeOverrideTag = svc->tileVersionOverride();
52  } else if (node == "MuonSpectrometer") {
53  nodeOverrideTag = svc->muonVersionOverride();
54  } else if (node == "Calorimeter") {
55  nodeOverrideTag = svc->caloVersionOverride();
56  } else if (node == "ForwardDetectors") {
57  nodeOverrideTag = svc->forwardDetectorsVersionOverride();
58  } else {
59  std::cout << "DecodeVersionKey passed an unknown node:" << node << std::endl;
60  nodeOverrideTag = "";
61  }
62 
63  // Default to atlas version
64  m_tag = svc->atlasVersion();
65  m_node = "ATLAS";
66 
67  // If indetOverrideTag is specified (and is not just "CUSTOM") then override with the indet tag.
68  std::string indetTag;
69  if (!indetOverrideTag.empty()) {
70  // We dont care about the return value (custom = true/false). We only take notice of the custom
71  // flag if the override is at the node we have selected. Ie we only look at nodeOverrideTag
72  // in order to set m_custom. At any rate, we have to remove the CUSTOM string if it is present.
73  getCustomTag(indetOverrideTag, indetTag);
74  }
75  if (!indetTag.empty()) {
76  m_tag = indetTag;
77  m_node = "InnerDetector";
78  }
79 
80  // Finally if subsystem tag is overriden then use that.
81  std::string outputTag;
82  m_custom = getCustomTag(nodeOverrideTag, outputTag);
83 
84  if (!outputTag.empty()) {
85  m_tag = outputTag;
86  m_node = node;
87  }
88 }
89 
90 const std::string &
92 {
93  return m_tag;
94 }
95 
96 const std::string &
98 {
99  return m_node;
100 }
101 
102 bool
104 {
105  return m_custom;
106 }
107 
108 
109 
110 bool
111 DecodeVersionKey::getCustomTag(const std::string & inputTag, std::string & outputTag)
112 {
113  //
114  // Check if CUSTOM is specified. If it is not specified then outputTag = inputTag.
115  // If the tag is just "CUSTOM" then set output tag to "" so that we use the higher level tag.
116  // If the tag is of the form CUSTOM-XXXXX use the XXXXX as the tag
117  // The separating character (in this example a '-') can be any character.
118  //
119  bool custom = false;
120  outputTag = inputTag;
121  if (!inputTag.empty()) {
122  if (inputTag.compare(0,6,"CUSTOM") == 0) {
123  custom = true;
124  // If its CUSTOM-something skip the next character and get the something
125  outputTag = inputTag.substr(6);
126  if (!outputTag.empty()) outputTag = outputTag.substr(1);
127  }
128  }
129  return custom;
130 }
131 
DecodeVersionKey::defineTag
void defineTag(const T *svc, const std::string &node)
Definition: DecodeVersionKey.cxx:31
IGeoModelSvc
Definition: IGeoModelSvc.h:17
DecodeVersionKey::custom
bool custom() const
Return true if CUSTOM is selected.
Definition: DecodeVersionKey.cxx:103
DecodeVersionKey::node
const std::string & node() const
Return the version node.
Definition: DecodeVersionKey.cxx:97
DecodeVersionKey::getCustomTag
bool getCustomTag(const std::string &inputTag, std::string &outputTag)
Definition: DecodeVersionKey.cxx:111
DecodeVersionKey::tag
const std::string & tag() const
Return version tag.
Definition: DecodeVersionKey.cxx:91
IGeoDbTagSvc
Definition: IGeoDbTagSvc.h:26
Handler::svc
AthROOTErrorHandlerSvc * svc
Definition: AthROOTErrorHandlerSvc.cxx:10
DecodeVersionKey::m_node
std::string m_node
Definition: DecodeVersionKey.h:47
DecodeVersionKey::m_tag
std::string m_tag
Definition: DecodeVersionKey.h:46
DecodeVersionKey.h
DecodeVersionKey::DecodeVersionKey
DecodeVersionKey(const IGeoModelSvc *, const std::string &node)
Constructor is passed a pointer to GeoModelSvc plus the node for which you want the tag.
Definition: DecodeVersionKey.cxx:13
IGeoModelSvc.h
DecodeVersionKey::m_custom
bool m_custom
Definition: DecodeVersionKey.h:48
IGeoDbTagSvc.h
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35
node
Definition: memory_hooks-stdcmalloc.h:74