ATLAS Offline Software
Loading...
Searching...
No Matches
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.
StatusCode init (IAddVariable *tree, const std::string &prefix)
 Initialize the variable.
void resize (size_t sz, size_t pos)
 Resize the vector.
void next ()
 Move the variable pointer to the next element.
void free ()
 Free allocated storage.

Private Attributes

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

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

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 541 of file VectorFillerToolBase.cxx.

542{
543 delete [] m_default;
544}

◆ 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 m_contptr,
486}
#define REPORT_MESSAGE(LVL)
Report a message.
std::string typeinfoToName(const std::type_info &ti)
Convert from a type_info to a name.
TChain * tree

◆ 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 494 of file VectorFillerToolBase.cxx.

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

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: