Skip to content
Snippets Groups Projects

changes for running online

Merged Rosen Matev requested to merge rm-align-online into master
1 file
+ 23
13
Compare changes
  • Side-by-side
  • Inline
@@ -45,10 +45,13 @@
#include "TH1D.h"
#include <algorithm>
#include <filesystem>
#include <string>
#include <thread>
#include <vector>
namespace fs = std::filesystem;
namespace {
using namespace LHCb::Det::LbDD4hep;
using ConditionContext = IDD4hepSvc::DD4HepSlicePtr;
@@ -137,7 +140,7 @@ namespace LHCb::Alignment {
StatusCode pause();
void doContinue();
void handle( const Incident& inc ) override;
StatusCode doIteration();
void doIteration();
virtual StatusCode finalize() override;
void doStop();
@@ -154,6 +157,7 @@ namespace LHCb::Alignment {
private:
std::thread* m_thread = nullptr;
int m_iteration = 0;
StatusCode m_status = StatusCode::SUCCESS;
std::map<std::string, double> m_initAlConsts; // inital alignment constants. Comapred with constants after
// convergence to see if update is needed
@@ -169,12 +173,12 @@ namespace LHCb::Alignment {
int AlignOnlineIteratorThreadFunction( void* t ) {
AlignOnlineIterator* f = (AlignOnlineIterator*)t;
IteratorInstance = f;
f->doIteration().ignore();
f->doIteration();
return 1;
}
}
StatusCode AlignOnlineIterator::doIteration() {
void AlignOnlineIterator::doIteration() {
#ifdef USE_DD4HEP
// LHCb::standard_geometry_top
const dd4hep::ConditionKey::KeyMaker m( dd4hep::detail::hash32( "/world/BeforeMagnetRegion/VP" ),
@@ -198,8 +202,7 @@ namespace LHCb::Alignment {
if ( elementProvider == nullptr ) error() << "elementProvider is null!" << endmsg;
if ( m_iteration == 0 ) { m_initAlConsts = elementProvider->getAlignmentConstants(); }
int iteration = 0;
int maxIteration = 0;
int maxIteration = 5;
ConvergenceStatus convergencestatus = ConvergenceStatus::Unknown;
Equations equations( 0 );
// TODO: read multiple files
@@ -215,22 +218,27 @@ namespace LHCb::Alignment {
#ifdef USE_DD4HEP
StatusCode sc =
m_updatetool->process( equations, *elementProvider, iteration, maxIteration, convergencestatus, *m_dd4hepSvc )
m_updatetool->process( equations, *elementProvider, m_iteration, maxIteration, convergencestatus, *m_dd4hepSvc )
.andThen( [&] {
m_dd4hepSvc->write_alignments( m_overlayRoot );
return StatusCode::SUCCESS;
} );
#else
StatusCode sc =
m_updatetool->process( equations, *elementProvider, iteration, maxIteration, convergencestatus ).andThen( [&] {
elementProvider->writeAlignmentConditions( m_xmlWriters.value(), warning() );
} );
m_updatetool->process( equations, *elementProvider, m_iteration, maxIteration, convergencestatus )
.andThen( [&] { elementProvider->writeAlignmentConditions( m_xmlWriters.value(), warning() ); } );
#endif
fs::copy( m_overlayRoot.value(), m_overlayRoot + "." + std::to_string( m_iteration ),
fs::copy_options::overwrite_existing | fs::copy_options::recursive );
if ( sc.isFailure() ) {
error() << "Iteration failed. Stopping" << endmsg;
// TODO are we supposed to use DAQ_ERROR?
// this->m_incidentSvc->fireIncident( Incident( this->name(), "DAQ_ERROR" ) );
m_status = sc;
doStop();
return sc;
return;
}
// for testing and debugigng, always continue
if ( convergencestatus == ConvergenceStatus::Converged ) {
@@ -239,6 +247,7 @@ namespace LHCb::Alignment {
cmp.SetVerbosity( true );
cmp.Compare();
info() << "Iteration converged. Stopping" << endmsg;
m_status = StatusCode::SUCCESS;
doStop();
} else {
info() << "Iteration not converged. Continue" << endmsg;
@@ -247,11 +256,10 @@ namespace LHCb::Alignment {
m_dd4hepSvc->load_alignments( m_overlayRoot );
// force a reload of the conditions at the next possible occasion
m_dd4hepSvc->clear_slice_cache();
m_status = StatusCode::SUCCESS;
doContinue();
}
m_iteration++;
return StatusCode::SUCCESS;
}
DECLARE_COMPONENT_WITH_ID( AlignOnlineIterator, "AlignOnlineIterator" )
@@ -306,7 +314,9 @@ namespace LHCb::Alignment {
m_thread->join();
delete m_thread;
}
return Service::stop();
auto sc = Service::stop();
sc &= m_status;
return sc;
}
StatusCode AlignOnlineIterator::finalize() {
Loading