Gaudi Framework, version v23r5

Home   Generated: Wed Nov 28 2012
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Public Member Functions | Private Attributes | Static Private Attributes | List of all members
CollectionCloneAlg Class Reference

Small algorithm, which allows to merge N-tuples in a generic way. More...

Inheritance diagram for CollectionCloneAlg:
Inheritance graph
[legend]
Collaboration diagram for CollectionCloneAlg:
Collaboration graph
[legend]

Public Member Functions

 CollectionCloneAlg (const std::string &name, ISvcLocator *pSvcLocator)
 Standard algorithm constructor.
 
virtual ~CollectionCloneAlg ()
 Standard Destructor.
 
virtual StatusCode initialize ()
 Initialize.
 
virtual StatusCode finalize ()
 Finalize.
 
virtual StatusCode execute ()
 Execute procedure.
 
virtual StatusCode book (const NTuple::Tuple *nt)
 Book the N-tuple according to the specification.
 
virtual StatusCode checkInput (const NTuple::Tuple *clone, const NTuple::Tuple *src)
 
StatusCode mergeEntries (const std::string &input)
 Merge the entries of a single input tuple into the output.
 
StatusCode connect ()
 Connect input and output N-tuples.
 
StatusCode mergeInputTuples ()
 Merge all N-tuple entries.
 
- Public Member Functions inherited from Algorithm
 Algorithm (const std::string &name, ISvcLocator *svcloc, const std::string &version=PACKAGE_VERSION)
 Constructor.
 
virtual ~Algorithm ()
 Destructor.
 
virtual StatusCode sysStart ()
 Reinitialization method invoked by the framework.
 
virtual StatusCode sysInitialize ()
 Initialization method invoked by the framework.
 
virtual StatusCode sysReinitialize ()
 Reinitialization method invoked by the framework.
 
virtual StatusCode sysRestart ()
 Restart method invoked by the framework.
 
virtual StatusCode sysExecute ()
 The actions to be performed by the algorithm on an event.
 
virtual StatusCode sysStop ()
 System stop.
 
virtual StatusCode sysFinalize ()
 System finalization.
 
virtual StatusCode sysBeginRun ()
 beginRun method invoked by the framework.
 
virtual StatusCode sysEndRun ()
 endRun method invoked by the framework.
 
virtual const std::stringname () const
 The identifying name of the algorithm object.
 
virtual const std::stringversion () const
 
virtual StatusCode configure ()
 Dummy implementation of IStateful::configure() method.
 
virtual StatusCode terminate ()
 Dummy implementation of IStateful::terminate() method.
 
virtual StatusCode start ()
 the default (empty) implementation of IStateful::start() method
 
virtual StatusCode stop ()
 the default (empty) implementation of IStateful::stop() method
 
virtual StatusCode reinitialize ()
 the default (empty) implementation of IStateful::reinitialize() method
 
virtual StatusCode restart ()
 the default (empty) implementation of IStateful::restart() method
 
virtual bool isExecuted () const
 Has this algorithm been executed since the last reset?
 
virtual void setExecuted (bool state)
 Set the executed flag to the specified state.
 
virtual void resetExecuted ()
 Reset the executed state of the Algorithm for the duration of the current event.
 
virtual StatusCode beginRun ()
 Algorithm begin run.
 
virtual StatusCode endRun ()
 Algorithm end run. This method is called at the end of the event loop.
 
virtual Gaudi::StateMachine::State FSMState () const
 returns the current state of the algorithm
 
virtual Gaudi::StateMachine::State targetFSMState () const
 returns the state the algorithm will be in after the ongoing transition
 
virtual bool isEnabled () const
 Is this algorithm enabled or disabled?
 
virtual bool filterPassed () const
 Did this algorithm pass or fail its filter criterion for the last event?
 
virtual void setFilterPassed (bool state)
 Set the filter passed flag to the specified state.
 
template<class T >
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.
 
template<class T >
StatusCode service (const std::string &svcType, const std::string &svcName, T *&psvc) const
 Access a service by name and type, creating it if it doesn't already exist.
 
SmartIF< IServiceservice (const std::string &name, const bool createIf=true, const bool quiet=false) const
 Return a pointer to the service identified by name (or "type/name")
 
void setOutputLevel (int level)
 Set the output level for current algorithm.
 
SmartIF< IAuditorSvc > & auditorSvc () const
 The standard auditor service.May not be invoked before sysInitialize() has been invoked.
 
