Skip to content
Snippets Groups Projects

WIP: Functional version of filterdesktop

Closed Victor Renaudin requested to merge vrenaudi_functional_filterdesktop into master
3 unresolved threads
3 files
+ 226
2
Compare changes
  • Side-by-side
  • Inline
Files
3
/*****************************************************************************\
* (c) Copyright 2000-2019 CERN for the benefit of the LHCb Collaboration *
* *
* This software is distributed under the terms of the GNU General Public *
* Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". *
* *
* In applying this licence, CERN does not waive the privileges and immunities *
* granted to it by virtue of its status as an Intergovernmental Organization *
* or submit itself to any jurisdiction. *
\*****************************************************************************/
#include "FunctionalFilterDesktop.h"
#include <algorithm>
#include <functional>
#include "GaudiKernel/StatEntity.h"
#include "GaudiKernel/IAlgContextSvc.h"
#include "Kernel/DaVinciFun.h"
#include "LoKi/IHybridFactory.h"
#include "boost/algorithm/string.hpp"
DECLARE_COMPONENT(FunctionalFilterDesktop)
typedef LoKi::BasicFunctors<const LHCb::Particle*>::BooleanConstant _PBOOL ;
FunctionalFilterDesktop::FunctionalFilterDesktop(const std::string& name, ISvcLocator* pSvcLocator)
: MultiTransformer(name, pSvcLocator,
// Inputs
{KeyValue{"InputParticles", LHCb::ParticleLocation::Production},
KeyValue{"InputVertices", LHCb::VertexLocation::Production}},
// Outputs
{KeyValue{"SelectedParticles", ""},
KeyValue{"SelectedVertices", ""}}),
m_factory("LoKi::Hybrid::Tool/HybridFactory:PUBLIC"),
    • why not give this "default" directly into the property constructor? In fact, did you check that this works? I just played around with it a bit, and i needed to remove this and the next two lines to have the properties available in python...

Please register or sign in to reply
m_preambulo(),
m_code("PNONE"),
m_cut(_PBOOL(false)),
m_to_be_updated1(true) {}
StatusCode FunctionalFilterDesktop::initialize() {
auto sc = MultiTransformer::initialize();
if (sc.isFailure()) return sc;
if ( msgLevel( MSG::DEBUG ) ) debug() << "==> Initialize" << endmsg;
svc<IService> ("LoKiSvc");
Please register or sign in to reply
// decode the cut:
sc = updateMajor();
if ( sc.isFailure() )
{ return Error ("The error from updateMajor" , sc ); }
return StatusCode::SUCCESS;
}
StatusCode FunctionalFilterDesktop::finalize()
{
auto sc = MultiTransformer::finalize();
if (sc.isFailure()) {
return sc;
}
// reset functors
m_cut = _PBOOL(false);
m_to_be_updated1 = true;
return sc;
}
std::string FunctionalFilterDesktop::preambulo() const
{
std::string result ;
for ( std::vector<std::string>::const_iterator iline =
m_preambulo.begin() ; m_preambulo.end() != iline ; ++iline )
{
if ( m_preambulo.begin() != iline ) { result += "\n" ; }
result += (*iline) ;
}
return result;
}
StatusCode FunctionalFilterDesktop::updateMajor()
{
// decode the code
StatusCode sc = decodeCode();
if (sc.isFailure()){return Error ("Error from decodeCode()'");}
// locate the factory
LoKi::IHybridFactory* factory = tool<LoKi::IHybridFactory> (m_factory, this);
release(factory).ignore();
m_to_be_updated1 = false;
return StatusCode::SUCCESS;
}
StatusCode FunctionalFilterDesktop::filter(
const LHCb::Particle::Range& input_particles,
const LHCb::Vertex::Range& input_vertices,
LHCb::Particle::Selection& selected_particles,
LHCb::Vertex::Selection& selected_vertices) const {
for (const auto particle : input_particles) {
if(!m_cut(particle)){
m_npassed_filter+=false;
}
else{
m_npassed_filter+=true;
selected_particles.insert(particle);
}
}
return StatusCode::SUCCESS;
}
std::tuple<LHCb::Particle::Selection, LHCb::Vertex::Selection>
FunctionalFilterDesktop::operator()(const LHCb::Particle::Range& input_particles, const LHCb::Vertex::Range& input_vertices) const {
/* if (m_to_be_updated1) */
/* { */
/* StatusCode sc = updateMajor() ; */
/* /1* if (sc.isFailure()) return Error ("Error from updateMajor", sc); *1/ */
/* } */
std::tuple<LHCb::Particle::Selection, LHCb::Vertex::Selection> output_selection;
LHCb::Particle::Selection selected_particles;
LHCb::Vertex::Selection selected_vertices;
StatusCode sc = filter(input_particles, input_vertices, std::get<0>(output_selection), std::get<1>(output_selection));
/* return std::make_tuple("Selection", selected_particles, selected_vertices); */
return output_selection;
}
StatusCode FunctionalFilterDesktop::decodeCode()
{
// locate the factory
LoKi::IHybridFactory* factory_ = tool<LoKi::IHybridFactory>(factory(), this);
// use the factory
StatusCode sc = factory_ -> get(code(), m_cut ,preambulo());
if (sc.isFailure()){
return Error ( "Error from LoKi/Bender 'hybrid' factory for Code='" + code() + "'", sc);
}
release ( factory_ ).ignore();
return sc ;
}
Loading