The Gaudi Framework  master (ff829712)
Loading...
Searching...
No Matches
CollectionCloneAlg Class Reference

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

Inheritance diagram for CollectionCloneAlg:
Collaboration diagram for CollectionCloneAlg:

Public Member Functions

StatusCode initialize () override
 Initialize.
 
StatusCode finalize () override
 Finalize.
 
StatusCode execute () override
 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
 LegacyAlgorithmAdapter (std::string name, ISvcLocator *svcloc, std::string version=PACKAGE_VERSION)
 
- Public Member Functions inherited from Gaudi::details::LegacyAlgorithmAdapter
 LegacyAlgorithmAdapter (std::string name, ISvcLocator *svcloc, std::string version=PACKAGE_VERSION)
 
const EventContextgetContext () const
 
bool isExecuted () const
 Has this algorithm been executed since the last reset?
 
void setExecuted (bool state) const
 Set the executed flag to the specified state.
 
bool filterPassed () const
 Did this algorithm pass or fail its filter criterion for the last event?
 
void setFilterPassed (bool state) const
 Set the filter passed flag to the specified state.
 
- Public Member Functions inherited from Gaudi::Algorithm
 Algorithm (std::string name, ISvcLocator *svcloc, std::string version=PACKAGE_VERSION)
 Constructor.
 
StatusCode sysStart () override
 Reinitialization method invoked by the framework.
 
StatusCode sysInitialize () override
 Initialization method invoked by the framework.
 
StatusCode sysReinitialize () override
 Reinitialization method invoked by the framework.
 
StatusCode sysRestart () override
 Restart method invoked by the framework.
 
StatusCode sysExecute (const EventContext &ctx) override
 The actions to be performed by the algorithm on an event.
 
StatusCode sysStop () override
 System stop.
 
StatusCode sysFinalize () override
 System finalization.
 
const std::string & name () const override
 The identifying name of the algorithm object.
 
const Gaudi::StringKeynameKey () const override
 
const std::string & type () const override
 The type of the algorithm object.
 
void setType (std::string type) override
 
const std::string & version () const override
 
unsigned int index () const override
 
StatusCode configure () override
 Dummy implementation of IStateful::configure() method.
 
StatusCode terminate () override
 Dummy implementation of IStateful::terminate() method.
 
StatusCode initialize () override
 the default (empty) implementation of IStateful::initialize() method
 
StatusCode start () override
 the default (empty) implementation of IStateful::start() method
 
StatusCode stop () override
 the default (empty) implementation of IStateful::stop() method
 
StatusCode finalize () override
 the default (empty) implementation of IStateful::finalize() method
 
StatusCode reinitialize () override
 the default (empty) implementation of IStateful::reinitialize() method
 
StatusCode restart () override
 the default (empty) implementation of IStateful::restart() method
 
Gaudi::StateMachine::State FSMState () const override
 returns the current state of the algorithm
 
Gaudi::StateMachine::State targetFSMState () const override
 returns the state the algorithm will be in after the ongoing transition
 
bool isEnabled () const override
 Is this algorithm enabled or disabled?
 
bool isSequence () const override
 Are we a Sequence?
 
unsigned int errorCount () const
 Get the number of failures of the algorithm.
 
SmartIF< IServiceservice (std::string_view name, const bool createIf=true, const bool quiet=false) const
 Return a pointer to the service identified by name (or "type/name")
 
template<class T>
SmartIF< T > service (std::string_view name, bool createIf=true, bool quiet=false) const
 
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< IDataProviderSvc > & detSvc () const
 The standard detector data service.
 
SmartIF< IConversionSvc > & detCnvSvc () const
 The standard detector data persistency conversion service.
 
SmartIF< IDataProviderSvc > & eventSvc () const
 The standard event data service.
 
SmartIF< IDataProviderSvc > & evtSvc () const
 shortcut for method eventSvc
 
SmartIF< IConversionSvc > & eventCnvSvc () const
 The standard event data persistency conversion service.
 
