ATLAS Offline Software
TConverterRegistry.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
19 #include "TMemberStreamer.h"
20 #include "TClass.h"
21 #include "TROOT.h"
22 
23 
25 
26 
37 {
38  AddConverter (conv, false);
39 }
40 
41 
51  bool takeown)
52 {
53  lock_t lock (fMutex);
54  // Make sure the branch element is properly initialized.
56 
57  // Look up the checksum->converter map.
58  // (This will make an empty one if this is the first time we've
59  // seen this name.)
60  TClass* cls = conv->GetTransClass();
61  CheckSumMap& cmap = fMap[cls->GetName()];
62 
63  // If this is the first converter for this transient class,
64  // set up a streamer for non-split mode conversions.
65  if (cmap.size() == 0)
66  cls->AdoptStreamer (new TConverterStreamer (cmap, cls));
67 
68  // Add this converter to the map.
69  cmap[conv->GetCheckSum()] = std::make_pair (conv, takeown);
70 }
71 
72 
81 bool TConverterRegistry::AddConverter (const char* convname)
82 {
83  TClass* cl = gROOT->GetClass (convname);
84  if (!cl) return false;
85  TClass* basecl = gROOT->GetClass ("TVirtualConverter");
86  int offs = cl->GetBaseClassOffset (basecl);
87  if (offs < 0) return false;
88  char* cnv = reinterpret_cast<char*> (cl->New());
89  AddConverter (reinterpret_cast<TVirtualConverter*> (cnv + offs), true);
90  return true;
91 }
92 
93 
101  int checksum) const
102 {
103  lock_t lock (fMutex);
104  MapType::const_iterator i = fMap.find (name);
105  if (i != fMap.end()) {
106  CheckSumMap::const_iterator i2 = i->second.find (checksum);
107  if (i2 != i->second.end())
108  return i2->second.first;
109  }
110  return 0;
111 }
112 
113 
114 void TConverterRegistry::AddStreamerConverter (const std::string& from_type,
115  const std::string& to_type,
116  TMemberStreamer* streamer)
117 {
118  lock_t lock (fMutex);
119  std::string key = from_type + "-" + to_type;
120  SMapType::const_iterator i = fSMap.find (key);
121  if (i != fSMap.end())
122  delete i->second;
123  fSMap[key] = streamer;
124 }
125 
126 
127 TMemberStreamer*
128 TConverterRegistry::GetStreamerConverter (const std::string& from_type,
129  const std::string& to_type) const
130 {
131  lock_t lock (fMutex);
132  std::string key = from_type + "-" + to_type;
133  SMapType::const_iterator i = fSMap.find (key);
134  if (i != fSMap.end())
135  return i->second;
136  return 0;
137 }
138 
139 
144 {
145  // Do it like this so that the object gets destroyed automatically
146  // at program termination.
148  return &instance;
149 }
150 
151 
158 {
159  for (MapType::iterator i = fMap.begin(); i != fMap.end(); ++i) {
160  for (CheckSumMap::iterator j = i->second.begin();
161  j != i->second.end();
162  ++j)
163  {
164  if (j->second.second)
165  delete j->second.first;
166  }
167  }
168 
169  for (SMapType::iterator i = fSMap.begin(); i != fSMap.end(); ++i)
170  delete i->second;
171 }
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
TConverterRegistry::fSMap
SMapType fSMap
Definition: TConverterRegistry.h:125
TConvertingBranchElement_init
void TConvertingBranchElement_init()
To allow calling Initialize without having to depend on the header.
Definition: TConvertingBranchElement.cxx:1375
TConverterRegistry::CheckSumMap
std::map< UInt_t, Payload > CheckSumMap
Definition: TConverterRegistry.h:112
CaloClusterListBadChannel.cls
cls
Definition: CaloClusterListBadChannel.py:8
TConverterRegistry::GetStreamerConverter
TMemberStreamer * GetStreamerConverter(const std::string &from_type, const std::string &to_type) const
Definition: TConverterRegistry.cxx:128
TConverterRegistry::~TConverterRegistry
~TConverterRegistry()
Destructor.
Definition: TConverterRegistry.cxx:157
TConverterStreamer
Root streamer that calls our converter when reading in non-split mode.
Definition: TConverterStreamer.h:45
TVirtualConverter.h
Base class for Root converters.
TConverterRegistry::fMutex
std::mutex fMutex
Protect access to the map.
Definition: TConverterRegistry.h:119
instance
std::map< std::string, double > instance
Definition: Run_To_Get_Tags.h:8
lumiFormat.i
int i
Definition: lumiFormat.py:85
TVirtualConverter
Base class for converters for Root schema evolution.
Definition: TVirtualConverter.h:110
TConverterRegistry::lock_t
std::lock_guard< std::mutex > lock_t
Definition: TConverterRegistry.h:120
TConverterRegistry::AddStreamerConverter
void AddStreamerConverter(const std::string &from_type, const std::string &to_type, TMemberStreamer *streamer)
Definition: TConverterRegistry.cxx:114
TConverterRegistry
Registry for Root converters.
Definition: TConverterRegistry.h:41
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
TConverterStreamer.h
Root streamer that calls our converters when reading in non-split mode.
TConverterRegistry::fMap
MapType fMap
Map of registered converters.
Definition: TConverterRegistry.h:116
TConverterRegistry::AddConverter
void AddConverter(TVirtualConverter *conv)
Add a new converter to the registry.
Definition: TConverterRegistry.cxx:36
TConverterRegistry.h
Registry for Root converters.
TConverterRegistry::Instance
static TConverterRegistry * Instance()
Return a pointer to the global registry instance.
Definition: TConverterRegistry.cxx:143
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition: checker_macros.h:211
TConverterRegistry::GetConverter
TVirtualConverter * GetConverter(const char *name, int checksum) const
Look up a converter in the registry by name and checksum.
Definition: TConverterRegistry.cxx:100
checker_macros.h
Define macros for attributes used to control the static checker.
dq_make_web_display.cl
cl
print [x.__class__ for x in toList(dqregion.getSubRegions()) ]
Definition: dq_make_web_display.py:26
pdg_comparison.conv
conv
Definition: pdg_comparison.py:321
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37