SmartIF< IChronoStatSvc > & chronoSvc () const
 The standard Chrono & Stat service, Return a pointer to the service if present.
 
SmartIF< IChronoStatSvc > & chronoStatService () const
 Obsoleted name, kept due to the backwards compatibility.
 
SmartIF< IDataProviderSvc > & detSvc () const
 The standard detector data service.
 
SmartIF< IDataProviderSvc > & detDataService () const
 Obsoleted name, kept due to the backwards compatibility.
 
SmartIF< IConversionSvc > & detCnvSvc () const
 The standard detector data persistency conversion service.
 
SmartIF< IConversionSvc > & detDataCnvService () const
 Obsoleted name, kept due to the backwards compatibility.
 
SmartIF< IDataProviderSvc > & eventSvc () const
 The standard event data service.
 
SmartIF< IDataProviderSvc > & evtSvc () const
 shortcut for method eventSvc
 
SmartIF< IDataProviderSvc > & eventDataService () const
 Obsoleted name, kept due to the backwards compatibility.
 
SmartIF< IConversionSvc > & eventCnvSvc () const
 The standard event data persistency conversion service.
 
SmartIF< IConversionSvc > & eventDataCnvService () const
 Obsoleted name, kept due to the backwards compatibility.
 
SmartIF< IHistogramSvc > & histoSvc () const
 The standard histogram service.
 
SmartIF< IHistogramSvc > & histogramDataService () const
 Obsoleted name, kept due to the backwards compatibility.
 
SmartIF< IMessageSvc > & msgSvc () const
 The standard message service.
 
SmartIF< IMessageSvc > & messageService () const
 Obsoleted name, kept due to the backwards compatibility.
 
SmartIF< INTupleSvc > & ntupleSvc () const
 The standard N tuple service.
 
SmartIF< INTupleSvc > & ntupleService () const
 Obsoleted name, kept due to the backwards compatibility.
 
SmartIF< IRndmGenSvc > & randSvc () const
 AIDA-based NTuple service Returns a pointer to the AIDATuple service if present.
 
SmartIF< IToolSvc > & toolSvc () const
 The standard ToolSvc service, Return a pointer to the service if present.
 
SmartIF< IExceptionSvc > & exceptionSvc () const
 Get the exception Service.
 
SmartIF< IAlgContextSvc > & contextSvc () const
 get Algorithm Context Service
 
SmartIF< ISvcLocator > & serviceLocator () const
 The standard service locator.
 
SmartIF< ISvcLocator > & svcLoc () const
 shortcut for method serviceLocator
 
bool registerContext () const
 register for Algorithm Context Service?
 
StatusCode createSubAlgorithm (const std::string &type, const std::string &name, Algorithm *&pSubAlg)
 Create a sub algorithm.
 
std::vector< Algorithm * > * subAlgorithms () const
 List of sub-algorithms. Returns a pointer to a vector of (sub) Algorithms.
 
virtual StatusCode setProperty (const Property &p)
 Implementation of IProperty::setProperty.
 
virtual StatusCode setProperty (const std::string &s)
 Implementation of IProperty::setProperty.
 
virtual StatusCode setProperty (const std::string &n, const std::string &v)
 Implementation of IProperty::setProperty.
 
virtual StatusCode getProperty (Property *p) const
 Implementation of IProperty::getProperty.
 
virtual const PropertygetProperty (const std::string &name) const
 Implementation of IProperty::getProperty.
 
virtual StatusCode getProperty (const std::string &n, std::string &v) const
 Implementation of IProperty::getProperty.
 
virtual const std::vector
< Property * > & 
getProperties () const
 Implementation of IProperty::getProperties.
 
StatusCode setProperties ()
 Set the algorithm's properties.
 
template<class T >
PropertydeclareProperty (const std::string &name, T &property, const std::string &doc="none") const
 Declare the named property.
 
PropertydeclareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="") const
 Declare remote named properties.
 
SmartIF< IMonitorSvc > & monitorSvc () const
 Access the monitor service.
 
template<class T >
void declareInfo (const std::string &name, const T &var, const std::string &desc) const
 Declare monitoring information.
 
void declareInfo (const std::string &name, const std::string &format, const void *var, int size, const std::string &desc) const
 Declare monitoring information (special case)
 
template<class TYPE >
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value
 

Private Attributes