SmartIF< IHistogramSvc > & histoSvc () const
 The standard histogram service.
 
SmartIF< INTupleSvc > & ntupleSvc () const
 The standard N tuple service.
 
SmartIF< IRndmGenSvc > & randSvc () const
 The standard RandomGen service, Return a pointer to the 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< ITimelineSvc > & timelineSvc () const
 
SmartIF< ISvcLocator > & serviceLocator () const override
 The standard service locator.
 
SmartIF< ISvcLocator > & svcLoc () const
 shortcut for method serviceLocator
 
SmartIF< IHiveWhiteBoard > & whiteboard () const
 
SmartIF< IAlgExecStateSvc > & algExecStateSvc () const
 
bool registerContext () const
 register for Algorithm Context Service?
 
template<class T>
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, ToolHandle< T > &hndl, const std::string &doc="none")
 
template<class T>
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, ToolHandleArray< T > &hndlArr, const std::string &doc="none")
 
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)
 
void acceptDHVisitor (IDataHandleVisitor *) const override
 
void registerTool (IAlgTool *tool) const
 
void deregisterTool (IAlgTool *tool) const
 
template<class T>
StatusCode declareTool (ToolHandle< T > &handle, bool createIf=true)
 
template<class T>
StatusCode declareTool (ToolHandle< T > &handle, const std::string &toolTypeAndName, bool createIf=true)
 
template<class T>
void addToolsArray (ToolHandleArray< T > &hndlArr)
 
const std::vector< IAlgTool * > & tools () const
 
bool isAsynchronous () const
 
void setAsynchronous (bool value)
 
unsigned int cardinality () const override
 Return the cardinality.
 
const std::vector< std::string > & neededResources () const override
 
AlgExecStateRef execState (const EventContext &ctx) const override
 get the AlgExecStateRef of current algorithm Actually a small wrapper around it, thus the plain object return type
 
std::ostream & toControlFlowExpression (std::ostream &os) const override
 Produce string represention of the control flow expression.
 
- Public Member Functions inherited from DataHandleHolderBase< PropertyHolder< CommonMessaging< implements< IAlgorithm, IDataHandleHolder, IProperty, IStateful > > > >
std::vector< Gaudi::DataHandle * > inputHandles () const override
 
std::vector< Gaudi::DataHandle * > outputHandles () const override
 
virtual const DataObjIDCollextraInputDeps () const override
 
virtual const DataObjIDCollextraOutputDeps () const override
 
void declare (Gaudi::DataHandle &handle) override
 
void renounce (Gaudi::DataHandle &handle) override
 
bool renounceInput (const DataObjID &id) override
 
const DataObjIDCollinputDataObjs () const override
 
const DataObjIDColloutputDataObjs () const override
 
void addDependency (const DataObjID &id, const Gaudi::DataHandle::Mode &mode) override
 
- Public Member Functions inherited from extends< PropertyHolder< CommonMessaging< implements< IAlgorithm, IDataHandleHolder, IProperty, IStateful > > >, IDataHandleHolder >
void const * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast.
 
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface.
 
std::vector< std::string > getInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames.
 
- Public Member Functions inherited from PropertyHolder< CommonMessaging< implements< IAlgorithm, IDataHandleHolder, IProperty, IStateful > > >
StatusCode setProperty (const Gaudi::Details::PropertyBase &p)
 Set the property from a property.
 
StatusCode setProperty (const std::string &name, const char *v)
 Special case for string literals.
 
StatusCode setProperty (const std::string &name, const std::string &v)
 Special case for std::string.
 
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value
 
 PropertyHolder ()=default
 
Gaudi::Details::PropertyBasedeclareProperty (Gaudi::Details::PropertyBase &prop)
 Declare a property.
 
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, TYPE &value, const std::string &doc="none")
 Helper to wrap a regular data member and use it as a regular property.
 
