diff --git a/DDCond/include/DDCond/AlignmentsLoaderImp.h b/DDCond/include/DDCond/AlignmentsLoaderImp.h new file mode 100644 index 0000000000000000000000000000000000000000..b4e4d6a9bf0e4f5411dcfbcce060c1efa0175106 --- /dev/null +++ b/DDCond/include/DDCond/AlignmentsLoaderImp.h @@ -0,0 +1,61 @@ +// $Id$ +//========================================================================== +// AIDA Detector description implementation for LCD +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : M.Frank +// +//========================================================================== +#ifndef DDCOND_ALIGNMENTSLOADERIMP_H +#define DDCOND_ALIGNMENTSLOADERIMP_H + +// Framework include files +#include "DD4hep/objects/AlignmentsInterna.h" +#include "DDCond/ConditionsPool.h" + +/// Namespace for the AIDA detector description toolkit +namespace DD4hep { + + /// Namespace for the geometry part of the AIDA detector description toolkit + namespace Conditions { + + /// Concrete class to interface conditions loading from DetElements + /** + * + * \author M.Frank + * \version 1.0 + */ + class AlignmentsLoaderImp : public Alignments::AlignmentsLoader { + public: + typedef Alignments::Alignment Alignment; + + protected: + /// Reference to conditions manager + ConditionsManager m_manager; + /// Referenec count + long m_refCount; + + public: + /// Default constructor + AlignmentsLoaderImp(ConditionsManager mgr); + /// Default destructor + virtual ~AlignmentsLoaderImp(); + /// Addreference count. Use object + virtual void addRef(); + /// Release object. The client may not use any reference any further. + virtual void release(); + /// Access the alignments loading mechanism + virtual Alignment get(key_type key, const iov_type& iov); + /// Access the alignments loading mechanism. Only alignments in the user pool will be accessed. + virtual Alignment get(key_type key, const UserPool& pool); + }; + + } /* End namespace Conditions */ +} /* End namespace DD4hep */ + +#endif /* DDCOND_ALIGNMENTSLOADERIMP_H */ diff --git a/DDCond/src/AlignmentsLoaderImp.cpp b/DDCond/src/AlignmentsLoaderImp.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9346f54c2b4799ce7f4141e36da3e92fc8525534 --- /dev/null +++ b/DDCond/src/AlignmentsLoaderImp.cpp @@ -0,0 +1,56 @@ +// $Id$ +//========================================================================== +// AIDA Detector description implementation for LCD +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : M.Frank +// +//========================================================================== + +// Framework include files +#include "DDCond/ConditionsPool.h" +#include "DDCond/ConditionsInterna.h" +#include "DDCond/AlignmentsLoaderImp.h" + +using namespace DD4hep::Conditions; +using DD4hep::Alignments::Alignment; +using DD4hep::Alignments::AlignmentCondition; + +/// Default constructor +AlignmentsLoaderImp::AlignmentsLoaderImp(ConditionsManager mgr) + : m_manager(mgr), m_refCount(1) +{ +} + +/// Default destructor +AlignmentsLoaderImp::~AlignmentsLoaderImp() { +} + +/// Addreference count. Use object +void AlignmentsLoaderImp::addRef() { + ++m_refCount; +} + +/// Release object. The client may not use any reference any further. +void AlignmentsLoaderImp::release() { + if ( --m_refCount <= 0 ) { + delete this; + } +} + +/// Access the conditions loading mechanism +Alignment AlignmentsLoaderImp::get(key_type key, const Condition::iov_type& iov) { + AlignmentCondition cond = m_manager.ptr()->get(key, iov); + return &cond.data(); +} + +/// Access the conditions loading mechanism. Only conditions in the user pool will be accessed. +Alignment AlignmentsLoaderImp::get(key_type key, const UserPool& pool) { + AlignmentCondition cond = pool.get(key); + return &cond.data(); +} diff --git a/DDCond/src/ConditionsInterna.cpp b/DDCond/src/ConditionsInterna.cpp index 0575f30e5ada844160e569a574a33bf40d56a71c..42069ff65769d547c79c0508eafdf653bc57b760 100644 --- a/DDCond/src/ConditionsInterna.cpp +++ b/DDCond/src/ConditionsInterna.cpp @@ -25,6 +25,7 @@ #include "DD4hep/DetFactoryHelper.h" #include "DD4hep/objects/DetectorInterna.h" #include "DD4hep/objects/ConditionsInterna.h" +#include "DD4hep/objects/AlignmentsInterna.h" #include "DDCond/ConditionsPool.h" #include "DDCond/ConditionsEntry.h" @@ -33,11 +34,13 @@ #include "DDCond/ConditionsInterna.h" #include "DDCond/ConditionsListener.h" #include "DDCond/ConditionsLoaderImp.h" +#include "DDCond/AlignmentsLoaderImp.h" using namespace std; using namespace DD4hep; using namespace DD4hep::Conditions; +typedef Alignments::AlignmentsLoader AlignmentsLoader; typedef UpdatePool::UpdateEntries Updates; typedef RangeConditions RC; @@ -151,9 +154,12 @@ ConditionsManagerObject::ConditionsManagerObject(LCDD& lcdd_instance) ConditionsManagerObject::~ConditionsManagerObject() { Geometry::World world(m_lcdd.world()); for_each(m_rawPool.begin(), m_rawPool.end(), DestroyObject<ConditionsIOVPool*>()); - ConditionsLoader* ld = world->conditionsLoader; + ConditionsLoader* cld = world->conditionsLoader; + AlignmentsLoader* ald = world->alignmentsLoader; world->conditionsLoader = 0; - if ( ld ) ld->release(); + world->alignmentsLoader = 0; + if ( cld ) cld->release(); + if ( ald ) ald->release(); InstanceCount::decrement(this); } @@ -173,6 +179,7 @@ void ConditionsManagerObject::initialize() { ref->SetTitle("updates"); Geometry::World world(m_lcdd.world()); world->conditionsLoader = new ConditionsLoaderImp(this); + world->alignmentsLoader = new AlignmentsLoaderImp(this); } } diff --git a/DDCore/include/DD4hep/AlignmentData.h b/DDCore/include/DD4hep/AlignmentData.h index 691ef1bd4e881c80891db554bf7832935e772d53..35af9d8ac33b8a932988fd573bd5fe6f218f3206 100644 --- a/DDCore/include/DD4hep/AlignmentData.h +++ b/DDCore/include/DD4hep/AlignmentData.h @@ -38,7 +38,8 @@ namespace DD4hep { // Forward declarations class Alignment; - + class AlignmentCondition; + /// Class describing an condition to re-adjust an alignment /** * @@ -126,6 +127,8 @@ namespace DD4hep { DetElement detector; /// The subdetector placement corresponding to the actual detector element's volume PlacedVolume placement; + /// Reference to the original condition object (May not be present!) + Ref_t condition; /// Flag to remember internally calculated quatities mutable BitMask flag; /// Magic word to verify object if necessary @@ -141,16 +144,17 @@ namespace DD4hep { /// Assignment operator necessary due to copy constructor AlignmentData& operator=(const AlignmentData& copy); /// Data accessor for decorator - inline AlignmentData& data() { return *this; } - + inline AlignmentData& data() { return *this; } + /// Accessor if a conditions object is behind + bool hasCondition() const { return condition.isValid(); } /// Access the ideal/nominal alignment/placement matrix Alignment nominal() const; /// Create cached matrix to transform to world coordinates - const TGeoHMatrix& worldTransformation() const { return worldTrafo; } + const TGeoHMatrix& worldTransformation() const { return worldTrafo; } /// Access the alignment/placement matrix with respect to the world - const TGeoHMatrix& detectorTransformation() const { return detectorTrafo; } + const TGeoHMatrix& detectorTransformation() const { return detectorTrafo; } /// Access the currently applied alignment/placement matrix - const Transform3D& localToWorld() const { return trToWorld; } + const Transform3D& localToWorld() const { return trToWorld; } /** Aliases for the transformation from local coordinates to the world system */ /// Transformation from local coordinates of the placed volume to the world system @@ -161,7 +165,7 @@ namespace DD4hep { Position localToWorld(const Position& local) const; /// Transformation from local coordinates of the placed volume to the world system Position localToWorld(const Double_t local[3]) const - { return localToWorld(Position(local[0],local[1],local[2])); } + { return localToWorld(Position(local[0],local[1],local[2])); } /** Aliases for the transformation from world coordinates to the local volume */ /// Transformation from world coordinates of the local placed volume coordinates @@ -172,7 +176,7 @@ namespace DD4hep { Position worldToLocal(const Position& global) const; /// Transformation from local coordinates of the placed volume to the world system Position worldToLocal(const Double_t global[3]) const - { return worldToLocal(Position(global[0],global[1],global[2])); } + { return worldToLocal(Position(global[0],global[1],global[2])); } /** Aliases for the transformation from local coordinates to the next DetElement system */ /// Transformation from local coordinates of the placed volume to the detector system @@ -183,7 +187,7 @@ namespace DD4hep { Position localToDetector(const Position& local) const; /// Transformation from local coordinates of the placed volume to the world system Position localToDetector(const Double_t local[3]) const - { return localToDetector(Position(local[0],local[1],local[2])); } + { return localToDetector(Position(local[0],local[1],local[2])); } /** Aliases for the transformation from the next DetElement to local coordinates */ /// Transformation from detector element coordinates to the local placed volume coordinates @@ -194,7 +198,7 @@ namespace DD4hep { Position detectorToLocal(const Position& detector) const; /// Transformation from detector element coordinates to the local placed volume coordinates Position detectorToLocal(const Double_t det[3]) const - { return detectorToLocal(Position(det[0],det[1],det[2])); } + { return detectorToLocal(Position(det[0],det[1],det[2])); } }; /** diff --git a/DDCore/src/Alignments.cpp b/DDCore/src/Alignments.cpp index 0755d9ba6296704236160838bb6bbdfd0e7539f4..df7d24f12923693c49580c3e71bb8ef1794e2b3b 100644 --- a/DDCore/src/Alignments.cpp +++ b/DDCore/src/Alignments.cpp @@ -75,6 +75,7 @@ AlignmentCondition::Data& AlignmentCondition::data() { return *(o->alignment_data); Conditions::Condition c(*this); o->alignment_data = c.is_bound() ? &c.get<Data>() : &c.bind<Data>(); + o->alignment_data->condition = c; return *(o->alignment_data); } @@ -85,6 +86,7 @@ const AlignmentCondition::Data& AlignmentCondition::data() const { return *(o->alignment_data); Conditions::Condition c(*this); o->alignment_data = c.is_bound() ? &c.get<Data>() : &c.bind<Data>(); + o->alignment_data->condition = c; return *(o->alignment_data); } diff --git a/DDCore/src/Detector.cpp b/DDCore/src/Detector.cpp index 49eb1ee1574639f0d584048c6a44e35517f33909..b64625c96a45d75f3cbf5d167b5866a03727bf70 100644 --- a/DDCore/src/Detector.cpp +++ b/DDCore/src/Detector.cpp @@ -15,6 +15,7 @@ // Framework include files #include "DD4hep/objects/DetectorInterna.h" #include "DD4hep/objects/ConditionsInterna.h" +#include "DD4hep/objects/AlignmentsInterna.h" #include "DD4hep/AlignmentTools.h" #include "DD4hep/DetectorTools.h" #include "DD4hep/World.h" @@ -229,6 +230,14 @@ bool DetElement::hasConditions() const { return false; } +/// Check if alignments are at all present +bool DetElement::hasAlignments() const { + Object* o = access(); + if ( o->alignments.isValid() && !o->alignments->keys.empty() ) + return true; + return false; +} + void DetElement::check(bool cond, const string& msg) const { if (cond) { throw runtime_error("DD4hep: " + msg); diff --git a/DDDB/include/DDDB/DDDBAlignmentUpdateCall.h b/DDDB/include/DDDB/DDDBAlignmentUpdateCall.h new file mode 100644 index 0000000000000000000000000000000000000000..2be998090935941dcfdb97ea899d33c9260d2406 --- /dev/null +++ b/DDDB/include/DDDB/DDDBAlignmentUpdateCall.h @@ -0,0 +1,66 @@ +// $Id$ +//========================================================================== +// AIDA Detector description implementation for LCD +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : M.Frank +// +//========================================================================== +// +// DDDB is a detector description convention developed by the LHCb experiment. +// For further information concerning the DTD, please see: +// http://lhcb-comp.web.cern.ch/lhcb-comp/Frameworks/DetDesc/Documents/lhcbDtd.pdf +// +//========================================================================== +#ifndef DD4HEP_DDDB_DDDBALIGNMENTUPDATECALL_H +#define DD4HEP_DDDB_DDDBALIGNMENTUPDATECALL_H + +// Framework includes +#include "DD4hep/ConditionDerived.h" + +/// Namespace for the AIDA detector description toolkit +namespace DD4hep { + + /// Namespace of the DDDB conversion stuff + namespace DDDB { + + /// Specialized conditions update callback for DDDB alignments + /** + * Used by clients to update an alignment condition. + * The input data, a condition with an AbstractMap data structure + * containing the alignment delta data. + * + * The condition must be fully computed in two steps: + * - firstly it is created here and the alignment delta copied. + * - secondly, once all updates are processed, the world-transformations + * for the alignment object(s) are computed by the AlignmentManager + * objects. + * The AlignmentManager also keeps track of newly created alignment + * conditions and is informed in the callback. + * + * \author M.Frank + * \version 1.0 + * \ingroup DD4HEP_CONDITIONS + */ + class DDDBAlignmentUpdateCall : public Conditions::ConditionUpdateCall { + public: + typedef Conditions::Condition Condition; + typedef Conditions::ConditionKey ConditionKey; + typedef Conditions::ConditionUpdateContext UpdateContext; + public: + /// Default constructor + DDDBAlignmentUpdateCall(); + /// Default destructor + virtual ~DDDBAlignmentUpdateCall(); + /// Interface to client Callback in order to update the condition + virtual Condition operator()(const ConditionKey& key, const UpdateContext& context); + }; + + } /* End namespace DDDB */ +} /* End namespace DD4hep */ +#endif /* DD4HEP_DDDB_DDDBALIGNMENTUPDATECALL_H */ diff --git a/DDDB/src/DDDBAlignmentTest.cpp b/DDDB/src/DDDBAlignmentTest.cpp index 0802eda1483c6dfddad135e7760038f2d0be3448..c02531ed124095765e18fe3734018d0d35d64ee9 100644 --- a/DDDB/src/DDDBAlignmentTest.cpp +++ b/DDDB/src/DDDBAlignmentTest.cpp @@ -20,80 +20,26 @@ // Framework includes #include "DD4hep/LCDD.h" -#include "DD4hep/Plugins.h" +#include "DD4hep/DetAlign.h" #include "DD4hep/Printout.h" #include "DD4hep/Factories.h" -#include "DD4hep/ConditionsData.h" #include "DD4hep/InstanceCount.h" -#include "DDAlign/AlignmentsManager.h" -#include "DDCond/ConditionsManager.h" +#include "DD4hep/objects/AlignmentsInterna.h" #include "DDCond/ConditionsPool.h" +#include "DDAlign/AlignmentsManager.h" #include "DDDB/DDDBReader.h" #include "DDDB/DDDBConversion.h" -#include "DDDB/DDDBConditionPrinter.h" +#include "DDDB/DDDBAlignmentUpdateCall.h" using namespace std; using namespace DD4hep; using namespace DD4hep::Conditions; - -using DDDB::Document; -using Geometry::LCDD; -using Geometry::DetElement; -using Geometry::Position; -using Geometry::RotationZYX; -using Geometry::Transform3D; -using Geometry::Translation3D; +using Alignments::AlignmentsManager; /// Anonymous namespace for plugins namespace { - using Alignments::AlignmentsManager; - - /// Specialized conditions update callback for alignments - /** - * Used by clients to update a condition. - * - * \author M.Frank - * \version 1.0 - * \ingroup DD4HEP_CONDITIONS - */ - class AlignmentUpdate : public ConditionUpdateCall { - typedef AbstractMap::Params::value_type::second_type Param; - typedef Alignments::AlignmentData Data; - public: - AlignmentUpdate() { } - virtual ~AlignmentUpdate() { } - /// Interface to client Callback in order to update the condition - virtual Condition operator()(const ConditionKey& key, const Context& context) { - Alignments::AlignmentCondition target(key.name); - Data& data = target.data(); - Condition cond = context.condition(0); - AbstractMap& src = cond.get<AbstractMap>(); - const Param& par = src.firstParam().second; - DetElement det = context.dependency.detector; - printout(DEBUG,"AlignmentUpdate","++ Building dependent condition: %s Detector [%d]: %s ", - key.name.c_str(), det.level(), det.path().c_str()); - if ( par.typeInfo() == typeid(Data::Delta) ) { - const Data::Delta& delta = src.first<Data::Delta>(); - data.delta = delta; - data.flag = Data::HAVE_NONE; - } - else { - printout(INFO,"AlignmentUpdate","++ Failed to access alignment-Delta from %s", - cond->value.c_str()); - DDDB::ConditionPrinter()(cond); - } - data.detector = det; - AlignmentsManager::newEntry(context, det, &context.dependency, target); - // A callback returning no condition is illegal! - // Need to crosscheck though if the alignment IOV interval of parents may be - // smaller then the daughter IOV interval. - // I though expect, that this is a purely academic case. - return target; - } - }; - /// DDDB Conditions analyser to select alignments. /** * \author M.Frank @@ -103,23 +49,22 @@ namespace { */ class AlignmentSelector { public: - typedef ConditionsManager::Dependencies Dependencies; - LCDD& lcdd; - AlignmentUpdate* updateCall; - long int time; - string m_name; + ConditionUpdateCall* updateCall; + LCDD& lcdd; + string m_name; /// Initializing constructor - AlignmentSelector(LCDD& l, long t) : lcdd(l), time(t), m_name("Selector") { + AlignmentSelector(LCDD& l) : lcdd(l), m_name("Selector") { // The alignment update call can be re-used over and over. It has not state. - updateCall = new AlignmentUpdate(); + updateCall = new DDDB::DDDBAlignmentUpdateCall(); } /// Default destructor virtual ~AlignmentSelector() { releasePtr(updateCall); } /// Recursive alignment collector - long collect(DetElement de, dd4hep_ptr<UserPool>& user_pool, AlignmentsManager& am, int level) { + long collect(DetElement de, dd4hep_ptr<UserPool>& user_pool, AlignmentsManager& am, int level) + { char fmt[64]; try { DDDB::Catalog* cat = de.extension<DDDB::Catalog>(); @@ -127,7 +72,18 @@ namespace { ConditionKey key(cat->condition); Condition cond = user_pool->get(key.hash); if ( cond.isValid() ) { - DependencyBuilder b(ConditionKey(cat->condition+"/Tranformations"), updateCall->addRef()); + ConditionKey k(cat->condition+"/Tranformations"); + // + // The alignment access through the DetElement object is optional! + // It is slow and deprecated. The access using the UserPool directly + // is highly favored. + // + Alignments::DetAlign align(de); + align.alignments()->addKey(k.name); + align.alignments()->addKey("Alignment",k.name); + // + // Now add the dependency to the alignmant manager + DependencyBuilder b(k, updateCall->addRef()); b->detector = de; b.add(ConditionKey(cond->value)); am.adoptDependency(b.release()); @@ -149,36 +105,74 @@ namespace { return 1; } /// Initial collector call - long collect(ConditionsManager manager, AlignmentsManager& context) { + long collect(ConditionsManager manager, AlignmentsManager& context, long time) { const IOVType* iovType = manager.iovType("epoch"); IOV iov(iovType, IOV::Key(time,time)); dd4hep_ptr<UserPool> user_pool; manager.prepare(iov, user_pool); return collect(lcdd.world(), user_pool, context, 0); } - - int computeDependencies(ConditionsManager manager, AlignmentsManager& am) { - const IOVType* iovType = manager.iovType("epoch"); - for(int i=0; i<10; ++i) { { - int t = time + i*3600; - IOV iov(iovType, IOV::Key(t,t)); - dd4hep_ptr<UserPool> user_pool; - long num_expired = manager.prepare(iov, user_pool); - printout(INFO,"Conditions", - "+++ ConditionsUpdate: Updated %ld conditions... IOV:%s", - num_expired, iov.str().c_str()); - am.compute(user_pool); - user_pool->clear(); + /// Compute dependent alignment conditions + int computeDependencies(dd4hep_ptr<UserPool>& user_pool, + ConditionsManager conds, + AlignmentsManager align, + long time) + { + const IOVType* iovType = conds.iovType("epoch"); + IOV iov(iovType, IOV::Key(time,time)); + long num_expired = conds.prepare(iov, user_pool); + printout(INFO,"Conditions", + "+++ ConditionsUpdate: Updated %ld conditions... IOV:%s", + num_expired, iov.str().c_str()); + align.compute(user_pool); + return 1; + } + /// Access dependent alignment conditions from DetElement object using global and local keys + int access(ConditionsManager conds,AlignmentsManager align,long time) { + typedef ConditionsManager::Dependencies Deps; + dd4hep_ptr<UserPool> pool; + int ret = computeDependencies(pool, conds, align, time); + if ( ret == 1 ) { + const Deps& deps = align.knownDependencies(); + int count = 0; + for(Deps::const_iterator i=deps.begin(); i!=deps.end(); ++i) { + const ConditionDependency* d = (*i).second.get(); + if ( d->detector.hasAlignments() ) { + UserPool& p = *(pool.get()); + Alignments::DetAlign det(d->detector); + const ConditionKey& k = d->target; + Alignments::Container c = det.alignments(); + { + Alignments::Alignment a = c.get(k.hash,p); + const Alignments::Delta& D = a.data().delta; + printout(INFO,"Alignment","++ [%08X] (%11s-%8s-%5s) Cond:%p '%s'", k.hash, + D.hasTranslation() ? "Translation" : "", + D.hasRotation() ? "Rotation" : "", + D.hasPivot() ? "Pivot" : "", + a.data().hasCondition() ? a.data().condition.ptr() : 0, + k.name.c_str()); + ++count; + } + { + Alignments::Alignment a = c.get("Alignment",p); + const Alignments::Delta& D = a.data().delta; + printout(INFO,"Alignment","++ [%08X] (%11s-%8s-%5s) Cond:%p 'Alignment'", k.hash, + D.hasTranslation() ? "Translation" : "", + D.hasRotation() ? "Rotation" : "", + D.hasPivot() ? "Pivot" : "", + a.data().hasCondition() ? a.data().condition.ptr() : 0); + ++count; + } + } } - DD4hep::InstanceCount::dump(); + printout(INFO,m_name,"++ Accessed %d conditions from the DetElement objects.",count); } - return 1; + return ret; } }; - - /// Plugin function - long dddb_derived_alignments(LCDD& lcdd, int argc, char** argv) { - long int long init_time = DDDB::DDDBReader::makeTime(2016,4,1,12); + //======================================================================== + long make_time(int argc, char** argv) { + long int time = DDDB::DDDBReader::makeTime(2016,4,1,12); if ( argc>0 ) { struct tm tm; char* c = ::strptime(argv[0],"%d-%m-%Y %H:%M:%S",&tm); @@ -186,23 +180,55 @@ namespace { except("DerivedAlignmentsTest","Invalid time format given for update:%s " " should be: %d-%m-%Y %H:%M:%S", argv[0]); } + time = ::mktime(&tm); } - AlignmentSelector selector(lcdd, init_time); - AlignmentsManager alig_manager("Test"); - ConditionsManager cond_manager(ConditionsManager::from(lcdd)); - int ret = 0; - try { - ret = selector.collect(cond_manager,alig_manager); - if ( ret == 1 ) { - ret = selector.computeDependencies(cond_manager,alig_manager); + return time; + } +} + +//========================================================================== +namespace { + /// Plugin function + /// Load dependent alignment conditions according to time stamps. + long dddb_derived_alignments(LCDD& lcdd, int argc, char** argv) { + long time = make_time(argc, argv); + AlignmentsManager align("Test"); + AlignmentSelector selector(lcdd); + ConditionsManager conds(ConditionsManager::from(lcdd)); + int ret = selector.collect(conds,align,time); + if ( ret == 1 ) { + for(int i=0; i<10; ++i) { { + long ti = time + i*3600; + dd4hep_ptr<UserPool> pool; + ret = selector.computeDependencies(pool,conds,align,ti); + pool->clear(); + } + DD4hep::InstanceCount::dump(); } } - catch(...) { - } - alig_manager.destroy(); + align.destroy(); return ret; } } /* End anonymous namespace */ DECLARE_APPLY(DDDB_DerivedAlignmentsTest,dddb_derived_alignments) //========================================================================== + +namespace { + /// Plugin function + /// Access dependent alignment conditions from DetElement object using global and local keys + long dddb_access_alignments(LCDD& lcdd, int argc, char** argv) { + long time = make_time(argc, argv); + AlignmentsManager align("Test"); + AlignmentSelector selector(lcdd); + ConditionsManager conds(ConditionsManager::from(lcdd)); + int ret = selector.collect(conds,align,time); + if ( ret == 1 ) { + ret = selector.access(conds,align,time); + } + align.destroy(); + return ret; + } +} /* End anonymous namespace */ + +DECLARE_APPLY(DDDB_AlignmentsAccessTest,dddb_access_alignments) diff --git a/DDDB/src/DDDBAlignmentUpdateCall.cpp b/DDDB/src/DDDBAlignmentUpdateCall.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6cb42f909dce1c07e6c3166fe97dcae873fa01bd --- /dev/null +++ b/DDDB/src/DDDBAlignmentUpdateCall.cpp @@ -0,0 +1,73 @@ +// $Id$ +//========================================================================== +// AIDA Detector description implementation for LCD +//-------------------------------------------------------------------------- +// Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN) +// All rights reserved. +// +// For the licensing terms see $DD4hepINSTALL/LICENSE. +// For the list of contributors see $DD4hepINSTALL/doc/CREDITS. +// +// Author : M.Frank +// +//========================================================================== +// +// DDDB is a detector description convention developed by the LHCb experiment. +// For further information concerning the DTD, please see: +// http://lhcb-comp.web.cern.ch/lhcb-comp/Frameworks/DetDesc/Documents/lhcbDtd.pdf +// +//========================================================================== + +// Framework includes +#include "DDDB/DDDBAlignmentUpdateCall.h" +#include "DDDB/DDDBConditionPrinter.h" +#include "DDAlign/AlignmentsManager.h" +#include "DD4hep/ConditionsData.h" +#include "DD4hep/Alignments.h" +#include "DD4hep/Printout.h" + +using namespace DD4hep; +using namespace DD4hep::Conditions; + +/// Default constructor +DDDB::DDDBAlignmentUpdateCall::DDDBAlignmentUpdateCall() + : Conditions::ConditionUpdateCall() +{ +} + +/// Default destructor +DDDB::DDDBAlignmentUpdateCall::~DDDBAlignmentUpdateCall() { +} + +/// Interface to client Callback in order to update the condition +DDDB::DDDBAlignmentUpdateCall::Condition +DDDB::DDDBAlignmentUpdateCall::operator()(const ConditionKey& key, const UpdateContext& context) +{ + typedef OpaqueDataBlock Param; + typedef Alignments::AlignmentData Data; + Alignments::AlignmentCondition target(key.name); + Data& data = target.data(); + Condition cond = context.condition(0); + AbstractMap& src = cond.get<AbstractMap>(); + const Param& par = src.firstParam().second; + DetElement det = context.dependency.detector; + printout(DEBUG,"AlignmentUpdate","++ Building dependent condition: %s Detector [%d]: %s ", + key.name.c_str(), det.level(), det.path().c_str()); + if ( par.typeInfo() == typeid(Data::Delta) ) { + const Data::Delta& delta = src.first<Data::Delta>(); + data.delta = delta; + data.flag = Data::HAVE_NONE; + } + else { + printout(INFO,"AlignmentUpdate","++ Failed to access alignment-Delta from %s", + cond->value.c_str()); + ConditionPrinter()(cond); + } + data.detector = det; + Alignments::AlignmentsManager::newEntry(context, det, &context.dependency, target); + // A callback returning no condition is illegal! + // Need to crosscheck though if the alignment IOV interval of parents may be + // smaller then the daughter IOV interval. + // I though expect, that this is a purely academic case. + return target; +} diff --git a/examples/DDDB/CMakeLists.txt b/examples/DDDB/CMakeLists.txt index a986586bd3ba7a429a49014a2207d9695215cd06..c4c5e0079b71760c930be692237ed6d44516981e 100644 --- a/examples/DDDB/CMakeLists.txt +++ b/examples/DDDB/CMakeLists.txt @@ -130,6 +130,15 @@ if (DD4HEP_USE_XERCESC) -exec DDDB_DerivedAlignmentsTest REGEX_PASS "| 24950| 24950| 0|DD4hep::Alignments::Interna::AlignmentConditionObject" ) + # + #---Testing: Load the geometry + conditions + access derived alignments from DetElement structures + dd4hep_add_test_reg( test_DDDB_alignment_access + COMMAND "${CMAKE_INSTALL_PREFIX}/bin/run_test_DDDB.sh" + EXEC_ARGS ${CMAKE_INSTALL_PREFIX}/bin/run_dddb.sh + -config DD4hep_ConditionsManagerInstaller + -exec DDDB_AlignmentsAccessTest + REGEX_PASS "Accessed 4990 conditions from the DetElement objects" ) + # #---Testing: Extract DDDB data from zip archive ------------------------------- dd4hep_add_test_reg( test_DDDB_clean