ATLAS Offline Software
Loading...
Searching...
No Matches
TConverterRegistry Class Reference

Registry for Root converters. More...

#include <TConverterRegistry.h>

Collaboration diagram for TConverterRegistry:

Public Member Functions

void AddConverter (TVirtualConverter *conv)
 Add a new converter to the registry.
void AddConverter (TVirtualConverter *conv, bool takeown)
 Add a new converter to the registry.
bool AddConverter (const char *convname)
 Add a new converter to the registry.
TVirtualConverterGetConverter (const char *name, int checksum) const
 Look up a converter in the registry by name and checksum.
void AddStreamerConverter (const std::string &from_type, const std::string &to_type, TMemberStreamer *streamer)
TMemberStreamer * GetStreamerConverter (const std::string &from_type, const std::string &to_type) const

Static Public Member Functions

static TConverterRegistryInstance ()
 Return a pointer to the global registry instance.

Private Types

using Payload = std::pair<TVirtualConverter*, bool>
using CheckSumMap = std::map<UInt_t, Payload>
using MapType = std::map<std::string, CheckSumMap>
using lock_t = std::lock_guard<std::mutex>
using SMapType = std::map<std::string, TMemberStreamer*>
 Streamer converters.

Private Member Functions

 ~TConverterRegistry ()
 Destructor.

Private Attributes

MapType fMap
 Map of registered converters.
std::mutex fMutex
 Protect access to the map.
SMapType fSMap

Detailed Description

Registry for Root converters.

Definition at line 40 of file TConverterRegistry.h.

Member Typedef Documentation

◆ CheckSumMap

using TConverterRegistry::CheckSumMap = std::map<UInt_t, Payload>
private

Definition at line 112 of file TConverterRegistry.h.

◆ lock_t

using TConverterRegistry::lock_t = std::lock_guard<std::mutex>
private

Definition at line 120 of file TConverterRegistry.h.

◆ MapType

using TConverterRegistry::MapType = std::map<std::string, CheckSumMap>
private

Definition at line 113 of file TConverterRegistry.h.

◆ Payload

using TConverterRegistry::Payload = std::pair<TVirtualConverter*, bool>
private

Definition at line 111 of file TConverterRegistry.h.

◆ SMapType

using TConverterRegistry::SMapType = std::map<std::string, TMemberStreamer*>
private

Streamer converters.

Definition at line 124 of file TConverterRegistry.h.

Constructor & Destructor Documentation

◆ ~TConverterRegistry()

TConverterRegistry::~TConverterRegistry ( )
private

Destructor.

Destroy the registered converters.

Definition at line 156 of file TConverterRegistry.cxx.

157{
158 for (auto& [name, checksum_map] : fMap) {
159 for (auto& [checksum, payload] : checksum_map) {
160 if (payload.second)
161 delete payload.first;
162 }
163 }
164
165 for (auto& [key, streamer] : fSMap)
166 delete streamer;
167}
MapType fMap
Map of registered converters.

Member Function Documentation

◆ AddConverter() [1/3]

bool TConverterRegistry::AddConverter ( const char * convname)

Add a new converter to the registry.

Parameters
convnameThe name of the converter class to add.
Returns
True if successful, false if the class couldn't be found.

This will also add a streamer for the class, to support conversion in non-split mode.

Definition at line 80 of file TConverterRegistry.cxx.

81{
82 TClass* cl = gROOT->GetClass (convname);
83 if (!cl) return false;
84 TClass* basecl = gROOT->GetClass ("TVirtualConverter");
85 int offs = cl->GetBaseClassOffset (basecl);
86 if (offs < 0) return false;
87 char* cnv = reinterpret_cast<char*> (cl->New());
88 AddConverter (reinterpret_cast<TVirtualConverter*> (cnv + offs), true);
89 return true;
90}
void AddConverter(TVirtualConverter *conv)
Add a new converter to the registry.
cl
print [x.__class__ for x in toList(dqregion.getSubRegions()) ]

◆ AddConverter() [2/3]

void TConverterRegistry::AddConverter ( TVirtualConverter * conv)