Gaudi::Details::PropertyBasedeclareProperty (const std::string &name, Gaudi::Property< TYPE, VERIFIER, HANDLERS > &prop, const std::string &doc="none")
 Declare a PropertyBase instance setting name and documentation.
 
Gaudi::Details::PropertyBasedeclareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="")
 Declare a remote property.
 
StatusCode setProperty (const std::string &name, const Gaudi::Details::PropertyBase &p) override
 set the property from another property with a different name
 
StatusCode setProperty (const std::string &s) override
 set the property from the formatted string
 
StatusCode setProperty (const Gaudi::Details::PropertyBase &p)
 Set the property from a property.
 
StatusCode setProperty (const std::string &name, const char *v)
 Special case for string literals.
 
StatusCode setProperty (const std::string &name, const std::string &v)
 Special case for std::string.
 
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value
 
StatusCode setPropertyRepr (const std::string &n, const std::string &r) override
 set the property from name and value string representation
 
StatusCode getProperty (Gaudi::Details::PropertyBase *p) const override
 get the property
 
const Gaudi::Details::PropertyBasegetProperty (std::string_view name) const override
 get the property by name
 
StatusCode getProperty (std::string_view n, std::string &v) const override
 convert the property to the string
 
const std::vector< Gaudi::Details::PropertyBase * > & getProperties () const override
 get all properties
 
bool hasProperty (std::string_view name) const override
 Return true if we have a property with the given name.
 
Gaudi::Details::PropertyBaseproperty (std::string_view name) const
 \fixme property and bindPropertiesTo should be protected
 
void bindPropertiesTo (Gaudi::Interfaces::IOptionsSvc &optsSvc)
 
 PropertyHolder (const PropertyHolder &)=delete
 
PropertyHolderoperator= (const PropertyHolder &)=delete
 
- Public Member Functions inherited from CommonMessaging< implements< IAlgorithm, IDataHandleHolder, IProperty, IStateful > >
MSG::Level msgLevel () const
 get the cached level (originally extracted from the embedded MsgStream)
 
bool msgLevel (MSG::Level lvl) const
 get the output level from the embedded MsgStream
 
- Public Member Functions inherited from CommonMessagingBase
virtual ~CommonMessagingBase ()=default
 Virtual destructor.
 
const SmartIF< IMessageSvc > & msgSvc () const
 The standard message service.
 
MsgStreammsgStream () const
 Return an uninitialized MsgStream.
 
MsgStreammsgStream (const MSG::Level level) const
 Predefined configurable message stream for the efficient printouts.
 
MsgStreamalways () const
 shortcut for the method msgStream(MSG::ALWAYS)
 
MsgStreamfatal () const
 shortcut for the method msgStream(MSG::FATAL)
 
MsgStreamerr () const
 shortcut for the method msgStream(MSG::ERROR)
 
MsgStreamerror () const
 shortcut for the method msgStream(MSG::ERROR)
 
MsgStreamwarning () const
 shortcut for the method msgStream(MSG::WARNING)
 
MsgStreaminfo () const
 shortcut for the method msgStream(MSG::INFO)
 
MsgStreamdebug () const
 shortcut for the method msgStream(MSG::DEBUG)
 
MsgStreamverbose () const
 shortcut for the method msgStream(MSG::VERBOSE)
 
MsgStreammsg () const
 shortcut for the method msgStream(MSG::INFO)
 

Private Attributes

Gaudi::Property< std::string > m_tupleSvc { this, "EvtTupleSvc", "EvtTupleSvc", "name of the data provider service" }
 
Gaudi::Property< std::vector< std::string > > m_inputs { this, "Input", {}, "input specifications" }
 
Gaudi::Property< std::string > m_output { this, "Output", {}, "output specification" }
 
SmartIF< INTupleSvcm_dataSvc
 Reference to data provider service.
 
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.
 

Additional Inherited Members