std::string m_tupleSvc
 Name of the data provider service.
 
std::string m_output
 Output specification.
 
std::vector< std::stringm_inputs
 input specifications
 
std::string m_rootName
 Name of the root leaf (obtained at initialize)
 
std::string m_outName
 Output tuple name.
 
std::string m_criteria
 Selection criteria (if any)
 
std::string m_selectorName
 Selector factory.
 

Static Private Attributes

INTupleSvcm_dataSvc
 Reference to data provider service.
 

Additional Inherited Members

- Public Types inherited from implements3< IAlgorithm, IProperty, IStateful >
typedef implements3 base_class
 Typedef to this class.
 
typedef extend_interfaces3
< IAlgorithm, IProperty,
IStateful
extend_interfaces_base
 Typedef to the base of this class.
 
typedef
extend_interfaces_base::ext_iids 
interfaces
 MPL set of all the implemented interfaces.
 
- Protected Member Functions inherited from Algorithm
bool isInitialized () const
 Has the Algorithm already been initialized?
 
bool isFinalized () const
 Has the Algorithm already been finalized?
 
int outputLevel () const
 retrieve the Algorithm output level
 
IntegerPropertyoutputLevelProperty ()
 Accessor for the Message level property.
 
void initOutputLevel (Property &prop)
 callback for output level property
 

Detailed Description

Small algorithm, which allows to merge N-tuples in a generic way.

In the options directory an python interface is presented, which shows how to steer this algorithm in a standaqlone program.

Author
: M.Frank
Version
: 1.0

Definition at line 127 of file CollectionCloneAlg.cpp.

Constructor & Destructor Documentation

CollectionCloneAlg::CollectionCloneAlg ( const std::string name,
ISvcLocator pSvcLocator 
)
inline

Standard algorithm constructor.

Definition at line 147 of file CollectionCloneAlg.cpp.

: Algorithm(name, pSvcLocator), m_dataSvc(0)
{
declareProperty("EvtTupleSvc", m_tupleSvc="EvtTupleSvc");
}
virtual CollectionCloneAlg::~CollectionCloneAlg ( )
inlinevirtual

Standard Destructor.

Definition at line 155 of file CollectionCloneAlg.cpp.

{
}

Member Function Documentation

virtual StatusCode CollectionCloneAlg::book ( const NTuple::Tuple nt)
inlinevirtual

Book the N-tuple according to the specification.

Definition at line 220 of file CollectionCloneAlg.cpp.

{
const INTuple::ItemContainer& items = nt->items();
NTuple::Tuple* tuple = m_dataSvc->book(m_outName, nt->clID(), nt->title());
for (i = items.begin(); i != items.end(); ++i) {
long type = (*i)->type();
switch(type) {
status = createItem(log, tuple, *i, (unsigned char)0);
break;
status = createItem(log, tuple, *i, (unsigned short)0);
break;
status = createItem(log, tuple, *i, (unsigned int)0);
break;
status = createItem(log, tuple, *i, (unsigned long)0);
break;
status = createItem(log, tuple, *i, char(0));
break;
status = createItem(log, tuple, *i, short(0));
break;
status = createItem(log, tuple, *i, int(0));
break;
status = createItem(log, tuple, *i, long(0));
break;
status = createItem(log, tuple, *i, false);
break;
status = createItem(log, tuple, *i, float(0.0));
break;
status = createItem(log, tuple, *i, double(0.0));
break;
status = createItem(log, tuple, *i, (IOpaqueAddress*)0);
break;
status = createItem(log, tuple, *i, (void*)0);
break;
// status = createItem(log, tuple, *i, (std::string*)0);
// break;
// status = createItem(log, tuple, *i, (char*)0);
// break;
default:
break;
}
}
return status;
}
virtual StatusCode CollectionCloneAlg::checkInput ( const NTuple::Tuple clone,
const NTuple::Tuple src 
)
inlinevirtual

Definition at line 284 of file CollectionCloneAlg.cpp.

