ATLAS Offline Software
Public Member Functions | Private Attributes | List of all members
D3PD::VectorFillerToolBase::Var Class Reference

Description for a single variable. More...

Collaboration diagram for D3PD::VectorFillerToolBase::Var:

Public Member Functions

 Var (const std::string &name, const std::type_info &ti, void *&ptr, const std::string &dim, char *defval, size_t defsize)
 Constructor. More...
 
StatusCode init (IAddVariable *tree, const std::string &prefix)
 Initialize the variable. More...
 
void resize (size_t sz, size_t pos)
 Resize the vector. More...
 
void next ()
 Move the variable pointer to the next element. More...
 
void free ()
 Free allocated storage. More...
 

Private Attributes

std::string m_name
 The variable name. More...
 
const std::type_info * m_ti
 The type of the variable element (for each object). More...
 
char ** m_addr
 Pointer to the variable pointer. More...
 
std::string m_docstring
 Documentation string. More...
 
TVirtualCollectionProxy * m_proxy
 The root collection proxy. More...
 
size_t m_valdiff
 Offset between collection elements. More...
 
void * m_contptr
 Pointer to the vector instance. More...
 
char * m_default
 Pointer to the default value for this variable, if one has been requested. More...
 
size_t m_defsize
 Size of the object pointed to by m_default. More...
 

Detailed Description

Description for a single variable.

We need to be able to resize the vector and quickly adjust the pointer to the next entry. So we save the root collection proxy and the element-to-element to offset. So to move to a new element, all we need to do is to add the offset to the variable pointer.

The vector must have a root dictionary (but not necessarily a reflex dictionary).

Definition at line 227 of file VectorFillerToolBase.h.

Constructor & Destructor Documentation

◆ Var()

D3PD::VectorFillerToolBase::Var::Var ( const std::string &  name,
const std::type_info &  ti,
void *&  ptr,
const std::string &  docstring,
char *  defval,
size_t  defsize 
)

Constructor.

Parameters
nameThe variable name (without prefix).
tiThe element type of the variable.
ptrThe variable pointer provided by the block filler tool.
dimReserved.
defvalPointer to the default value to use for this variable. Null for no default. Of the type given by ti. Only works for basic types. We take ownership of this.
defsizeSize of the object pointed at by defval.
nameThe variable name (without prefix).
tiThe element type of the variable.
ptrThe variable pointer provided by the block filler tool.
docstringDocumentation string.
defvalPointer to the default value to use for this variable. Null for no default. Of the type given by ti. Only works for basic types. We take ownership of this.
defsizeSize of the object pointed at by defval.

Definition at line 408 of file VectorFillerToolBase.cxx.

414  : m_name (name),
415  m_ti (&ti),
416  m_addr (reinterpret_cast<char**> (&ptr)),
417  m_docstring (docstring),
418  m_proxy (0),
419  m_valdiff (0),
420  m_contptr (0),
421  m_default (defval),
422  m_defsize (defsize)
423 {
424 }

Member Function Documentation

◆ free()

void D3PD::VectorFillerToolBase::Var::free ( )

Free allocated storage.

Don't do this from the destructor since these guys get used in a vector.

Definition at line 542 of file VectorFillerToolBase.cxx.

543 {
544  delete [] m_default;
545 }

◆ init()

StatusCode D3PD::VectorFillerToolBase::Var::init ( IAddVariable tree,
const std::string &  prefix 
)

Initialize the variable.

Parameters
treeThe parent tree.
prefixThe variable name prefix.

Definition at line 432 of file VectorFillerToolBase.cxx.

434 {
435  // Get the name of the element variable.
436  std::string eltname = typeinfoToName (*m_ti);
437 
438  // Use vector<int> instead of vector<bool>.
439  if (eltname == "bool")
440  eltname = "int";
441 
442  // Construct the vector name.
443  std::string vname = "std::vector<" + eltname;
444  if (vname[vname.size()-1] == '>')
445  vname += ' ';
446  vname += '>';
447 
448  // Fetch the root dictionary for the vector and find the proxy.
449  TClass* cls = TClass::GetClass (vname.c_str());
450  if (!cls) {
451  REPORT_MESSAGE(MSG::ERROR) << "Can't find TClass for type "
452  << vname
453  << " for variable "
454  << prefix + m_name;
455  return StatusCode::FAILURE;
456  }
457  m_proxy = cls->GetCollectionProxy();
458 
459  if (!m_proxy) {
460  REPORT_MESSAGE(MSG::ERROR) << "Can't find root collection proxy for type "
461  << vname
462  << " for variable "
463  << prefix + m_name;
464  return StatusCode::FAILURE;
465  }
466 
467  if (!m_proxy->GetCollectionClass() ||
468  !m_proxy->GetCollectionClass()->GetTypeInfo())
469  {
470  REPORT_MESSAGE(MSG::ERROR) << "Dictionary error for collection class "
471  << vname
472  << " for variable "
473  << prefix + m_name;
474  return StatusCode::FAILURE;
475  }
476 
477  // Will be set at the first resize().
478  m_valdiff = 0;
479 
480  // Create the vector.
481  m_contptr = 0;
482  return tree->addVariable (prefix + m_name,
483  *m_proxy->GetCollectionClass()->GetTypeInfo(),
484  // cppcheck-suppress nullPointer; false positive
485  m_contptr,
486  m_docstring);
487 }

◆ next()

void D3PD::VectorFillerToolBase::Var::next ( )
inline

Move the variable pointer to the next element.

Definition at line 32 of file VectorFillerToolBase.cxx.

33 {
34  *m_addr += m_valdiff;
35 }

◆ resize()