- Public Types inherited from Gaudi::Algorithm
typedef Gaudi::PluginService::Factory< IAlgorithm *(const std::string &, ISvcLocator *)> Factory
 
- Public Types inherited from extends< PropertyHolder< CommonMessaging< implements< IAlgorithm, IDataHandleHolder, IProperty, IStateful > > >, IDataHandleHolder >
using base_class
 Typedef to this class.
 
using extend_interfaces_base
 Typedef to the base of this class.
 
- Public Types inherited from PropertyHolder< CommonMessaging< implements< IAlgorithm, IDataHandleHolder, IProperty, IStateful > > >
using PropertyHolderImpl
 Typedef used to refer to this class from derived classes, as in.
 
- Public Types inherited from CommonMessaging< implements< IAlgorithm, IDataHandleHolder, IProperty, IStateful > >
using base_class
 
- Public Types inherited from extend_interfaces< Interfaces... >
using ext_iids
 take union of the ext_iids of all Interfaces...
 
- Public Attributes inherited from Gaudi::Algorithm
friend AlgorithmManager
 
- Protected Member Functions inherited from Gaudi::details::LegacyAlgorithmAdapter
bool isReEntrant () const override
 
- Protected Member Functions inherited from Gaudi::Algorithm
std::vector< IAlgTool * > & tools ()
 
bool isInitialized () const override
 Has the Algorithm already been initialized?
 
bool isFinalized () const override
 Has the Algorithm already been finalized?
 
void setIndex (const unsigned int &idx) override
 set instantiation index of Alg
 
bool isReEntrant () const override
 
- Protected Member Functions inherited from DataHandleHolderBase< PropertyHolder< CommonMessaging< implements< IAlgorithm, IDataHandleHolder, IProperty, IStateful > > > >
void initDataHandleHolder ()
 initializes all handles - called by the sysInitialize method of any descendant of this
 
- Protected Member Functions inherited from CommonMessaging< implements< IAlgorithm, IDataHandleHolder, IProperty, IStateful > >
MSG::Level setUpMessaging () const
 Set up local caches.
 
MSG::Level resetMessaging ()
 Reinitialize internal states.
 
void updateMsgStreamOutputLevel (int level)
 Update the output level of the cached MsgStream.
 
- Protected Attributes inherited from Gaudi::Algorithm
std::unique_ptr< IDataHandleVisitorm_updateDataHandles
 Hook for for derived classes to provide a custom visitor for data handles.
 
- Protected Attributes inherited from DataHandleHolderBase< PropertyHolder< CommonMessaging< implements< IAlgorithm, IDataHandleHolder, IProperty, IStateful > > > >
DataObjIDColl m_inputDataObjs
 
DataObjIDColl m_outputDataObjs
 

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 122 of file CollectionCloneAlg.cpp.

Member Function Documentation

◆ book()

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

Book the N-tuple according to the specification.

Definition at line 196 of file CollectionCloneAlg.cpp.

196 {
197 MsgStream log( msgSvc(), name() );
198 StatusCode status = StatusCode::SUCCESS;
199 NTuple::Tuple* tuple = m_dataSvc->book( m_outName, nt->clID(), nt->title() );
200 for ( const auto& i : nt->items() ) {
201 switch ( i->type() ) {
203 status = createItem<unsigned char>( log, tuple, i, 0 );
204 break;
206 status = createItem<unsigned short>( log, tuple, i, 0 );
207 break;
209 status = createItem<unsigned int>( log, tuple, i, 0 );
210 break;
212 status = createItem<unsigned long>( log, tuple, i, 0 );
213 break;
215 status = createItem<char>( log, tuple, i, 0 );
216 break;
218 status = createItem<short>( log, tuple, i, 0 );
219 break;
221 status = createItem<int>( log, tuple, i, 0 );
222 break;
224 status = createItem<long>( log, tuple, i, 0 );
225 break;
227 status = createItem( log, tuple, i, false );
228 break;
230 status = createItem<float>( log, tuple, i, 0 );
231 break;
233 status = createItem<double>( log, tuple, i, 0 );
234 break;
236 status = createItem<IOpaqueAddress*>( log, tuple, i, nullptr );
237 break;
239 status = createItem<void*>( log, tuple, i, nullptr );
240 break;
242 // status = createItem(log, tuple, i, (std::string*)0);
243 // break;
245 // status = createItem(log, tuple, i, (char*)0);
246 // break;
248 default:
249 status = StatusCode::FAILURE;
250 break;
251 }
252 }
253 return status;
254 }
SmartIF< INTupleSvc > m_dataSvc
Reference to data provider service.
std::string m_outName
Output tuple name.
const SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
virtual const CLID & clID() const
Retrieve reference to class definition structure.
const std::string & name() const override
The identifying name of the algorithm object.
virtual ItemContainer & items()=0
Access item container.
virtual const std::string & title() const =0
Object title.
constexpr static const auto SUCCESS
Definition StatusCode.h:99
constexpr static const auto FAILURE
Definition StatusCode.h:100