Add a new converter to the registry.

Parameters
convThe converter to add.

This will also add a streamer for the class, to support conversion in non-split mode.

The caller will retain ownership of the converter.

Definition at line 35 of file TConverterRegistry.cxx.

36{
37 AddConverter (conv, false);
38}

◆ AddConverter() [3/3]

void TConverterRegistry::AddConverter ( TVirtualConverter * conv,
bool takeown )

Add a new converter to the registry.

Parameters
convThe converter to add.
takeownIf true, the registry takes ownership of the converter.

This will also add a streamer for the class, to support conversion in non-split mode.

Definition at line 49 of file TConverterRegistry.cxx.

51{
52 lock_t lock (fMutex);
53 // Make sure the branch element is properly initialized.
55
56 // Look up the checksum->converter map.
57 // (This will make an empty one if this is the first time we've
58 // seen this name.)
59 TClass* cls = conv->GetTransClass();
60 CheckSumMap& cmap = fMap[cls->GetName()];
61
62 // If this is the first converter for this transient class,
63 // set up a streamer for non-split mode conversions.
64 if (cmap.size() == 0)
65 cls->AdoptStreamer (new TConverterStreamer (cmap, cls));
66
67 // Add this converter to the map.
68 cmap[conv->GetCheckSum()] = std::make_pair (conv, takeown);
69}
void TConvertingBranchElement_init()
To allow calling Initialize without having to depend on the header.
std::map< UInt_t, Payload > CheckSumMap
std::lock_guard< std::mutex > lock_t
std::mutex fMutex
Protect access to the map.

◆ AddStreamerConverter()

void TConverterRegistry::AddStreamerConverter ( const std::string & from_type,
const std::string & to_type,
TMemberStreamer * streamer )

Definition at line 113 of file TConverterRegistry.cxx.

116{
117 lock_t lock (fMutex);
118 std::string key = from_type + "-" + to_type;
119 auto i = fSMap.find (key);
120 if (i != fSMap.end())
121 delete i->second;
122 fSMap[key] = streamer;
123}

◆ GetConverter()

TVirtualConverter * TConverterRegistry::GetConverter ( const char * name,
int checksum ) const

Look up a converter in the registry by name and checksum.

Parameters
nameThe name of the (transient) class.
checksumThe checksum of the persistent class.
Returns
The converter, or nullptr if none.

Definition at line 99 of file TConverterRegistry.cxx.

101{
102 lock_t lock (fMutex);
103 auto i = fMap.find (name);
104 if (i != fMap.end()) {
105 auto i2 = i->second.find (checksum);
106 if (i2 != i->second.end())
107 return i2->second.first;
108 }
109 return nullptr;
110}

◆ GetStreamerConverter()

TMemberStreamer * TConverterRegistry::GetStreamerConverter ( const std::string & from_type,
const std::string & to_type ) const

Definition at line 127 of file TConverterRegistry.cxx.

129{
130 lock_t lock (fMutex);
131 std::string key = from_type + "-" + to_type;
132 auto i = fSMap.find (key);
133 if (i != fSMap.end())
134 return i->second;
135 return nullptr;
136}

◆ Instance()

TConverterRegistry * TConverterRegistry::Instance ( )
static

Return a pointer to the global registry instance.

Definition at line 142 of file TConverterRegistry.cxx.

143{
144 // Do it like this so that the object gets destroyed automatically
145 // at program termination.
146 static TConverterRegistry instance ATLAS_THREAD_SAFE;
147 return &instance;
148}
std::map< std::string, double > instance
#define ATLAS_THREAD_SAFE

Member Data Documentation

◆ fMap

MapType TConverterRegistry::fMap
private

Map of registered converters.

Definition at line 116 of file TConverterRegistry.h.

◆ fMutex

std::mutex TConverterRegistry::fMutex
mutableprivate

Protect access to the map.

Definition at line 119 of file TConverterRegistry.h.

◆ fSMap

SMapType TConverterRegistry::fSMap
private

Definition at line 125 of file TConverterRegistry.h.


The documentation for this class was generated from the following files: