8 #include "GaudiKernel/IDataProviderSvc.h"
9 #include "GaudiKernel/ISelectStatement.h"
10 #include "GaudiKernel/IDataManagerSvc.h"
11 #include "GaudiKernel/GenericAddress.h"
12 #include "GaudiKernel/SmartDataPtr.h"
13 #include "GaudiKernel/AttribStringParser.h"
14 #include "GaudiKernel/IRegistry.h"
15 #include "GaudiKernel/Algorithm.h"
16 #include "GaudiKernel/MsgStream.h"
17 #include "GaudiKernel/SmartIF.h"
18 #include "GaudiKernel/NTuple.h"
19 #include "GaudiKernel/ObjectFactory.h"
25 return long(it->
range().upper());
28 template<
class TYP>
static
35 TYP low = source->
range().lower();
36 TYP high = source->
range().upper();
38 long ndim = source->
ndim();
39 const std::string&
name = source->
name();
41 long dim[4], idxLen = 0;
42 long dim1 = 1, dim2 = 1;
44 for (
int i = 0;
i < ndim;
i++ )
45 dim[
i] = source->
dim(
i);
49 idxName = index->
name();
50 switch( index->
type() ) {
52 idxLen = upper<unsigned char>(index);
55 idxLen = upper<unsigned short>(index);
58 idxLen = upper<unsigned int>(index);
61 idxLen = upper<unsigned long>(index);
64 idxLen = upper<char>(index);
67 idxLen = upper<short>(index);
70 idxLen = upper<int>(index);
73 idxLen = upper<long>(index);
77 <<
" is not a valid index column!" <<
endmsg;
86 dim1 = (hasIdx) ? idxLen : dim[0];
97 dim1 = (hasIdx) ? idxLen : dim[0];
98 dim2 = (hasIdx) ? dim[0] : dim[1];
112 return tuple->
add(it);
164 m_dataSvc =
service(m_tupleSvc,
true);
166 log <<
MSG::ERROR <<
"Failed to access service \""
167 << m_tupleSvc <<
"\"." <<
endmsg;
171 using Parser = Gaudi::Utils::AttribStringParser;
172 for (
auto attrib: Parser(m_output)) {
173 switch( ::
toupper(attrib.tag[0]) ) {
175 m_outName = std::move(attrib.value);
178 m_criteria = std::move(attrib.value);
181 fun = std::move(attrib.value);
187 if ( m_outName.empty() ) {
188 log <<
MSG::ERROR <<
"Failed to analyze output specs:" << m_output <<
endmsg;
191 if ( !fun.empty() || !m_criteria.empty() ) {
192 if ( !m_criteria.empty() && fun.empty() ) fun =
"NTuple::Selector";
193 m_selectorName =
fun;
218 INTuple::ItemContainer::const_iterator
i;
220 for (i = items.begin(); i != items.end(); ++
i) {
221 long type = (*i)->type();
224 status = createItem(log, tuple, *i, (
unsigned char)0);
227 status = createItem(log, tuple, *i, (
unsigned short)0);
230 status = createItem(log, tuple, *i, (
unsigned int)0);
233 status = createItem(log, tuple, *i, (
unsigned long)0);
236 status = createItem(log, tuple, *i,
char(0));
239 status = createItem(log, tuple, *i,
short(0));
242 status = createItem(log, tuple, *i,
int(0));
245 status = createItem(log, tuple, *i,
long(0));
248 status = createItem(log, tuple, *i,
false);
251 status = createItem(log, tuple, *i,
float(0.0));
254 status = createItem(log, tuple, *i,
double(0.0));
260 status = createItem(log, tuple, *i, (
void*)0);
280 if ( 0 != clone && 0 != src ) {
285 INTuple::ItemContainer::const_iterator
i;
287 for (i = clone_items.begin(); i != clone_items.end(); ++
i) {
289 const std::string& nam = itm->
name();
292 log <<
"Tuple item " << nam <<
" not present in " << src_id <<
endmsg;
295 if ( itm->
type() != src_itm->
type() ) {
296 log <<
"Tuple item " << nam <<
" are of different types in "
297 << src_id <<
":" << src_itm->
typeName() <<
" <-> "
301 if ( itm->
ndim() != src_itm->
ndim() ) {
302 log <<
"Tuple item " << nam <<
" have different dimensions in "
303 << src_id <<
":" << src_itm->
ndim() <<
" <-> "
307 for (
int j=0; j<itm->
ndim(); ++j) {
308 if ( src_itm->
dim(j) != itm->
dim(j) ) {
309 log <<
"Tuple item " << nam <<
" have different dimensions in "
310 << src_id <<
"[" << j <<
"]:" << src_itm->
dim(j) <<
" <-> "
311 << clone_id <<
"[" << j <<
"]:" << itm->
dim(j) <<
endmsg;
316 log <<
"Tuple item " << nam <<
" has different index colums "
317 << src_id <<
":" << src_itm->
hasIndex() <<
" <-> "
323 log <<
"Tuple item " << nam <<
" has different index colums "
324 << src_id <<
":" << src_itm->
index() <<
" <-> "
341 std::vector<GenericAddress> addrVector(clone_items.size());
344 size_t k = 0, nentry = 0;
347 for (k=0; k < source_items.size(); ++k ) {
352 while ( status.isSuccess() ) {
354 if ( status.isSuccess() ) {
355 INTuple::ItemContainer::const_iterator
i;
357 for (k=0,i = source_items.begin(); i != source_items.end(); ++
i,++k) {
361 switch((*i)->type()) {
363 size =
sizeof(
unsigned char);
366 size =
sizeof(
unsigned short);
369 size =
sizeof(
unsigned int);
372 size =
sizeof(
unsigned long);
378 size =
sizeof(short);
390 size =
sizeof(float);
393 size =
sizeof(double);
396 *(std::string*)out_itm->
buffer() = *(std::string*)src_itm->
buffer();
400 size = ::strlen((
const char*)src_itm->
buffer())+1;
404 *(
void**)out_itm->
buffer() = *(
void**)src_itm->
buffer();
426 if ( !status.isSuccess() ) {
427 log <<
MSG::ERROR <<
"Failed to write record " << nentry
428 <<
" from " << input <<
" to " << m_outName <<
endmsg;
432 log <<
MSG::INFO <<
"End of reading tuple " << input
433 <<
" after " << nentry <<
" entries." <<
endmsg;
435 if ( nentry > 0 || m_selectorName !=
"" ) {
448 for (
size_t i=0;
i < m_inputs.size(); ++
i) {
460 else if ( m_selectorName !=
"" ) {
463 if ( !m_criteria.empty() ) stmt->
setCriteria(m_criteria);
464 nt->attachSelector(stmt);
467 log <<
MSG::ERROR <<
"Failed to attach tuple selector to " << m_inputs[
i] <<
endmsg;
483 for(
const auto& input : m_inputs ) {
std::string m_tupleSvc
Name of the data provider service.
std::string m_criteria
Selection criteria (if any)
Definition of the MsgStream class used to transmit messages.
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
virtual long type() const =0
Type information of the item.
SmartIF< ISvcLocator > & serviceLocator() const
The standard service locator.
virtual StatusCode book(const NTuple::Tuple *nt)
Book the N-tuple according to the specification.
bool isSuccess() const
Test for a status code of SUCCESS.
CollectionCloneAlg(const std::string &name, ISvcLocator *pSvcLocator)
Standard algorithm constructor.
virtual StatusCode add(INTupleItem *item)=0
Add an item row to the N tuple.
std::vector< INTupleItem * > ItemContainer
virtual const std::string & title() const =0
Object title.
Property * declareProperty(const std::string &name, T &property, const std::string &doc="none") const
Declare the named property.
virtual const ItemRange & range() const =0
Access the range if specified.
virtual ~CollectionCloneAlg()
Standard Destructor.
const std::string & type() const override
The type of the algorithm object.
virtual bool hasIndex() const =0
Is the tuple have an index item?
IRegistry * registry() const
Get pointer to Registry.
static _Array * create(INTuple *tup, const std::string &name, const std::type_info &info, const std::string &index, long len, TYP min, TYP max, TYP def)
Create instance.
virtual const std::string & name() const =0
Access _Item name.
SmartIF< INTupleSvc > m_dataSvc
Reference to data provider service.
StatusCode mergeEntries(const std::string &input)
Merge the entries of a single input tuple into the output.
const std::string & name() const override
The identifying name of the algorithm object.
NTuple interface class definition.
TYPE * get() const
Get interface pointer.
std::string m_output
Output specification.
std::vector< std::string > m_inputs
input specifications
NTuple interface class definition.
virtual const CLID & clID() const
Retrieve reference to class definition structure.
virtual INTupleItem * indexItem()=0
Pointer to index column (if present, 0 else)
This class is used for returning status codes from appropriate routines.
virtual StatusCode writeRecord(NTuple::Tuple *tuple)=0
Write single record to N tuple.
#define DECLARE_COMPONENT(type)
std::string m_outName
Output tuple name.
StatusCode mergeInputTuples()
Merge all N-tuple entries.
virtual long dim(long i) const =0
Access individual dimensions.
Abstract class describing basic data in an Ntuple.
virtual StatusCode checkInput(const NTuple::Tuple *clone, const NTuple::Tuple *src)
std::string m_rootName
Name of the root leaf (obtained at initialize)
Abstract base class which allows the user to interact with the actual N tuple implementation.
Base class from which all concrete algorithm classes should be derived.
virtual StatusCode initialize()
Initialize.
virtual long ndim() const =0
Dimension.
StatusCode connect()
Connect input and output N-tuples.
virtual StatusCode execute()
Execute procedure.
virtual StatusCode finalize()
Finalize.
double fun(const std::vector< double > &x)
Small algorithm, which allows to merge N-tuples in a generic way.
virtual StatusCode readRecord(NTuple::Tuple *tuple)=0
Read single record from N tuple.
A small class used to access easily (and efficiently) data items residing in data stores...
virtual const id_type & identifier() const =0
Full identifier (or key)
void reset(TYPE *ptr=nullptr)
Set the internal pointer to the passed one disposing of the old one.
virtual ItemContainer & items()=0
Access item container.
static _Item * create(INTuple *tup, const std::string &name, const std::type_info &info, TYP min, TYP max, TYP def)
Create instance.
StatusCode service(const std::string &name, T *&psvc, bool createIf=true) const
Access a service by name, creating it if it doesn't already exist.
virtual std::string typeName() const =0
Proper type name of the object.
Opaque address interface definition.
std::string m_selectorName
Selector factory.
virtual void setCriteria(const std::string &crit)=0
Set the type.
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
void toupper(std::string &s)
virtual const INTupleItem * find(const std::string &name) const =0
Find an item row of the Ntuple (CONST)
virtual NTuple::Tuple * book(const std::string &fullPath, const CLID &type, const std::string &title)=0
Book Ntuple and register it with the data store.
virtual const std::string & index() const =0
Access the index _Item.
static _Matrix * create(INTuple *tup, const std::string &name, const std::type_info &info, const std::string &index, long ncol, long nrow, TYP min, TYP max, TYP def)
Create instance.
virtual long length() const =0
Access the buffer length.
virtual const void * buffer() const =0
Access data buffer (CONST)