◆ checkInput()

virtual StatusCode CollectionCloneAlg::checkInput ( const NTuple::Tuple * clone,
const NTuple::Tuple * src )
inlinevirtual

Definition at line 257 of file CollectionCloneAlg.cpp.

257 {
258 MsgStream log( msgSvc(), name() );
259 if ( clone && src ) {
260 const INTuple::ItemContainer& clone_items = clone->items();
261 const std::string clone_id = clone->registry()->identifier();
262 const std::string src_id = src->registry()->identifier();
263
264 log << MSG::ERROR;
265 for ( auto i = clone_items.begin(); i != clone_items.end(); ++i ) {
266 const INTupleItem* itm = *i;
267 const std::string& nam = itm->name();
268 const INTupleItem* src_itm = src->find( nam );
269 if ( !src_itm ) {
270 log << "Tuple item " << nam << " not present in " << src_id << endmsg;
271 return StatusCode::FAILURE;
272 }
273 if ( itm->type() != src_itm->type() ) {
274 log << "Tuple item " << nam << " are of different types in " << src_id << ":" << src_itm->typeName()
275 << " <-> " << clone_id << ":" << itm->typeName() << endmsg;
276 return StatusCode::FAILURE;
277 }
278 if ( itm->ndim() != src_itm->ndim() ) {
279 log << "Tuple item " << nam << " have different dimensions in " << src_id << ":" << src_itm->ndim() << " <-> "
280 << clone_id << ":" << itm->ndim() << endmsg;
281 return StatusCode::FAILURE;
282 }
283 for ( int j = 0; j < itm->ndim(); ++j ) {
284 if ( src_itm->dim( j ) != itm->dim( j ) ) {
285 log << "Tuple item " << nam << " have different dimensions in " << src_id << "[" << j
286 << "]:" << src_itm->dim( j ) << " <-> " << clone_id << "[" << j << "]:" << itm->dim( j ) << endmsg;
287 return StatusCode::FAILURE;
288 }
289 }
290 if ( itm->hasIndex() != src_itm->hasIndex() ) {
291 log << "Tuple item " << nam << " has different index colums " << src_id << ":" << src_itm->hasIndex()
292 << " <-> " << clone_id << ":" << itm->hasIndex() << endmsg;
293 return StatusCode::FAILURE;
294 }
295 if ( itm->hasIndex() ) {
296 if ( itm->index() != src_itm->index() ) {
297 log << "Tuple item " << nam << " has different index colums " << src_id << ":" << src_itm->index()
298 << " <-> " << clone_id << ":" << itm->index() << endmsg;
299 return StatusCode::FAILURE;
300 }
301 }
302 }
303 return StatusCode::SUCCESS;
304 }
305 return StatusCode::FAILURE;
306 }
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
IRegistry * registry() const
Get pointer to Registry.
Definition DataObject.h:79
std::vector< INTupleItem * > ItemContainer
Definition INTuple.h:93
virtual const INTupleItem * find(const std::string &name) const =0
Find an item row of the Ntuple (CONST)
virtual long ndim() const =0
Dimension.
virtual long dim(long i) const =0
Access individual dimensions.
virtual const std::string & index() const =0
Access the index _Item.
virtual std::string typeName() const =0
Proper type name of the object.
virtual long type() const =0
Type information of the item.
virtual const std::string & name() const =0
Access _Item name.
virtual bool hasIndex() const =0
Is the tuple have an index item?
virtual const id_type & identifier() const =0
Full identifier (or key)
@ ERROR
Definition IMessageSvc.h:22

