16#include "GaudiKernel/System.h"
20#include "TVirtualCollectionProxy.h"
32void VectorFillerToolBase::Var::next()
42void VectorFillerToolBase::Vars::next_all ()
44 for (
Var& v : *
this) {
56VectorFillerToolBase::VectorFillerToolBase (
const std::string&
type,
57 const std::string& name,
58 const IInterface* parent)
69 "List of contained block filler tools.");
70 declareProperty (
"Prefix",
m_prefix =
"",
71 "Variable name prefix for the contained blocks.");
73 "Name of the variable for the count of rows. "
76 "Name of the variable for the count of objects. "
79 "Name of the variable for the object index. "
88VectorFillerToolBase::initialize()
90 CHECK( AthAlgTool::initialize() );
91 CHECK( m_blockFillers.retrieve() );
92 return StatusCode::SUCCESS;
103 return StatusCode::SUCCESS;
112StatusCode VectorFillerToolBase::doBook()
117 "Number of ntuple rows.") );
119 "Number of ntuple rows.") );
123 "Number of objects.") );
125 "Number of objects.") );
129 "Index of this object.") );
135 return StatusCode::SUCCESS;
152 const std::type_info& ti = it.elementTypeinfo();
158 return StatusCode::SUCCESS;
167void VectorFillerToolBase::maybeExtend (
size_t& n,
size_t&
sz)
170 sz = std::max(
static_cast<size_t>(16), 2*
sz);
196VectorFillerToolBase::fillOnce (
const void* obj,
200 const std::vector<unsigned long>& codes_in,
201 std::vector<unsigned long>& codes_out)
209 bool all_empty =
true;
213 codes_in[j] == IBlockFillerTool::AGAIN);
214 codes_out[j] = scode.getCode();
215 if (codes_out[j] != IBlockFillerTool::EMPTY)
217 CHECK( IBlockFillerTool::againok (scode) );
232 return StatusCode::SUCCESS;
244VectorFillerToolBase::doFill (
IIteration& it,
size_t sizeHint)
247 m_vars.resize_all (sizeHint);
250 size_t sz = sizeHint;
252 std::vector<unsigned long> codes_in;
253 std::vector<unsigned long> codes_out;
258 while (
const void* obj = it.nextUntyped() ) {
261 codes_in.resize (
m_blockFillers.size(), StatusCode(StatusCode::SUCCESS).getCode());
263 codes_in = codes_out;
264 while (std::find (codes_out.begin(), codes_out.end(),
265 (
unsigned long)IBlockFillerTool::AGAIN)
273 it.releaseElementUntyped (obj);
287 return StatusCode::SUCCESS;
306VectorFillerToolBase::addVariable (
const std::string& name,
307 const std::type_info& ti,
309 const std::string& docstring ,
315 return StatusCode::SUCCESS;
322 EDataType
dt = TDataType::GetType (ti);
345 <<
"Requested a default value for variable " <<
name
346 <<
" of type " << System::typeinfoName (ti)
347 <<
"; but default values are only supported for basic types.";
348 return StatusCode::FAILURE;
351 TDataType*
tdt = gROOT->GetType (TDataType::GetTypeName (dt));
353 defsize =
tdt->Size();
354 defcopied =
new char[defsize];
355 std::memcpy (defcopied, defval, defsize);
358 m_vars.push_back (Var (name, ti, ptr, docstring, defcopied, defsize));
359 CHECK(
m_vars.back().init (&m_metadata, m_prefix) );
362 return StatusCode::SUCCESS;
383VectorFillerToolBase::addDimensionedVariable (
const std::string& ,
384 const std::type_info& ,
390 REPORT_MESSAGE(MSG::ERROR) <<
"addDimensionedVariable not yet implemented.";
391 return StatusCode::FAILURE;
408VectorFillerToolBase::Var::Var (
const std::string& name,
409 const std::type_info& ti,
411 const std::string& docstring,
416 m_addr (reinterpret_cast<
char**> (&
ptr)),
417 m_docstring (docstring),
433 const std::string& prefix)
439 if (eltname ==
"bool")
443 std::string vname =
"std::vector<" + eltname;
444 if (vname[vname.size()-1] ==
'>')
449 TClass*
cls = TClass::GetClass (vname.c_str());
455 return StatusCode::FAILURE;
457 m_proxy =
cls->GetCollectionProxy();
460 REPORT_MESSAGE(MSG::ERROR) <<
"Can't find root collection proxy for type "
464 return StatusCode::FAILURE;
467 if (!m_proxy->GetCollectionClass() ||
468 !m_proxy->GetCollectionClass()->GetTypeInfo())
470 REPORT_MESSAGE(MSG::ERROR) <<
"Dictionary error for collection class "
474 return StatusCode::FAILURE;
482 return tree->addVariable (prefix + m_name,
483 *m_proxy->GetCollectionClass()->GetTypeInfo(),
494void VectorFillerToolBase::Var::resize (
size_t sz,
size_t pos)
497 TVirtualCollectionProxy::TPushPop pushcont (m_proxy, m_contptr);
498 size_t oldsz = m_proxy->Size();
499 m_proxy->Allocate (
sz,
false);
505 char*
begin =
static_cast<char*
> (m_proxy->At(0));
512 if (m_valdiff == 0 &&
sz >= 2)
513 m_valdiff =
static_cast<char*
> (m_proxy->At(1)) -
begin;
519 if (m_default &&
sz > oldsz) {
521 std::memcpy (begin, m_default, m_defsize);
524 assert (m_defsize <= m_valdiff);
525 for (
char* p = begin + oldsz * m_valdiff;
529 std::memcpy (p, m_default, m_defsize);
541void VectorFillerToolBase::Var::free ()
550VectorFillerToolBase::Vars::~Vars()
552 for (Var& v : *
this) {
563void VectorFillerToolBase::Vars::resize_all (
size_t sz,
size_t pos )
565 for (Var& v : *
this) {
Helpers for checking error return status codes and reporting errors.
#define REPORT_MESSAGE(LVL)
Report a message.
#define CHECK(...)
Evaluate an expression and check for errors.
Abstract interface for iterating over a set of things.
Utility functions for converting between type names, type_info, and CLIDs.
Common interface for adding a variable to a tuple.
StatusCode addVariable(const std::string &name, T *&ptr, const std::string &docstring="")
Add a variable to the tuple.
Abstract interface for iterating over a set of things.
Description for a single variable.
std::string m_name
The primary name part of this expression.
Block filler tool for noisy FEB information.
virtual StatusCode configureD3PD(IAddVariable *tree, const std::type_info &ti)
Configure during initialization: type-check.
void maybeExtend(size_t &n, size_t &sz)
Extend vectors if needed.
std::string m_nobjName
Property: Name of the variable for the count of objects. Omitted if empty.
std::string m_nrowName
Property: Name of the variable for the count of rows. Omitted if empty.
virtual StatusCode book()
Declare tuple variables.
ID3PD * m_tree
Pointer to the ID3PD object used.
std::string m_objIndexName
Property: Name of the variable for the object index. Omitted if empty.
std::string typeinfoToName(const std::type_info &ti)
Convert from a type_info to a name.
std::string m_prefix
Property: The variable name prefix.
int * m_objIndex
Variable for the object index.
int * m_nobj
Variable for the object count.
StatusCode fillOnce(const void *obj, size_t objndx, size_t &n, size_t &sz, const std::vector< unsigned long > &codes_in, std::vector< unsigned long > &codes_out)
Make one loop over block filler tools.
int * m_nrow
Variable for the row count.
ToolHandleArray< IBlockFillerTool > m_blockFillers
Property: The list of block filler tools.
ObjectMetadata m_metadata
Metadata about the variables created by this tool.
Vars m_vars
All booked variables.
::StatusCode StatusCode
StatusCode definition for legacy code.