Skip to content
Snippets Groups Projects

WIP: fix MCLinking in TDR branch for LHCb::Tracks

Closed Renato Quagliani requested to merge TDR-rquaglia_fixhackMCLinking into TDR
Compare and
5 files
+ 186
15
Compare changes
  • Side-by-side
  • Inline
Files
5
+ 120
0
// Include files
// from Gaudi
#include <boost/algorithm/string/replace.hpp>
#include "GaudiKernel/IDataManagerSvc.h"
#include "GaudiKernel/SmartIF.h"
// from Event
#include "Event/Track.h"
// local
#include "PrTrackConverter.h"
DECLARE_COMPONENT( PrTrackConverter )
//=============================================================================
// Standard constructor, initializes variables
//=============================================================================
PrTrackConverter::PrTrackConverter( const std::string& name,
ISvcLocator* pSvcLocator ) :
GaudiAlgorithm( name, pSvcLocator )
{
declareProperty( "RootOfContainers", m_rootOfContainers = "/Event/Rec/Track" );
declareProperty( "RootOfOutContainers", m_rootOfOutContainers = "/Event/Rec/Track/Keyed" );
///Event/Rec/Track/Copy....
declareProperty( "SingleContainer", m_singleContainer = "" );
}
//=============================================================================
// Destructor
//=============================================================================
PrTrackConverter::~PrTrackConverter() {}
//=============================================================================
// Initialisation. Check parameters
//=============================================================================
StatusCode PrTrackConverter::initialize() {
// Mandatory initialization of GaudiAlgorithm
StatusCode sc = GaudiAlgorithm::initialize();
if( sc.isFailure() ) { return sc; }
if ( "" != m_singleContainer ) {
info() << "Processing only the container " << m_singleContainer << endmsg;
} else {
info() << "Processing all tracks containers in " << m_rootOfContainers << endmsg;
}
return StatusCode::SUCCESS;
}
//=============================================================================
// Main execution
//=============================================================================
StatusCode PrTrackConverter::execute() {
std::vector<std::string> trackContainers;
if ( "" != m_singleContainer ) {
trackContainers.push_back( m_singleContainer );
} else {
//== Scan the root directory and make a list of containers to process.
DataObject* root = getIfExists<DataObject*>( m_rootOfContainers );
if ( NULL == root ) {
info()<<"Root-of-Containers directory " << m_rootOfContainers << "' does not exist. Skipping." <<endmsg;
return StatusCode::SUCCESS;
}
SmartIF<IDataManagerSvc> mgr( eventSvc() );
typedef std::vector<IRegistry*> Leaves;
Leaves leaves;
StatusCode sc = mgr->objectLeaves( root, leaves );
if ( sc ) {
for ( Leaves::const_iterator iL = leaves.begin(); leaves.end() != iL; ++iL ) {
const std::string& id = (*iL)->identifier();
DataObject* tmp(NULL);
sc = eventSvc()->findObject( id, tmp );
if ( sc && NULL != tmp ) {
trackContainers.push_back( id );
}
}
}
}
if( msgLevel(MSG::DEBUG)){
debug()<<"Amoung of loaded TrackContainers = "<<trackContainers.size()<<endmsg;
}
for ( std::vector<std::string>::iterator itS = trackContainers.begin();
trackContainers.end() != itS; ++itS ) {
if( msgLevel(MSG::DEBUG)){
debug() << "Containers found, append to list : " << *itS << endmsg ;
}
// Retrieve the Tracks
std::vector<LHCb::Track>* tracks = getIfExists<std::vector<LHCb::Track> > ( *itS );
if ( tracks->size() ==0 ) {
info()<<"Container "<<*itS<< " is empty"<<endmsg;
continue;
}
// Loop over the Tracks
LHCb::Tracks* tracks_copy = new LHCb::Tracks();
std::string track_cont_out = *itS;
if( msgLevel(MSG::DEBUG)){
debug()<<"Processing track container = "<<(*itS)<<". It contains "<<tracks->size() <<" Tracks" << endmsg;
}
boost::replace_all( track_cont_out, m_rootOfContainers, m_rootOfOutContainers );
if( msgLevel(MSG::DEBUG)){
debug()<<"Copied Keyed track container at location "<<track_cont_out<<endmsg;
}
put( tracks_copy , track_cont_out );
for( auto& original_track : *tracks ){
LHCb::Track* tr = new LHCb::Track;
tr->copy( original_track);
tracks_copy->insert( tr );
} // End loop over Tracks
}
return StatusCode::SUCCESS;
}
Loading