◆ connect()

StatusCode CollectionCloneAlg::connect ( )
inline

Connect input and output N-tuples.

Definition at line 412 of file CollectionCloneAlg.cpp.

412 {
413 StatusCode status = StatusCode::SUCCESS;
414 for ( size_t i = 0; i < m_inputs.size(); ++i ) {
415 NTuplePtr nt( m_dataSvc.get(), m_inputs[i] );
416 if ( !( 0 == nt ) ) {
418 if ( 0 == out ) {
419 status = book( nt );
420 } else {
421 status = checkInput( out, nt );
422 }
423 if ( !status.isSuccess() ) {
424 return status;
425 } else if ( m_selectorName != "" ) {
426 SmartIF<ISelectStatement> stmt( ObjFactory::create( m_selectorName, serviceLocator() ).release() );
427 if ( stmt ) {
428 if ( !m_criteria.empty() ) stmt->setCriteria( m_criteria );
429 nt->attachSelector( stmt ).ignore( /* AUTOMATICALLY ADDED FOR gaudi/Gaudi!763 */ );
430 } else {
431 MsgStream log( msgSvc(), name() );
432 log << MSG::ERROR << "Failed to attach tuple selector to " << m_inputs[i] << endmsg;
433 return StatusCode::FAILURE;
434 }
435 }
436 } else {
437 MsgStream log( msgSvc(), name() );
438 log << MSG::ERROR << "Failed to access tuple: " << m_inputs[i] << endmsg;
439 return StatusCode::FAILURE;
440 }
441 }
442 return StatusCode::SUCCESS;
443 }
SmartDataPtr< NTuple::Tuple > NTuplePtr
Definition NTuple.h:1019
virtual StatusCode book(const NTuple::Tuple *nt)
Book the N-tuple according to the specification.
std::string m_criteria
Selection criteria (if any)
std::string m_selectorName
Selector factory.
Gaudi::Property< std::vector< std::string > > m_inputs
virtual StatusCode checkInput(const NTuple::Tuple *clone, const NTuple::Tuple *src)
SmartIF< ISvcLocator > & serviceLocator() const override
The standard service locator.
bool isSuccess() const
Definition StatusCode.h:314
str release
Definition conf.py:27

◆ execute()

StatusCode CollectionCloneAlg::execute ( )
inlineoverridevirtual

Execute procedure.

Implements Algorithm.

Definition at line 190 of file CollectionCloneAlg.cpp.

190 {
191 StatusCode status = connect();
192 return status.isSuccess() ? mergeInputTuples() : status;
193 }
StatusCode connect()
Connect input and output N-tuples.
StatusCode mergeInputTuples()
Merge all N-tuple entries.

◆ finalize()

StatusCode CollectionCloneAlg::finalize ( )
inlineoverride

Finalize.

Definition at line 184 of file CollectionCloneAlg.cpp.

184 {
185 m_dataSvc.reset();
186 return StatusCode::SUCCESS;
187 }

◆ initialize()

StatusCode CollectionCloneAlg::initialize ( )
inlineoverride

Initialize.

Definition at line 144 of file CollectionCloneAlg.cpp.