{
if ( 0 != clone && 0 != src ) {
const INTuple::ItemContainer& clone_items = clone->items();
const std::string clone_id = clone->registry()->identifier();
const std::string src_id = src->registry()->identifier();
for (i = clone_items.begin(); i != clone_items.end(); ++i) {
const INTupleItem* itm = *i;
const std::string& nam = itm->name();
const INTupleItem* src_itm = src->find(nam);
if ( !src_itm ) {
log << "Tuple item " << nam << " not present in " << src_id << endmsg;
}
if ( itm->type() != src_itm->type() ) {
log << "Tuple item " << nam << " are of different types in "
<< src_id << ":" << src_itm->typeName() << " <-> "
<< clone_id << ":" << itm->typeName() << endmsg;
}
if ( itm->ndim() != src_itm->ndim() ) {
log << "Tuple item " << nam << " have different dimensions in "
<< src_id << ":" << src_itm->ndim() << " <-> "
<< clone_id << ":" << itm->ndim() << endmsg;
}
for (int j=0; j<itm->ndim(); ++j) {
if ( src_itm->dim(j) != itm->dim(j) ) {
log << "Tuple item " << nam << " have different dimensions in "
<< src_id << "[" << j << "]:" << src_itm->dim(j) << " <-> "
<< clone_id << "[" << j << "]:" << itm->dim(j) << endmsg;
}
}
if ( itm->hasIndex() != src_itm->hasIndex() ) {
log << "Tuple item " << nam << " has different index colums "
<< src_id << ":" << src_itm->hasIndex() << " <-> "
<< clone_id << ":" << itm->hasIndex() << endmsg;
}
if ( itm->hasIndex() ) {
if ( itm->index() != src_itm->index() ) {
log << "Tuple item " << nam << " has different index colums "
<< src_id << ":" << src_itm->index() << " <-> "
<< clone_id << ":" << itm->index() << endmsg;
}
}
}
}
}
StatusCode CollectionCloneAlg::connect ( )
inline

Connect input and output N-tuples.

Definition at line 452 of file CollectionCloneAlg.cpp.

{
for (size_t i=0; i < m_inputs.size(); ++i) {
if ( !(0 == nt) ) {
if ( 0 == out ) {
status = book(nt);
}
else {
status = checkInput(out, nt);
}
if ( !status.isSuccess() ) {
return status;
}
else if ( m_selectorName != "" ) {
SmartIF<ISelectStatement> stmt(ROOT::Reflex::PluginService::Create<IInterface*>(m_selectorName,serviceLocator()));
if ( stmt.isValid( ) ) {
if ( m_criteria.length() > 0 ) stmt->setCriteria(m_criteria);
nt->attachSelector(stmt);
}
else {
log << MSG::ERROR << "Failed to attach tuple selector to " << m_inputs[i] << endmsg;
}
}
}
else {
log << MSG::ERROR << "Failed to access tuple: " << m_inputs[i] << endmsg;
}
}
}
virtual StatusCode CollectionCloneAlg::execute ( )
inlinevirtual

Execute procedure.

Definition at line 211 of file CollectionCloneAlg.cpp.

{
StatusCode status = connect();
if ( status.isSuccess() ) {
status = mergeInputTuples();
}
return status;
}
virtual StatusCode CollectionCloneAlg::finalize ( )
inlinevirtual

Finalize.

Reimplemented from Algorithm.

Definition at line 204 of file CollectionCloneAlg.cpp.

virtual StatusCode CollectionCloneAlg::initialize ( )
inlinevirtual

Initialize.

Reimplemented from Algorithm.

Definition at line 159 of file CollectionCloneAlg.cpp.

{
m_rootName = "";
m_outName = "";
m_criteria = "";
if ( sc.isSuccess() ) {
Tokenizer tok(true);
tok.analyse(m_output, " ", "", "", "=", "'", "'");
for ( Tokenizer::Items::iterator i = tok.items().begin(); i != tok.items().end(); i++ ) {
const std::string& tag = (*i).tag();
const std::string& val = (*i).value();
switch( ::toupper(tag[0]) ) {
case 'D':
m_outName = val;
break;
case 'S':
m_criteria = val;
break;
case 'F':
fun = val;
break ;
default:
break;
}
}
if ( m_outName.empty() ) {
log << MSG::ERROR << "Failed to analyze output specs:" << m_output << endmsg;
}
if ( fun.length() > 0 || m_criteria.length() > 0 ) {
if ( m_criteria.length() > 0 && fun.length() == 0 ) fun = "NTuple::Selector";
}
return sc;
}
log << MSG::ERROR << "Failed to access service \""
<< m_tupleSvc << "\"." << endmsg;
return sc;
}
StatusCode CollectionCloneAlg::mergeEntries ( const std::string input)
inline

Merge the entries of a single input tuple into the output.