void D3PD::VectorFillerToolBase::Var::resize ( size_t  sz,
size_t  pos 
)

Resize the vector.

Parameters
szThe new vector size.
posAfter the resize, move the variable pointer to this element.

Definition at line 495 of file VectorFillerToolBase.cxx.

496 {
497  // Resize the vector.
498  TVirtualCollectionProxy::TPushPop pushcont (m_proxy, m_contptr);
499  size_t oldsz = m_proxy->Size();
500  m_proxy->Allocate (sz, false);
501  if (sz == 0) {
502  *m_addr = 0;
503  return;
504  }
505 
506  char* begin = static_cast<char*> (m_proxy->At(0));
507 
508  // Calculate the element offset, if needed.
509  // We do this by finding the difference between the first two
510  // elements, so we can only do this if there are at least two elements
511  // in the vector. But if there are less than two elements, then
512  // the offset doesn't matter anyway.
513  if (m_valdiff == 0 && sz >= 2)
514  m_valdiff = static_cast<char*> (m_proxy->At(1)) - begin;
515 
516  // Set the pointer properly.
517  *m_addr = begin + pos * m_valdiff;
518 
519  // Fill in default value if requested.
520  if (m_default && sz > oldsz) {
521  if (sz == 1) {
522  std::memcpy (begin, m_default, m_defsize);
523  }
524  else {
525  assert (m_defsize <= m_valdiff);
526  for (char* p = begin + oldsz * m_valdiff;
527  p < begin + sz * m_valdiff;
528  p += m_valdiff)
529  {
530  std::memcpy (p, m_default, m_defsize);
531  }
532  }
533  }
534 }

Member Data Documentation

◆ m_addr

char** D3PD::VectorFillerToolBase::Var::m_addr
private

Pointer to the variable pointer.

Definition at line 290 of file VectorFillerToolBase.h.

◆ m_contptr

void* D3PD::VectorFillerToolBase::Var::m_contptr
private

Pointer to the vector instance.

Definition at line 302 of file VectorFillerToolBase.h.

◆ m_default

char* D3PD::VectorFillerToolBase::Var::m_default
private

Pointer to the default value for this variable, if one has been requested.

We own this object.

Definition at line 306 of file VectorFillerToolBase.h.

◆ m_defsize

size_t D3PD::VectorFillerToolBase::Var::m_defsize
private

Size of the object pointed to by m_default.

(Should generally be the same as m_valdiff, but it may possibly be smaller due to alignment considerations.)

Definition at line 311 of file VectorFillerToolBase.h.

◆ m_docstring

std::string D3PD::VectorFillerToolBase::Var::m_docstring
private

Documentation string.

Definition at line 293 of file VectorFillerToolBase.h.

◆ m_name

std::string D3PD::VectorFillerToolBase::Var::m_name
private

The variable name.

Definition at line 284 of file VectorFillerToolBase.h.

◆ m_proxy

TVirtualCollectionProxy* D3PD::VectorFillerToolBase::Var::m_proxy
private

The root collection proxy.

Definition at line 296 of file VectorFillerToolBase.h.

◆ m_ti

const std::type_info* D3PD::VectorFillerToolBase::Var::m_ti
private

The type of the variable element (for each object).

Definition at line 287 of file VectorFillerToolBase.h.

◆ m_valdiff

size_t D3PD::VectorFillerToolBase::Var::m_valdiff
private

Offset between collection elements.

Definition at line 299 of file VectorFillerToolBase.h.


The documentation for this class was generated from the following files:
fitman.sz
sz
Definition: fitman.py:527
D3PD::VectorFillerToolBase::Var::m_addr
char ** m_addr
Pointer to the variable pointer.
Definition: VectorFillerToolBase.h:290
tree
TChain * tree
Definition: tile_monitor.h:30
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
D3PD::VectorFillerToolBase::Var::m_proxy
TVirtualCollectionProxy * m_proxy
The root collection proxy.
Definition: VectorFillerToolBase.h:296
CaloClusterListBadChannel.cls
cls
Definition: CaloClusterListBadChannel.py:8
dbg::ptr
void * ptr(T *p)
Definition: SGImplSvc.cxx:74
D3PD::VectorFillerToolBase::Var::m_valdiff
size_t m_valdiff
Offset between collection elements.
Definition: VectorFillerToolBase.h:299
D3PD::VectorFillerToolBase::Var::m_docstring
std::string m_docstring
Documentation string.
Definition: VectorFillerToolBase.h:293
D3PD::VectorFillerToolBase::Var::m_ti
const std::type_info * m_ti
The type of the variable element (for each object).
Definition: VectorFillerToolBase.h:287
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
checkCorrelInHIST.prefix
dictionary prefix
Definition: checkCorrelInHIST.py:391
D3PD::typeinfoToName
std::string typeinfoToName(const std::type_info &ti)
Convert from a type_info to a name.
Definition: TypeNameConversions.cxx:130
D3PD::VectorFillerToolBase::Var::m_default
char * m_default
Pointer to the default value for this variable, if one has been requested.
Definition: VectorFillerToolBase.h:306
D3PD::VectorFillerToolBase::Var::m_contptr
void * m_contptr
Pointer to the vector instance.
Definition: VectorFillerToolBase.h:302
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
REPORT_MESSAGE
#define REPORT_MESSAGE(LVL)
Report a message.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:365
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
D3PD::VectorFillerToolBase::Var::m_defsize
size_t m_defsize
Size of the object pointed to by m_default.
Definition: VectorFillerToolBase.h:311
D3PD::VectorFillerToolBase::Var::m_name
std::string m_name
The variable name.
Definition: VectorFillerToolBase.h:284