144 {
145 MsgStream log( msgSvc(), name() );
146 m_rootName = "";
147 m_outName = "";
148 m_criteria = "";
149 m_selectorName = "";
150 m_dataSvc = service( m_tupleSvc, true );
151 if ( !m_dataSvc ) {
152 log << MSG::ERROR << "Failed to access service \"" << m_tupleSvc << "\"." << endmsg;
153 return StatusCode::FAILURE;
154 }
155 std::string fun;
156 using Parser = Gaudi::Utils::AttribStringParser;
157 for ( auto attrib : Parser( m_output ) ) {
158 switch ( ::toupper( attrib.tag[0] ) ) {
159 case 'D':
160 m_outName = std::move( attrib.value );
161 break;
162 case 'S':
163 m_criteria = std::move( attrib.value );
164 break;
165 case 'F':
166 fun = std::move( attrib.value );
167 break;
168 default:
169 break;
170 }
171 }
172 if ( m_outName.empty() ) {
173 log << MSG::ERROR << "Failed to analyze output specs:" << m_output << endmsg;
174 return StatusCode::FAILURE;
175 }
176 if ( !fun.empty() || !m_criteria.empty() ) {
177 if ( !m_criteria.empty() && fun.empty() ) fun = "NTuple::Selector";
178 m_selectorName = fun;
179 }
180 return StatusCode::SUCCESS;
181 }
void toupper(std::string &s)
std::string m_rootName
Name of the root leaf (obtained at initialize)
Gaudi::Property< std::string > m_output
Gaudi::Property< std::string > m_tupleSvc
SmartIF< IService > service(std::string_view name, const bool createIf=true, const bool quiet=false) const
Return a pointer to the service identified by name (or "type/name")

◆ mergeEntries()

StatusCode CollectionCloneAlg::mergeEntries ( const std::string & input)
inline

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

Definition at line 309 of file CollectionCloneAlg.cpp.

309 {
310 MsgStream log( msgSvc(), name() );
312 if ( 0 != out ) {
313 const INTuple::ItemContainer& clone_items = out->items();
314 std::vector<GenericAddress> addrVector( clone_items.size() );
315 StatusCode status = StatusCode::SUCCESS;
316 NTuplePtr nt( m_dataSvc.get(), input );
317 size_t k = 0, nentry = 0;
318 if ( 0 != nt ) {
319 const INTuple::ItemContainer& source_items = nt->items();
320 for ( k = 0; k < source_items.size(); ++k ) {
321 if ( source_items[k]->type() == DataTypeInfo::OBJECT_ADDR ) {
322 *(IOpaqueAddress**)source_items[k]->buffer() = &addrVector[k];
323 }
324 }
325 while ( status.isSuccess() ) {
326 status = m_dataSvc->readRecord( nt.ptr() );
327 if ( status.isSuccess() ) {
328 INTuple::ItemContainer::const_iterator i;
329 nentry++;
330 for ( k = 0, i = source_items.begin(); i != source_items.end(); ++i, ++k ) {
331 const INTupleItem* src_itm = *i;
332 const INTupleItem* out_itm = out->find( src_itm->name() );
333 size_t size = 0;
334 switch ( ( *i )->type() ) {
336 size = sizeof( unsigned char );
337 break;
339 size = sizeof( unsigned short );
340 break;
342 size = sizeof( unsigned int );
343 break;
345 size = sizeof( unsigned long );
346 break;
348 size = sizeof( char );
349 break;
351 size = sizeof( short );
352 break;
354 size = sizeof( int );
355 break;
357 size = sizeof( long );
358 break;
360 size = sizeof( bool );
361 break;
363 size = sizeof( float );
364 break;
366 size = sizeof( double );
367 break;
369 *(std::string*)out_itm->buffer() = *(std::string*)src_itm->buffer();
370 size = 0;
371 break;
373 size = ::strlen( (const char*)src_itm->buffer() ) + 1;
374 break;
376 *(void**)out_itm->buffer() = *(void**)src_itm->buffer();
377 size = 0;
378 } break;
380 IOpaqueAddress* ppA1 = &addrVector[k];
381 IOpaqueAddress** ppA2 = (IOpaqueAddress**)( out_itm->buffer() );
382 *ppA2 = ppA1;
383 size = 0;
384 } break;
386 default:
387 size = 0;
388 break;
389 }
390 if ( size > 0 ) {
391 ::memcpy( const_cast<void*>( out_itm->buffer() ), src_itm->buffer(), size * src_itm->length() );
392 }
393 }
394 status = m_dataSvc->writeRecord( out.ptr() );
395 if ( !status.isSuccess() ) {
396 log << MSG::ERROR << "Failed to write record " << nentry << " from " << input << " to " << m_outName
397 << endmsg;
398 }
399 }
400 }
401 log << MSG::INFO << "End of reading tuple " << input << " after " << nentry << " entries." << endmsg;
402
403 if ( nentry > 0 || m_selectorName != "" ) { return StatusCode::SUCCESS; }
404 return StatusCode::FAILURE;
405 }
406 log << MSG::ERROR << "Failed to access input: " << input << endmsg;
407 }
408 return StatusCode::FAILURE;
409 }
const std::string & type() const override
The type of the algorithm object.
Definition Algorithm.h:162
virtual const void * buffer() const =0
Access data buffer (CONST)
virtual long length() const =0
Access the buffer length.
@ INFO
Definition IMessageSvc.h:22
constexpr auto size(const T &, Args &&...) noexcept

