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);
147 :
Algorithm(name, pSvcLocator), m_dataSvc(0)
167 using Parser = Gaudi::Utils::AttribStringParser;
168 for (
auto attrib: Parser(m_output)) {
169 switch( ::
toupper(attrib.tag[0]) ) {
171 m_outName = std::move(attrib.value);
174 m_criteria = std::move(attrib.value);
177 fun = std::move(attrib.value);
183 if ( m_outName.empty() ) {
184 log <<
MSG::ERROR <<
"Failed to analyze output specs:" << m_output <<
endmsg;
187 if ( fun.length() > 0 || m_criteria.length() > 0 ) {
188 if ( m_criteria.length() > 0 && fun.length() == 0 ) fun =
"NTuple::Selector";
189 m_selectorName =
fun;
194 log <<
MSG::ERROR <<
"Failed to access service \""
195 << m_tupleSvc <<
"\"." <<
endmsg;
201 if ( m_dataSvc ) m_dataSvc->
release();
220 INTuple::ItemContainer::const_iterator
i;
222 for (i = items.begin(); i != items.end(); ++
i) {
223 long type = (*i)->type();
226 status = createItem(log, tuple, *i, (
unsigned char)0);
229 status = createItem(log, tuple, *i, (
unsigned short)0);
232 status = createItem(log, tuple, *i, (
unsigned int)0);
235 status = createItem(log, tuple, *i, (
unsigned long)0);
238 status = createItem(log, tuple, *i,
char(0));
241 status = createItem(log, tuple, *i,
short(0));
244 status = createItem(log, tuple, *i,
int(0));
247 status = createItem(log, tuple, *i,
long(0));
250 status = createItem(log, tuple, *i,
false);
253 status = createItem(log, tuple, *i,
float(0.0));
256 status = createItem(log, tuple, *i,
double(0.0));
262 status = createItem(log, tuple, *i, (
void*)0);
282 if ( 0 != clone && 0 != src ) {
287 INTuple::ItemContainer::const_iterator
i;
289 for (i = clone_items.begin(); i != clone_items.end(); ++
i) {
291 const std::string& nam = itm->
name();
294 log <<
"Tuple item " << nam <<
" not present in " << src_id <<
endmsg;
297 if ( itm->
type() != src_itm->
type() ) {
298 log <<
"Tuple item " << nam <<
" are of different types in "
299 << src_id <<
":" << src_itm->
typeName() <<
" <-> "
303 if ( itm->
ndim() != src_itm->
ndim() ) {
304 log <<
"Tuple item " << nam <<
" have different dimensions in "
305 << src_id <<
":" << src_itm->
ndim() <<
" <-> "
309 for (
int j=0; j<itm->
ndim(); ++j) {
310 if ( src_itm->
dim(j) != itm->
dim(j) ) {
311 log <<
"Tuple item " << nam <<
" have different dimensions in "
312 << src_id <<
"[" << j <<
"]:" << src_itm->
dim(j) <<
" <-> "
313 << clone_id <<
"[" << j <<
"]:" << itm->
dim(j) <<
endmsg;
318 log <<
"Tuple item " << nam <<
" has different index colums "
319 << src_id <<
":" << src_itm->
hasIndex() <<
" <-> "
325 log <<
"Tuple item " << nam <<
" has different index colums "
326 << src_id <<
":" << src_itm->
index() <<
" <-> "
343 std::vector<GenericAddress> addrVector(clone_items.size());
346 size_t k = 0, nentry = 0;
349 for (k=0; k < source_items.size(); ++k ) {
354 while ( status.isSuccess() ) {
356 if ( status.isSuccess() ) {
357 INTuple::ItemContainer::const_iterator
i;
359 for (k=0,i = source_items.begin(); i != source_items.end(); ++
i,++k) {
363 switch((*i)->type()) {
365 size =
sizeof(
unsigned char);
368 size =
sizeof(
unsigned short);
371 size =
sizeof(
unsigned int);
374 size =
sizeof(
unsigned long);
380 size =
sizeof(short);
392 size =
sizeof(float);
395 size =
sizeof(double);
398 *(std::string*)out_itm->
buffer() = *(std::string*)src_itm->
buffer();
402 size = ::strlen((
const char*)src_itm->
buffer())+1;
406 *(
void**)out_itm->
buffer() = *(
void**)src_itm->
buffer();
428 if ( !status.isSuccess() ) {
429 log <<
MSG::ERROR <<
"Failed to write record " << nentry
430 <<
" from " << input <<
" to " << m_outName <<
endmsg;
434 log <<
MSG::INFO <<
"End of reading tuple " << input
435 <<
" after " << nentry <<
" entries." <<
endmsg;
437 if ( nentry > 0 || m_selectorName !=
"" ) {
450 for (
size_t i=0;
i < m_inputs.size(); ++
i) {
463 else if ( m_selectorName !=
"" ) {
466 if ( m_criteria.length() > 0 ) stmt->
setCriteria(m_criteria);
467 nt->attachSelector(stmt);
471 log <<
MSG::ERROR <<
"Failed to attach tuple selector to " << m_inputs[
i] <<
endmsg;
488 for (
size_t inp=0; inp < m_inputs.size(); ++inp) {
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.
static DataObject * find(SmartDataObjectPtr *ptr)
Static Object find method.
Small smart pointer class with automatic reference counting for IInterface.
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
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.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
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.
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.
StatusCode mergeEntries(const std::string &input)
Merge the entries of a single input tuple into the output.
TYPE * ptr()
Automatic conversion to data type.
NTuple interface class definition.
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)
#define DECLARE_COMPONENT(type)
This class is used for returning status codes from appropriate routines.
virtual StatusCode writeRecord(NTuple::Tuple *tuple)=0
Write single record to N tuple.
std::string m_outName
Output tuple name.
virtual const std::string & name() const
The identifying name of the algorithm object.
StatusCode mergeInputTuples()
Merge all N-tuple entries.
virtual long dim(long i) const =0
Access individual dimensions.
INTupleSvc * m_dataSvc
Reference to data provider service.
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
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 unsigned long release()=0
Release Interface instance.
bool isValid() const
Allow for check if smart pointer is valid.
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)
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.
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)