Definition at line 342 of file CollectionCloneAlg.cpp.

{
if ( 0 != out ) {
const INTuple::ItemContainer& clone_items = out->items();
std::vector<GenericAddress> addrVector(clone_items.size());
NTuplePtr nt(m_dataSvc, input);
size_t k = 0, nentry = 0;
if ( 0 != nt ) {
const INTuple::ItemContainer& source_items = nt->items();
for (k=0; k < source_items.size(); ++k ) {
if ( source_items[k]->type() == DataTypeInfo::OBJECT_ADDR ) {
*(IOpaqueAddress**)source_items[k]->buffer() = &addrVector[k];
}
}
while ( status.isSuccess() ) {
status = m_dataSvc->readRecord(nt.ptr());
if ( status.isSuccess() ) {
nentry++;
for (k=0,i = source_items.begin(); i != source_items.end(); ++i,++k) {
const INTupleItem* src_itm = *i;
const INTupleItem* out_itm = out->find(src_itm->name());
size_t size = 0;
switch((*i)->type()) {
size = sizeof(unsigned char);
break;
size = sizeof(unsigned short);
break;
size = sizeof(unsigned int);
break;
size = sizeof(unsigned long);
break;
size = sizeof(char);
break;
size = sizeof(short);
break;
size = sizeof(int);
break;
size = sizeof(long);
break;
size = sizeof(bool);
break;
size = sizeof(float);
break;
size = sizeof(double);
break;
*(std::string*)out_itm->buffer() = *(std::string*)src_itm->buffer();
size = 0;
break;
size = ::strlen((const char*)src_itm->buffer())+1;
break;
{
*(void**)out_itm->buffer() = *(void**)src_itm->buffer();
size = 0;
}
break;
{
IOpaqueAddress* ppA1 = &addrVector[k];
IOpaqueAddress** ppA2 = (IOpaqueAddress**)out_itm->buffer();
*ppA2 = ppA1;
size = 0;
}
break;
default:
size = 0;
break;
}
if ( size > 0 ) {
::memcpy((void*)out_itm->buffer(), src_itm->buffer(), size*src_itm->length());
}
}
status = m_dataSvc->writeRecord(out.ptr());
if ( !status.isSuccess() ) {
log << MSG::ERROR << "Failed to write record " << nentry
<< " from " << input << " to " << m_outName << endmsg;
}
}
}
log << MSG::INFO << "End of reading tuple " << input
<< " after " << nentry << " entries." << endmsg;
if ( nentry > 0 || m_selectorName != "" ) {
}
}
log << MSG::ERROR << "Failed to access input: " << input << endmsg;
}
}
StatusCode CollectionCloneAlg::mergeInputTuples ( )
inline

Merge all N-tuple entries.

Definition at line 490 of file CollectionCloneAlg.cpp.

{
for (size_t inp=0; inp < m_inputs.size(); ++inp) {
if ( !sc.isSuccess() ) {
log << MSG::ERROR << "Failed to merge tuple:" << m_inputs[inp] << endmsg;
return sc;
}
}
}

Member Data Documentation

std::string CollectionCloneAlg::m_criteria
private

Selection criteria (if any)

Definition at line 141 of file CollectionCloneAlg.cpp.

INTupleSvc* CollectionCloneAlg::m_dataSvc
staticprivate

Reference to data provider service.

Definition at line 129 of file CollectionCloneAlg.cpp.

std::vector<std::string> CollectionCloneAlg::m_inputs
private

input specifications

Definition at line 135 of file CollectionCloneAlg.cpp.

std::string CollectionCloneAlg::m_outName
private

Output tuple name.

Definition at line 139 of file CollectionCloneAlg.cpp.

std::string CollectionCloneAlg::m_output
private

Output specification.

Definition at line 133 of file CollectionCloneAlg.cpp.

std::string CollectionCloneAlg::m_rootName
private

Name of the root leaf (obtained at initialize)

Definition at line 137 of file CollectionCloneAlg.cpp.

std::string CollectionCloneAlg::m_selectorName
private

Selector factory.

Definition at line 143 of file CollectionCloneAlg.cpp.

std::string CollectionCloneAlg::m_tupleSvc
private

Name of the data provider service.

Definition at line 131 of file CollectionCloneAlg.cpp.


The documentation for this class was generated from the following file:

Generated at Wed Nov 28 2012 12:17:25 for Gaudi Framework, version v23r5 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004