◆ mergeInputTuples()

StatusCode CollectionCloneAlg::mergeInputTuples ( )
inline

Merge all N-tuple entries.

Definition at line 446 of file CollectionCloneAlg.cpp.

446 {
447 MsgStream log( msgSvc(), name() );
448 for ( const auto& input : m_inputs ) {
449 StatusCode sc = mergeEntries( input );
450 if ( !sc.isSuccess() ) {
451 log << MSG::ERROR << "Failed to merge tuple:" << input << endmsg;
452 return sc;
453 }
454 }
455 return StatusCode::SUCCESS;
456 }
StatusCode mergeEntries(const std::string &input)
Merge the entries of a single input tuple into the output.

Member Data Documentation

◆ m_criteria

std::string CollectionCloneAlg::m_criteria
private

Selection criteria (if any)

Definition at line 135 of file CollectionCloneAlg.cpp.

◆ m_dataSvc

SmartIF<INTupleSvc> CollectionCloneAlg::m_dataSvc
private

Reference to data provider service.

Definition at line 129 of file CollectionCloneAlg.cpp.

◆ m_inputs

Gaudi::Property<std::vector<std::string> > CollectionCloneAlg::m_inputs { this, "Input", {}, "input specifications" }
private

Definition at line 125 of file CollectionCloneAlg.cpp.

125{ this, "Input", {}, "input specifications" };

◆ m_outName

std::string CollectionCloneAlg::m_outName
private

Output tuple name.

Definition at line 133 of file CollectionCloneAlg.cpp.

◆ m_output

Gaudi::Property<std::string> CollectionCloneAlg::m_output { this, "Output", {}, "output specification" }
private

Definition at line 126 of file CollectionCloneAlg.cpp.

126{ this, "Output", {}, "output specification" };

◆ m_rootName

std::string CollectionCloneAlg::m_rootName
private

Name of the root leaf (obtained at initialize)

Definition at line 131 of file CollectionCloneAlg.cpp.

◆ m_selectorName

std::string CollectionCloneAlg::m_selectorName
private

Selector factory.

Definition at line 137 of file CollectionCloneAlg.cpp.

◆ m_tupleSvc

Gaudi::Property<std::string> CollectionCloneAlg::m_tupleSvc { this, "EvtTupleSvc", "EvtTupleSvc", "name of the data provider service" }
private

Definition at line 124 of file CollectionCloneAlg.cpp.

124{ this, "EvtTupleSvc", "EvtTupleSvc", "name of the data provider service" };

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