Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement CONST properties to optical sufaces. (Requires new release of ROOT) #1226

Merged
merged 15 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
35 changes: 16 additions & 19 deletions DDAlign/src/AlignmentsCalib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,14 @@
//==========================================================================

// Framework includes
#include "DDAlign/AlignmentsCalib.h"
#include <DDAlign/AlignmentsCalib.h>

#include "DD4hep/Memory.h"
#include "DD4hep/Printout.h"
#include "DD4hep/DetectorTools.h"
#include "DD4hep/detail/AlignmentsInterna.h"
#include <DD4hep/Memory.h>
#include <DD4hep/Printout.h>
#include <DD4hep/DetectorTools.h>
#include <DD4hep/detail/AlignmentsInterna.h>

using namespace std;
using namespace dd4hep;
using namespace dd4hep::align;
typedef Condition::key_type key_type;

/// Helper class to store information about alignment calibration items
/** Implementation details: Alignment context entry
Expand All @@ -34,12 +31,12 @@ typedef Condition::key_type key_type;
*/
class AlignmentsCalib::Entry {
public:
Delta delta;
Delta original;
Condition source;
DetElement detector;
Condition::key_type target = 0;
int dirty = 0;
dd4hep::Delta delta;
dd4hep::Delta original;
dd4hep::Condition source;
dd4hep::DetElement detector;
dd4hep::Condition::key_type target = 0;
int dirty = 0;
Entry() = default;
Entry(const Entry& c) = delete;
Entry& operator=(const Entry& c) = delete;
Expand All @@ -57,13 +54,13 @@ AlignmentsCalib::~AlignmentsCalib() noexcept(false) {
}

/// Convenience only: Access detector element by path
DetElement AlignmentsCalib::detector(const string& path) const {
dd4hep::DetElement AlignmentsCalib::detector(const std::string& path) const {
DetElement det(detail::tools::findElement(description,path));
return det;
}

/// Implementation: Add a new entry to the transaction stack.
pair<key_type,AlignmentsCalib::Entry*>
std::pair<dd4hep::Condition::key_type,AlignmentsCalib::Entry*>
AlignmentsCalib::_set(DetElement detector, const Delta& delta) {
ConditionKey tar_key(detector.key(),Keys::alignmentKey);
UsedConditions::iterator i = used.find(tar_key.hash);
Expand Down Expand Up @@ -103,14 +100,14 @@ AlignmentsCalib::_set(DetElement detector, const Delta& delta) {
}

/// (1) Add a new entry to an existing DetElement structure.
Condition::key_type
dd4hep::Condition::key_type
AlignmentsCalib::set(DetElement det, const Delta& delta) {
return _set(det.access(), delta).first;
}

/// (2) Add a new entry to an existing DetElement structure.
Condition::key_type
AlignmentsCalib::set(const string& path, const Delta& delta) {
dd4hep::Condition::key_type
AlignmentsCalib::set(const std::string& path, const Delta& delta) {
return _set(detector(path).access(), delta).first;
}

Expand Down
82 changes: 41 additions & 41 deletions DDAlign/src/GlobalAlignmentCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,43 +12,41 @@
//==========================================================================

// Framework include files
#include "DD4hep/Detector.h"
#include "DD4hep/Printout.h"
#include "DDAlign/GlobalAlignmentCache.h"
#include "DDAlign/GlobalAlignmentOperators.h"
#include "DD4hep/detail/DetectorInterna.h"
#include <DD4hep/Detector.h>
#include <DD4hep/Printout.h>
#include <DDAlign/GlobalAlignmentCache.h>
#include <DDAlign/GlobalAlignmentOperators.h>
#include <DD4hep/detail/DetectorInterna.h>

// ROOT include files
#include "TGeoManager.h"
#include <TGeoManager.h>

using namespace std;
using namespace dd4hep;
using namespace dd4hep::align;
using namespace dd4hep::align::DDAlign_standard_operations;
typedef GlobalAlignmentStack::StackEntry Entry;
using Entry = GlobalAlignmentStack::StackEntry;

DetElement _detector(DetElement child) {
dd4hep::DetElement _detector(dd4hep::DetElement child) {
if ( child.isValid() ) {
DetElement p(child.parent());
dd4hep::DetElement p(child.parent());
if ( p.isValid() && !p.parent().isValid() )
return child;
else if ( !p.isValid() ) // World detector element...
return child;
return _detector(p);
}
throw runtime_error("dd4hep: DetElement cannot determine detector parent [Invalid handle]");
dd4hep::except("GlobalAlignmentCache", "DetElement cannot determine detector parent [Invalid handle]");
return {};
}

/// Default constructor
GlobalAlignmentCache::GlobalAlignmentCache(Detector& description, const string& sdPath, bool top)
GlobalAlignmentCache::GlobalAlignmentCache(Detector& description, const std::string& sdPath, bool top)
: m_detDesc(description), m_sdPath(sdPath), m_sdPathLen(sdPath.length()), m_refCount(1), m_top(top)
{
}

/// Default destructor
GlobalAlignmentCache::~GlobalAlignmentCache() {
int nentries = (int)m_cache.size();
int nsect = (int)m_detectors.size();
int nsect = (int)m_detectors.size();
detail::releaseObjects(m_detectors);
m_cache.clear();
printout(INFO,"GlobalAlignmentCache",
Expand Down Expand Up @@ -103,26 +101,26 @@ bool GlobalAlignmentCache::insert(GlobalAlignment alignment) {
}

/// Retrieve the cache section corresponding to the path of an entry.
GlobalAlignmentCache* GlobalAlignmentCache::section(const string& path_name) const {
size_t idx, idq;
GlobalAlignmentCache* GlobalAlignmentCache::section(const std::string& path_name) const {
std::size_t idx, idq;
if ( path_name[0] != '/' ) {
return section(m_detDesc.world().placementPath()+'/'+path_name);
}
else if ( (idx=path_name.find('/',1)) == string::npos ) {
else if ( (idx=path_name.find('/',1)) == std::string::npos ) {
return (m_sdPath == path_name.c_str()+1) ? (GlobalAlignmentCache*)this : 0;
}
else if ( m_detectors.empty() ) {
return 0;
}
if ( (idq=path_name.find('/',idx+1)) != string::npos ) --idq;
string path = path_name.substr(idx+1,idq-idx);
if ( (idq=path_name.find('/',idx+1)) != std::string::npos ) --idq;
std::string path = path_name.substr(idx+1,idq-idx);
SubdetectorAlignments::const_iterator j = m_detectors.find(path);
return (j==m_detectors.end()) ? 0 : (*j).second;
}

/// Retrieve an alignment entry by its placement path
GlobalAlignment GlobalAlignmentCache::get(const string& path_name) const {
size_t idx, idq;
GlobalAlignment GlobalAlignmentCache::get(const std::string& path_name) const {
std::size_t idx, idq;
unsigned int index = detail::hash32(path_name.c_str()+m_sdPathLen);
Cache::const_iterator i = m_cache.find(index);
if ( i != m_cache.end() ) {
Expand All @@ -134,23 +132,24 @@ GlobalAlignment GlobalAlignmentCache::get(const string& path_name) const {
else if ( path_name[0] != '/' ) {
return get(m_detDesc.world().placementPath()+'/'+path_name);
}
else if ( (idx=path_name.find('/',1)) == string::npos ) {
else if ( (idx=path_name.find('/',1)) == std::string::npos ) {
// Escape: World volume and not found in cache --> not present
return GlobalAlignment(0);
}
if ( (idq=path_name.find('/',idx+1)) != string::npos ) --idq;
string path = path_name.substr(idx+1,idq-idx);
if ( (idq=path_name.find('/',idx+1)) != std::string::npos ) --idq;
std::string path = path_name.substr(idx+1, idq-idx);
SubdetectorAlignments::const_iterator j = m_detectors.find(path);
if ( j != m_detectors.end() ) return (*j).second->get(path_name);
return GlobalAlignment(0);
}

/// Return all entries matching a given path.
vector<GlobalAlignment> GlobalAlignmentCache::matches(const string& match, bool exclude_exact) const {
vector<GlobalAlignment> result;
std::vector<GlobalAlignment>
GlobalAlignmentCache::matches(const std::string& match, bool exclude_exact) const {
std::vector<GlobalAlignment> result;
GlobalAlignmentCache* c = section(match);
if ( c ) {
size_t len = match.length();
std::size_t len = match.length();
result.reserve(c->m_cache.size());
for(Cache::const_iterator i=c->m_cache.begin(); i!=c->m_cache.end();++i) {
const Cache::value_type& v = *i;
Expand All @@ -173,7 +172,7 @@ void GlobalAlignmentCache::commit(GlobalAlignmentStack& stack) {
}

/// Retrieve branch cache by name. If not present it will be created
GlobalAlignmentCache* GlobalAlignmentCache::subdetectorAlignments(const string& nam) {
GlobalAlignmentCache* GlobalAlignmentCache::subdetectorAlignments(const std::string& nam) {
SubdetectorAlignments::const_iterator i = m_detectors.find(nam);
if ( i == m_detectors.end() ) {
GlobalAlignmentCache* ptr = new GlobalAlignmentCache(m_detDesc,nam,false);
Expand All @@ -185,8 +184,8 @@ GlobalAlignmentCache* GlobalAlignmentCache::subdetectorAlignments(const string&

/// Apply a complete stack of ordered alignments to the geometry structure
void GlobalAlignmentCache::apply(GlobalAlignmentStack& stack) {
typedef map<string,DetElement> DetElementUpdates;
typedef map<DetElement,vector<Entry*> > sd_entries_t;
typedef std::map<std::string,DetElement> DetElementUpdates;
typedef std::map<DetElement,std::vector<Entry*> > sd_entries_t;
TGeoManager& mgr = m_detDesc.manager();
DetElementUpdates detelt_updates;
sd_entries_t all;
Expand Down Expand Up @@ -218,10 +217,10 @@ void GlobalAlignmentCache::apply(GlobalAlignmentStack& stack) {
elt->update(DetElement::PLACEMENT_CHANGED|DetElement::PLACEMENT_ELEMENT,elt.ptr());
}
// Provide update callback for the highest detector element
string last_path = "?????";
std::string last_path = "?????";
for(DetElementUpdates::iterator i=detelt_updates.begin(); i!=detelt_updates.end(); ++i) {
const string& path = (*i).first;
if ( path.find(last_path) == string::npos ) {
const std::string& path = (*i).first;
if ( path.find(last_path) == std::string::npos ) {
DetElement elt((*i).second);
printout(DEBUG,"GlobalAlignmentCache","+++ Trigger placement update for %s [1]",elt.path().c_str());
elt->update(DetElement::PLACEMENT_CHANGED|DetElement::PLACEMENT_HIGHEST,elt.ptr());
Expand All @@ -237,15 +236,16 @@ void GlobalAlignmentCache::apply(GlobalAlignmentStack& stack) {
}

/// Apply a vector of SD entries of ordered alignments to the geometry structure
void GlobalAlignmentCache::apply(const vector<Entry*>& changes) {
typedef map<string,pair<TGeoPhysicalNode*,Entry*> > Nodes;
Nodes nodes;
void GlobalAlignmentCache::apply(const std::vector<Entry*>& changes) {
std::map<std::string,std::pair<TGeoPhysicalNode*,Entry*> > nodes;
namespace ops = dd4hep::align::DDAlign_standard_operations;
GlobalAlignmentSelector selector(*this,nodes,changes);

for_each(m_cache.begin(),m_cache.end(),selector.reset());
for_each(nodes.begin(),nodes.end(),GlobalAlignmentActor<node_print>(*this,nodes));
for_each(nodes.begin(),nodes.end(),GlobalAlignmentActor<node_reset>(*this,nodes));
for_each(nodes.begin(),nodes.end(),GlobalAlignmentActor<ops::node_print>(*this,nodes));
for_each(nodes.begin(),nodes.end(),GlobalAlignmentActor<ops::node_reset>(*this,nodes));

for_each(changes.begin(),changes.end(),selector.reset());
for_each(nodes.begin(),nodes.end(),GlobalAlignmentActor<node_align>(*this,nodes));
for_each(nodes.begin(),nodes.end(),GlobalAlignmentActor<node_delete>(*this,nodes));
for_each(nodes.begin(),nodes.end(),GlobalAlignmentActor<ops::node_align>(*this,nodes));
for_each(nodes.begin(),nodes.end(),GlobalAlignmentActor<ops::node_delete>(*this,nodes));
}
22 changes: 10 additions & 12 deletions DDAlign/src/GlobalAlignmentOperators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,15 @@
//==========================================================================

// Framework include files
#include "DD4hep/Detector.h"
#include "DD4hep/Printout.h"
#include "DD4hep/detail/DetectorInterna.h"
#include "DDAlign/GlobalAlignmentOperators.h"
#include "DDAlign/GlobalDetectorAlignment.h"
#include <DD4hep/Detector.h>
#include <DD4hep/Printout.h>
#include <DD4hep/detail/DetectorInterna.h>
#include <DDAlign/GlobalAlignmentOperators.h>
#include <DDAlign/GlobalDetectorAlignment.h>

// C/C++ include files
#include <stdexcept>

using namespace std;
using namespace dd4hep;
using namespace dd4hep::align;

void GlobalAlignmentOperator::insert(GlobalAlignment alignment) const {
Expand All @@ -33,7 +31,7 @@ void GlobalAlignmentOperator::insert(GlobalAlignment alignment) const {

void GlobalAlignmentSelector::operator()(Entries::value_type e) const {
TGeoPhysicalNode* pn = 0;
nodes.emplace(e->path,make_pair(pn,e));
nodes.emplace(e->path,std::make_pair(pn,e));
}

void GlobalAlignmentSelector::operator()(const Cache::value_type& entry) const {
Expand All @@ -44,11 +42,11 @@ void GlobalAlignmentSelector::operator()(const Cache::value_type& entry) const
const char* p = pn->GetName();
bool reset_children = GlobalAlignmentStack::resetChildren(*e);
if ( reset_children && ::strstr(p,e->path.c_str()) == p ) {
nodes.emplace(p,make_pair(pn,e));
nodes.emplace(p,std::make_pair(pn,e));
break;
}
else if ( e->path == p ) {
nodes.emplace(p,make_pair(pn,e));
nodes.emplace(p,std::make_pair(pn,e));
break;
}
}
Expand All @@ -75,12 +73,12 @@ template <> void GlobalAlignmentActor<DDAlign_standard_operations::node_delete>:

template <> void GlobalAlignmentActor<DDAlign_standard_operations::node_reset>::operator()(Nodes::value_type& n) const {
TGeoPhysicalNode* p = n.second.first;
string np;
std::string np;
if ( p->IsAligned() ) {
for (Int_t i=0, nLvl=p->GetLevel(); i<=nLvl; i++) {
TGeoNode* node = p->GetNode(i);
TGeoMatrix* mat = node->GetMatrix(); // Node's relative matrix
np += string("/")+node->GetName();
np += std::string("/")+node->GetName();
if ( !mat->IsIdentity() && i > 0 ) { // Ignore the 'world', is identity anyhow
GlobalAlignment a = cache.get(np);
if ( a.isValid() ) {
Expand Down
Loading
Loading