diff --git a/DDAlign/include/DDAlign/AlignmentsForward.h b/DDAlign/include/DDAlign/AlignmentsForward.h index fdee57db0225db8481bc66869018ccb3fce8a3a4..34e2c7350a0b12afd71622e3ba3ff8eb942942fd 100644 --- a/DDAlign/include/DDAlign/AlignmentsForward.h +++ b/DDAlign/include/DDAlign/AlignmentsForward.h @@ -28,11 +28,14 @@ namespace DD4hep { // Forward declarations class AlignmentUpdateCall; - /// Create lignment dependencies from conditions + /// Create alignment dependencies for child elements if a parent has re-alignments /** - * Conditions analyser to select alignments.and create the + * Conditions analyser to select alignments and create the * corresponding alignment condition dependencies. * + * This class has the same interface like AlignmentsRegister. + * Please see AlignmentsRegister.h for further information. + * * \author M.Frank * \version 1.0 * \date 31/03/2016 @@ -40,9 +43,18 @@ namespace DD4hep { */ class AlignmentsForward : public DetElement::Processor { public: + /// Reference to the alignment manager object AlignmentsManager alignmentMgr; + /// The callback to be registered for the update mechanism AlignmentUpdateCall* updateCall; + /// Conditions pool used to access the basic conditions object Conditions::UserPool* user_pool; + /// Extension property to construct the name of the alignment condition + std::string extension; + /// Name of the alignment alias for the detector elements alignment object + std::string alias; + /// Flag if an alias to the real alignment object should be registered + bool haveAlias; /// Initializing constructor AlignmentsForward(AlignmentsManager m, AlignmentUpdateCall* c, UserPool* p); @@ -50,6 +62,15 @@ namespace DD4hep { virtual ~AlignmentsForward(); /// Callback to output conditions information virtual int processElement(DetElement de); + /// Overloadable: call to construct the alignment conditions name. + /** + * Specialize for user defined implementation. + * + * Default implementation returns "de.path()+extension" + * Please note, that the corrsponding implementation of + * 'AlignmentsRegister::construct_name' must match + */ + virtual std::string construct_name(DetElement de) const; }; } /* End namespace Alignments */ } /* End namespace DD4hep */ diff --git a/DDAlign/include/DDAlign/AlignmentsManager.h b/DDAlign/include/DDAlign/AlignmentsManager.h index feb74bcc4b5d33505b60992e24ca47d0107d70b0..4d9a1df8553ea1d1eef63ea166f2d2dba9a8de4f 100644 --- a/DDAlign/include/DDAlign/AlignmentsManager.h +++ b/DDAlign/include/DDAlign/AlignmentsManager.h @@ -14,7 +14,6 @@ #define DD4HEP_DDALIGN_ALIGNMENTMANAGER_H // Framework include files -#include "DD4hep/Memory.h" #include "DD4hep/Alignments.h" #include "DD4hep/ConditionDerived.h" @@ -24,6 +23,7 @@ namespace DD4hep { /// Namespace for the conditions part of the AIDA detector description toolkit namespace Conditions { class UserPool; + class ConditionsSlice; class ConditionDependency; class ConditionUpdateContext; class ConditionsDependencyCollection; @@ -47,6 +47,10 @@ namespace DD4hep { public: /// Standard object type typedef AlignmentsManagerObject Object; + /// Conditions user pool definition + typedef Conditions::UserPool Pool; + /// Conditions slice definitions + typedef Conditions::ConditionsSlice Slice; /// Conditions derivation context typedef Conditions::ConditionUpdateContext Context; /// Alignments re-use conditions dependency definition from the conditions manager @@ -87,9 +91,13 @@ namespace DD4hep { /// Access all known dependencies const Dependencies& knownDependencies() const; /// Compute all alignment conditions of the internal dependency list - void compute(dd4hep_ptr<UserPool>& user_pool) const; + void compute(Slice& slice) const; /// Compute all alignment conditions of the specified dependency list - void compute(dd4hep_ptr<UserPool>& user_pool, const Dependencies& deps) const; + void compute(Slice& slice, const Dependencies& deps) const; + /// Compute all alignment conditions of the internal dependency list + void compute(Pool& pool) const; + /// Compute all alignment conditions of the specified dependency list + void compute(Pool& pool, const Dependencies& deps) const; /// Register new updated derived alignment during the computation step static void newEntry(const Context& parameter, DetElement& det, @@ -108,6 +116,7 @@ namespace DD4hep { */ class AlignmentsManagerObject : public NamedObject { public: + typedef AlignmentsManager::Pool Pool; typedef AlignmentsManager::Dependencies Dependencies; /// Full list of alignment dependencies @@ -117,9 +126,9 @@ namespace DD4hep { protected: /// Compute the transformation from the closest detector element of the alignment to the world system - void to_world(AlignContext& new_alignments, UserPool& pool, DetElement det, TGeoHMatrix& mat) const; + void to_world(AlignContext& new_alignments, Pool& pool, DetElement det, TGeoHMatrix& mat) const; /// Compute all alignment conditions of the lower levels - void compute(AlignContext& new_alignments, UserPool& pool, DetElement child) const; + void compute(AlignContext& new_alignments, Pool& pool, DetElement child) const; public: /// Initializing constructor @@ -127,9 +136,9 @@ namespace DD4hep { /// Default destructor virtual ~AlignmentsManagerObject(); /// Compute all alignment conditions of the internal dependency list - void compute(UserPool& user_pool) const; + void compute(Pool& pool) const; /// Compute all alignment conditions of the specified dependency list - void compute(UserPool& user_pool, const Dependencies& deps) const; + void compute(Pool& pool, const Dependencies& deps) const; }; } /* End namespace Geometry */ diff --git a/DDAlign/include/DDAlign/AlignmentsRegister.h b/DDAlign/include/DDAlign/AlignmentsRegister.h index 82bd54d55ddc64d76374f0b410ff82b0cd2b96cd..c2f06e0f31ea4895529f0b0688a1287ee2c02b1a 100644 --- a/DDAlign/include/DDAlign/AlignmentsRegister.h +++ b/DDAlign/include/DDAlign/AlignmentsRegister.h @@ -30,9 +30,25 @@ namespace DD4hep { /// Create lignment dependencies from conditions /** - * Conditions analyser to select alignments.and create the + * Conditions analyser to select alignments and create the * corresponding alignment condition dependencies. * + * This algorithm only serves as an example showing how + * to program the alignments container of each detector + * element. + * + * The procedure implemented here is as follows: + * For each registered and existing condition with a datatype + * Alignments::Delta and a flag Condition::ALIGNMENT, + * an entry is constructed to the alignments container. + * The entry is identified by a name returned by a call to + * construct_name(...). The optional alias is registered if the + * flag 'haveAlias' is set and the property 'alais' is not empty. + * + * This does NOT mean, that every experiment must do it this way. + * The way to register the alignments with the detector element + * strongly depend on the surrounding experiment framework. + * * \author M.Frank * \version 1.0 * \date 31/03/2016 @@ -40,16 +56,34 @@ namespace DD4hep { */ class AlignmentsRegister : public DetElement::Processor { public: + /// Reference to the alignment manager object AlignmentsManager alignmentMgr; + /// The callback to be registered for the update mechanism AlignmentUpdateCall* updateCall; + /// Conditions pool used to access the basic conditions object Conditions::UserPool* user_pool; - + /// Extension property to construct the name of the alignment condition + std::string extension; + /// Name of the alignment alias for the detector elements alignment object + std::string alias; + /// Flag if an alias to the real alignment object should be registered + bool haveAlias; + /// Initializing constructor AlignmentsRegister(AlignmentsManager m, AlignmentUpdateCall* c, UserPool* p); /// Default destructor virtual ~AlignmentsRegister(); /// Callback to output conditions information virtual int processElement(DetElement de); + /// Overloadable: call to construct the alignment conditions name. + /** + * Specialize for user defined implementation. + * + * Default implementation returns "cond.name()+extension". + * Please note, that the corrsponding implementation of + * 'AlignmentsForward::construct_name' must match + */ + virtual std::string construct_name(DetElement de, Conditions::Condition cond) const; }; } /* End namespace Alignments */ } /* End namespace DD4hep */ diff --git a/DDAlign/src/AlignmentsForward.cpp b/DDAlign/src/AlignmentsForward.cpp index 9f6fb7c51491cc08e67760a9b1371e9ff87b4fa6..0aad284e33b474716c80cf3f057c11cab91f5bee 100644 --- a/DDAlign/src/AlignmentsForward.cpp +++ b/DDAlign/src/AlignmentsForward.cpp @@ -15,7 +15,6 @@ #include "DD4hep/Printout.h" #include "DD4hep/DetAlign.h" #include "DD4hep/DetConditions.h" -#include "DD4hep/objects/AlignmentsInterna.h" #include "DDAlign/AlignmentsForward.h" #include "DDAlign/AlignmentUpdateCall.h" @@ -25,7 +24,7 @@ using namespace DD4hep::Alignments; /// Initializing constructor AlignmentsForward::AlignmentsForward(AlignmentsManager m, AlignmentUpdateCall* c, UserPool* p) - : alignmentMgr(m), updateCall(c), user_pool(p) + : alignmentMgr(m), updateCall(c), user_pool(p), extension("#alignment/Tranformations"), alias("Alignment"), haveAlias(true) { } @@ -34,33 +33,43 @@ AlignmentsForward::~AlignmentsForward() { releasePtr(updateCall); } +/// Overloadable: call to construct the alignment conditions name. Specialize for change +std::string AlignmentsForward::construct_name(DetElement de) const { + return de.path()+extension; +} + /// Callback to output conditions information int AlignmentsForward::processElement(DetElement de) { if ( de.isValid() ) { DetElement parent = de.parent(); if ( parent.isValid() && parent.hasAlignments() && !de.hasAlignments() ) { - DetAlign align(de); - Conditions::ConditionKey k(de.path()+"#alignment/Tranformations"); - // - // The alignment access through the DetElement object is optional! - // It is slow and deprecated. The access using the UserPool directly - // is highly favored. - // - align.alignments()->addKey(k.name); - align.alignments()->addKey("Alignment",k.name); - // - // Now add the dependency to the alignmant manager - Conditions::DependencyBuilder b(k, updateCall->addRef(), de); - bool result = alignmentMgr.adoptDependency(b.release()); - if ( result ) { - printout(INFO,"AlignForward", - "++ Added Alignment child dependency Cond:%s Key:%08X", + std::string alignment_name = construct_name(de); + if ( !alignment_name.empty() ) { + DetAlign align(de); + Conditions::ConditionKey k(alignment_name); + // + // The alignment access through the DetElement object is optional! + // It is slow and deprecated. The access using the UserPool directly + // is highly favored. + // + align.alignments().addKey(k.name); + if ( haveAlias && !alias.empty() ) { + align.alignments().addKey("Alignment",k.name); + } + // + // Now add the dependency to the alignmant manager + Conditions::DependencyBuilder b(k, updateCall->addRef(), de); + bool result = alignmentMgr.adoptDependency(b.release()); + if ( result ) { + printout(INFO,"AlignForward", + "++ Added Alignment child dependency Cond:%s Key:%08X", + k.name.c_str(), k.hash); + return 1; + } + printout(ERROR,"AlignForward", + "++ FAILED to add Alignment dependency Cond:%s Key:%08X", k.name.c_str(), k.hash); - return 1; } - printout(ERROR,"AlignForward", - "++ FAILED to add Alignment dependency Cond:%s Key:%08X", - k.name.c_str(), k.hash); } } return 1; diff --git a/DDAlign/src/AlignmentsManager.cpp b/DDAlign/src/AlignmentsManager.cpp index 672ffb8167ac7ae72293f727aa8622a7a8ac06a4..91596ea9d62734462ee13ee36d97717635922e8c 100644 --- a/DDAlign/src/AlignmentsManager.cpp +++ b/DDAlign/src/AlignmentsManager.cpp @@ -19,6 +19,7 @@ #include "DD4hep/MatrixHelpers.h" #include "DD4hep/ConditionDerived.h" #include "DDCond/ConditionsPool.h" +#include "DDCond/ConditionsSlice.h" #include "DDCond/ConditionsDependencyCollection.h" #include "DDAlign/AlignmentsManager.h" @@ -173,19 +174,17 @@ void AlignmentsManagerObject::to_world(AlignContext& new_alignments, } /// Compute all alignment conditions of the internal dependency list -void AlignmentsManagerObject::compute(UserPool& user_pool) const { - compute(user_pool, *dependencies); +void AlignmentsManagerObject::compute(Pool& pool) const { + compute(pool, *dependencies); } /// Compute all alignment conditions of the specified dependency list -void AlignmentsManagerObject::compute(UserPool& pool, const Dependencies& deps) const { +void AlignmentsManagerObject::compute(Pool& pool, const Dependencies& deps) const { AlignContext new_alignments; new_alignments.entries.reserve(deps.size()); pool.compute(deps, &new_alignments); for(auto i=new_alignments.entries.begin(); i != new_alignments.entries.end(); ++i) compute(new_alignments, pool, (*i).det); - for(auto i=new_alignments.entries.begin(); i != new_alignments.entries.end(); ++i) - compute(new_alignments, pool, (*i).det); #if 0 std::string prev = "-----"; for(auto i=new_alignments.detectors.begin(); i!=new_alignments.detectors.end(); ++i) { @@ -341,14 +340,25 @@ const AlignmentsManager::Dependencies& AlignmentsManager::knownDependencies() c } /// Compute all alignment conditions of the internal dependency list -void AlignmentsManager::compute(dd4hep_ptr<UserPool>& user_pool) const { +void AlignmentsManager::compute(Slice& slice) const { + Object* o = access(); + o->compute(*slice.pool(), *(o->dependencies)); +} + +/// Compute all alignment conditions of the specified dependency list +void AlignmentsManager::compute(Slice& slice, const Dependencies& deps) const { + access()->compute(*slice.pool(), deps); +} + +/// Compute all alignment conditions of the internal dependency list +void AlignmentsManager::compute(Pool& pool) const { Object* o = access(); - o->compute(*user_pool, *(o->dependencies)); + o->compute(pool, *(o->dependencies)); } /// Compute all alignment conditions of the specified dependency list -void AlignmentsManager::compute(dd4hep_ptr<UserPool>& user_pool, const Dependencies& deps) const { - access()->compute(*user_pool, deps); +void AlignmentsManager::compute(Pool& pool, const Dependencies& deps) const { + access()->compute(pool, deps); } /// Register new updated derived alignment during the computation step diff --git a/DDAlign/src/AlignmentsRegister.cpp b/DDAlign/src/AlignmentsRegister.cpp index b1a892e228d8a3b704e786e1ffbef5631d352180..134bed08e6d4990a787e00d9148c019238070a46 100644 --- a/DDAlign/src/AlignmentsRegister.cpp +++ b/DDAlign/src/AlignmentsRegister.cpp @@ -15,19 +15,19 @@ #include "DD4hep/Printout.h" #include "DD4hep/DetAlign.h" #include "DD4hep/DetConditions.h" -#include "DD4hep/objects/AlignmentsInterna.h" #include "DDAlign/AlignmentsRegister.h" #include "DDAlign/AlignmentUpdateCall.h" using namespace DD4hep; using namespace DD4hep::Alignments; +using Conditions::Condition; // ====================================================================================== /// Initializing constructor AlignmentsRegister::AlignmentsRegister(AlignmentsManager m, AlignmentUpdateCall* c, UserPool* p) - : alignmentMgr(m), updateCall(c), user_pool(p) + : alignmentMgr(m), updateCall(c), user_pool(p), extension("/Tranformations"), alias("Alignment"), haveAlias(true) { } @@ -36,9 +36,15 @@ AlignmentsRegister::~AlignmentsRegister() { releasePtr(updateCall); } +/// Overloadable: call to construct the alignment conditions name. Specialize for change +std::string +AlignmentsRegister::construct_name(DetElement /* de */, Condition cond) const +{ + return cond.name()+extension; +} + /// Callback to output conditions information int AlignmentsRegister::processElement(DetElement de) { - using Conditions::Condition; if ( de.isValid() ) { if ( de.hasConditions() ) { DetAlign align(de); @@ -53,28 +59,33 @@ int AlignmentsRegister::processElement(DetElement de) { "++ Processing DE %s Cond:%s Key:%08X flags:%d", de.path().c_str(), cond.name(), cond.key(), cond->flags); if ( (cond->flags&Condition::ALIGNMENT) ) { - Conditions::ConditionKey k(cond->name+"/Tranformations"); - // - // The alignment access through the DetElement object is optional! - // It is slow and deprecated. The access using the UserPool directly - // is highly favored. - // - align.alignments()->addKey(k.name); - align.alignments()->addKey("Alignment",k.name); - // - // Now add the dependency to the alignmant manager - Conditions::DependencyBuilder b(k, updateCall->addRef(), de); - b.add(Conditions::ConditionKey(cond->name)); - bool result = alignmentMgr.adoptDependency(b.release()); - if ( result ) { - printout(INFO,"AlignRegister", - "++ Added Alignment dependency Cond:%s Key:%08X flags:%d", + std::string alignment_name = construct_name(de, cond); + if ( !alignment_name.empty() ) { + Conditions::ConditionKey k(alignment_name); + // + // The alignment access through the DetElement object is optional! + // It is slow and deprecated. The access using the UserPool directly + // is highly favored. + // + align.alignments().addKey(k.name); + if ( haveAlias && !alias.empty() ) { + align.alignments().addKey(alias,k.name); + } + // + // Now add the dependency to the alignmant manager + Conditions::DependencyBuilder b(k, updateCall->addRef(), de); + b.add(Conditions::ConditionKey(cond->name)); + bool result = alignmentMgr.adoptDependency(b.release()); + if ( result ) { + printout(INFO,"AlignRegister", + "++ Added Alignment dependency Cond:%s Key:%08X flags:%d", + k.name.c_str(), k.hash, cond->flags); + continue; + } + printout(ERROR,"AlignRegister", + "++ FAILED to add Alignment dependency Cond:%s Key:%08X flags:%d", k.name.c_str(), k.hash, cond->flags); - continue; } - printout(ERROR,"AlignRegister", - "++ FAILED to add Alignment dependency Cond:%s Key:%08X flags:%d", - k.name.c_str(), k.hash, cond->flags); } } return 1; diff --git a/DDAlign/src/plugins/AlignmentPlugins.cpp b/DDAlign/src/plugins/AlignmentPlugins.cpp index f2c18e3027ca1c6903ae6be6c595cf39f899a7cf..136876a1dbb8ab72f56d413d3cf2a12d39492368 100644 --- a/DDAlign/src/plugins/AlignmentPlugins.cpp +++ b/DDAlign/src/plugins/AlignmentPlugins.cpp @@ -48,51 +48,49 @@ DECLARE_APPLY(DD4hep_AlignmentsManagerInstaller,ddalign_install_align_mgr) // ====================================================================================== #include "DDAlign/GlobalAlignmentWriter.h" -namespace { +long create_global_alignment_file(Geometry::LCDD& lcdd, int argc, char** argv) { namespace DetectorTools = DD4hep::Geometry::DetectorTools; - long create_global_alignment_file(Geometry::LCDD& lcdd, int argc, char** argv) { - Geometry::DetElement top; - string output, path = "/world"; - bool enable_transactions = false, arg_error = false; - for(int i=1; i<argc;++i) { - if ( argv[i] && (argv[i][0]=='-' || argv[i][0]=='/') ) { - const char* p = ::strchr(argv[i],'='); - if ( p && strncmp(argv[i]+1,"-output",7)==0 ) - output = p+1; - else if ( p && strncmp(argv[i]+1,"-path",5)==0 ) - path = p+1; - else if ( strncmp(argv[i]+1,"-transactions",5)==0 ) - enable_transactions = true; - else - arg_error = true; - } + Geometry::DetElement top; + string output, path = "/world"; + bool enable_transactions = false, arg_error = false; + for(int i=1; i<argc;++i) { + if ( argv[i] && (argv[i][0]=='-' || argv[i][0]=='/') ) { + const char* p = ::strchr(argv[i],'='); + if ( p && strncmp(argv[i]+1,"-output",7)==0 ) + output = p+1; + else if ( p && strncmp(argv[i]+1,"-path",5)==0 ) + path = p+1; + else if ( strncmp(argv[i]+1,"-transactions",5)==0 ) + enable_transactions = true; + else + arg_error = true; } + } - if ( arg_error || output.empty() || path.empty() ) { - /// Help printout describing the basic command line interface - cout << - "Usage: -plugin <name> -arg [-arg] \n" - " name: factory nameDD4hep_GlobalAlignmentWriter \n\n" - " -output <string> Path to the output file generated. \n" - " -path <string> Path to the detector element for which \n" - " the alignment file should be written. \n" - " -transactions Enable output transactions. \n" - "\tArguments given: " << arguments(argc,argv) << endl << flush; - ::exit(EINVAL); - } + if ( arg_error || output.empty() || path.empty() ) { + /// Help printout describing the basic command line interface + cout << + "Usage: -plugin <name> -arg [-arg] \n" + " name: factory nameDD4hep_GlobalAlignmentWriter \n\n" + " -output <string> Path to the output file generated. \n" + " -path <string> Path to the detector element for which \n" + " the alignment file should be written. \n" + " -transactions Enable output transactions. \n" + "\tArguments given: " << arguments(argc,argv) << endl << flush; + ::exit(EINVAL); + } - printout(ALWAYS,"AlignmentWriter", - "++ Writing DD4hep alignment constants of the \"%s\" DetElement tree to file \"%s\"", - path.c_str(), output.c_str()); - top = DetectorTools::findDaughterElement(lcdd.world(),path); - if ( top.isValid() ) { - GlobalAlignmentWriter wr(lcdd); - return wr.write(wr.dump(top,enable_transactions), output); - } - except("AlignmentWriter","++ Invalid top level detector element name: %s",path.c_str()); - return 1; + printout(ALWAYS,"AlignmentWriter", + "++ Writing DD4hep alignment constants of the \"%s\" DetElement tree to file \"%s\"", + path.c_str(), output.c_str()); + top = DetectorTools::findDaughterElement(lcdd.world(),path); + if ( top.isValid() ) { + GlobalAlignmentWriter wr(lcdd); + return wr.write(wr.dump(top,enable_transactions), output); } -} /* End anonymous namespace */ + except("AlignmentWriter","++ Invalid top level detector element name: %s",path.c_str()); + return 1; +} DECLARE_APPLY(DD4hep_GlobalAlignmentWriter, create_global_alignment_file) // ====================================================================================== @@ -116,7 +114,7 @@ static long compute_alignments(Geometry::LCDD& lcdd, int /* argc */, char** /* a AlignmentsManager mgr = AlignmentsManager::from(lcdd); PluginTester* tst = lcdd.extension<PluginTester>(); dd4hep_ptr<UserPool> pool(tst->extension<UserPool>("ConditionsTestUserPool")); - mgr.compute(pool); + mgr.compute(*pool); pool.release(); return 1; } @@ -129,18 +127,37 @@ DECLARE_APPLY(DDAlign_ComputeAlignments, compute_alignments) /// Convert alignments conditions to alignment objects static void* ddalign_AlignmentsRegister(Geometry::LCDD& lcdd, int argc, char** argv) { std::vector<char*> args_prepare, args_call; - + bool arg_error = false; for(int i=0; i<argc && argv[i]; ++i) { if ( ::strcmp(argv[i],"-prepare") == 0 ) { while( (++i)<argc && argv[i] && 0 != ::strcmp(argv[i],"-prepare-end") ) args_prepare.push_back(argv[i]); } - if ( ::strcmp(argv[i],"-call") == 0 ) { + else if ( ::strcmp(argv[i],"-call") == 0 ) { while( (++i)<argc && argv[i] && 0 != ::strcmp(argv[i],"-call-end") ) args_call.push_back(argv[i]); } + else { + arg_error = true; + } } + if ( arg_error ) { + /// Help printout describing the basic command line interface + cout << + "Usage: -plugin <name> -arg [-arg] \n" + " name: factory DDAlign_AlignmentsRegister \n\n" + " Create and return the AlignmentsRegister object. \n" + " \n" + " -prepare ... args ... -prepare-end \n" + " Arguments to the 'prepare' plugin. \n" + " -call ... args ... -call-end \n" + " Arguments to the 'call' plugin, which \n" + " create the AlignmentUpdateCall callback. \n" + "\tArguments given: " << arguments(argc,argv) << endl << flush; + ::exit(EINVAL); + } + PluginTester* test = lcdd.extension<PluginTester>(); Conditions::UserPool* pool = (Conditions::UserPool*) PluginService::Create<void*>((const char*)args_prepare[0],&lcdd, @@ -157,7 +174,7 @@ static void* ddalign_AlignmentsRegister(Geometry::LCDD& lcdd, int argc, char** a if ( 0 == call ) { except("AlignRegister","++ Failed to create update call!"); } - AlignmentsManager mgr = AlignmentsManager::from(lcdd); + AlignmentsManager mgr = AlignmentsManager::from(lcdd); AlignmentsRegister* obj = new AlignmentsRegister(mgr, call, pool); return obj; } @@ -170,12 +187,29 @@ DECLARE_LCDD_CONSTRUCTOR(DDAlign_AlignmentsRegister,ddalign_AlignmentsRegister) /// Convert alignments conditions to alignment objects static void* ddalign_AlignmentsForward(Geometry::LCDD& lcdd, int argc, char** argv) { std::vector<char*> args_prepare, args_call; - + bool arg_error = false; for(int i=0; i<argc && argv[i]; ++i) { if ( ::strcmp(argv[i],"-call") == 0 ) { while( (++i)<argc && argv[i] && 0 != ::strcmp(argv[i],"-call-end") ) args_call.push_back(argv[i]); } + else { + arg_error = true; + } + } + + if ( arg_error ) { + /// Help printout describing the basic command line interface + cout << + "Usage: -plugin <name> -arg [-arg] \n" + " name: factory DDAlign_AlignmentsForward \n\n" + " Create and return the AlignmentsForward object. \n" + " \n" + " -call ... args ... -call-end \n" + " Arguments to the 'call' plugin, which \n" + " create the AlignmentUpdateCall callback. \n" + "\tArguments given: " << arguments(argc,argv) << endl << flush; + ::exit(EINVAL); } PluginTester* test = lcdd.extension<PluginTester>(); diff --git a/DDCond/include/DDCond/ConditionsDataLoader.h b/DDCond/include/DDCond/ConditionsDataLoader.h index fc1f29081c3e77182891130ff3b7777c08861a96..3a2dd8b2dee3b349f0ed5ec6d2329c279b8fa1b9 100644 --- a/DDCond/include/DDCond/ConditionsDataLoader.h +++ b/DDCond/include/DDCond/ConditionsDataLoader.h @@ -17,6 +17,7 @@ #include "DD4hep/Conditions.h" #include "DD4hep/NamedObject.h" #include "DD4hep/ComponentProperties.h" +#include "DDCond/ConditionsSlice.h" #include "DDCond/ConditionsManager.h" // C/C++ include files @@ -31,8 +32,7 @@ namespace DD4hep { // Forward declarations class Entry; - class ConditionsDataLoader; - class ConditionsManagerObject; + class ConditionsSlice; typedef std::list<Entry*> ConditionsStack; /// Interface for a generic conditions loader @@ -50,6 +50,8 @@ namespace DD4hep { typedef Condition::iov_type iov_type; typedef Condition::key_type key_type; + typedef std::vector<std::pair<key_type,ConditionsSlice::Entry*> > EntryVector; + protected: /// Reference to main detector description object LCDD& m_lcdd; @@ -71,20 +73,20 @@ namespace DD4hep { virtual ~ConditionsDataLoader(); /// Add data source definition to loader void addSource(const std::string& source, const iov_type& iov); + /// Load a condition set given the conditions key according to their validity + virtual size_t load_single(key_type key, + const iov_type& req_validity, + RangeConditions& conditions) = 0; /// Load a condition set given a Detector Element and the conditions name according to their validity - virtual size_t load(key_type key, - const iov_type& req_validity, - RangeConditions& conditions) = 0; - /// Load a condition set given a Detector Element and the conditions name according to their validity - virtual size_t load_range(key_type key, - const iov_type& req_validity, - RangeConditions& conditions) = 0; - virtual size_t update(const iov_type& req_validity, - RangeConditions& conditions, - iov_type& conditions_validity) = 0; + virtual size_t load_range( key_type key, + const iov_type& req_validity, + RangeConditions& conditions) = 0; + virtual size_t load_many( const iov_type& req_validity, + EntryVector& work, + EntryVector& loaded, + EntryVector& missing, + iov_type& combined_validity) = 0; }; - - } /* End namespace Conditions */ -} /* End namespace DD4hep */ - + } /* End namespace Conditions */ +} /* End namespace DD4hep */ #endif /* DDCOND_CONDITIONSDATALOADER_H */ diff --git a/DDCond/include/DDCond/ConditionsDependencyCollection.h b/DDCond/include/DDCond/ConditionsDependencyCollection.h index 79a678b27ecc43bdac2fe005ca79a90f0dc08f77..c886940168f33f83117c9cbea96adac84eb446a9 100644 --- a/DDCond/include/DDCond/ConditionsDependencyCollection.h +++ b/DDCond/include/DDCond/ConditionsDependencyCollection.h @@ -80,6 +80,13 @@ namespace DD4hep { public: /// Initializing constructor ConditionsDependencyCollection(); + /// Initializing constructor + template <typename I> ConditionsDependencyCollection(I first, I last) + { std::for_each(first, last, [this](typename I::reference& v) { this->insert(v); }); } + /// Initializing constructor + template <typename I, typename R> + ConditionsDependencyCollection(I first, I last, R (*func)(typename I::reference val)) + { std::for_each(first, last, [this,func](typename I::reference v) { this->insert(func(v)); }); } /// Copy constructor ConditionsDependencyCollection(const ConditionsDependencyCollection& copy); /// Default destructor @@ -108,6 +115,13 @@ namespace DD4hep { std::pair<iterator,bool> insert(const Dependencies::value_type& entry); /// Insert new element by key std::pair<iterator,bool> insert(Dependency* dep); + /// Insert a range of items with a item converting adjustment + template <typename I> void insert(I first, I last) + { std::for_each(first,last,[this](typename I::reference v) { this->insert(v); }); } + /// Insert a range of items with a item converting adjustment + template <typename I, typename R> + void insert(I first, I last, R (*func)(typename I::reference val)) + { std::for_each(first, last, [this,func](typename I::reference v) { this->insert(func(v)); }); } /// Create view by application of functor template <typename T> void for_each(const T& function) const { std::for_each(dependencies.begin(),dependencies.end(),function); } diff --git a/DDCond/include/DDCond/ConditionsDependencyHandler.h b/DDCond/include/DDCond/ConditionsDependencyHandler.h index 65e30e29b60ed72f20b9555386f3538a99716ac0..e59002db6209e06edab440eb91fc217d05d6ac9f 100644 --- a/DDCond/include/DDCond/ConditionsDependencyHandler.h +++ b/DDCond/include/DDCond/ConditionsDependencyHandler.h @@ -17,6 +17,7 @@ #include "DD4hep/Detector.h" #include "DD4hep/ConditionDerived.h" #include "DDCond/ConditionsPool.h" +#include "DDCond/ConditionsManager.h" #include "DDCond/ConditionsDependencyCollection.h" /// Namespace for the AIDA detector description toolkit @@ -27,6 +28,7 @@ namespace DD4hep { // Forward declarations class UserPool; + class ConditionsPool; class ConditionsManagerObject; class ConditionsDependencyCollection; @@ -42,20 +44,22 @@ namespace DD4hep { protected: /// Reference to conditions manager - ConditionsManagerObject* m_manager; + ConditionsManagerObject* m_manager; /// Reference to the user pool object - UserPool& m_pool; + UserPool& m_pool; /// Dependency container to be resolved. - const Dependencies& m_dependencies; + const Dependencies& m_dependencies; + /// IOV target pool for this handler + ConditionsPool* m_iovPool; /// User defined optional processing parameter - void* m_userParam; + void* m_userParam; /// Internal call to trigger update callback Condition::Object* do_callback(const ConditionDependency& dep) const; public: /// Initializing constructor - ConditionsDependencyHandler(ConditionsManagerObject* mgr, + ConditionsDependencyHandler(ConditionsManager mgr, UserPool& pool, const Dependencies& dependencies, void* user_param); diff --git a/DDCond/include/DDCond/ConditionsIOVPool.h b/DDCond/include/DDCond/ConditionsIOVPool.h index 7ea835735e6c433d5f3ac2d1931d73a9769ced42..b392375b081ea0804ed31e14f12c14308ea92623 100644 --- a/DDCond/include/DDCond/ConditionsIOVPool.h +++ b/DDCond/include/DDCond/ConditionsIOVPool.h @@ -27,7 +27,7 @@ namespace DD4hep { /// Forward declarations class ConditionsDataLoader; - + /// Pool of conditions satisfying one IOV type (epoch, run, fill, etc) /** * Purely internal class to the conditions manager implementation. @@ -44,21 +44,24 @@ namespace DD4hep { /// Container of IOV dependent conditions pools Elements elements; - + const IOVType* type; + public: /// Default constructor - ConditionsIOVPool(); + ConditionsIOVPool(const IOVType* type); /// Default destructor virtual ~ConditionsIOVPool(); /// Retrieve a condition set given the key according to their validity - void select(Condition::key_type key, const Condition::iov_type& req_validity, RangeConditions& result); + size_t select(Condition::key_type key, const Condition::iov_type& req_validity, RangeConditions& result); /// Retrieve a condition set given the key according to their validity - void selectRange(Condition::key_type key, const Condition::iov_type& req_validity, RangeConditions& result); - /// Select all ACTIVE conditions, which do no longer match the IOV requirement - void select(const Condition::iov_type& required_validity, - RangeConditions& valid, - RangeConditions& expired, - Condition::iov_type& conditions_validity); + size_t selectRange(Condition::key_type key, const Condition::iov_type& req_validity, RangeConditions& result); + /// Select all ACTIVE conditions, which do match the IOV requirement + size_t select(const IOV& req_validity, RangeConditions& valid, IOV& cond_validity); + /// Select all ACTIVE conditions, which do match the IOV requirement + size_t select(const IOV& req_validity, const ConditionsSelect& valid, IOV& cond_validity); + /// Select all ACTIVE conditions pools, which do match the IOV requirement + size_t select(const IOV& req_validity, Elements& valid, IOV& cond_validity); + /// Remove all key based pools with an age beyon the minimum age. /** @return Number of conditions cleaned up and removed. */ int clean(int max_age); diff --git a/DDCond/include/DDCond/ConditionsLoaderImp.h b/DDCond/include/DDCond/ConditionsLoaderImp.h index 624c23cf69bbcc4b77f8c3c9495302add8cf3669..f7da178a21a82fa6634ef9fdcdf39f59115dd410 100644 --- a/DDCond/include/DDCond/ConditionsLoaderImp.h +++ b/DDCond/include/DDCond/ConditionsLoaderImp.h @@ -15,6 +15,7 @@ // Framework include files #include "DDCond/ConditionsPool.h" +#include "DDCond/ConditionsDataLoader.h" /// Namespace for the AIDA detector description toolkit namespace DD4hep { diff --git a/DDCond/include/DDCond/ConditionsManager.h b/DDCond/include/DDCond/ConditionsManager.h index c1f6fe0de934763cf69e214cbf62324f63ad204f..baa7142cfbfb6d73523417ab046a46666f35b4d0 100644 --- a/DDCond/include/DDCond/ConditionsManager.h +++ b/DDCond/include/DDCond/ConditionsManager.h @@ -14,11 +14,11 @@ #define DDCOND_CONDITIONSMANAGER_H // Framework include files -#include "DD4hep/Memory.h" -#include "DD4hep/Detector.h" #include "DD4hep/Conditions.h" #include "DD4hep/ComponentProperties.h" -#include "DDCond/ConditionsDependencyCollection.h" + +// C/C++ include files +#include <set> /// Namespace for the AIDA detector description toolkit namespace DD4hep { @@ -27,13 +27,11 @@ namespace DD4hep { namespace Conditions { // Forward declarations - class Entry; class UserPool; class ConditionsPool; + class ConditionsSlice; class ConditionsIOVPool; - class ConditionDependency; class ConditionsDataLoader; - class ConditionUpdateContext; class ConditionsManagerObject; /// Manager class for condition handles @@ -46,14 +44,9 @@ namespace DD4hep { public: /// Standard object type - typedef ConditionsManagerObject Object; - typedef ConditionsDataLoader Loader; - typedef std::vector<IOVType> IOVTypes; - typedef std::map<IOVType*,Container> TypeConditions; - typedef std::map<DetElement,Container> DetectorConditions; - typedef std::set<ConditionKey> ConditionKeys; - typedef ConditionDependency Dependency; - typedef ConditionsDependencyCollection Dependencies; + typedef ConditionsManagerObject Object; + typedef ConditionsDataLoader Loader; + typedef std::vector<IOVType> IOVTypes; public: @@ -139,26 +132,9 @@ namespace DD4hep { /// Full cleanup of all managed conditions. void clear() const; - /// Prepare all updates for the given keys to the clients with the defined IOV - long prepare(const IOV& required_validity, - const ConditionKeys& keys, - dd4hep_ptr<UserPool>& user_pool); - - /// Prepare all updates for the given keys to the clients with the defined IOV - long prepare(const IOV& required_validity, - const ConditionKeys& keys, - dd4hep_ptr<UserPool>& user_pool, - const Dependencies& dependencies, - bool verify_dependencies=true); - - /// Prepare all updates to the clients with the defined IOV - long prepare(const IOV& required_validity, dd4hep_ptr<UserPool>& user_pool); - /// Prepare all updates to the clients with the defined IOV - long prepare(const IOV& required_validity, - dd4hep_ptr<UserPool>& user_pool, - const Dependencies& dependencies, - bool verify_dependencies=true); + long prepare(const IOV& required_validity, + ConditionsSlice& slice) const; }; } /* End namespace Conditions */ } /* End namespace DD4hep */ diff --git a/DDCond/include/DDCond/ConditionsManagerObject.h b/DDCond/include/DDCond/ConditionsManagerObject.h index 30a5ad86d88c63726004da97a6a347c888edc5ca..abc8f42d677fedfe767b5d74825970695c6979b6 100644 --- a/DDCond/include/DDCond/ConditionsManagerObject.h +++ b/DDCond/include/DDCond/ConditionsManagerObject.h @@ -17,8 +17,8 @@ #include "DD4hep/Memory.h" #include "DD4hep/Conditions.h" #include "DD4hep/NamedObject.h" +#include "DDCond/ConditionsSlice.h" #include "DD4hep/ComponentProperties.h" - #include "DDCond/ConditionsPool.h" // C/C++ include files @@ -37,10 +37,8 @@ namespace DD4hep { // Forward declarations class ConditionsPool; class ConditionsListener; - class ConditionDependency; class ConditionsDataLoader; class ConditionsIOVPool; - class ConditionsDependencyCollection; /// Basic conditions manager implementation /** @@ -62,9 +60,6 @@ namespace DD4hep { typedef Condition::iov_type iov_type; typedef std::pair<ConditionsListener*,void*> Listener; typedef std::set<Listener> Listeners; - typedef std::set<ConditionKey> ConditionKeys; - typedef ConditionDependency Dependency; - typedef ConditionsDependencyCollection Dependencies; typedef dd4hep_ptr<ConditionsDataLoader> Loader; protected: @@ -85,7 +80,7 @@ namespace DD4hep { /// Default destructor virtual ~ConditionsManagerObject(); /// Access to the detector description instance - LCDD& lcdd() const { return m_lcdd; } + LCDD& lcdd() const { return m_lcdd; } /// Access to the data loader ConditionsDataLoader* loader() const { return m_loader.get(); } /// Listener invocation when a condition is registered to the cache @@ -106,54 +101,47 @@ namespace DD4hep { /** Overloadable interface */ /// Initialize the object after having set the properties virtual void initialize() = 0; + /// Access IOV by its type virtual const IOVTypes& iovTypes () const = 0; + /// Access IOV by its type virtual const IOVType* iovType (size_t iov_type) const = 0; + /// Access IOV by its name virtual const IOVType* iovType (const std::string& iov_name) const = 0; + /// Register new IOV type if it does not (yet) exist. /** Returns (false,pointer) if IOV existed and * (true,pointer) if new IOV was registered to the manager. */ virtual std::pair<bool, const IOVType*> registerIOVType(size_t iov_type, const std::string& iov_name) = 0; + /// Register IOV with type and key (much more performant...) virtual ConditionsPool* registerIOV(const IOVType& typ, IOV::Key key) = 0; /// Access conditions multi IOV pool by iov type virtual ConditionsIOVPool* iovPool(const IOVType& type) const = 0; + /// Retrieve a condition set given a Detector Element and the conditions name according to their validity virtual Condition get(key_type key, const iov_type& req_validity) = 0; + /// Retrieve a condition given a Detector Element and the conditions name virtual RangeConditions getRange(key_type key, const iov_type& req_validity) = 0; + /// Push all pending updates to the conditions store. /** Note: * This does not yet make the new conditions availible to the clients */ virtual void pushUpdates() = 0; + /// Register new condition with the conditions store. Unlocked version, not multi-threaded virtual bool registerUnlocked(ConditionsPool* pool, Condition cond) = 0; - /// Prepare all updates for the given keys to the clients with the defined IOV - virtual long prepare(const IOV& required_validity, - const ConditionKeys& keys, - dd4hep_ptr<UserPool>& user_pool) = 0; - - /// Prepare all updates for the given keys to the clients with the defined IOV - virtual long prepare(const IOV& required_validity, - const ConditionKeys& keys, - dd4hep_ptr<UserPool>& user_pool, - const Dependencies& dependencies, - bool verify_dependencies=true) = 0; - /// Prepare all updates to the clients with the defined IOV - virtual long prepare(const IOV& required_validity, dd4hep_ptr<UserPool>& user_pool) = 0; + virtual UserPool::Result prepare(const IOV& req_iov, + ConditionsSlice& slice) = 0; - /// Prepare all updates to the clients with the defined IOV - virtual long prepare(const IOV& required_validity, - dd4hep_ptr<UserPool>& user_pool, - const Dependencies& dependencies, - bool verify_dependencies=true) = 0; /// Clean conditions, which are above the age limit. /** @return Number of conditions cleaned/removed from the IOV pool of the given type */ virtual int clean(const IOVType* typ, int max_age) = 0; diff --git a/DDCond/include/DDCond/ConditionsPool.h b/DDCond/include/DDCond/ConditionsPool.h index 90f6537daaab0596f788dcf4dc7fa6a708b412b7..3e2184d6667f97646a91828695bdb99c09964c9f 100644 --- a/DDCond/include/DDCond/ConditionsPool.h +++ b/DDCond/include/DDCond/ConditionsPool.h @@ -14,7 +14,7 @@ #define DDCOND_CONDITIONSPOOL_H // Framework include files -#include "DD4hep/Detector.h" +#include "DD4hep/NamedObject.h" #include "DDCond/ConditionsManager.h" // C/C++ include files @@ -27,11 +27,11 @@ namespace DD4hep { namespace Conditions { // Forward declarations + class ConditionsSlice; class ConditionsIOVPool; - class ConditionsPoolInsert; class ConditionDependency; class ConditionsDependencyCollection; - + /// Class implementing the conditions collection for a given IOV type /** * Implementation is mostly virtual, to allow to switch between @@ -72,10 +72,7 @@ namespace DD4hep { /// Aging value int age_value; - protected: - friend class ConditionsPoolInsert; - friend class ConditionsPoolRemove; - + public: /// Listener invocation when a condition is registered to the cache void onRegister(Condition condition); /// Listener invocation when a condition is deregistered from the cache @@ -88,24 +85,24 @@ namespace DD4hep { virtual ~ConditionsPool(); /// Print pool basics void print(const std::string& opt) const; + /// Total entry count + virtual size_t size() const = 0; /// Full cleanup of all managed conditions. virtual void clear() = 0; /// Register a new condition to this pool - virtual void insert(Condition cond) = 0; + virtual bool insert(Condition cond) = 0; /// Register a new condition to this pool. May overload for performance reasons. virtual void insert(RangeConditions& cond) = 0; /// Check if a condition exists in the pool virtual Condition exists(Condition::key_type key) const = 0; /// Select the conditions matching the DetElement and the conditions name - virtual void select(Condition::key_type key, RangeConditions& result) = 0; + virtual size_t select(Condition::key_type key, RangeConditions& result) = 0; /// Select all conditions contained - virtual void select_all(RangeConditions& result) = 0; + virtual size_t select_all(RangeConditions& result) = 0; + /// Select the conditons, passing a predicate + virtual size_t select_all(const ConditionsSelect& predicate) = 0; /// Select all conditions contained - virtual void select_all(ConditionsPool& selection_pool) = 0; - /// Select the conditons, used also by the DetElement of the condition - virtual void select_used(RangeConditions& result) = 0; - /// Total entry count - virtual size_t count() const = 0; + virtual size_t select_all(ConditionsPool& selection_pool) = 0; }; /// Interface for conditions pool optimized to host conditions updates. @@ -126,7 +123,7 @@ namespace DD4hep { /// Default destructor. virtual ~UpdatePool(); /// Adopt all entries sorted by IOV. Entries will be removed from the pool - virtual void popEntries(UpdateEntries& entries) = 0; + virtual size_t popEntries(UpdateEntries& entries) = 0; /// Select the conditions matching the key virtual void select_range(Condition::key_type key, const Condition::iov_type& req_validity, @@ -145,18 +142,23 @@ namespace DD4hep { typedef std::set<ConditionKey> ConditionKeys; typedef ConditionDependency Dependency; typedef ConditionsDependencyCollection Dependencies; - + class Result { + public: + size_t selected = 0; + size_t missing = 0; + Result() = default; + Result(const Result& result) = default; + Result& operator=(const Result& result) = default; + }; protected: /// The pool's interval of validity IOV m_iov; /// Handle to conditions manager object ConditionsManager m_manager; - /// IOV Pool as data source - ConditionsIOVPool* m_iovPool; public: /// Default constructor - UserPool(ConditionsManager mgr, ConditionsIOVPool* pool); + UserPool(ConditionsManager mgr); /// Default destructor. virtual ~UserPool(); /// Access the interval of validity for this user pool @@ -166,7 +168,7 @@ namespace DD4hep { /// Print pool content virtual void print(const std::string& opt) const = 0; /// Total entry count - virtual size_t count() const = 0; + virtual size_t size() const = 0; /// Full cleanup of all managed conditions. virtual void clear() = 0; /// Check a condition for existence @@ -184,14 +186,13 @@ namespace DD4hep { /// Register a new condition to this pool virtual bool insert(Condition cond) = 0; /// Prepare user pool for usage (load, fill etc.) according to required IOV - virtual long prepare(const IOV& required) = 0; - /// Prepare user pool for usage (load, fill etc.) according to required IOV - virtual long prepare(const IOV& required, const ConditionKeys& keys) = 0; + virtual Result prepare(const IOV& required, + ConditionsSlice& slice, + void* user_param = 0) = 0; + /// Evaluate and register all derived conditions from the dependency list - virtual long compute(const Dependencies& dependencies, void* user_param=0) = 0; + virtual size_t compute(const Dependencies& dependencies, void* user_param = 0) = 0; }; - - } /* End namespace Conditions */ -} /* End namespace DD4hep */ - -#endif /* DDCOND_CONDITIONSPOOL_H */ + } /* End namespace Conditions */ +} /* End namespace DD4hep */ +#endif /* DDCOND_CONDITIONSPOOL_H */ diff --git a/DDCond/include/DDCond/ConditionsSelectors.h b/DDCond/include/DDCond/ConditionsSelectors.h index 8eb9b861f6bdb05b2c7375da3651048ccfb069b9..61cb8b08fd32f518f32b85a10debac8aa95d9c6c 100644 --- a/DDCond/include/DDCond/ConditionsSelectors.h +++ b/DDCond/include/DDCond/ConditionsSelectors.h @@ -15,6 +15,7 @@ #define DDCOND_CONDITIONSSELECTORS_H // Framework include files +#include "DD4hep/Conditions.h" #include "DD4hep/objects/ConditionsInterna.h" /// Namespace for the AIDA detector description toolkit @@ -23,145 +24,223 @@ namespace DD4hep { /// Namespace for the geometry part of the AIDA detector description toolkit namespace Conditions { - class Cond__Oper { - public: - typedef Condition cond_t; - typedef Condition::Object object_t; - typedef std::pair<const Condition::key_type,Condition> mapentry_t; - typedef std::pair<const Condition::key_type,object_t*> ptr_mapentry_t; - }; - - /// Helper to insert objects into a conditions pool - /** - * \author M.Frank - * \version 1.0 - */ - class ConditionsPoolInsert : public Cond__Oper { - ConditionsPool& pool; - public: - ConditionsPoolInsert(ConditionsPool& p) : pool(p) { } - void operator()(object_t* o) const { pool.insert(o); } - void operator()(const cond_t& o) const { pool.insert(o.ptr()); } - void operator()(const mapentry_t& o) const { (*this)(o.second.ptr()); } - void operator()(const ptr_mapentry_t& o) const { (*this)(o.second); } - }; - - /// Helper to insert objects into a conditions pool - /** - * \author M.Frank - * \version 1.0 - */ - class ConditionsPoolRemove : public Cond__Oper { - ConditionsPool& pool; - public: - ConditionsPoolRemove(ConditionsPool& p) : pool(p) { } - void operator()(object_t* o) const { - pool.onRemove(o); - delete o; + /// Namespace for condition operators to avoid clashes + namespace Operators { + class Cond__Oper { + public: + typedef Condition cond_t; + typedef Condition::Object object_t; + typedef std::pair<const Condition::key_type,Condition> mapentry_t; + typedef std::pair<const Condition::key_type,object_t*> ptr_mapentry_t; + }; + + template <typename T> struct SequenceSelect : public Cond__Oper { + T& mapping; + SequenceSelect(T& o) : mapping(o) { } + bool operator()(Condition::Object* o) const + { mapping.insert(mapping.end(), o); return true; } + }; + + template <typename T> struct MapSelect : public Cond__Oper { + T& mapping; + MapSelect(T& o) : mapping(o) { } + bool operator()(Condition::Object* o) const + { return mapping.insert(std::make_pair(o->hash,o)).second; } + }; + + /// Helper to collect conditions using a ConditionsSelect base class + /** + * \author M.Frank + * \version 1.0 + */ + template <typename T> struct MapConditionsSelect : public ConditionsSelect { + T& mapping; + MapConditionsSelect(T& o) : mapping(o) { } + virtual bool operator()(Condition::Object* o) const + { return mapping.insert(std::make_pair(o->hash,o)).second; } + virtual size_t size() const { return mapping.size(); } + }; + + /// Helper to insert objects into a conditions pool + /** + * \author M.Frank + * \version 1.0 + */ + template <typename T> struct PoolSelect : public Cond__Oper { + T& pool; + PoolSelect(T& o) : pool(o) { } + bool operator()(Condition::Object* o) const { return pool.insert(o); } + }; + + /// Helper to remove objects from a conditions pool + /** + * \author M.Frank + * \version 1.0 + */ + template <typename T> struct PoolRemove : public Cond__Oper { + T& pool; + PoolRemove(T& o) : pool(o) { } + bool operator()(object_t* o) const { pool.onRemove(o); delete(o); return true; } + }; + + template <typename T> struct ActiveSelect : public Cond__Oper { + public: + T& collection; + ActiveSelect(T& p) : collection(p) {} + bool operator()(object_t* o) const { + if ( (o->flags & cond_t::ACTIVE) ) { + collection.insert(collection.end(),o); + return true; + } + return false; + } + }; + + /// Helper to select keyed objects from a conditions pool + /** + * \author M.Frank + * \version 1.0 + */ + template<typename collection_type> class KeyedSelect : public Cond__Oper { + cond_t::key_type key; + collection_type& collection; + public: + KeyedSelect(cond_t::key_type k, collection_type& p) : key(k), collection(p) { } + bool operator()(object_t* o) const { + if ( o->hash == key ) { + collection.insert(collection.end(),o); + return true; + } + return false; + } + }; + + /// Helper to select condition objects by hash key from a conditions pool + /** + * \author M.Frank + * \version 1.0 + */ + class KeyFind : public Cond__Oper { + cond_t::key_type hash; + public: + KeyFind(cond_t::key_type h) : hash(h) { } + bool operator()(const object_t* o) const { return o->hash == hash; } + }; + + /// Helper to wrap another object and make it copyable + /** + * \author M.Frank + * \version 1.0 + */ + template <typename OPER> class OperatorWrapper : public Cond__Oper { + public: + typedef OPER operator_t; + typedef OperatorWrapper<operator_t> wrapper_t; + operator_t& oper; + public: + OperatorWrapper(operator_t& o) : oper(o) { } + bool operator()(object_t* o) const { return oper(o); } + bool operator()(const cond_t& o) const { return oper(o.ptr()); } + bool operator()(const mapentry_t& o) const { return oper(o.second.ptr()); } + bool operator()(const ptr_mapentry_t& o) const { return oper(o.second); } + }; + template <typename oper_type> OperatorWrapper<oper_type> operatorWrapper(oper_type& oper) { + return OperatorWrapper<oper_type>(oper); } - void operator()(const cond_t& o) const { (*this)(o.ptr()); } - void operator()(const mapentry_t& o) const { (*this)(o.second.ptr()); } - void operator()(const ptr_mapentry_t& o) const { (*this)(o.second); } - }; - - /// Helper to insert objects into a conditions pool - /** - * \author M.Frank - * \version 1.0 - */ - template<typename pool_type> class PoolInsert : public Cond__Oper { - pool_type& pool; - public: - PoolInsert(pool_type& p) : pool(p) { } - void operator()(object_t* o) const { pool.insert(o); } - void operator()(const cond_t& o) const { pool.insert(o.ptr()); } - void operator()(const mapentry_t& o) const { (*this)(o.second.ptr()); } - void operator()(const ptr_mapentry_t& o) const { (*this)(o.second); } - }; - template <typename pool_type> PoolInsert<pool_type> poolInsert(pool_type& pool) { - return PoolInsert<pool_type>(pool); - } - - /// Helper to select objects from a conditions pool - /** - * \author M.Frank - * \version 1.0 - */ - template<typename collection_type> class CollectionSelect : public Cond__Oper { - collection_type& coll; - public: - CollectionSelect(collection_type& p) : coll(p) { } - void operator()(object_t* o) const { coll.insert(coll.end(),o); } - void operator()(const cond_t& o) const { coll.insert(coll.end(),o.ptr()); } - void operator()(const mapentry_t& o) const { (*this)(o.second.ptr()); } - void operator()(const ptr_mapentry_t& o) { (*this)(o.second); } - }; - template <typename collection_type> - CollectionSelect<collection_type> collectionSelect(collection_type& collection) { - return CollectionSelect<collection_type>(collection); - } - - /// Helper to select active objects from a conditions pool - /** - * \author M.Frank - * \version 1.0 - */ - template<typename collection_type> class ActiveSelect : public Cond__Oper { - collection_type& collection; - public: - ActiveSelect(collection_type& p) : collection(p) {} - void operator()(object_t* o) const { - if ( (o->flags & cond_t::ACTIVE) ) - collection.insert(collection.end(),o); + template <typename OPER> class ConditionsOperation : public Cond__Oper { + public: + typedef OPER operator_t; + typedef ConditionsOperation<operator_t> wrapper_t; + operator_t oper; + public: + ConditionsOperation(const operator_t& o) : oper(o) { } + bool operator()(object_t* o) const { return oper(o); } + bool operator()(const cond_t& o) const { return oper(o.ptr()); } + bool operator()(const mapentry_t& o) const { return oper(o.second.ptr()); } + bool operator()(const ptr_mapentry_t& o) const { return oper(o.second); } + }; + + /// Helper to insert objects into a conditions pool + /** + * \author M.Frank + * \version 1.0 + */ + //class ConditionsPoolSelect : public ConditionsOperation<ConditionsPoolSelect> { + //public: ConditionsPoolSelect(ConditionsPool& p) : wrapper_t(operator_t(p)) {} + //}; + + /// Helper to remove objects from a conditions pool + /** + * \author M.Frank + * \version 1.0 + */ + template <typename P> inline ConditionsOperation<PoolRemove<P> > poolRemove(P& pool) + { return ConditionsOperation<PoolRemove<P> >(PoolRemove<P>(pool)); } + + /// Helper to insert objects into a conditions pool + /** + * \author M.Frank + * \version 1.0 + */ + template <typename P> inline ConditionsOperation<PoolSelect<P> > poolSelect(P& pool) + { return ConditionsOperation<PoolSelect<P> >(PoolSelect<P>(pool)); } + + /// Helper to collect conditions using a ConditionsSelect base class + /** + * \author M.Frank + * \version 1.0 + */ + template <typename T> inline MapConditionsSelect<T> mapConditionsSelect(T& collection) + { return MapConditionsSelect<T>(collection); } + + /// Helper to select objects from a conditions pool into a sequential container + /** + * \author M.Frank + * \version 1.0 + */ + template <typename C> inline + ConditionsOperation<SequenceSelect<C> > sequenceSelect(C& coll) { + typedef SequenceSelect<C> operator_t; + return ConditionsOperation<operator_t>(operator_t(coll)); } - void operator()(const cond_t& o) const { (*this)(o.ptr()); } - void operator()(const mapentry_t& o) const { (*this)(o.second.ptr()); } - void operator()(const ptr_mapentry_t& o) const { (*this)(o.second); } - }; - template <typename collection_type> - ActiveSelect<collection_type> activeSelect(collection_type& active) { - return ActiveSelect<collection_type>(active); - } - - /// Helper to select keyed objects from a conditions pool - /** - * \author M.Frank - * \version 1.0 - */ - template<typename collection_type> class KeyedSelect : public Cond__Oper { - cond_t::key_type key; - collection_type& collection; - public: - KeyedSelect(cond_t::key_type k, collection_type& p) : key(k), collection(p) {} - void operator()(object_t* o) const { - if ( o->hash == key ) - collection.insert(collection.end(),o); + + /// Helper to select objects from a conditions pool into a mapped container + /** + * \author M.Frank + * \version 1.0 + */ + template <typename C> inline + ConditionsOperation<SequenceSelect<C> > mapSelect(C& coll) { + typedef MapSelect<C> operator_t; + return ConditionsOperation<operator_t>(operator_t(coll)); } - void operator()(const cond_t& o) const { (*this)(o.ptr()); } - void operator()(const mapentry_t& o) const { (*this)(o.second.ptr()); } - void operator()(const ptr_mapentry_t& o) const { (*this)(o.second); } - }; - template <typename collection_type> - KeyedSelect<collection_type> keyedSelect(Condition::key_type k, collection_type& keyed) { - return KeyedSelect<collection_type>(k, keyed); - } - - /// Helper to select condition objects by hash key from a conditions pool - /** - * \author M.Frank - * \version 1.0 - */ - class HashConditionFind : public Cond__Oper { - cond_t::key_type hash; - public: - HashConditionFind(cond_t::key_type h) : hash(h) { } - bool operator()(const cond_t& o) const { return o->hash == hash; } - bool operator()(const object_t* o) const { return o->hash == hash; } - bool operator()(const mapentry_t& o) const { return (*this)(o.second); } - bool operator()(const ptr_mapentry_t& o) const { return (*this)(o.second); } - }; - - } /* End namespace Conditions */ -} /* End namespace DD4hep */ - -#endif /* DDCOND_CONDITIONSSELECTORS_H */ + + /// Helper to select active objects from a conditions pool + /** + * \author M.Frank + * \version 1.0 + */ + template <typename C> inline ConditionsOperation<ActiveSelect<C> > activeSelect(C& coll) + { return ConditionsOperation<ActiveSelect<C> >(ActiveSelect<C>(coll)); } + + /// Helper to select keyed objects from a conditions pool + /** + * \author M.Frank + * \version 1.0 + */ + template <typename C> inline + ConditionsOperation<KeyedSelect<C> > keyedSelect(Condition::key_type key, C& coll) + { return ConditionsOperation<KeyedSelect<C> >(KeyedSelect<C>(key, coll)); } + + /// Helper to find conditions objects by hash key + /** + * \author M.Frank + * \version 1.0 + */ + ConditionsOperation<KeyFind> inline keyFind(Condition::key_type key) + { return ConditionsOperation<KeyFind>(KeyFind(key)); } + + } /* End namespace Operators */ + } /* End namespace Conditions */ +} /* End namespace DD4hep */ +#endif /* DDCOND_CONDITIONSSELECTORS_H */ diff --git a/DDCond/include/DDCond/ConditionsSlice.h b/DDCond/include/DDCond/ConditionsSlice.h new file mode 100644 index 0000000000000000000000000000000000000000..0093d775b43182042303217fd249fb0e69fc8b7b --- /dev/null +++ b/DDCond/include/DDCond/ConditionsSlice.h @@ -0,0 +1,190 @@ +//========================================================================== +// 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 DD4HEP_DDCOND_CONDITIONSSLICE_H +#define DD4HEP_DDCOND_CONDITIONSSLICE_H + +// Framework include files +#include "DD4hep/Memory.h" +#include "DD4hep/Conditions.h" +#include "DD4hep/ConditionDerived.h" + +#include "DDCond/ConditionsPool.h" +#include "DDCond/ConditionsManager.h" +#include "DDCond/ConditionsDependencyCollection.h" + +// C/C++ include files + + +/// Namespace for the AIDA detector description toolkit +namespace DD4hep { + + /// Namespace for the geometry part of the AIDA detector description toolkit + namespace Conditions { + + // Forward declarations + class UserPool; + class ConditionsSlice; + + /// Conditions slice object. Defines which conditions should be loaded by the ConditionsManager. + /** + * Object contains set of required conditions keys to be loaded to the user pool. + * It alkso contains the load information for the required conditions (conditions addresses). + * The address objects depend on the actual loader mechanism and must be specified the user. + * The information is then chained through the calls and made availible to the loader object. + * + * On return it contains the individual condition load information. + * + * Referenced by: ConditonsUserPool, ConditionsManager + * + * \author M.Frank + * \version 1.0 + * \ingroup DD4HEP_CONDITIONS + */ + class ConditionsSlice { + public: + /// Base class for data loading information. + /** + * Must be specialized to fit the needs of the concrete ConditionsDataLoader object. + * + * \author M.Frank + * \version 1.0 + * \date 31/03/2016 + */ + struct Info { + /// Default destructor. + virtual ~Info(); + }; + /// Slice entry class. Describes all information to load a condition. + /** + * \author M.Frank + * \version 1.0 + * \date 31/03/2016 + */ + struct Entry { + friend class ConditionsSlice; + private: + /// Default assignment operator + Entry& operator=(const Entry& copy) = delete; + /// Copy constructor (special!) + Entry(const Entry& copy, Info* l); + protected: + public: + ConditionKey key; + Condition condition; + ConditionDependency* dependency = 0; + Condition::mask_type mask = 0; + Info* loadinfo = 0; + /// Default constructor + Entry() = default; + /// Initializing constructor + Entry(const ConditionKey& k, Info* l); + /// Default destructor. + virtual ~Entry(); + /// Clone the entry + virtual Entry* clone(); + }; + + /// Concrete slice entry class. Includes the load information + /** + * T must be specialized and must + * + * \author M.Frank + * \version 1.0 + * \date 31/03/2016 + */ + template <typename T> class ConditionsLoaderEntry : public Entry, public T + { + friend class ConditionsSlice; + /// No default constructor + ConditionsLoaderEntry() = delete; + /// Default assignment operator + ConditionsLoaderEntry& operator=(const ConditionsLoaderEntry& copy) = delete; + /// Copy constructor + ConditionsLoaderEntry(const ConditionsLoaderEntry& copy) + : Entry(copy, this), T(copy) { } + private: + /// Initializing constructor + ConditionsLoaderEntry(const ConditionKey& k, const T& d) + : Entry(k, this), T(d) { } + virtual ~ConditionsLoaderEntry() = default; + virtual Entry* clone() { return new ConditionsLoaderEntry(*this); } + }; + + typedef Condition::key_type key_type; + typedef ConditionDependency Dependency; + typedef ConditionsDependencyCollection Dependencies; + typedef std::map<key_type,Entry*> ConditionsProxy; + + public: + /// Reference to the conditions manager. + /** Not used by the object, simple for convenience. + * Then all actora are lumped together. + */ + ConditionsManager manager; + + protected: + /// Reference to the user pool + dd4hep_ptr<UserPool> m_pool; + ConditionsProxy m_conditions; + ConditionsProxy m_derived; + Dependencies m_dependencies; + IOV m_iov; + /// Default assignment operator + ConditionsSlice& operator=(const ConditionsSlice& copy) = delete; + + /// Add a new conditions entry + bool insert_condition(Entry* entry); + + public: + /// Default constructor + ConditionsSlice() : manager(), m_iov(0) {} + /// Initializing constructor + ConditionsSlice(ConditionsManager m, const IOV& value) : manager(m), m_iov(value) {} + /// Copy constructor (Special, partial copy only. Hence no assignment!) + ConditionsSlice(const ConditionsSlice& copy); + /// Default destructor. + virtual ~ConditionsSlice(); + /// Required IOV + const IOV& iov() const { return m_iov; } + /// Set a new IOV + void setNewIOV(const IOV& value) { m_iov = value; } + /// Access the user condition pool + dd4hep_ptr<UserPool>& pool() { return m_pool; } + /// Access dependency list + const Dependencies& dependencies() const { return m_dependencies; } + /// Access to the real condition entries to be loaded + const ConditionsProxy& conditions() const { return m_conditions; } + /// Access to the derived condition entries to be computed + const ConditionsProxy& derived() const { return m_derived; } + /// Number of entries + size_t size() const { return m_conditions.size()+m_derived.size(); } + /// Clear the container. Destroys the contained stuff + void clear(); + /// Clear the conditions access and the user pool. + void reset(); + /// Add a new conditions dependency collection + void insert(const Dependencies& deps); + /// Add a new shared conditions dependency + bool insert(Dependency* dependency); + /// Add a new conditions key. T must inherot from class ConditionsSlice::Info + template <typename T=Info> bool insert(const ConditionKey& key, const T& loadinfo) { + Entry* e = new ConditionsLoaderEntry<T>(key,loadinfo); + return insert_condition(e); + } + }; + + /// Populate the conditions slice from the conditions manager (convenience) + ConditionsSlice* createSlice(ConditionsManager mgr, const IOVType& typ); + } /* End namespace Conditions */ +} /* End namespace DD4hep */ +#endif /* DD4HEP_DDCOND_CONDITIONSSLICE_H */ diff --git a/DDCond/include/DDCond/Type1/Manager_Type1.h b/DDCond/include/DDCond/Type1/Manager_Type1.h index 2368d1a0b170959f7e7e152ce43afb448dd16648..a562833401d2221719ff9fc408195d2dfd5612f7 100644 --- a/DDCond/include/DDCond/Type1/Manager_Type1.h +++ b/DDCond/include/DDCond/Type1/Manager_Type1.h @@ -16,19 +16,10 @@ // Framework include files% #include "DD4hep/Mutex.h" #include "DD4hep/Memory.h" -#include "DD4hep/Callback.h" -#include "DD4hep/ConditionDerived.h" #include "DD4hep/ObjectExtensions.h" -#include "DD4hep/objects/ConditionsInterna.h" - -#include "DDCond/ConditionsPool.h" -#include "DDCond/ConditionsIOVPool.h" -#include "DDCond/ConditionsDataLoader.h" #include "DDCond/ConditionsManagerObject.h" // C/C++ include files -#include <set> -#include <list> /// Namespace for the AIDA detector description toolkit namespace DD4hep { @@ -38,6 +29,7 @@ namespace DD4hep { class Entry; class ConditionsPool; + class ConditionsSlice; class ConditionsIOVPool; class ConditionsDataLoader; @@ -50,44 +42,43 @@ namespace DD4hep { * \version 1.0 * \ingroup DD4HEP_CONDITIONS */ - class ConditionsManagerObject_Type1 : public ConditionsManagerObject, - public ObjectExtensions + class Manager_Type1 : public ConditionsManagerObject, + public ObjectExtensions { + public: + typedef std::vector<ConditionsIOVPool*> TypedConditionPool; + protected: /** Generic interface of any concrete instance */ /// Property: maximal number of IOV types to be handled - int m_maxIOVTypes; + int m_maxIOVTypes; /// Property: ConditionsPool constructor type (default: empty. MUST BE SET!) - std::string m_poolType; + std::string m_poolType; /// Property: UpdatePool constructor type (default: DD4hep_ConditionsLinearUpdatePool) - std::string m_updateType; + std::string m_updateType; /// Property: UserPool constructor type (default: DD4hep_ConditionsLinearUserPool) - std::string m_userType; + std::string m_userType; /// Property: Conditions loader type (default: "multi" -> DD4hep_Conditions_multi_Loader) - std::string m_loaderType; + std::string m_loaderType; /// Collection of IOV types managed - IOVTypes m_iovTypes; + IOVTypes m_iovTypes; /** Specialized interface only used by this implementation */ - - public: - typedef std::vector<ConditionsIOVPool*> TypedConditionPool; - /// Managed pool of typed conditions indexed by IOV-type and IOV key - TypedConditionPool m_rawPool; - - protected: /// Lock to protect the update/delayed conditions pool - dd4hep_mutex_t m_updateLock; + dd4hep_mutex_t m_updateLock; /// Lock to protect the pool of all known conditions - dd4hep_mutex_t m_poolLock; + dd4hep_mutex_t m_poolLock; /// Reference to update conditions pool - dd4hep_ptr<UpdatePool> m_updatePool; + dd4hep_ptr<UpdatePool> m_updatePool; + public: + /// Managed pool of typed conditions indexed by IOV-type and IOV key + TypedConditionPool m_rawPool; /// Public access: if locked, DetElements stay intact and are not altered - int m_locked; + int m_locked; protected: /// Retrieve a condition set given a Detector Element and the conditions name according to their validity @@ -109,17 +100,12 @@ namespace DD4hep { /// Requires EXTERNALLY held lock on update pool! Condition __queue_update(Conditions::Entry* data); - protected: - /// Register a new managed condition. (Unused) - //void registerCondition(Condition c); - - public: /// Standard constructor - ConditionsManagerObject_Type1(LCDD& lcdd); + Manager_Type1(LCDD& lcdd); /// Default destructor - virtual ~ConditionsManagerObject_Type1(); + virtual ~Manager_Type1(); /// Access to managed pool of typed conditions indexed by IOV-type and IOV key //const TypedConditionPool& conditionsPool() const { return m_rawPool; } @@ -134,7 +120,7 @@ namespace DD4hep { virtual std::pair<bool, const IOVType*> registerIOVType(size_t iov_type, const std::string& iov_name); /// Access IOV by its type - virtual const IOVTypes& iovTypes () const { return m_iovTypes; } + virtual const IOVTypes& iovTypes () const { return m_iovTypes; } /// Access IOV by its type virtual const IOVType* iovType (size_t iov_type) const; @@ -151,27 +137,6 @@ namespace DD4hep { /// Register new condition with the conditions store. Unlocked version, not multi-threaded virtual bool registerUnlocked(ConditionsPool* pool, Condition cond); - /// Prepare all updates for the given keys to the clients with the defined IOV - long prepare(const IOV& required_validity, - const ConditionKeys& keys, - dd4hep_ptr<UserPool>& user_pool); - - /// Prepare all updates for the given keys to the clients with the defined IOV - long prepare(const IOV& required_validity, - const ConditionKeys& keys, - dd4hep_ptr<UserPool>& user_pool, - const Dependencies& dependencies, - bool verify_dependencies=true); - - /// Prepare all updates to the clients with the defined IOV - long prepare(const IOV& required_validity, dd4hep_ptr<UserPool>& user_pool); - - /// Prepare all updates to the clients with the defined IOV - long prepare(const IOV& required_validity, - dd4hep_ptr<UserPool>& user_pool, - const Dependencies& dependencies, - bool verify_dependencies=true); - /// Clean conditions, which are above the age limit. /** @return Number of conditions cleaned/removed from the IOV pool of the given type */ int clean(const IOVType* typ, int max_age); @@ -186,11 +151,22 @@ namespace DD4hep { */ virtual void pushUpdates(); - /// Retrieve a condition set given a Detector Element and the conditions name according to their validity + /// Retrieve a condition set given a Detector Element and the conditions name according to their validity (deprecated) virtual Condition get(key_type key, const iov_type& req_validity); - /// Retrieve a condition given a Detector Element and the conditions name + /// Retrieve a condition given a Detector Element and the conditions name (deprecated) virtual RangeConditions getRange(key_type key, const iov_type& req_validity); + + /// Prepare all updates for the given keys to the clients with the defined IOV + /** + * @arg req_validity [IOV] Required interval of validity of the selected conditions + * @arg slice [] Conditions slice with load/computation recipes. + * + * @return + */ + UserPool::Result prepare(const IOV& req_validity, + ConditionsSlice& slice); + }; } /* End namespace Conditions */ } /* End namespace DD4hep */ diff --git a/DDCond/src/ConditionsDependencyHandler.cpp b/DDCond/src/ConditionsDependencyHandler.cpp index 1fd64f3e8bc0fab9e0fd3b0e280325e37cb50172..47466b95bc3e56ea50aa837b74095033b2988316 100644 --- a/DDCond/src/ConditionsDependencyHandler.cpp +++ b/DDCond/src/ConditionsDependencyHandler.cpp @@ -20,12 +20,14 @@ using namespace DD4hep; using namespace DD4hep::Conditions; /// Default constructor -ConditionsDependencyHandler::ConditionsDependencyHandler(ConditionsManagerObject* mgr, +ConditionsDependencyHandler::ConditionsDependencyHandler(ConditionsManager mgr, UserPool& pool, const Dependencies& dependencies, void* user_param) - : m_manager(mgr), m_pool(pool), m_dependencies(dependencies), m_userParam(user_param) + : m_manager(mgr.access()), m_pool(pool), m_dependencies(dependencies), m_userParam(user_param) { + const IOV& iov = m_pool.validity(); + m_iovPool = m_manager->registerIOV(*iov.iovType, iov.keyData); } /// Default destructor @@ -43,7 +45,7 @@ Condition ConditionsDependencyHandler::get(unsigned int key) const { if ( c.isValid() ) { Condition::Object* obj = c.ptr(); const IOV& required = m_pool.validity(); - if ( obj->iov && IOV::key_is_contained(required.keyData,obj->iov->keyData) ) + if ( obj && obj->iov && IOV::key_is_contained(required.keyData,obj->iov->keyData) ) return c; Dependencies::const_iterator i = m_dependencies.find(key); if ( i != m_dependencies.end() ) { @@ -76,24 +78,25 @@ ConditionsDependencyHandler::do_callback(const ConditionDependency& dep) const cond->iov = m_pool.validityPtr(); // Must IMMEDIATELY insert to handle inter-dependencies. m_pool.insert(cond); + m_manager->registerUnlocked(m_iovPool, cond); } return obj; } catch(const std::exception& e) { printout(ERROR,"ConditionDependency", "+++ Exception while creating dependent Condition %s:", - dep.target.name.c_str()); + dep.name()); printout(ERROR,"ConditionDependency","\t\t%s", e.what()); } catch(...) { printout(ERROR,"ConditionDependency", "+++ UNKNOWN exception while creating dependent Condition %s.", - dep.target.name.c_str()); + dep.name()); } m_pool.print("*"); except("ConditionDependency", "++ Exception while creating dependent Condition %s.", - dep.target.name.c_str()); + dep.name()); return 0; } diff --git a/DDCond/src/ConditionsIOVPool.cpp b/DDCond/src/ConditionsIOVPool.cpp index 99a996dc01487ef8bb6a2d4fd6dc7e4a8bf4e4b2..a93d6fab5ff311dddb1aed8119daeb67b6f05d03 100644 --- a/DDCond/src/ConditionsIOVPool.cpp +++ b/DDCond/src/ConditionsIOVPool.cpp @@ -22,7 +22,7 @@ using namespace DD4hep; using namespace DD4hep::Conditions; /// Default constructor -ConditionsIOVPool::ConditionsIOVPool() { +ConditionsIOVPool::ConditionsIOVPool(const IOVType* typ) : type(typ) { InstanceCount::increment(this); } @@ -32,20 +32,24 @@ ConditionsIOVPool::~ConditionsIOVPool() { InstanceCount::decrement(this); } -void ConditionsIOVPool::select(Condition::key_type key, const Condition::iov_type& req_validity, RangeConditions& result) +size_t ConditionsIOVPool::select(Condition::key_type key, const Condition::iov_type& req_validity, RangeConditions& result) { if ( !elements.empty() ) { + size_t len = result.size(); const IOV::Key req_key = req_validity.key(); // 16 bytes => better copy! for(Elements::const_iterator i=elements.begin(); i!=elements.end(); ++i) { if ( IOV::key_contains_range((*i).first, req_key) ) { (*i).second->select(key, result); } } + return result.size() - len; } + return 0; } -void ConditionsIOVPool::selectRange(Condition::key_type key, const Condition::iov_type& req_validity, RangeConditions& result) +size_t ConditionsIOVPool::selectRange(Condition::key_type key, const Condition::iov_type& req_validity, RangeConditions& result) { + size_t len = result.size(); const IOV::Key range = req_validity.key(); for(Elements::const_iterator i=elements.begin(); i!=elements.end(); ++i) { const IOV::Key& k = (*i).first; @@ -59,6 +63,7 @@ void ConditionsIOVPool::selectRange(Condition::key_type key, const Condition::io // IOV overlap of test on the higher end of key (*i).second->select(key, result); } + return result.size() - len; } /// Remove all key based pools with an age beyon the minimum age @@ -68,7 +73,7 @@ int ConditionsIOVPool::clean(int max_age) { for(Elements::const_iterator i=elements.begin(); i!=elements.end(); ++i) { ConditionsPool* pool = (*i).second; if ( pool->age_value >= max_age ) { - count += pool->count(); + count += pool->size(); pool->print("Remove"); delete pool; } @@ -79,27 +84,69 @@ int ConditionsIOVPool::clean(int max_age) { return count; } -/// Select all ACTIVE conditions, which do no longer match the IOV requirement -void ConditionsIOVPool::select(const Condition::iov_type& required_validity, - RangeConditions& valid, - RangeConditions& expired, - Condition::iov_type& conditions_validity) +/// Select all ACTIVE conditions, which do match the IOV requirement +size_t ConditionsIOVPool::select(const IOV& req_validity, + RangeConditions& valid, + IOV& cond_validity) { + size_t num_selected = 0; if ( !elements.empty() ) { - const IOV::Key req_key = required_validity.key(); // 16 bytes => better copy! + const IOV::Key req_key = req_validity.key(); // 16 bytes => better copy! for(Elements::const_iterator i=elements.begin(); i!=elements.end(); ++i) { ConditionsPool* pool = (*i).second; if ( !IOV::key_contains_range((*i).first, req_key) ) { - if ( pool->age_value == ConditionsPool::AGE_NONE ) { - // Now check the content: - pool->select_used(expired); - } ++pool->age_value; continue; } - conditions_validity.iov_intersection((*i).first); - pool->select_used(valid); + cond_validity.iov_intersection((*i).first); + num_selected += pool->select_all(valid); + pool->age_value = 0; + } + } + return num_selected; +} + +/// Select all ACTIVE conditions, which do match the IOV requirement +size_t ConditionsIOVPool::select(const IOV& req_validity, + const ConditionsSelect& predicate_processor, + IOV& cond_validity) +{ + size_t num_selected = 0; + if ( !elements.empty() ) { + const IOV::Key req_key = req_validity.key(); // 16 bytes => better copy! + for(const auto& i : elements ) { + ConditionsPool* pool = i.second; + if ( !IOV::key_contains_range(i.first, req_key) ) { + ++pool->age_value; + continue; + } + cond_validity.iov_intersection(i.first); + num_selected += pool->select_all(predicate_processor); + pool->age_value = 0; + } + } + return num_selected; +} + +/// Select all ACTIVE conditions, which do match the IOV requirement +size_t ConditionsIOVPool::select(const IOV& req_validity, + Elements& valid, + IOV& cond_validity) +{ + size_t num_selected = 0; + if ( !elements.empty() ) { + const IOV::Key req_key = req_validity.key(); // 16 bytes => better copy! + for(const auto& i : elements ) { + ConditionsPool* pool = i.second; + if ( !IOV::key_contains_range(i.first, req_key) ) { + ++pool->age_value; + continue; + } + cond_validity.iov_intersection(i.first); + valid[i.first] = pool; pool->age_value = 0; + ++num_selected; } } + return num_selected; } diff --git a/DDCond/src/ConditionsManager.cpp b/DDCond/src/ConditionsManager.cpp index 5d22477d56149e0cd3a6f6672f41cecdae7ed8ee..44c7d95ceeea275ac50f497449f34842d62a4c4f 100644 --- a/DDCond/src/ConditionsManager.cpp +++ b/DDCond/src/ConditionsManager.cpp @@ -235,32 +235,8 @@ void ConditionsManager::clear() const { access()->clear(); } -/// Prepare all updates for the given keys to the clients with the defined IOV -long ConditionsManager::prepare(const IOV& required_validity, - const ConditionKeys& keys, - dd4hep_ptr<UserPool>& user_pool) { - return access()->prepare(required_validity, keys, user_pool); -} - - -/// Prepare all updates for the given keys to the clients with the defined IOV -long ConditionsManager::prepare(const IOV& required_validity, - const ConditionKeys& keys, - dd4hep_ptr<UserPool>& user_pool, - const Dependencies& dependencies, - bool verify_dependencies) { - return access()->prepare(required_validity, keys, user_pool, dependencies, verify_dependencies); -} - -/// Prepare all updates to the clients with the defined new IOV. Changes are not yet applied -long ConditionsManager::prepare(const IOV& required_validity, dd4hep_ptr<UserPool>& user_pool) { - return access()->prepare(required_validity, user_pool); -} - /// Prepare all updates to the clients with the defined IOV -long ConditionsManager::prepare(const IOV& required_validity, - dd4hep_ptr<UserPool>& user_pool, - const Dependencies& dependencies, - bool verify_dependencies) { - return access()->prepare(required_validity, user_pool, dependencies, verify_dependencies); +long ConditionsManager::prepare(const IOV& req_iov, + ConditionsSlice& slice) const { + return access()->prepare(req_iov, slice).missing; } diff --git a/DDCond/src/ConditionsOperators.cpp b/DDCond/src/ConditionsOperators.cpp index 66e71c6a16e24f7c12f84f426f460518a214d286..47e2d6d0555f8b67a0f343618aa15ef0b69658f4 100644 --- a/DDCond/src/ConditionsOperators.cpp +++ b/DDCond/src/ConditionsOperators.cpp @@ -14,9 +14,13 @@ // Framework include files #include "DD4hep/Printout.h" #include "DD4hep/InstanceCount.h" -#include "DDCond/ConditionsOperators.h" -#include "DDCond/ConditionsIOVPool.h" +#include "DD4hep/objects/ConditionsInterna.h" #include "DDCond/ConditionsPool.h" +#include "DDCond/ConditionsIOVPool.h" +#include "DDCond/ConditionsOperators.h" + +// C/C++ include files +#include <cstring> using namespace std; using namespace DD4hep; diff --git a/DDCond/src/ConditionsPool.cpp b/DDCond/src/ConditionsPool.cpp index c8902a02527535fc5e24c1c9f67c63b7c72e9f31..2184ae4290efbb1c556b2a1697bef1551aab751a 100644 --- a/DDCond/src/ConditionsPool.cpp +++ b/DDCond/src/ConditionsPool.cpp @@ -41,7 +41,7 @@ ConditionsPool::~ConditionsPool() { /// Print pool basics void ConditionsPool::print(const string& opt) const { printout(INFO,"ConditionsPool","+++ %s Conditions for pool with IOV: %-32s age:%3d [%4d entries]", - opt.c_str(), iov->str().c_str(), age_value, count()); + opt.c_str(), iov->str().c_str(), age_value, size()); } /// Listener invocation when a condition is registered to the cache @@ -64,8 +64,8 @@ UpdatePool::~UpdatePool() { } /// Default constructor -UserPool::UserPool(ConditionsManager mgr, ConditionsIOVPool* pool) - : m_iov(0), m_manager(mgr), m_iovPool(pool) +UserPool::UserPool(ConditionsManager mgr) + : m_iov(0), m_manager(mgr) { InstanceCount::increment(this); } diff --git a/DDCond/src/ConditionsRepository.cpp b/DDCond/src/ConditionsRepository.cpp index a241a95c21a4549576f6575b5a59ff12416da092..20b9bda2a7d8352b52b9d02fe38fa00aed50fc07 100644 --- a/DDCond/src/ConditionsRepository.cpp +++ b/DDCond/src/ConditionsRepository.cpp @@ -16,11 +16,13 @@ #include "DDCond/ConditionsManager.h" #include "DDCond/ConditionsIOVPool.h" #include "DDCond/ConditionsTags.h" +#include "DD4hep/objects/ConditionsInterna.h" #include "DD4hep/Printout.h" #include "XML/DocumentHandler.h" #include "XML/XMLTags.h" // C/C++ include files +#include <cstring> #include <fstream> #include <climits> #include <cerrno> diff --git a/DDCond/src/ConditionsSlice.cpp b/DDCond/src/ConditionsSlice.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5b1bfc8cbeea902931d60d55645fab452725dd92 --- /dev/null +++ b/DDCond/src/ConditionsSlice.cpp @@ -0,0 +1,151 @@ +//========================================================================== +// 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/ConditionsSlice.h" +#include "DDCond/ConditionsIOVPool.h" +#include "DD4hep/Printout.h" + +using namespace DD4hep::Conditions; + +/// Default destructor. +ConditionsSlice::Info::~Info() { +} + +/// Copy constructor (special!) +ConditionsSlice::Entry::Entry(const Entry& copy, Info* l) + : key(copy.key), condition(0), loadinfo(l) +{ + if ( copy.dependency ) dependency = copy.dependency->addRef(); +} + +/// Initializing constructor +ConditionsSlice::Entry::Entry(const ConditionKey& k, Info* l) + : key(k), condition(0), loadinfo(l) +{ +} + +/// Clone the entry +ConditionsSlice::Entry* ConditionsSlice::Entry::clone() { + Entry* e = new Entry(*this); + return e; +} + +/// Default destructor. +ConditionsSlice::Entry::~Entry() { + releasePtr(dependency); +} + +/// Copy constructor (Special, partial copy only. Hence no assignment!) +ConditionsSlice::ConditionsSlice(const ConditionsSlice& copy) + : manager(copy.manager), m_iov(copy.m_iov.iovType) +{ + for(const auto& c : copy.m_conditions ) { + Entry* e = new Entry(*c.second); + m_conditions.insert(std::make_pair(e->key.hash,e)); + } + for(const auto& c : copy.m_derived ) { + Entry* e = new Entry(*c.second); + if ( m_derived.insert(std::make_pair(e->key.hash,e)).second ) { + if ( e->dependency ) m_dependencies.insert(e->dependency); + } + } +} + +/// Default destructor. +ConditionsSlice::~ConditionsSlice() { + destroyObjects(m_conditions); + destroyObjects(m_derived); + m_dependencies.clear(); +} + +/// Clear the container. Destroys the contained stuff +void ConditionsSlice::clear() { + destroyObjects(m_conditions); + destroyObjects(m_derived); + m_dependencies.clear(); +} + +/// Clear the conditions access and the user pool. +void ConditionsSlice::reset() { + for(const auto& e : m_conditions ) e.second->condition = 0; + for(const auto& e : m_derived ) e.second->condition = 0; + if ( pool().get() ) pool()->clear(); + m_iov.reset(); +} + +/// Add a new conditions dependency collection +void ConditionsSlice::insert(const Dependencies& deps) { + for ( const auto& d : deps ) insert(d.second.get()); +} + +/// Add a new conditions dependency (shared) +bool ConditionsSlice::insert(Dependency* dependency) { + Entry* entry = new Entry(); + entry->dependency = dependency->addRef(); + entry->mask |= Condition::DERIVED; + entry->key = entry->dependency->target; + if ( m_derived.insert(std::make_pair(entry->key.hash,entry)).second ) { + if ( entry->dependency ) m_dependencies.insert(entry->dependency); + return true; + } + deletePtr(entry); + return false; +} + +/// Add a new entry +bool ConditionsSlice::insert_condition(Entry* entry) { + if ( entry->dependency ) { + // ERROR: This call should not be invoked for derivatives! + DD4hep::except("ConditionsSlice", + "insert_condition: Bad invokation. No dependency allowed here!"); + } + + if ( m_conditions.insert(std::make_pair(entry->key.hash,entry)).second ) { + return true; + } + deletePtr(entry); + return false; +} + +namespace { + + struct SliceOper : public ConditionsSelect { + struct LoadInfo : public ConditionsSlice::Info { + std::string info; + LoadInfo(const std::string& i) : info(i) {} + virtual ~LoadInfo() {} + }; + ConditionsSlice* slice; + SliceOper(ConditionsSlice* s) : slice(s) {} + void operator()(const ConditionsIOVPool::Elements::value_type& v) { + v.second->select_all(*this); + } + bool operator()(Condition::Object* c) const { + slice->insert(ConditionKey(c->name,c->hash),LoadInfo(c->name)); + return true; + } + /// Return number of conditions selected + virtual size_t size() const { return slice->conditions().size(); } + }; +} + +/// Populate the conditions slice from the conditions manager (convenience) +ConditionsSlice* +DD4hep::Conditions::createSlice(ConditionsManager mgr, const IOVType& typ) { + dd4hep_ptr<ConditionsSlice> slice(new ConditionsSlice(mgr, IOV(&typ))); + Conditions::ConditionsIOVPool* iovPool = mgr.iovPool(typ); + Conditions::ConditionsIOVPool::Elements& pools = iovPool->elements; + for_each(begin(pools),end(pools),SliceOper(slice.get())); + return slice.release(); +} diff --git a/DDCond/src/ConditionsTextRepository.cpp b/DDCond/src/ConditionsTextRepository.cpp index 1d2e43277d601d622285871f38b0d0447e3bffde..d9f7cffb01e4b2fa3fc085921131374c61028cd0 100644 --- a/DDCond/src/ConditionsTextRepository.cpp +++ b/DDCond/src/ConditionsTextRepository.cpp @@ -21,6 +21,7 @@ #include "XML/XMLTags.h" // C/C++ include files +#include <cstring> #include <fstream> #include <climits> #include <cerrno> diff --git a/DDCond/src/Type1/Manager_Type1.cpp b/DDCond/src/Type1/Manager_Type1.cpp index 99123df3a9ce42e979cb05ac2e38f5a61789d333..436d4114e8e8be22ee9edc0d20db11e44fc1afce 100644 --- a/DDCond/src/Type1/Manager_Type1.cpp +++ b/DDCond/src/Type1/Manager_Type1.cpp @@ -12,29 +12,28 @@ //========================================================================== // Framework include files +#include "DDCond/Type1/Manager_Type1.h" + #include "DD4hep/LCDD.h" +#include "DD4hep/World.h" #include "DD4hep/Errors.h" #include "DD4hep/Plugins.h" #include "DD4hep/Printout.h" -#include "DD4hep/World.h" #include "DD4hep/Handle.inl" -#include "DD4hep/DetectorTools.h" +#include "DD4hep/Factories.h" #include "DD4hep/InstanceCount.h" #include "DD4hep/PluginCreators.h" -#include "DD4hep/DetFactoryHelper.h" #include "DD4hep/ConditionsListener.h" #include "DD4hep/objects/DetectorInterna.h" #include "DD4hep/objects/ConditionsInterna.h" -#include "DD4hep/objects/AlignmentsInterna.h" -#include "DD4hep/DetFactoryHelper.h" #include "DDCond/ConditionsPool.h" #include "DDCond/ConditionsEntry.h" #include "DDCond/ConditionsManager.h" +#include "DDCond/ConditionsIOVPool.h" #include "DDCond/ConditionsDataLoader.h" #include "DDCond/ConditionsLoaderImp.h" #include "DDCond/AlignmentsLoaderImp.h" -#include "DDCond/Type1/Manager_Type1.h" using namespace std; using namespace DD4hep; @@ -44,10 +43,10 @@ typedef Alignments::AlignmentsLoader AlignmentsLoader; typedef UpdatePool::UpdateEntries Updates; typedef RangeConditions RC; -DD4HEP_INSTANTIATE_HANDLE_NAMED(ConditionsManagerObject_Type1); +DD4HEP_INSTANTIATE_HANDLE_NAMED(Manager_Type1); static void* ddcond_create_manager_instance(LCDD& lcdd, int, char**) { - return (ConditionsManagerObject*)new ConditionsManagerObject_Type1(lcdd); + return (ConditionsManagerObject*)new Manager_Type1(lcdd); } DECLARE_LCDD_CONSTRUCTOR(DD4hep_ConditionsManager_Type1,ddcond_create_manager_instance) @@ -60,10 +59,10 @@ namespace { int s_debug = INFO; /// Helper: IOV Check function declaration - template <typename T> const IOVType* check_iov_type(const ConditionsManagerObject_Type1* o, const IOV* iov); + template <typename T> const IOVType* check_iov_type(const Manager_Type1* o, const IOV* iov); /// Helper: Specialized IOV check - template <> const IOVType* check_iov_type<void>(const ConditionsManagerObject_Type1* o, const IOV* iov) { + template <> const IOVType* check_iov_type<void>(const Manager_Type1* o, const IOV* iov) { if ( iov ) { const IOVType* typ = iov->iovType ? iov->iovType : o->iovType(iov->type); if ( typ ) { @@ -80,20 +79,20 @@ namespace { } /// Helper: Specialized IOV check for discrete IOV values - template <> const IOVType* check_iov_type<Discrete>(const ConditionsManagerObject_Type1* o, const IOV* iov) { + template <> const IOVType* check_iov_type<Discrete>(const Manager_Type1* o, const IOV* iov) { const IOVType* typ = check_iov_type<void>(o,iov); if ( typ && !iov->has_range() ) return typ; return 0; } /// Helper: Specialized IOV check for range IOV values - template <> const IOVType* check_iov_type<Range>(const ConditionsManagerObject_Type1* o, const IOV* iov) { + template <> const IOVType* check_iov_type<Range>(const Manager_Type1* o, const IOV* iov) { const IOVType* typ = check_iov_type<void>(o,iov); if ( typ && iov->has_range() ) return typ; return 0; } /// Helper: Check conditions result for consistency - template <typename T> void __check_values__(const ConditionsManagerObject_Type1* o, Condition::key_type key, const IOV* iov) + template <typename T> void __check_values__(const Manager_Type1* o, Condition::key_type key, const IOV* iov) { if ( !iov ) { except("ConditionsManager","+++ Invalid IOV to access condition: %08X. [Null-reference]",key); @@ -130,16 +129,16 @@ namespace { } template <typename PMF> - void __callListeners(const ConditionsManagerObject_Type1::Listeners& listeners, PMF pmf, Condition& cond) { + void __callListeners(const Manager_Type1::Listeners& listeners, PMF pmf, Condition& cond) { for(const auto& listener : listeners ) (listener.first->*pmf)(cond, listener.second); } } /// Standard constructor -ConditionsManagerObject_Type1::ConditionsManagerObject_Type1(LCDD& lcdd_instance) - : ConditionsManagerObject(lcdd_instance), ObjectExtensions(typeid(ConditionsManagerObject_Type1)), - m_rawPool(), m_updateLock(), m_poolLock(), m_updatePool(), m_locked(0) +Manager_Type1::Manager_Type1(LCDD& lcdd_instance) + : ConditionsManagerObject(lcdd_instance), ObjectExtensions(typeid(Manager_Type1)), + m_updateLock(), m_poolLock(), m_updatePool(), m_rawPool(), m_locked(0) { InstanceCount::increment(this); declareProperty("MaxIOVTypes", m_maxIOVTypes=32); @@ -152,7 +151,7 @@ ConditionsManagerObject_Type1::ConditionsManagerObject_Type1(LCDD& lcdd_instance } /// Default destructor -ConditionsManagerObject_Type1::~ConditionsManagerObject_Type1() { +Manager_Type1::~Manager_Type1() { Geometry::World world(m_lcdd.world()); for_each(m_rawPool.begin(), m_rawPool.end(), DestroyObject<ConditionsIOVPool*>()); if ( world.isValid() ) { @@ -166,7 +165,7 @@ ConditionsManagerObject_Type1::~ConditionsManagerObject_Type1() { InstanceCount::decrement(this); } -void ConditionsManagerObject_Type1::initialize() { +void Manager_Type1::initialize() { if ( !m_updatePool.get() ) { string typ = "DD4hep_Conditions_"+m_loaderType+"_Loader"; const void* argv_loader[] = {"ConditionsDataLoader", this, 0}; @@ -187,22 +186,22 @@ void ConditionsManagerObject_Type1::initialize() { } /// Register new IOV type if it does not (yet) exist. -pair<bool, const IOVType*> ConditionsManagerObject_Type1::registerIOVType(size_t iov_type, const string& iov_name) { +pair<bool, const IOVType*> Manager_Type1::registerIOVType(size_t iov_type, const string& iov_name) { if ( iov_type<m_iovTypes.size() ) { - IOVType& t = m_iovTypes[iov_type]; - bool eq_type = t.type == iov_type; - bool eq_name = t.name == iov_name; + IOVType& typ = m_iovTypes[iov_type]; + bool eq_type = typ.type == iov_type; + bool eq_name = typ.name == iov_name; if ( eq_type && eq_name ) { - return make_pair(false,&t); + return make_pair(false,&typ); } - else if ( t.type != 0 && eq_type && !eq_name ) { + else if ( typ.type != 0 && eq_type && !eq_name ) { except("ConditionsManager","Cannot register IOV %s. Type %d already in use!", iov_name.c_str(), iov_type); } - t.name = iov_name; - t.type = iov_type; - m_rawPool[t.type] = new ConditionsIOVPool(); - return make_pair(true,&t); + typ.name = iov_name; + typ.type = iov_type; + m_rawPool[typ.type] = new ConditionsIOVPool(&typ); + return make_pair(true,&typ); } except("ConditionsManager","Cannot register IOV section %d of type %d. Value out of bounds: [%d,%d]", iov_name.c_str(), iov_type, 0, int(m_iovTypes.size())); @@ -210,17 +209,17 @@ pair<bool, const IOVType*> ConditionsManagerObject_Type1::registerIOVType(size_t } /// Access IOV by its type -const IOVType* ConditionsManagerObject_Type1::iovType (size_t iov_type) const { +const IOVType* Manager_Type1::iovType (size_t iov_type) const { if ( iov_type<m_iovTypes.size() ) { - const IOVType& t = m_iovTypes[iov_type]; - if ( t.type == iov_type ) return &t; + const IOVType& typ = m_iovTypes[iov_type]; + if ( typ.type == iov_type ) return &typ; } except("ConditionsManager","Request to access an unregistered IOV type: %d.", iov_type); return 0; } /// Access IOV by its name -const IOVType* ConditionsManagerObject_Type1::iovType (const string& iov_name) const { +const IOVType* Manager_Type1::iovType (const string& iov_name) const { for( const auto& i : m_iovTypes ) if ( i.name == iov_name ) return &i; except("ConditionsManager","Request to access an unregistered IOV type: %s.", iov_name.c_str()); @@ -228,12 +227,12 @@ const IOVType* ConditionsManagerObject_Type1::iovType (const string& iov_name) c } /// Register IOV with type and key -ConditionsPool* ConditionsManagerObject_Type1::registerIOV(const IOVType& typ, IOV::Key key) { +ConditionsPool* Manager_Type1::registerIOV(const IOVType& typ, IOV::Key key) { // IOV read and checked. Now register it, but always locked! ConditionsIOVPool* pool = m_rawPool[typ.type]; dd4hep_lock_t lock(m_poolLock); if ( !pool ) { - m_rawPool[typ.type] = pool = new ConditionsIOVPool(); + m_rawPool[typ.type] = pool = new ConditionsIOVPool(&typ); } ConditionsIOVPool::Elements::const_iterator i = pool->elements.find(key); if ( i != pool->elements.end() ) { @@ -250,12 +249,12 @@ ConditionsPool* ConditionsManagerObject_Type1::registerIOV(const IOVType& typ, I } /// Access conditions multi IOV pool by iov type -ConditionsIOVPool* ConditionsManagerObject_Type1::iovPool(const IOVType& iov_type) const { +ConditionsIOVPool* Manager_Type1::iovPool(const IOVType& iov_type) const { return m_rawPool[iov_type.type]; } /// Register new condition with the conditions store. Unlocked version, not multi-threaded -bool ConditionsManagerObject_Type1::registerUnlocked(ConditionsPool* pool, Condition cond) { +bool Manager_Type1::registerUnlocked(ConditionsPool* pool, Condition cond) { if ( pool && cond.isValid() ) { cond->pool = pool; cond->iov = pool->iov; @@ -274,7 +273,7 @@ bool ConditionsManagerObject_Type1::registerUnlocked(ConditionsPool* pool, Condi /// Set a single conditions value to be managed. /// Requires external lock on update pool! -Condition ConditionsManagerObject_Type1::__queue_update(Conditions::Entry* e) { +Condition Manager_Type1::__queue_update(Conditions::Entry* e) { if ( e ) { ConditionsPool* p = this->ConditionsManagerObject::registerIOV(e->validity); Condition condition(e->name,e->type); @@ -291,15 +290,34 @@ Condition ConditionsManagerObject_Type1::__queue_update(Conditions::Entry* e) if ( s_debug > INFO ) { printout(INFO,"Conditions","+++ Loaded condition: %s.%s to %s [%s] V: %s", e->detector.path().c_str(), c->name.c_str(), - c->value.c_str(), c->type.c_str(), c->validity.c_str()); + c->value.c_str(), c->type.c_str(), c->validity.c_str()); } return c; } return Condition(); } +/// Helper to check iov and user pool and create user pool if not present +void Manager_Type1::__get_checked_pool(const IOV& req_iov, + dd4hep_ptr<UserPool>& up) +{ + const IOVType* typ = check_iov_type<Discrete>(this, &req_iov); + if ( typ ) { + ConditionsIOVPool* pool = m_rawPool[typ->type]; + if ( 0 == up.get() ) { + const void* argv[] = {this, pool, 0}; + UserPool* p = createPlugin<UserPool>(m_userType,m_lcdd,2,argv); + up.adopt(p); + } + return; + } + // Invalid IOV type. Throw exception + except("ConditionsManager","+++ Unknown IOV type requested to enable conditions. [%s]", + Errors::invalidArg().c_str()); +} + /// Clean conditions, which are above the age limit. -int ConditionsManagerObject_Type1::clean(const IOVType* typ, int max_age) { +int Manager_Type1::clean(const IOVType* typ, int max_age) { int count = 0; dd4hep_lock_t lock(m_updateLock); ConditionsIOVPool* pool = m_rawPool[typ->type]; @@ -310,7 +328,7 @@ int ConditionsManagerObject_Type1::clean(const IOVType* typ, int max_age) { } /// Full cleanup of all managed conditions. -pair<int,int> ConditionsManagerObject_Type1::clear() { +pair<int,int> Manager_Type1::clear() { pair<int,int> count(0,0); for( TypedConditionPool::iterator i=m_rawPool.begin(); i != m_rawPool.end(); ++i) { ConditionsIOVPool* p = *i; @@ -323,7 +341,7 @@ pair<int,int> ConditionsManagerObject_Type1::clear() { } /// Push all pending updates to the conditions store -void ConditionsManagerObject_Type1::pushUpdates() { +void Manager_Type1::pushUpdates() { Updates entries; { dd4hep_lock_t lock(m_updateLock); m_updatePool->popEntries(entries); @@ -342,82 +360,10 @@ void ConditionsManagerObject_Type1::pushUpdates() { } } -/// Helper to check iov and user pool and create user pool if not present -void ConditionsManagerObject_Type1::__get_checked_pool(const IOV& req_iov, - dd4hep_ptr<UserPool>& up) -{ - const IOVType* typ = check_iov_type<Discrete>(this, &req_iov); - if ( typ ) { - ConditionsIOVPool* pool = m_rawPool[typ->type]; - if ( 0 == up.get() ) { - const void* argv[] = {this, pool, 0}; - UserPool* p = createPlugin<UserPool>(m_userType,m_lcdd,2,argv); - up.adopt(p); - } - return; - } - // Invalid IOV type. Throw exception - except("ConditionsManager","+++ Unknown IOV type requested to enable conditions. [%s]", - Errors::invalidArg().c_str()); -} - -/// Prepare all updates for the given keys to the clients with the defined IOV -long ConditionsManagerObject_Type1::prepare(const IOV& req_iov, - const ConditionKeys& keys, - dd4hep_ptr<UserPool>& up) -{ - RC valid, expired; - __get_checked_pool(req_iov, up); - /// First push any pending updates and register them to pending pools... - pushUpdates(); - /// Now update/fill the user pool - return up->prepare(req_iov,keys); -} - - -/// Prepare all updates for the given keys to the clients with the defined IOV -long ConditionsManagerObject_Type1::prepare(const IOV& req_iov, - const ConditionKeys& keys, - dd4hep_ptr<UserPool>& up, - const Dependencies& dependencies, - bool verify_dependencies) -{ - long num_raw_updates = prepare(req_iov, keys, up); - if ( num_raw_updates > 0 || verify_dependencies ) { - long num_dep_updates = up->compute(dependencies); - return num_raw_updates+num_dep_updates; - } - return num_raw_updates; -} - -/// Prepare all updates to the clients with the defined IOV -long ConditionsManagerObject_Type1::prepare(const Condition::iov_type& req_iov, dd4hep_ptr<UserPool>& up) { - RC valid, expired; - __get_checked_pool(req_iov, up); - /// First push any pending updates and register them to pending pools... - pushUpdates(); - /// Now update/fill the user pool - return up->prepare(req_iov); -} - -/// Prepare all updates to the clients with the defined IOV -long ConditionsManagerObject_Type1::prepare(const Condition::iov_type& req_iov, - dd4hep_ptr<UserPool>& up, - const Dependencies& dependencies, - bool verify_dependencies) -{ - long num_raw_updates = prepare(req_iov, up); - if ( num_raw_updates > 0 || verify_dependencies ) { - long num_dep_updates = up->compute(dependencies); - return num_raw_updates+num_dep_updates; - } - return num_raw_updates; -} - /// Retrieve a condition set given a Detector Element and the conditions name according to their validity -bool ConditionsManagerObject_Type1::select(Condition::key_type key, - const Condition::iov_type& req_validity, - RangeConditions& conditions) { +bool Manager_Type1::select(Condition::key_type key, + const Condition::iov_type& req_validity, + RangeConditions& conditions) { { ConditionsIOVPool* p = 0; dd4hep_lock_t locked_action(m_poolLock); @@ -432,9 +378,9 @@ bool ConditionsManagerObject_Type1::select(Condition::key_type key, } /// Retrieve a condition set given a Detector Element and the conditions name according to their validity -bool ConditionsManagerObject_Type1::select_range(Condition::key_type key, - const Condition::iov_type& req_validity, - RangeConditions& conditions) +bool Manager_Type1::select_range(Condition::key_type key, + const Condition::iov_type& req_validity, + RangeConditions& conditions) { { ConditionsIOVPool* p = 0; @@ -451,14 +397,14 @@ bool ConditionsManagerObject_Type1::select_range(Condition::key_type key, /// Retrieve a condition given a Detector Element and the conditions name Condition -ConditionsManagerObject_Type1::get(Condition::key_type key, const Condition::iov_type& iov) +Manager_Type1::get(Condition::key_type key, const Condition::iov_type& iov) { RC conditions; __check_values__<Discrete>(this, key, &iov); bool rc = select(key, iov, conditions); if ( !rc ) { dd4hep_lock_t locked_load(m_updateLock); - m_loader->load(key, iov, conditions); + m_loader->load_single(key, iov, conditions); } if ( conditions.size() == 1 ) { conditions[0]->flags |= Condition::ACTIVE; @@ -486,7 +432,7 @@ ConditionsManagerObject_Type1::get(Condition::key_type key, const Condition::iov /// Retrieve a condition given a Detector Element and the conditions name RangeConditions -ConditionsManagerObject_Type1::getRange(Condition::key_type key, const Condition::iov_type& iov) +Manager_Type1::getRange(Condition::key_type key, const Condition::iov_type& iov) { RC conditions; __check_values__<Range>(this, key, &iov); @@ -499,14 +445,27 @@ ConditionsManagerObject_Type1::getRange(Condition::key_type key, const Condition m_loader->load_range(key, iov, conditions); if ( conditions.empty() ) { except("ConditionsManager","+++ Conditions %08X for IOV %s do not exist.", - key, iov.str().c_str()); + key, iov.str().c_str()); } conditions.clear(); } rc = select_range(key, iov, conditions); if ( !rc ) { except("ConditionsManager","+++ Conditions %08X for IOV %s do not exist.", - key, iov.str().c_str()); + key, iov.str().c_str()); } return conditions; } + +/// Prepare all updates for the given keys to the clients with the defined IOV +UserPool::Result +Manager_Type1::prepare(const IOV& req_iov, + ConditionsSlice& slice) +{ + dd4hep_ptr<UserPool>& up = slice.pool(); + __get_checked_pool(req_iov, up); + /// First push any pending updates and register them to pending pools... + pushUpdates(); + /// Now update/fill the user pool + return up->prepare(req_iov, slice); +} diff --git a/DDCond/src/plugins/ConditionsLinearPool.cpp b/DDCond/src/plugins/ConditionsLinearPool.cpp index 1407d0b43f6bfef35c95b0f832fdf41926d60c73..cdceec670137910c96641141efd5fa557ff2e79f 100644 --- a/DDCond/src/plugins/ConditionsLinearPool.cpp +++ b/DDCond/src/plugins/ConditionsLinearPool.cpp @@ -47,6 +47,12 @@ namespace DD4hep { typedef typename BASE::key_type key_type; Mapping m_entries; + /// Helper function to loop over the conditions container and apply a functor + template <typename R,typename T> size_t loop(R& result, T functor) { + size_t len = result.size(); + for_each(m_entries.begin(),m_entries.end(),functor); + return result.size() - len; + } public: /// Default constructor ConditionsLinearPool(ConditionsManager mgr); @@ -55,46 +61,45 @@ namespace DD4hep { virtual ~ConditionsLinearPool(); /// Total entry count - virtual size_t count() const { + virtual size_t size() const { return m_entries.size(); } /// Full cleanup of all managed conditions. virtual void clear() { - for_each(m_entries.begin(), m_entries.end(), ConditionsPoolRemove(*this)); + for_each(m_entries.begin(), m_entries.end(), Operators::poolRemove(*this)); m_entries.clear(); } /// Check if a condition exists in the pool virtual Condition exists(Condition::key_type key) const { - typename Mapping::const_iterator i= - find_if(m_entries.begin(), m_entries.end(), HashConditionFind(key)); + auto i = find_if(m_entries.begin(), m_entries.end(), Operators::keyFind(key)); return i==m_entries.end() ? Condition() : (*i); } /// Register a new condition to this pool - virtual void insert(Condition condition) - { m_entries.insert(m_entries.end(),condition.access()); } + virtual bool insert(Condition condition) + { m_entries.insert(m_entries.end(),condition.access()); return true; } /// Register a new condition to this pool. May overload for performance reasons. - virtual void insert(RangeConditions& new_entries) - { for_each(new_entries.begin(), new_entries.end(), collectionSelect(m_entries)); } + virtual void insert(RangeConditions& rc) + { for_each(rc.begin(), rc.end(), Operators::sequenceSelect(m_entries)); } /// Select the conditions matching the DetElement and the conditions name - virtual void select(Condition::key_type key, RangeConditions& result) - { for_each(m_entries.begin(), m_entries.end(), keyedSelect(key, result)); } + virtual size_t select(Condition::key_type key, RangeConditions& result) + { return loop(result, Operators::keyedSelect(key, result)); } /// Select the conditons, used also by the DetElement of the condition - virtual void select_used(RangeConditions& result) - { for_each(m_entries.begin(), m_entries.end(), activeSelect(result)); } + virtual size_t select_all(const ConditionsSelect& result) + { return loop(result, Operators::operatorWrapper(result)); } /// Select the conditons, used also by the DetElement of the condition - virtual void select_all(RangeConditions& result) - { for_each(m_entries.begin(), m_entries.end(), collectionSelect(result)); } + virtual size_t select_all(RangeConditions& result) + { return loop(result, Operators::sequenceSelect(result)); } /// Select the conditons, used also by the DetElement of the condition - virtual void select_all(ConditionsPool& selection_pool) - { for_each(m_entries.begin(), m_entries.end(), ConditionsPoolInsert(selection_pool)); } + virtual size_t select_all(ConditionsPool& result) + { return loop(result, Operators::poolSelect(result)); } }; /// Class implementing the conditions update pool for a given IOV type @@ -119,8 +124,9 @@ namespace DD4hep { virtual ~ConditionsLinearUpdatePool() {} /// Adopt all entries sorted by IOV. Entries will be removed from the pool - virtual void popEntries(UpdatePool::UpdateEntries& entries) { + virtual size_t popEntries(UpdatePool::UpdateEntries& entries) { MAPPING& m = this->ConditionsLinearPool<MAPPING,BASE>::m_entries; + size_t len = entries.size(); if ( !m.empty() ) { for(typename MAPPING::iterator i=m.begin(); i!=m.end(); ++i) { Condition::Object* o = *i; @@ -128,6 +134,7 @@ namespace DD4hep { } m.clear(); } + return entries.size()-len; } /// Select the conditions matching the DetElement and the conditions name diff --git a/DDCond/src/plugins/ConditionsMappedPool.cpp b/DDCond/src/plugins/ConditionsMappedPool.cpp index 5b66ae171980ccdfe1733f9e889b67acc0eb7773..28c6a5425e3c7f92ee5e75250ac1641cc6e6fb4f 100644 --- a/DDCond/src/plugins/ConditionsMappedPool.cpp +++ b/DDCond/src/plugins/ConditionsMappedPool.cpp @@ -46,8 +46,16 @@ namespace DD4hep { protected: typedef BASE Base; typedef MAPPING Mapping; + typedef ConditionsMappedPool<Mapping,Base> Self; typedef typename BASE::key_type key_type; Mapping m_entries; + + /// Helper function to loop over the conditions container and apply a functor + template <typename R,typename T> size_t loop(R& result, T functor) { + size_t len = result.size(); + for_each(m_entries.begin(),m_entries.end(),functor); + return result.size() - len; + } public: /// Default constructor ConditionsMappedPool(ConditionsManager mgr); @@ -56,51 +64,52 @@ namespace DD4hep { virtual ~ConditionsMappedPool(); /// Total entry count - virtual size_t count() const { + virtual size_t size() const { return m_entries.size(); } /// Register a new condition to this pool - virtual void insert(Condition condition) { + virtual bool insert(Condition condition) { Condition::Object* c = condition.access(); - m_entries.insert(std::make_pair(c->hash,c)); + return m_entries.insert(std::make_pair(c->hash,c)).second; } /// Register a new condition to this pool. May overload for performance reasons. virtual void insert(RangeConditions& new_entries) { - for(RangeConditions::iterator i=new_entries.begin(); i!=new_entries.end(); ++i) { - Condition::Object* c = (*i).access(); - m_entries.insert(std::make_pair(c->hash,c)); + Condition::Object* o; + for( Condition c : new_entries ) { + o = c.access(); + m_entries.insert(std::make_pair(o->hash,o)); } } /// Full cleanup of all managed conditions. virtual void clear() { - for_each(m_entries.begin(), m_entries.end(), ConditionsPoolRemove(*this)); + for_each(m_entries.begin(), m_entries.end(), Operators::poolRemove(*this)); m_entries.clear(); } /// Check if a condition exists in the pool virtual Condition exists(Condition::key_type key) const { - typename Mapping::const_iterator i= - find_if(m_entries.begin(), m_entries.end(), HashConditionFind(key)); + auto i=find_if(m_entries.begin(), m_entries.end(), Operators::keyFind(key)); return i==m_entries.end() ? Condition() : (*i).second; } + /// Select the conditions matching the DetElement and the conditions name - virtual void select(Condition::key_type key, RangeConditions& result) - { for_each(m_entries.begin(),m_entries.end(),keyedSelect(key,result)); } + virtual size_t select(Condition::key_type key, RangeConditions& result) + { return loop(result, Operators::keyedSelect(key,result)); } /// Select the conditons, used also by the DetElement of the condition - virtual void select_used(RangeConditions& result) - { for_each(m_entries.begin(),m_entries.end(),activeSelect(result)); } + virtual size_t select_all(const ConditionsSelect& result) + { return loop(result, Operators::operatorWrapper(result)); } /// Select the conditons, used also by the DetElement of the condition - virtual void select_all(RangeConditions& result) - { for_each(m_entries.begin(),m_entries.end(),collectionSelect(result)); } + virtual size_t select_all(RangeConditions& result) + { return loop(result, Operators::sequenceSelect(result)); } /// Select the conditons, used also by the DetElement of the condition - virtual void select_all(ConditionsPool& selection_pool) - { for_each(m_entries.begin(),m_entries.end(),ConditionsPoolInsert(selection_pool)); } + virtual size_t select_all(ConditionsPool& result) + { return loop(result, Operators::poolSelect(result)); } }; /// Class implementing the conditions update pool for a given IOV type @@ -113,27 +122,34 @@ namespace DD4hep { template<typename MAPPING, typename BASE> class ConditionsMappedUpdatePool : public ConditionsMappedPool<MAPPING,BASE> { + typedef ConditionsMappedPool<MAPPING,BASE> Self; typedef typename ConditionsMappedPool<MAPPING,BASE>::key_type key_type; public: /// Default constructor ConditionsMappedUpdatePool(ConditionsManager mgr) - : ConditionsMappedPool<MAPPING,BASE>(mgr) - { - } + : ConditionsMappedPool<MAPPING,BASE>(mgr) { } /// Default destructor - virtual ~ConditionsMappedUpdatePool() {} + virtual ~ConditionsMappedUpdatePool() { } /// Adopt all entries sorted by IOV. Entries will be removed from the pool - virtual void popEntries(UpdatePool::UpdateEntries& entries) { + virtual size_t popEntries(UpdatePool::UpdateEntries& entries) { + ClearOnReturn<MAPPING> clear(this->Self::m_entries); + return this->Self::loop(entries, [&entries](const std::pair<key_type,Condition::Object*>& o) { + entries[o.second->iov].push_back(Condition(o.second));}); +#if 0 MAPPING& m = this->ConditionsMappedPool<MAPPING,BASE>::m_entries; + size_t len = entries.size(); + size_t len = m.size(); if ( !m.empty() ) { for(typename MAPPING::iterator i=m.begin(); i!=m.end(); ++i) { Condition::Object* o = (*i).second; entries[o->iov].push_back(Condition(o)); } - m.clear(); + m.clear(); } + return len; +#endif } /// Select the conditions matching the DetElement and the conditions name @@ -141,6 +157,8 @@ namespace DD4hep { const Condition::iov_type& req, RangeConditions& result) { + //return this->Self::loop(entries, [&entries](const std::pair<key_type,Condition::Object*>& o) { + // entries[o.second->iov].push_back(Condition(o.second));}); MAPPING& m = this->ConditionsMappedPool<MAPPING,BASE>::m_entries; if ( !m.empty() ) { unsigned int req_typ = req.iovType ? req.iovType->type : req.type; @@ -166,11 +184,9 @@ namespace DD4hep { } } }; - - - } /* End namespace Conditions */ -} /* End namespace DD4hep */ -#endif // DDCOND_CONDITIONSMAPPEDPOOL_H + } /* End namespace Conditions */ +} /* End namespace DD4hep */ +#endif /* DDCOND_CONDITIONSMAPPEDPOOL_H */ //========================================================================== // AIDA Detector description implementation for LCD diff --git a/DDCond/src/plugins/ConditionsMultiLoader.cpp b/DDCond/src/plugins/ConditionsMultiLoader.cpp index 65738ad12061f81dd9bf96bc82a1f5781cf217bf..76dd9ce0bed87758912eb2e69b13d29d14364fd2 100644 --- a/DDCond/src/plugins/ConditionsMultiLoader.cpp +++ b/DDCond/src/plugins/ConditionsMultiLoader.cpp @@ -17,6 +17,7 @@ // Framework include files #include "DDCond/ConditionsDataLoader.h" +#include "DD4hep/Printout.h" /// Namespace for the AIDA detector description toolkit namespace DD4hep { @@ -47,22 +48,27 @@ namespace DD4hep { /// Default destructor virtual ~ConditionsMultiLoader(); /// Load a condition set given a Detector Element and the conditions name according to their validity - virtual size_t load(key_type key, - const iov_type& req_validity, - RangeConditions& conditions); + virtual size_t load_single(key_type key, + const iov_type& req_validity, + RangeConditions& conditions); /// Load a condition set given a Detector Element and the conditions name according to their validity - virtual size_t load_range(key_type key, - const iov_type& req_validity, - RangeConditions& conditions); - /// Update a range of conditions according to the required IOV - virtual size_t update(const iov_type& req_validity, - RangeConditions& conditions, - iov_type& conditions_validity); + virtual size_t load_range( key_type key, + const iov_type& req_validity, + RangeConditions& conditions); + /// Optimized update using conditions slice data + virtual size_t load_many( const iov_type& /* req_validity */, + EntryVector& /* work */, + EntryVector& /* loaded */, + EntryVector& /* missing */, + iov_type& /* conditions_validity */) + { + except("ConditionsLoader","+++ update: Invalid call!"); + return 0; + } }; - } /* End namespace Geometry */ -} /* End namespace DD4hep */ - -#endif /* DD4HEP_CONDITIONS_MULTICONDITONSLOADER_H */ + } /* End namespace Geometry */ +} /* End namespace DD4hep */ +#endif /* DD4HEP_CONDITIONS_MULTICONDITONSLOADER_H */ // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- @@ -155,7 +161,7 @@ size_t ConditionsMultiLoader::load_range(key_type key, if ( IOV::key_partially_contained(iov.keyData,req_validity.keyData) ) { const string& nam = (*i).first; ConditionsDataLoader* loader = load_source(nam, req_validity); - loader->load(key, req_validity, conditions); + loader->load_range(key, req_validity, conditions); } } } @@ -163,9 +169,9 @@ size_t ConditionsMultiLoader::load_range(key_type key, } -size_t ConditionsMultiLoader::load(key_type key, - const iov_type& req_validity, - RangeConditions& conditions) +size_t ConditionsMultiLoader::load_single(key_type key, + const iov_type& req_validity, + RangeConditions& conditions) { size_t len = conditions.size(); // No better idea: Must chack all sources to find the required condition @@ -175,31 +181,9 @@ size_t ConditionsMultiLoader::load(key_type key, if ( IOV::key_partially_contained(iov.keyData,req_validity.keyData) ) { const string& nam = (*i).first; ConditionsDataLoader* loader = load_source(nam, req_validity); - loader->load(key, req_validity, conditions); + loader->load_single(key, req_validity, conditions); } } } return conditions.size() - len; } - -/// Update a range of conditions according to the required IOV -size_t ConditionsMultiLoader::update(const iov_type& req_validity, - RangeConditions& conditions, - iov_type& conditions_validity) -{ - RangeConditions upda; - for(RangeConditions::const_iterator i=conditions.begin(); i!=conditions.end(); ++i) { - Condition::Object* cond = (*i).ptr(); - size_t items = load(cond->hash,req_validity,upda); - if ( items < 1 ) { - // Error: no such condition - except("MultiLoader", - "+++ update_expired: Cannot update condition %s [%s] to iov:%s.", - cond->name.c_str(), cond->iov->str().c_str(), req_validity.str().c_str()); - } - } - conditions = upda; - for(RangeConditions::const_iterator i=conditions.begin(); i!=conditions.end(); ++i) - conditions_validity.iov_intersection((*i).iov()); - return conditions.size(); -} diff --git a/DDCond/src/plugins/ConditionsPlugins.cpp b/DDCond/src/plugins/ConditionsPlugins.cpp index 91f1318aa5e44667652d405e1c0e269489cde6ff..b58d955aac45e9088116f6a7bc8e009beb626508 100644 --- a/DDCond/src/plugins/ConditionsPlugins.cpp +++ b/DDCond/src/plugins/ConditionsPlugins.cpp @@ -20,13 +20,13 @@ #include "DD4hep/DetFactoryHelper.h" #include "DD4hep/ConditionsPrinter.h" #include "DD4hep/DetectorProcessor.h" -#include "DD4hep/objects/ConditionsInterna.h" +#include "DDCond/ConditionsPool.h" +#include "DDCond/ConditionsSlice.h" #include "DDCond/ConditionsManager.h" -#include "DDCond/ConditionsManagerObject.h" #include "DDCond/ConditionsIOVPool.h" -#include "DDCond/ConditionsPool.h" #include "DDCond/ConditionsRepository.h" +#include "DDCond/ConditionsManagerObject.h" using namespace std; using namespace DD4hep; @@ -92,6 +92,41 @@ static int ddcond_install_cond_mgr (LCDD& lcdd, int argc, char** argv) { } DECLARE_APPLY(DD4hep_ConditionsManagerInstaller,ddcond_install_cond_mgr) +/** + * Prepare the conditions manager for execution + * + * \author M.Frank + * \version 1.0 + * \date 01/04/2016 + */ +static ConditionsSlice* ddcond_prepare(lcdd_t& lcdd, const string& iov_typ, long iov_val, int argc, char** argv) { + const IOVType* iovtype = 0; + long iovvalue = iov_val; + ConditionsManager manager = ConditionsManager::from(lcdd); + + for(int i=0; i<argc; ++i) { + if ( ::strncmp(argv[i],"-iov_type",7) == 0 ) + iovtype = manager.iovType(argv[++i]); + else if ( ::strncmp(argv[i],"-iov_value",7) == 0 ) + iovvalue = ::atol(argv[++i]); + } + if ( 0 == iovtype ) + iovtype = manager.iovType(iov_typ); + if ( 0 == iovtype ) + except("ConditionsPrepare","++ Unknown IOV type supplied."); + if ( 0 > iovvalue ) + except("ConditionsPrepare", + "++ Unknown IOV value supplied for iov type %s.",iovtype->str().c_str()); + + IOV iov(iovtype,iovvalue); + dd4hep_ptr<ConditionsSlice> slice(Conditions::createSlice(manager,*iovtype)); + manager.prepare(iov, *slice); + printout(INFO,"Conditions", + "+++ ConditionsUpdate: Collected %ld conditions of type %s [iov-value:%ld].", + long(slice->size()), iovtype ? iovtype->str().c_str() : "???", iovvalue); + return slice.release(); +} + // ====================================================================================== /// Plugin function: Dump of all Conditions pool with or without conditions /** @@ -189,32 +224,21 @@ DECLARE_APPLY(DD4hep_ConditionsDump,ddcond_dump_conditions) * \version 1.0 * \date 01/04/2016 */ -static int ddcond_detelement_dump(LCDD& lcdd, int /* argc */, char** /* argv */) { +static int ddcond_detelement_dump(LCDD& lcdd, int argc, char** argv) { + /// Internal class to perform recursive printout + /* + * \author M.Frank + * \version 1.0 + * \date 01/12/2016 + */ struct Actor : public Geometry::DetectorProcessor { - ConditionsManager manager; - ConditionsPrinter printer; - dd4hep_ptr<UserPool> user_pool; - const IOVType* iov_type; - + /// Object printer object + ConditionsPrinter printer; /// Standard constructor - Actor(ConditionsManager m) : manager(m) { - iov_type = manager.iovType("run"); - IOV iov(iov_type); - iov.set(1500); - long num_updated = manager.prepare(iov, user_pool); - printout(INFO,"Conditions", - "+++ ConditionsUpdate: Updated %ld conditions of type %s.", - num_updated, iov_type ? iov_type->str().c_str() : "???"); - user_pool->print("User pool"); - printer.setPool(user_pool.get()); - } + Actor() { } /// Default destructor - virtual ~Actor() { - manager.clean(iov_type, 20); - user_pool->clear(); - user_pool.release(); - } + virtual ~Actor() { } /// Dump method. virtual int operator()(DetElement de,int level) { const DetElement::Children& children = de.children(); @@ -231,8 +255,14 @@ static int ddcond_detelement_dump(LCDD& lcdd, int /* argc */, char** /* argv */) } return 1; } - }; - return Actor(ConditionsManager::from(lcdd)).process(lcdd.world(),0,true); + } actor; + dd4hep_ptr<ConditionsSlice> slice(ddcond_prepare(lcdd,"run",1500,argc,argv)); + UserPool* pool = slice->pool().get(); + pool->print("User pool"); + actor.printer.setPool(pool); + int ret = actor.process(lcdd.world(),0,true); + slice->manager.clean(slice->iov().iovType, 20); + return ret; } DECLARE_APPLY(DD4hep_DetElementConditionsDump,ddcond_detelement_dump) @@ -245,34 +275,12 @@ DECLARE_APPLY(DD4hep_DetElementConditionsDump,ddcond_detelement_dump) * \version 1.0 * \date 01/04/2016 */ -static void* ddcond_prepare(LCDD& lcdd, int argc, char** argv) { - long iov_val = -1; - const IOVType* iov_typ = 0; - ConditionsManager manager = ConditionsManager::from(lcdd); - - for(int i=0; i<argc; ++i) { - if ( ::strncmp(argv[i],"-iov_type",7) == 0 ) - iov_typ = manager.iovType(argv[++i]); - else if ( ::strncmp(argv[i],"-iov_value",7) == 0 ) - iov_val = ::atol(argv[++i]); - } - if ( 0 == iov_typ ) { - except("ConditionsPrepare","++ Unknown IOV type supplied."); - } - if ( 0 > iov_val ) { - except("ConditionsPrepare", - "++ Unknown IOV value supplied for iov type %s.",iov_typ->str().c_str()); - } - dd4hep_ptr<UserPool> user_pool; - IOV iov(iov_typ); - iov.set(iov_val); - long num_updated = manager.prepare(iov, user_pool); - printout(DEBUG,"Conditions", - "+++ ConditionsUpdate: Updated %ld conditions of type %s.", - num_updated, iov_typ ? iov_typ->str().c_str() : "???"); - return user_pool.get() && user_pool->count() > 0 ? user_pool.release() : 0; +static void* ddcond_prepare_plugin(LCDD& lcdd, int argc, char** argv) { + dd4hep_ptr<ConditionsSlice> slice(ddcond_prepare(lcdd,"",-1,argc,argv)); + UserPool* p = slice->pool().get(); + return p && p->size() > 0 ? slice.release() : 0; } -DECLARE_LCDD_CONSTRUCTOR(DD4hep_ConditionsPrepare,ddcond_prepare) +DECLARE_LCDD_CONSTRUCTOR(DD4hep_ConditionsPrepare,ddcond_prepare_plugin) // ====================================================================================== /// Plugin function: Dump of all Conditions associated to the detector elements @@ -285,39 +293,21 @@ DECLARE_LCDD_CONSTRUCTOR(DD4hep_ConditionsPrepare,ddcond_prepare) */ static int ddcond_detelement_processor(LCDD& lcdd, int argc, char** argv) { + /// Internal class to perform recursive printout + /* + * \author M.Frank + * \version 1.0 + * \date 01/12/2016 + */ struct Actor : public Geometry::DetElementProcessor<ConditionsProcessor> { - ConditionsManager manager; - dd4hep_ptr<UserPool> user_pool; - const IOVType* iov_type; - /// Standard constructor - Actor(ConditionsProcessor* p, ConditionsManager m) - : DetElementProcessor<ConditionsProcessor>(p), manager(m) - { - iov_type = manager.iovType("run"); - IOV iov(iov_type); - iov.set(1500); - long num_updated = manager.prepare(iov, user_pool); - printout(INFO,"Conditions", - "+++ ConditionsUpdate: Updated %ld conditions of type %s.", - num_updated, iov_type ? iov_type->str().c_str() : "???"); - user_pool->print("User pool"); - processor->setPool(user_pool.get()); - } + Actor(ConditionsProcessor* p) : DetElementProcessor<ConditionsProcessor>(p){} /// Default destructor - virtual ~Actor() { - manager.clean(iov_type, 20); - user_pool->clear(); - user_pool.release(); - } + virtual ~Actor() { } /// Dump method. - virtual int operator()(DetElement de, int) { - if ( de.hasConditions() ) { - return processor->processElement(de); - } - return 1; - } + virtual int operator()(DetElement de, int) + { return de.hasConditions() ? processor->processElement(de) : 1; } }; ConditionsProcessor* processor = 0; if ( argc > 0 ) { @@ -327,7 +317,14 @@ static int ddcond_detelement_processor(LCDD& lcdd, int argc, char** argv) { const void* args[] = { "-processor", "DD4hepConditionsPrinter", 0}; processor = createProcessor<ConditionsProcessor>(lcdd, 2, (char**)args); } - return Actor(processor,ConditionsManager::from(lcdd)).process(lcdd.world(),0,true); + dd4hep_ptr<ConditionsSlice> slice(ddcond_prepare(lcdd,"run",1500,argc,argv)); + UserPool* pool = slice->pool().get(); + Actor actor(processor); + pool->print("User pool"); + processor->setPool(pool); + int ret = Actor(processor).process(lcdd.world(),0,true); + slice->manager.clean(pool->validity().iovType, 20); + return ret; } DECLARE_APPLY(DD4hep_DetElementConditionsProcessor,ddcond_detelement_processor) @@ -342,31 +339,13 @@ DECLARE_APPLY(DD4hep_DetElementConditionsProcessor,ddcond_detelement_processor) */ static long ddcond_synchronize_conditions(lcdd_t& lcdd, int argc, char** argv) { if ( argc >= 2 ) { - string iov_type = argv[0]; + string iov_typ = argv[0]; IOV::Key::first_type iov_key = *(IOV::Key::first_type*)argv[1]; - ConditionsManager manager = ConditionsManager::from(lcdd); - const IOVType* epoch = manager.iovType(iov_type); - dd4hep_ptr<UserPool> user_pool; - IOV iov(epoch); - - iov.set(iov_key); - long num_updated = manager.prepare(iov, user_pool); - if ( iov_type == "epoch" ) { - char c_evt[64]; - struct tm evt; - ::gmtime_r(&iov_key, &evt); - ::strftime(c_evt,sizeof(c_evt),"%T %F",&evt); - printout(INFO,"Conditions", - "+++ ConditionsUpdate: Updated %ld conditions... event time: %s", - num_updated, c_evt); - } - else { - printout(INFO,"Conditions","+++ ConditionsUpdate: Updated %ld conditions... key[%s]: %ld", - num_updated, iov_type.c_str(), iov_key); - } - user_pool->print("User pool"); - manager.clean(epoch, 20); - user_pool->clear(); + dd4hep_ptr<ConditionsSlice> slice(ddcond_prepare(lcdd,iov_typ,iov_key,argc,argv)); + UserPool* pool = slice->pool().get(); + pool->print("User pool"); + slice->manager.clean(pool->validity().iovType, 20); + pool->clear(); return 1; } except("Conditions","+++ Failed update conditions. Arguments were: '%s'", @@ -387,13 +366,13 @@ DECLARE_APPLY(DD4hep_ConditionsSynchronize,ddcond_synchronize_conditions) static long ddcond_clean_conditions(lcdd_t& lcdd, int argc, char** argv) { if ( argc > 0 ) { string iov_type = argv[0]; - int max_age = *(int*)argv[1]; + int max_age = *(int*)argv[1]; printout(INFO,"Conditions", "+++ ConditionsUpdate: Cleaning conditions... type:%s max age:%d", iov_type.c_str(), max_age); ConditionsManager manager = ConditionsManager::from(lcdd); - const IOVType* epoch = manager.iovType(iov_type); - manager.clean(epoch, max_age); + const IOVType* iov_typ = manager.iovType(iov_type); + manager.clean(iov_typ, max_age); return 1; } except("Conditions","+++ Failed cleaning conditions. Insufficient arguments!"); @@ -432,7 +411,9 @@ static void* create_printer(Geometry::LCDD& lcdd, int argc,char** argv) { /// Help printout describing the basic command line interface cout << "Usage: -plugin <name> -arg [-arg] \n" - " name: factory name DD4hep_ConditionsPrinter, DD4hep_AlignmentsPrinter\n\n" + " name: factory name(s) DD4hep_ConditionsPrinter, \n" + " DD4hep_AlignmentsPrinter \n" + " DD4hep_AlignedVolumePrinter \n" " -prefix <string> Printout prefix for user customized output. \n" " -flags <number> Printout processing flags. \n" " -pool Attach conditions user pool from \n" diff --git a/DDCond/src/plugins/ConditionsRepositoryParser.cpp b/DDCond/src/plugins/ConditionsRepositoryParser.cpp index 9f9f5b4668945511ba416dbeb9db9be651348d96..db7bfef90e2ba7bb6e14a39dfdb8cb9ae4873d32 100644 --- a/DDCond/src/plugins/ConditionsRepositoryParser.cpp +++ b/DDCond/src/plugins/ConditionsRepositoryParser.cpp @@ -23,6 +23,7 @@ #include "DD4hep/OpaqueDataBinder.h" #include "DD4hep/ConditionsKeyAssign.h" #include "DD4hep/DetFactoryHelper.h" +#include "DD4hep/objects/ConditionsInterna.h" #include "DDCond/ConditionsTags.h" #include "DDCond/ConditionsManager.h" diff --git a/DDCond/src/plugins/ConditionsUserPool.cpp b/DDCond/src/plugins/ConditionsUserPool.cpp index bb1c21fd8e7120c4de936748fd4b36584393afd7..5120172bcf0a0aa9d41e1b46e8f17316c55c3403 100644 --- a/DDCond/src/plugins/ConditionsUserPool.cpp +++ b/DDCond/src/plugins/ConditionsUserPool.cpp @@ -45,9 +45,17 @@ namespace DD4hep { class ConditionsMappedUserPool : public UserPool { typedef MAPPING Mapping; Mapping m_conditions; - ConditionsDataLoader* m_loader; + /// IOV Pool as data source + ConditionsIOVPool* m_iovPool = 0; + /// The loader to access non-existing conditions + ConditionsDataLoader* m_loader = 0; + + /// Internal helper to find conditions Condition::Object* i_findCondition(key_type key) const; + /// Internal insertion helper + bool i_insert(Condition::Object* o); + public: /// Default constructor ConditionsMappedUserPool(ConditionsManager mgr, ConditionsIOVPool* pool); @@ -56,7 +64,7 @@ namespace DD4hep { /// Print pool content virtual void print(const std::string& opt) const; /// Total entry count - virtual size_t count() const; + virtual size_t size() const; /// Full cleanup of all managed conditions. virtual void clear(); /// Check a condition for existence @@ -74,11 +82,18 @@ namespace DD4hep { /// Register a new condition to this pool virtual bool insert(Condition cond); /// Prepare user pool for usage (load, fill etc.) according to required IOV - virtual long prepare(const IOV& required); + virtual Result prepare(const IOV& required, + ConditionsSlice& slice, + void* user_param) { + return prepare_VSN_1(required, slice, user_param); + } /// Prepare user pool for usage (load, fill etc.) according to required IOV - virtual long prepare(const IOV& required, const ConditionKeys& keys); + Result prepare_VSN_1(const IOV& required, + ConditionsSlice& slice, + void* user_param); /// Evaluate and register all derived conditions from the dependency list - virtual long compute(const Dependencies& dependencies, void* user_param); + virtual size_t compute(const Dependencies& dependencies, + void* user_param); }; } /* End namespace Conditions */ } /* End namespace DD4hep */ @@ -109,32 +124,76 @@ namespace DD4hep { #include "DDCond/ConditionsManagerObject.h" #include "DDCond/ConditionsDependencyHandler.h" -using namespace DD4hep::Conditions; using namespace std; +using namespace DD4hep; +using namespace DD4hep::Conditions; namespace { - template <typename T> struct Inserter { + + template <typename T> struct MapSelector : public ConditionsSelect { T& m; - Inserter(T& o) : m(o) {} + MapSelector(T& o) : m(o) {} + bool operator()(Condition::Object* o) const + { return m.insert(make_pair(o->hash,o)).second; } + }; + template <typename T> MapSelector<T> mapSelector(T& container) + { return MapSelector<T>(container); } + + template <typename T> struct MapInserter { + T& m; + MapInserter(T& o) : m(o) {} void operator()(Condition& c) { Condition::Object* o = c.ptr(); m.insert(make_pair(o->hash,o)); } + void operator()(ConditionsSlice::Entry* e) { (*this)(e->condition); } + }; + template <typename T> MapInserter<T> mapInsert(T& container) + { return MapInserter<T>(container); } + + template <typename T> struct Inserter { + T& m; + IOV* iov; + Inserter(T& o, IOV* i=0) : m(o), iov(i) {} + void operator()(const Condition& c) { + Condition::Object* o = c.ptr(); + m.insert(make_pair(o->hash,o)); + if ( iov ) iov->iov_intersection(o->iov->key()); + } + void operator()(ConditionsSlice::Entry* e) { (*this)(e->condition); } + void operator()(const pair<Condition::key_type,ConditionsSlice::Entry*>& e) + { (*this)(e.second->condition); } + }; + template <typename T> struct Updater { + T& m; + IOV* iov; + Updater(T& o, IOV* i=0) : m(o), iov(i) {} + void operator()(Condition& c) { + Condition::Object* o = c.ptr(); + typename T::iterator i=m.find(o->hash); + (*i).second = o; + if ( iov ) iov->iov_intersection(o->iov->key()); + } + void operator()(ConditionsSlice::Entry* e) { (*this)(e->condition); } }; } /// Default constructor template<typename MAPPING> ConditionsMappedUserPool<MAPPING>::ConditionsMappedUserPool(ConditionsManager mgr, ConditionsIOVPool* pool) - : UserPool(mgr, pool) + : UserPool(mgr), m_iovPool(pool) { InstanceCount::increment(this); if ( mgr.isValid() ) { - m_loader = mgr->loader(); - if ( m_loader ) return; - except("UserPool","The conditions manager is not properly setup. No conditions loader present."); + if ( m_iovPool ) { + m_iov.iovType = m_iovPool->type; + m_loader = mgr->loader(); + if ( m_loader ) return; + except("UserPool","The conditions manager is not properly setup. No conditions loader present."); + } + except("UserPool","FAILED to create mapped user pool. [Invalid IOV pool]"); } - except("UserPool","FAILED to create user pool. [Invalid conditions manager]"); + except("UserPool","FAILED to create mapped user pool. [Invalid conditions manager]"); } /// Default destructor @@ -155,9 +214,14 @@ ConditionsMappedUserPool<MAPPING>::i_findCondition(key_type key) const { return i != m_conditions.end() ? (*i).second : 0; } +template<typename MAPPING> inline bool +ConditionsMappedUserPool<MAPPING>::i_insert(Condition::Object* o) { + return m_conditions.insert(make_pair(o->hash,o)).second; +} + /// Total entry count template<typename MAPPING> -size_t ConditionsMappedUserPool<MAPPING>::count() const { +size_t ConditionsMappedUserPool<MAPPING>::size() const { return m_conditions.size(); } @@ -166,7 +230,7 @@ template<typename MAPPING> void ConditionsMappedUserPool<MAPPING>::print(const std::string& opt) const { const IOV* iov = &m_iov; printout(INFO,"UserPool","+++ %s Conditions for USER pool with IOV: %-32s [%4d entries]", - opt.c_str(), iov->str().c_str(), count()); + opt.c_str(), iov->str().c_str(), size()); if ( opt == "*" ) { for( const auto& i : m_conditions ) { Condition c = i.second; @@ -209,8 +273,11 @@ Condition ConditionsMappedUserPool<MAPPING>::get(const ConditionKey& key) const /// Register a new condition to this pool template<typename MAPPING> bool ConditionsMappedUserPool<MAPPING>::insert(Condition cond) { - Condition::Object* o = cond.ptr(); - return m_conditions.insert(make_pair(o->hash,o)).second; + bool result = i_insert(cond.ptr()); + //printout(INFO,"UserPool","++ INSERT: %08X Name:%s",cond->hash, cond.name()); + if ( result ) return true; + except("UserPool","++ Attempt to double insert condition: %s", cond.name()); + return false; } /// Remove condition by key from pool. @@ -222,7 +289,7 @@ bool ConditionsMappedUserPool<MAPPING>::remove(const ConditionKey& key) { /// Remove condition by key from pool. template<typename MAPPING> bool ConditionsMappedUserPool<MAPPING>::remove(key_type hash_key) { - typename MAPPING::iterator i=m_conditions.find(hash_key); + typename MAPPING::iterator i = m_conditions.find(hash_key); if ( i != m_conditions.end() ) { m_conditions.erase(i); return true; @@ -230,84 +297,127 @@ bool ConditionsMappedUserPool<MAPPING>::remove(key_type hash_key) { return false; } -/// Prepare user pool for usage (load, fill etc.) according to required IOV -template<typename MAPPING> -long ConditionsMappedUserPool<MAPPING>::prepare(const IOV& required) { - if ( m_iovPool ) { - RangeConditions valid, expired; - IOV pool_iov(required.iovType); - pool_iov.reset().invert(); - m_iovPool->select(required, valid, expired, pool_iov); - clear(); - for_each(valid.begin(),valid.end(),Inserter<MAPPING>(m_conditions)); - long num_expired = (long)expired.size(); - if ( num_expired > 0 ) { - m_loader->update(required, expired, pool_iov); - for_each(expired.begin(),expired.end(),Inserter<MAPPING>(m_conditions)); - } - m_iov = pool_iov; - return num_expired; - } - DD4hep::except("UserPool","++ Invalid reference to iov pool! [Internal Error]"); - return -1; -} - -/// Prepare user pool for usage (load, fill etc.) according to required IOV -template<typename MAPPING> -long ConditionsMappedUserPool<MAPPING>::prepare(const IOV& required, const ConditionKeys& keys) { - long num_expired = prepare(required); // Update all what is present! Re-use pre-cond checking! - if ( !keys.empty() ) { - for ( const auto& k : keys ) { // Now load all keys, which are not present - typename MAPPING::const_iterator i=m_conditions.find(k.hash); - if ( i == m_conditions.end() ) { - RangeConditions loaded; - m_loader->load(k.hash, required, loaded); - if ( loaded.empty() ) { - DD4hep::except("UserPool","++ Failed to load condition: %s",k.name.c_str()); - } - for_each(loaded.begin(),loaded.end(),Inserter<MAPPING>(m_conditions)); - } - } - } - return num_expired; -} - /// Evaluate and register all derived conditions from the dependency list template<typename MAPPING> -long ConditionsMappedUserPool<MAPPING>::compute(const Dependencies& deps, void* user_param) { - long num_updates = 0; +size_t ConditionsMappedUserPool<MAPPING>::compute(const Dependencies& deps, + void* user_param) +{ + size_t num_updates = 0; if ( !deps.empty() ) { - ConditionsManagerObject* m = m_manager.access(); - ConditionsDependencyHandler handler(m, *this, deps, user_param); - ConditionsPool* pool = m->registerIOV(*m_iov.iovType, m_iov.keyData); + vector<const ConditionDependency*> missing; // Loop over the dependencies and check if they have to be upgraded + missing.reserve(deps.size()); for ( const auto& i : deps ) { typename MAPPING::iterator j = m_conditions.find(i.first); if ( j != m_conditions.end() ) { - Condition::Object* cond = (*j).second; - if ( IOV::key_is_contained(m_iov.keyData,cond->iov->keyData) ) - continue; - /// This condition is no longer valid. remove it! Will be added again afterwards. - m_conditions.erase(j); + Condition::Object* c = (*j).second; + // Remeber: key ist first, test is second! + if ( IOV::key_is_contained(m_iov.keyData,c->iov->keyData) ) { + /// This condition is no longer valid. remove it! + /// This condition will be added again by the handler. + m_conditions.erase(j); + missing.push_back(i.second.get()); + } + continue; + } + missing.push_back(i.second.get()); + } + if ( !missing.empty() ) { + ConditionsManagerObject* m(m_manager.access()); + ConditionsDependencyHandler h(m, *this, deps, user_param); + for ( const ConditionDependency* d : missing ) { + Condition::Object* c = h(d); + if ( c ) ++num_updates; } - const ConditionDependency* d = i.second.get(); - Condition::Object* cond = handler(d); - m->registerUnlocked(pool, cond); // Would bulk update be more efficient? - ++num_updates; } } return num_updates; } +typedef ConditionsSlice::Entry SliceEntry; +namespace { + bool _compare(const pair<Condition::key_type,void*>& a,const pair<Condition::key_type,void*>& b) + { return a.first < b.first; } + pair<Condition::key_type,ConditionDependency*> _to_dep(pair<Condition::key_type,SliceEntry*>& e) + { return make_pair(e.first,e.second->dependency); } +} + +template<typename MAPPING> UserPool::Result +ConditionsMappedUserPool<MAPPING>::prepare_VSN_1(const IOV& required, + ConditionsSlice& slice, + void* user_param) +{ + typedef vector<pair<key_type,SliceEntry*> > _Missing; + Result result; + IOV pool_iov(required.iovType); + const auto& slice_cond = slice.conditions(); + const auto& slice_calc = slice.derived(); + + m_conditions.clear(); + pool_iov.reset().invert(); + m_iovPool->select(required, Operators::mapConditionsSelect(m_conditions), pool_iov); + m_iov = pool_iov; + _Missing cond_missing(slice_cond.size()), calc_missing(slice_cond.size()); + _Missing::iterator cond_last = set_difference(slice_cond.begin(), slice_cond.end(), + m_conditions.begin(), m_conditions.end(), + cond_missing.begin(), _compare); + int num_cond_miss = int(cond_last-cond_missing.begin()); + printout(INFO,"UserPool","Found %ld missing conditions out of %ld conditions.", + num_cond_miss, m_conditions.size()); + + _Missing::iterator calc_last = set_difference(slice_calc.begin(), slice_calc.end(), + m_conditions.begin(), m_conditions.end(), + calc_missing.begin(), _compare); + int num_calc_miss = int(calc_last-calc_missing.begin()); + printout(INFO,"UserPool","Found %ld missing derived conditions out of %ld conditions.", + int(calc_last-calc_missing.begin()), m_conditions.size()); + + result.selected = m_conditions.size(); + result.missing = num_cond_miss+num_calc_miss; + // + // Now we load the missing conditions from the conditions loader + // + if ( int(cond_last-cond_missing.begin())>0 ) { + vector<pair<key_type,SliceEntry*> > loaded, missing; + size_t updates = m_loader->load_many(required, cond_missing, loaded, missing, pool_iov); + for_each(loaded.begin(),loaded.end(),Inserter<MAPPING>(m_conditions,&m_iov)); + result.selected += updates; + result.missing -= updates; + if ( !missing.empty() ) { + // ERROR! + } + } + // + // Now we update the already existing dependencies, which have expired + if ( int(calc_last-calc_missing.begin()) > 0 ) { + ConditionsDependencyCollection deps(calc_missing.begin(), calc_last, _to_dep); + ConditionsDependencyHandler h(m_manager, *this, deps, user_param); + for(auto i=begin(deps); i != end(deps); ++i) { + const ConditionDependency* d = (*i).second.get(); + typename MAPPING::iterator j = m_conditions.find(d->key()); + // If we would know, that dependencies are only ONE level, we could skip this search.... + if ( j == m_conditions.end() ) { + Condition::Object* c = h(d); + ( c != 0 ) ? ++result.selected : ++result.missing; + continue; + } + // printout(INFO,"UserPool","Already calcluated: %s",d->name()); + ++result.selected; + continue; + } + } + return result; +} + namespace { - void* create_user_pool(DD4hep::Geometry::LCDD&, int argc, char** argv) { + void* create_user_pool(Geometry::LCDD&, int argc, char** argv) { if ( argc > 1 ) { ConditionsManagerObject* m = (ConditionsManagerObject*)argv[0]; ConditionsIOVPool* p = (ConditionsIOVPool*)argv[1]; UserPool* pool = new ConditionsMappedUserPool<std::map<Condition::key_type,Condition::Object*> >(m, p); return pool; } - DD4hep::except("ConditionsMappedUserPool","++ Insufficient arguments: arg[0] = ConditionManager!"); + except("ConditionsMappedUserPool","++ Insufficient arguments: arg[0] = ConditionManager!"); return 0; } } diff --git a/DDCond/src/plugins/ConditionsXmlLoader.cpp b/DDCond/src/plugins/ConditionsXmlLoader.cpp index 87ecd64fbf9c69ce2c6c835b2315cd57bcb824cd..8c7ffaf6e30b1130ad60fa92796a793e39be1771 100644 --- a/DDCond/src/plugins/ConditionsXmlLoader.cpp +++ b/DDCond/src/plugins/ConditionsXmlLoader.cpp @@ -16,6 +16,7 @@ // Framework include files #include "DDCond/ConditionsDataLoader.h" +#include "DD4hep/Printout.h" /// Namespace for the AIDA detector description toolkit namespace DD4hep { @@ -43,22 +44,26 @@ namespace DD4hep { /// Default destructor virtual ~ConditionsXmlLoader(); /// Load a condition set given a Detector Element and the conditions name according to their validity - virtual size_t load(key_type key, - const iov_type& req_validity, - RangeConditions& conditions); + virtual size_t load_single(key_type key, + const iov_type& req_validity, + RangeConditions& conditions); /// Load a condition set given a Detector Element and the conditions name according to their validity - virtual size_t load_range(key_type key, - const iov_type& req_validity, - RangeConditions& conditions); - /// Update a range of conditions according to the required IOV - virtual size_t update(const iov_type& req_validity, - RangeConditions& conditions, - iov_type& iov_intersection); + virtual size_t load_range( key_type key, + const iov_type& req_validity, + RangeConditions& conditions); + /// Optimized update using conditions slice data + virtual size_t load_many( const iov_type& /* req_validity */, + EntryVector& /* work */, + EntryVector& /* loaded */, + EntryVector& /* missing */, + iov_type& /* conditions_validity */) + { + except("ConditionsLoader","+++ update: Invalid call!"); + return 0; + } }; - - } /* End namespace Conditions */ -} /* End namespace DD4hep */ - + } /* End namespace Conditions */ +} /* End namespace DD4hep */ #endif /* DD4HEP_CONDITIONS_XMLCONDITONSLOADER_H */ //#include "ConditionsXmlLoader.h" @@ -132,9 +137,9 @@ size_t ConditionsXmlLoader::load_source(const std::string& nam, return conditions.size()-len; } -size_t ConditionsXmlLoader::load(key_type key, - const iov_type& req_validity, - RangeConditions& conditions) +size_t ConditionsXmlLoader::load_single(key_type key, + const iov_type& req_validity, + RangeConditions& conditions) { size_t len = conditions.size(); if ( m_buffer.empty() && !m_sources.empty() ) { @@ -177,8 +182,3 @@ size_t ConditionsXmlLoader::load_range(key_type key, return conditions.size()-len; } -/// Update a range of conditions according to the required IOV -size_t ConditionsXmlLoader::update(const IOV&,RangeConditions&, IOV&) { - except("ConditionsXmlLoader","+++ update: Invalid call!"); - return 0; -} diff --git a/DDCore/include/DD4hep/Alignments.h b/DDCore/include/DD4hep/Alignments.h index f3bc6aee32851dc7a01d2eb451252b44cbfa41fb..a434a421e1ba9c5a53555e3eb8c57f653a570539 100644 --- a/DDCore/include/DD4hep/Alignments.h +++ b/DDCore/include/DD4hep/Alignments.h @@ -248,6 +248,14 @@ namespace DD4hep { /// Known keys of conditions in this container const Keys& keys() const; + /// Add a new key to the conditions access map. + /** Caution: This is not thread protected! */ + void addKey(const std::string& key_val); + + /// Add a new key to the conditions access map: Allow for alias if key_val != data_val + /** Caution: This is not thread protected! */ + void addKey(const std::string& key_val, const std::string& data_val); + /// Access to alignment objects by key and IOV. Alignment get(const std::string& alignment_key, const iov_type& iov); diff --git a/DDCore/include/DD4hep/ConditionDerived.h b/DDCore/include/DD4hep/ConditionDerived.h index e7b8095a94426ec38ffd6c32a0c7336e646e8780..142e8257d01dfbea623367b6920bb993a731a5e1 100644 --- a/DDCore/include/DD4hep/ConditionDerived.h +++ b/DDCore/include/DD4hep/ConditionDerived.h @@ -187,6 +187,8 @@ namespace DD4hep { ConditionDependency(); /// Access the dependency key key_type key() const { return target.hash; } + /// Access the dependency key + const char* name() const { return target.name.c_str(); } /// Add use count to the object ConditionDependency* addRef() { ++m_refCount; return this; } /// Release object. May not be used any longer diff --git a/DDCore/include/DD4hep/Conditions.h b/DDCore/include/DD4hep/Conditions.h index 3a53d62c5bd3d3bc23b0fe8386038228af113142..7ef0dfee572a3df169e9b11629b71a660e0614c2 100644 --- a/DDCore/include/DD4hep/Conditions.h +++ b/DDCore/include/DD4hep/Conditions.h @@ -248,8 +248,17 @@ namespace DD4hep { size_t numKeys() const; /// Known keys of conditions in this container + /** Caution: This is not thread protected! */ const Keys& keys() const; - + + /// Add a new key to the conditions access map. + /** Caution: This is not thread protected! */ + void addKey(const std::string& key_val); + + /// Add a new key to the conditions access map: Allow for alias if key_val != data_val + /** Caution: This is not thread protected! */ + void addKey(const std::string& key_val, const std::string& data_val); + /// Access to condition objects by key and IOV. Condition get(const std::string& condition_key, const iov_type& iov); @@ -263,6 +272,89 @@ namespace DD4hep { Condition get(key_type condition_key, const UserPool& pool); }; + /// Conditions selector functor. Default implementation selects everything evaluated. + /** + * Please note: + * This class should never be directly instantiated by the user. + * A typical use-case is to do so in a wrapper class, which contains a refernce + * to a counter object, which in turn allows to deduce information from the + * processed objects. + * + * See class ConditionsSelectWrapper below + * + * \author M.Frank + * \version 1.0 + * \ingroup DD4HEP_CONDITIONS + */ + class ConditionsSelect { + protected: + /// Default constructor + ConditionsSelect() = default; + /// Copy constructor + ConditionsSelect(const ConditionsSelect& copy) = default; + /// Default destructor. + virtual ~ConditionsSelect(); + /// Default assignment operator + ConditionsSelect& operator=(const ConditionsSelect& copy) = default; + + public: + /// Selection callback: return true if the condition should be selected + bool operator()(Condition cond) const { return (*this)(cond.ptr()); } + /// Selection callback: return true if the condition should be selected + bool operator()(std::pair<Condition::key_type,Condition::Object*> cond) const + /** Arg is 2 longwords. No need to pass by reference. */ + { return (*this)(cond.second); } + /// Selection callback: return true if the condition should be selected + /** Arg is 2 longwords. No need to pass by reference. */ + bool operator()(std::pair<Condition::key_type,Condition> cond) const + { return (*this)(cond.second.ptr()); } + + /// Overloadable entry: Return number of conditions selected. Default does nothing.... + virtual size_t size() const { return 0; } + /// Overloadable entry: Selection callback: return true if the condition should be selected + virtual bool operator()(Condition::Object* cond) const = 0; + }; + + /// Conditions selector functor. Wraps a user defined object by reference + /** + * Example usage for the slow ones: + * + * class MyCounter : public ConditionsSelectWrapper<long> { + * MyCounter(long& cnt) : ConditionsSelectWrapper<long>(cnt) {} + * virtual bool operator()(Condition::Object* cond) const { if ( cond != 0 ) ++object; } + * // Optionally overload: virtual size_t size() const { return object; } + * }; + * + * long counter = 0; + * for_each(conditons.begin(), conditions.end(), MyCounter(counter)); + * + * \author M.Frank + * \version 1.0 + * \ingroup DD4HEP_CONDITIONS + */ + template <typename OBJECT> class ConditionsSelectWrapper : public ConditionsSelect { + private: + /// Default constructor + ConditionsSelectWrapper() = delete; + /// Default assignment operator + bool operator==(const ConditionsSelectWrapper& compare) = delete; + public: + /// Information collector type + typedef OBJECT object_t; + /// Reference to the infomation collector + object_t& object; + public: + /// Default constructor + ConditionsSelectWrapper(object_t& o) : ConditionsSelect(), object(o) {} + /// Copy constructor + ConditionsSelectWrapper(const ConditionsSelectWrapper& copy) = default; + /// Default destructor. + virtual ~ConditionsSelectWrapper() = default; + /// Default assignment operator + ConditionsSelectWrapper& operator=(const ConditionsSelectWrapper& copy) = default; + }; + + /// Key definition to optimize ans simplyfy the access to conditions entities /** * \author M.Frank @@ -277,17 +369,17 @@ namespace DD4hep { /// String representation of the key object std::string name; /// Hashed key representation - key_type hash; + key_type hash = 0; public: /// Default constructor - ConditionKey() : hash(0) {} + ConditionKey() = default; /// Constructor from string ConditionKey(const std::string& compare); /// Constructor from string ConditionKey(const std::string& s, key_type h) : name(s), hash(h) {} /// Copy constructor - ConditionKey(const ConditionKey& c) : name(c.name), hash(c.hash) {} + ConditionKey(const ConditionKey& c) = default; /// Hash code generation from input string static key_type hashCode(const char* value); @@ -297,7 +389,7 @@ namespace DD4hep { /// Assignment operator from the string representation ConditionKey& operator=(const std::string& value); /// Assignment operator from object copy - ConditionKey& operator=(const ConditionKey& key); + ConditionKey& operator=(const ConditionKey& key) = default; /// Equality operator using key object bool operator==(const ConditionKey& compare) const; /// Equality operator using hash value @@ -326,15 +418,6 @@ namespace DD4hep { inline ConditionKey::key_type ConditionKey::hashCode(const std::string& value) { return hash32(value); } - /// Assignment operator from object copy - inline ConditionKey& ConditionKey::operator=(const ConditionKey& key) { - if ( this != &key ) { - hash = key.hash; - name = key.name; - } - return *this; - } - /// Equality operator using key object inline bool ConditionKey::operator==(const ConditionKey& compare) const { return hash == compare.hash; } @@ -358,6 +441,6 @@ namespace DD4hep { typedef std::vector<Condition> RangeConditions; typedef std::pair<RangeConditions,bool> RangeStatus; - } /* End namespace Conditions */ -} /* End namespace DD4hep */ -#endif /* DD4HEP_CONDITIONS_CONDITIONS_H */ + } /* End namespace Conditions */ +} /* End namespace DD4hep */ +#endif /* DD4HEP_CONDITIONS_CONDITIONS_H */ diff --git a/DDCore/include/DD4hep/FieldTypes.h b/DDCore/include/DD4hep/FieldTypes.h index da332ce22a019184f9c0aaf20f27e45c33c72c51..1b822c33960bcb643c74cb3595fd198186112ed7 100644 --- a/DDCore/include/DD4hep/FieldTypes.h +++ b/DDCore/include/DD4hep/FieldTypes.h @@ -10,7 +10,6 @@ // Author : M.Frank // //========================================================================== - #ifndef DD4HEP_GEOMETRY_FIELDTYPES_H #define DD4HEP_GEOMETRY_FIELDTYPES_H @@ -19,7 +18,6 @@ #include "DD4hep/Shapes.h" #include <vector> - /// Namespace for the AIDA detector description toolkit namespace DD4hep { @@ -40,9 +38,7 @@ namespace DD4hep { Direction direction; public: /// Initializing constructor - ConstantField() - : direction() { - } + ConstantField() : direction() { } /// Call to access the field components at a given location virtual void fieldComponents(const double* /* pos */, double* field); }; @@ -158,11 +154,12 @@ namespace DD4hep { class MultipoleField: public CartesianField::Object { public: typedef std::vector<double> Coefficents; - Coefficents coefficents; - Coefficents skews; - Solid volume; - Transform3D transform; - double B_z; + Coefficents coefficents; + Coefficents skews; + Solid volume; + Transform3D transform; + double B_z; + public: /// Initializing constructor MultipoleField(); @@ -170,6 +167,6 @@ namespace DD4hep { virtual void fieldComponents(const double* pos, double* field); }; - } /* End namespace Geometry */ -} /* End namespace DD4hep */ + } /* End namespace Geometry */ +} /* End namespace DD4hep */ #endif /* DD4HEP_GEOMETRY_FIELDTYPES_H */ diff --git a/DDCore/include/DD4hep/Fields.h b/DDCore/include/DD4hep/Fields.h index 1861241d58305ac4dce6c5fa23e7ab7adffa6d62..394a75880e0ade48a958bf393c6a9db8127d9f89 100644 --- a/DDCore/include/DD4hep/Fields.h +++ b/DDCore/include/DD4hep/Fields.h @@ -204,7 +204,7 @@ namespace DD4hep { /// Returns the 3 electric field components (x, y, z). void electricField(const double* pos, double* field) const { - field[0] = field[1] = field[2] = 0.0; + field[0] = field[1] = field[2] = 0.0; CartesianField f = data<Object>()->electric; f.isValid() ? f.value(pos, field) : combinedElectric(pos, field); } @@ -221,7 +221,7 @@ namespace DD4hep { /// Returns the 3 magnetic field components (x, y, z). void magneticField(const double* pos, double* field) const { - field[0] = field[1] = field[2] = 0.0; + field[0] = field[1] = field[2] = 0.0; CartesianField f = data<Object>()->magnetic; f.isValid() ? f.value(pos, field) : combinedMagnetic(pos, field); } diff --git a/DDCore/include/DD4hep/IOV.h b/DDCore/include/DD4hep/IOV.h index b3fabbf5a88a2d60c98ff00bd5d3352636876884..b1c9b4325d6b2c944fb4ea7bffc3c2e67e72e071 100644 --- a/DDCore/include/DD4hep/IOV.h +++ b/DDCore/include/DD4hep/IOV.h @@ -127,7 +127,7 @@ namespace DD4hep { return typ1 == typ2; } /// Check if IOV 'test' is fully contained in IOV 'key' - static bool key_is_contained(const Key& key, const Key& test) + static bool key_is_contained(const Key& key, const Key& test) { return key.first >= test.first && key.second <= test.second; } /// Same as above, but reverse logic. Gives sometimes more understandable logic. static bool key_contains_range(const Key& key, const Key& test) diff --git a/DDCore/include/DD4hep/Primitives.h b/DDCore/include/DD4hep/Primitives.h index 0aa675043058841f7afdccbcb632a11a2a7d7d7c..3fa86764daab16ca1e843ab030046ae5a0959562 100644 --- a/DDCore/include/DD4hep/Primitives.h +++ b/DDCore/include/DD4hep/Primitives.h @@ -221,6 +221,12 @@ namespace DD4hep { using DDSegmentation::BitFieldValue; #endif + template<typename C> struct ClearOnReturn { + C& container; + ClearOnReturn(C& c) : container(c) { } + ~ClearOnReturn() { container.clear(); } + }; + /// Helper to copy objects. template <typename T> inline void copyObject(void* target,const void* source) { const T* s = (const T*)source; diff --git a/DDCore/src/Alignments.cpp b/DDCore/src/Alignments.cpp index 1ef0b6afdbbd895cb3c5dab8e15672f216ef97b6..5417522cb23a9f7e6c814aaf9120b267dd62cf32 100644 --- a/DDCore/src/Alignments.cpp +++ b/DDCore/src/Alignments.cpp @@ -137,6 +137,16 @@ const Container::Keys& Container::keys() const { return o->keys; } +/// Add a new key to the alignments access map +void Container::addKey(const string& key_val) { + access()->addKey(key_val); +} + +/// Add a new key to the alignments access map: Allow for alias if key_val != data_val +void Container::addKey(const string& key_val, const string& data_val) { + access()->addKey(key_val, data_val); +} + /// Access to alignment objects Alignment Container::get(const string& alignment_key, const iov_type& iov) { Object* o = ptr(); diff --git a/DDCore/src/AlignmentsKeyAssign.cpp b/DDCore/src/AlignmentsKeyAssign.cpp index 08bd059f548f764ca48c82d8015e8df40c38c7db..8e6d529d9d5dffff546a83bf37ad3865618ee777 100644 --- a/DDCore/src/AlignmentsKeyAssign.cpp +++ b/DDCore/src/AlignmentsKeyAssign.cpp @@ -23,7 +23,7 @@ using namespace DD4hep::Alignments; const AlignmentsKeyAssign& AlignmentsKeyAssign::addKey(const string& key_value) const { DetAlign conds(detector); - conds.alignments()->addKey(key_value); + conds.alignments().addKey(key_value); return *this; } @@ -31,7 +31,7 @@ AlignmentsKeyAssign::addKey(const string& key_value) const { const AlignmentsKeyAssign& AlignmentsKeyAssign::addKey(const string& key_value, const string& data_value) const { DetAlign conds(detector); - conds.alignments()->addKey(key_value, data_value); + conds.alignments().addKey(key_value, data_value); return *this; } diff --git a/DDCore/src/ComponentProperties.cpp b/DDCore/src/ComponentProperties.cpp index 2528e428da1de0fe1d2f01ed65582d99a0df34fd..d4d697c5edb6886a85a3cf825f189ca41f63f49b 100644 --- a/DDCore/src/ComponentProperties.cpp +++ b/DDCore/src/ComponentProperties.cpp @@ -34,12 +34,16 @@ PropertyGrammar::~PropertyGrammar() { } /// Error callback on invalid conversion -void PropertyGrammar::invalidConversion(const std::type_info& from, const std::type_info& to) { +void PropertyGrammar::invalidConversion(const std::type_info& from, + const std::type_info& to) +{ BasicGrammar::invalidConversion(from,to); } /// Error callback on invalid conversion -void PropertyGrammar::invalidConversion(const std::string& value, const std::type_info& to) { +void PropertyGrammar::invalidConversion(const std::string& value, + const std::type_info& to) +{ BasicGrammar::invalidConversion(value,to); } @@ -140,7 +144,8 @@ void PropertyManager::verifyNonExistence(const string& name) const { } /// Verify that this property exists (throw exception if the name was not found) -PropertyManager::Properties::const_iterator PropertyManager::verifyExistence(const string& name) const { +PropertyManager::Properties::const_iterator +PropertyManager::verifyExistence(const string& name) const { Properties::const_iterator i = m_properties.find(name); if (i != m_properties.end()) return i; @@ -148,7 +153,8 @@ PropertyManager::Properties::const_iterator PropertyManager::verifyExistence(con } /// Verify that this property exists (throw exception if the name was not found) -PropertyManager::Properties::iterator PropertyManager::verifyExistence(const string& name) { +PropertyManager::Properties::iterator +PropertyManager::verifyExistence(const string& name) { Properties::iterator i = m_properties.find(name); if (i != m_properties.end()) return i; @@ -183,18 +189,15 @@ void PropertyManager::add(const string& name, const Property& prop) { /// Bulk set of all properties void PropertyManager::set(const string& component_name, PropertyConfigurator& cfg) { - for (Properties::iterator i = m_properties.begin(); i != m_properties.end(); ++i) { - Property& p = (*i).second; - cfg.set(p.grammar(), component_name, (*i).first, p.ptr()); - } + for (auto& i : m_properties ) + cfg.set(i.second.grammar(), component_name, i.first, i.second.ptr()); } /// Dump string values void PropertyManager::dump() const { - for (Properties::const_iterator i = m_properties.begin(); i != m_properties.end(); ++i) { - const Property& p = (*i).second; - printout(ALWAYS, "PropertyManager", "Property %s = %s", (*i).first.c_str(), p.str().c_str()); - } + for (const auto& i : m_properties ) + printout(ALWAYS, "PropertyManager", "Property %s = %s", + i.first.c_str(), i.second.str().c_str()); } /// Standard PropertyConfigurable constructor diff --git a/DDCore/src/ConditionDerived.cpp b/DDCore/src/ConditionDerived.cpp index 5be7a996f2607e1169ad3d47c5907e8f5026cf48..9da81b8686dceb76b3980bed35e17b19bdd00374 100644 --- a/DDCore/src/ConditionDerived.cpp +++ b/DDCore/src/ConditionDerived.cpp @@ -58,7 +58,9 @@ ConditionDependency::ConditionDependency() /// Copy constructor ConditionDependency::ConditionDependency(const ConditionDependency& c) - : m_refCount(0), target(c.target), dependencies(c.dependencies), callback(c.callback) + : m_refCount(0), target(c.target), + dependencies(c.dependencies), + callback(c.callback) { InstanceCount::increment(this); if ( callback ) callback->addRef(); @@ -82,13 +84,16 @@ ConditionDependency& ConditionDependency::operator=(const ConditionDependency& ) } /// Initializing constructor -DependencyBuilder::DependencyBuilder(const ConditionKey& target, ConditionUpdateCall* call) +DependencyBuilder::DependencyBuilder(const ConditionKey& target, + ConditionUpdateCall* call) : m_dependency(new ConditionDependency(target,call)) { } /// Initializing constructor -DependencyBuilder::DependencyBuilder(const ConditionKey& target, ConditionUpdateCall* call, Geometry::DetElement de) +DependencyBuilder::DependencyBuilder(const ConditionKey& target, + ConditionUpdateCall* call, + Geometry::DetElement de) : m_dependency(new ConditionDependency(target,call)) { m_dependency->detector = de; diff --git a/DDCore/src/Conditions.cpp b/DDCore/src/Conditions.cpp index d7f46714815573a1215cb2cc617f7062db7af9fd..5927f2d90251efe97b9851df08d702cb7542032a 100644 --- a/DDCore/src/Conditions.cpp +++ b/DDCore/src/Conditions.cpp @@ -27,33 +27,6 @@ using namespace DD4hep::Conditions; Condition::Processor::Processor() { } -/// Access the key of the condition -ConditionKey DD4hep::Conditions::make_key(Condition c) { - Condition::Object* p = c.ptr(); - if ( p ) return ConditionKey(p->name,p->hash); - invalidHandleError<Condition>(); - return ConditionKey(); -} - -/// Constructor from string -ConditionKey::ConditionKey(const string& value) - : name(value), hash(hashCode(value)) -{ -} - -/// Assignment operator from the string representation -ConditionKey& ConditionKey::operator=(const string& value) { - ConditionKey key(value); - hash = hashCode(value); - name = value; - return *this; -} - -/// Operator less (for map insertions) using the string representation -bool ConditionKey::operator<(const string& compare) const { - return hash < hashCode(compare); -} - /// Initializing constructor Condition::Condition(const string& nam,const string& typ) : Handle<Object>() { Object* o = new Object(); @@ -185,6 +158,16 @@ const Container::Keys& Container::keys() const { return o->keys; } +/// Add a new key to the conditions access map +void Container::addKey(const string& key_val) { + access()->addKey(key_val); +} + +/// Add a new key to the conditions access map: Allow for alias if key_val != data_val +void Container::addKey(const string& key_val, const string& data_val) { + access()->addKey(key_val, data_val); +} + /// Access to condition objects Condition Container::get(const string& condition_key, const iov_type& iov) { Object* o = ptr(); @@ -240,3 +223,34 @@ Condition Container::get(key_type condition_key, const UserPool& pool) { invalidHandleError<Container>(); return Condition(); } + +/// Default destructor. +ConditionsSelect::~ConditionsSelect() { +} + +/// Access the key of the condition +ConditionKey DD4hep::Conditions::make_key(Condition c) { + Condition::Object* p = c.ptr(); + if ( p ) return ConditionKey(p->name,p->hash); + invalidHandleError<Condition>(); + return ConditionKey(); +} + +/// Constructor from string +ConditionKey::ConditionKey(const string& value) + : name(value), hash(hashCode(value)) +{ +} + +/// Assignment operator from the string representation +ConditionKey& ConditionKey::operator=(const string& value) { + ConditionKey key(value); + hash = hashCode(value); + name = value; + return *this; +} + +/// Operator less (for map insertions) using the string representation +bool ConditionKey::operator<(const string& compare) const { + return hash < hashCode(compare); +} diff --git a/DDCore/src/ConditionsKeyAssign.cpp b/DDCore/src/ConditionsKeyAssign.cpp index 799c8add5c48d93b59670b7b82f73f3781f26cc9..08f77dbe5f6751c12847aa01392bc5b30d41459e 100644 --- a/DDCore/src/ConditionsKeyAssign.cpp +++ b/DDCore/src/ConditionsKeyAssign.cpp @@ -24,7 +24,7 @@ const ConditionsKeyAssign& ConditionsKeyAssign::addKey(const string& key_value) const { DetConditions conds(detector); - conds.conditions()->addKey(key_value); + conds.conditions().addKey(key_value); return *this; } @@ -33,7 +33,7 @@ const ConditionsKeyAssign& ConditionsKeyAssign::addKey(const string& key_value, const string& data_value) const { DetConditions conds(detector); - conds.conditions()->addKey(key_value, data_value); + conds.conditions().addKey(key_value, data_value); return *this; } diff --git a/DDCore/src/DetectorInterna.cpp b/DDCore/src/DetectorInterna.cpp index 83fad3846974633702c5f0986e92a411923015f6..9cdfb3907666f94ff4e06138d262ba30fc8f915c 100644 --- a/DDCore/src/DetectorInterna.cpp +++ b/DDCore/src/DetectorInterna.cpp @@ -124,9 +124,9 @@ DetElementObject* DetElementObject::clone(int new_id, int flg) const { obj->ObjectExtensions::copyFrom(extensions, obj); obj->children.clear(); - for (DetElement::Children::const_iterator i = children.begin(); i != children.end(); ++i) { - const NamedObject* pc = (*i).second.ptr(); - const DetElementObject& d = (*i).second._data(); + for (const auto& i : children ) { + const NamedObject* pc = i.second.ptr(); + const DetElementObject& d = i.second._data(); DetElement child(d.clone(d.id, DetElement::COPY_PLACEMENT), pc->GetName(), pc->GetTitle()); pair<Children::iterator, bool> r = obj->children.insert(make_pair(child.name(), child)); if (r.second) { @@ -249,15 +249,13 @@ void DetElementObject::revalidate(TGeoHMatrix* parent_world_trafo) { deletePtr (referenceTrafo); /// Now iterate down the children.... - for(Children::const_iterator i = children.begin(); i!=children.end(); ++i) { - DetElement d((*i).second); - d->revalidate(&worldTrafo); - } + for(const auto& i : children ) + i.second->revalidate(&worldTrafo); } /// Remove callback from object void DetElementObject::removeAtUpdate(unsigned int typ, void* pointer) { - for(UpdateCallbacks::iterator i=updateCalls.begin(); i != updateCalls.end(); ++i) { + for (auto i=updateCalls.begin(); i != updateCalls.end(); ++i) { if ( (typ&((*i).second)) == typ && (*i).first.par == pointer ) { updateCalls.erase(i); return; @@ -280,10 +278,9 @@ void DetElementObject::update(unsigned int tags, void* param) { } revalidate(parent_world_trafo); } - for(UpdateCallbacks::const_iterator i=updateCalls.begin(); i != updateCalls.end(); ++i) { - if ( (tags&((*i).second)) ) { - (*i).first.execute(args); - } + for ( const auto& i : updateCalls ) { + if ( (tags&i.second) ) + i.first.execute(args); } } diff --git a/DDCore/src/DetectorTools.cpp b/DDCore/src/DetectorTools.cpp index d9c58e9e68710489435ccae91c6338b0a0294591..20bb87df09e71ef301114ab3508e30d2f938961c 100644 --- a/DDCore/src/DetectorTools.cpp +++ b/DDCore/src/DetectorTools.cpp @@ -185,11 +185,11 @@ void DetectorTools::elementPath(DetElement element, PlacementPath& det_nodes) { std::string DetectorTools::elementPath(const PlacementPath& nodes, bool reverse) { string s = ""; if ( reverse ) { - for(PlacementPath::const_reverse_iterator i=nodes.rbegin();i!=nodes.rend();++i) + for(auto i=nodes.rbegin(); i != nodes.rend(); ++i) s += "/" + string((*i).name()); } else { - for(PlacementPath::const_iterator i=nodes.begin();i!=nodes.end();++i) + for(auto i=begin(nodes); i != end(nodes); ++i) s += "/" + string((*i)->GetName()); } return s; @@ -384,16 +384,15 @@ PlacedVolume DetectorTools::findNode(PlacedVolume top_place, const std::string& /// Convert VolumeID to string std::string DetectorTools::toString(const PlacedVolume::VolIDs& ids) { stringstream log; - for (PlacedVolume::VolIDs::const_iterator vit = ids.begin(); vit != ids.end(); ++vit) - log << (*vit).first << "=" << (*vit).second << "; "; + for( const PlacedVolume::VolID& v : ids ) + log << v.first << "=" << v.second << "; "; return log.str(); } /// Convert VolumeID to string std::string DetectorTools::toString(const IDDescriptor& dsc, const PlacedVolume::VolIDs& ids, VolumeID code) { stringstream log; - for (PlacedVolume::VolIDs::const_iterator idIt = ids.begin(); idIt != ids.end(); ++idIt) { - const PlacedVolume::VolID& id = (*idIt); + for( const PlacedVolume::VolID& id : ids ) { IDDescriptor::Field f = dsc.field(id.first); VolumeID value = f->value(code); log << id.first << "=" << id.second << "," << value << " [" << f->offset() << "," << f->width() << "] "; diff --git a/DDDB/include/DDDB/DDDBConditionsLoader.h b/DDDB/include/DDDB/DDDBConditionsLoader.h index 6a9bd4ac194befcf77d3e30d59bcc8465e54a02c..ddc21c1ce3ed896b3d54f245a984d4ba4db76ab3 100644 --- a/DDDB/include/DDDB/DDDBConditionsLoader.h +++ b/DDDB/include/DDDB/DDDBConditionsLoader.h @@ -23,8 +23,9 @@ #define DD4HEP_DDDB_DDDBCONDITONSLOADER_H // Framework include files -#include "DD4hep/ConditionsListener.h" #include "DDCond/ConditionsDataLoader.h" +#include "DD4hep/ConditionsListener.h" +#include "DD4hep/Printout.h" #include "XML/UriReader.h" /// Namespace for the AIDA detector description toolkit @@ -41,7 +42,7 @@ namespace DD4hep { */ class DDDBConditionsLoader : public Conditions::ConditionsDataLoader, - public Conditions::ConditionsListener + public Conditions::ConditionsListener { typedef Conditions::Condition Condition; typedef Conditions::RangeConditions RangeConditions; @@ -55,12 +56,12 @@ namespace DD4hep { */ class KeyCollector : public Conditions::ConditionsListener { public: - std::pair<ConditionsListener*,void*> call; - KeyMap keys; - /// Initializing constructor + std::pair<ConditionsListener*,void*> call; + KeyMap keys; + /// Initializing constructor KeyCollector(); - /// ConditionsListener overload: onRegister new condition - virtual void onRegisterCondition(Conditions::Condition cond, void* param); + /// ConditionsListener overload: onRegister new condition + virtual void onRegisterCondition(Conditions::Condition cond, void* param); }; XML::UriReader* m_resolver; KeyCollector m_keys; @@ -69,8 +70,8 @@ namespace DD4hep { void loadDocument(XML::UriContextReader& rdr, const Key& k); /// Load single conditions document void loadDocument(XML::UriContextReader& rdr, - const std::string& sys_id, - const std::string& obj_id); + const std::string& sys_id, + const std::string& obj_id); public: /// Default constructor @@ -78,17 +79,20 @@ namespace DD4hep { /// Default destructor virtual ~DDDBConditionsLoader(); /// Load a condition set given a Detector Element and the conditions name according to their validity - virtual size_t load(key_type key, - const iov_type& req_validity, - RangeConditions& conditions); + virtual size_t load_single(key_type key, + const iov_type& req_validity, + RangeConditions& conditions); /// Load a condition set given a Detector Element and the conditions name according to their validity - virtual size_t load_range(key_type key, - const iov_type& req_validity, - RangeConditions& conditions); - /// Update a range of conditions according to the required IOV - virtual size_t update(const iov_type& req_validity, - RangeConditions& conditions, - iov_type& conditions_validity); + virtual size_t load_range( key_type key, + const iov_type& req_validity, + RangeConditions& conditions); + /// Optimized update using conditions slice data + virtual size_t load_many( const iov_type& req_validity, + EntryVector& work, + EntryVector& loaded, + EntryVector& missing, + iov_type& conditions_validity); + /// ConditionsListener overload: onRegister new condition virtual void onRegisterCondition(Conditions::Condition cond, void* param); diff --git a/DDDB/src/DDDBAlignmentTest.cpp b/DDDB/src/DDDBAlignmentTest.cpp index 450e5a5707581e86848662e9547b67765bc82dbc..ff26b1dd93413da04d5883253d4b7189b7e8268d 100644 --- a/DDDB/src/DDDBAlignmentTest.cpp +++ b/DDDB/src/DDDBAlignmentTest.cpp @@ -24,7 +24,7 @@ #include "DD4hep/Factories.h" #include "DD4hep/InstanceCount.h" #include "DD4hep/objects/AlignmentsInterna.h" -#include "DDCond/ConditionsPool.h" +#include "DDCond/ConditionsSlice.h" #include "DDAlign/AlignmentsManager.h" #include "DDDB/DDDBConversion.h" @@ -106,37 +106,38 @@ namespace { 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); + dd4hep_ptr<ConditionsSlice> slice(createSlice(manager,*iovType)); + manager.prepare(iov, *slice); + return collect(lcdd.world(), slice->pool(), context, 0); } /// Compute dependent alignment conditions - int computeDependencies(dd4hep_ptr<UserPool>& user_pool, + int computeDependencies(dd4hep_ptr<ConditionsSlice>& slice, 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); + slice.adopt(createSlice(conds,*iovType)); + long num_expired = conds.prepare(iov, *slice); printout(INFO,"Conditions", "+++ ConditionsUpdate: Updated %ld conditions... IOV:%s", num_expired, iov.str().c_str()); - align.compute(user_pool); + align.compute(*(slice->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); + typedef ConditionsDependencyCollection Deps; + dd4hep_ptr<ConditionsSlice> slice; + int ret = computeDependencies(slice, 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()); + UserPool& p = *(slice->pool().get()); Alignments::DetAlign det(d->detector); const ConditionKey& k = d->target; Alignments::Container c = det.alignments(); @@ -187,9 +188,9 @@ namespace { if ( ret == 1 ) { for(int i=0; i<10; ++i) { { long ti = time + i*3600; - dd4hep_ptr<UserPool> pool; - ret = selec.computeDependencies(pool,conds,align,ti); - pool->clear(); + dd4hep_ptr<ConditionsSlice> slice; + ret = selec.computeDependencies(slice,conds,align,ti); + slice->reset(); } DD4hep::InstanceCount::dump(); } diff --git a/DDDB/src/DDDBConditionsLoader.cpp b/DDDB/src/DDDBConditionsLoader.cpp index 64ec484fed118b27bc194abcb75284a142765ad7..413ff4c6db50a6106c11a6a698425ef8e12eddd4 100644 --- a/DDDB/src/DDDBConditionsLoader.cpp +++ b/DDDB/src/DDDBConditionsLoader.cpp @@ -167,9 +167,9 @@ size_t DDDBConditionsLoader::load_range(key_type key, return 0; } -size_t DDDBConditionsLoader::load(key_type key, - const iov_type& req_validity, - RangeConditions& conditions) { +size_t DDDBConditionsLoader::load_single(key_type key, + const iov_type& req_validity, + RangeConditions& conditions) { KeyMap::const_iterator k = m_keys.keys.find(key); if ( k != m_keys.keys.end() ) { size_t len = conditions.size(); @@ -191,6 +191,7 @@ size_t DDDBConditionsLoader::load(key_type key, return 0; } +#if 0 /// Update a range of conditions according to the required IOV size_t DDDBConditionsLoader::update(const iov_type& req_validity, RangeConditions& conditions, @@ -228,6 +229,52 @@ size_t DDDBConditionsLoader::update(const iov_type& req_validity, m_mgr->callOnRegister(call,false); return 0; } +#endif + +/// Optimized update using conditions slice data +size_t DDDBConditionsLoader::load_many(const iov_type& /* req_validity */, + EntryVector& /* work */, + EntryVector& /* loaded */, + EntryVector& /* missing */, + iov_type& /* conditions_validity*/) +{ +#if 0 + CallArgs arg(REPLACE, 0, conditions_validity, conditions); + pair<ConditionsListener*,void*> call(this,&arg); + map<string,Condition::Object*> urls; + DDDBReaderContext local; + + local.event_time = req_validity.keyData.first; + local.valid_since = 0; + local.valid_until = 0; + m_mgr->callOnRegister(call,true); + + XML::UriContextReader local_reader(m_resolver, &local); + + /// First collect all required URIs + for(RC::const_iterator i=conditions.begin(); i!=conditions.end(); ++i) { + Condition::Object* c = (*i).ptr(); + size_t idx = c->address.find('#'); + string url = (idx == string::npos) ? c->address : c->address.substr(0,idx); +#if 0 + printout(INFO,"DDDB","++ Need to update: %-40s [%08X] --> %s", + c->name.c_str(), c->hash, url.c_str()); +#endif + urls.insert(make_pair(url,c)); + } + /// Now load them. In the callbacks we can check if we got all required conditions + for(map<string,Condition::Object*>::const_iterator j=urls.begin(); j!=urls.end(); ++j) { + Condition cond = (*j).second; + const AbstractMap& data = cond.get<AbstractMap>(); + const Document* doc = data.option<Document>(); + loadDocument(local_reader, doc->id, doc->name); + } + m_mgr->callOnRegister(call,false); +#endif + except("ConditionsLoader","+++ update: Invalid call!"); + return 0; +} + /// ConditionsListener overload: onRegister new condition void DDDBConditionsLoader::onRegisterCondition(Condition cond, void* param) { diff --git a/DDDB/src/DDDBDerivedCondTest.cpp b/DDDB/src/DDDBDerivedCondTest.cpp index 896397c6c0151cdc622f585e462d4afdd3e50d29..a9870b0355c7b7f48211560f2495cf99bb223635 100644 --- a/DDDB/src/DDDBDerivedCondTest.cpp +++ b/DDDB/src/DDDBDerivedCondTest.cpp @@ -26,10 +26,9 @@ #include "DD4hep/ConditionDerived.h" #include "DD4hep/Alignments.h" +#include "DDCond/ConditionsSlice.h" #include "DDCond/ConditionsAccess.h" -#include "DDCond/ConditionsManager.h" #include "DDCond/ConditionsIOVPool.h" -#include "DDCond/ConditionsPool.h" #include "DDCond/ConditionsManagerObject.h" #include "DDCond/ConditionsOperators.h" @@ -178,7 +177,7 @@ namespace { */ class ConditionsSelector { public: - typedef ConditionsManager::Dependencies Dependencies; + typedef ConditionsDependencyCollection Dependencies; string m_name; RangeConditions m_allConditions; Dependencies m_allDependencies; @@ -279,15 +278,16 @@ namespace { } int computeDependencies(long time) { - dd4hep_ptr<UserPool> user_pool; - const Dependencies& dependencies = m_allDependencies; + const ConditionsDependencyCollection& deps = m_allDependencies; const IOVType* iovType = m_manager.iovType("epoch"); + dd4hep_ptr<ConditionsSlice> slice(createSlice(m_manager,*iovType)); IOV iov(iovType, IOV::Key(time,time)); - long num_expired = m_manager.prepare(iov, user_pool, dependencies); + slice->insert(deps); + m_manager.prepare(iov, *slice); printout(INFO,"Conditions", "+++ ConditionsUpdate: Updated %ld conditions... IOV:%s", - num_expired, iov.str().c_str()); - user_pool->clear(); + long(slice->pool()->size()), iov.str().c_str()); + slice->pool()->clear(); return 1; } }; diff --git a/DDG4/python/DD4hep.py b/DDG4/python/DD4hep.py index d4dabf2daa598da15116e95b725dcaf0a3b15e6a..b8a56060b0e3d7606f1cf77fec987f157bc24448 100644 --- a/DDG4/python/DD4hep.py +++ b/DDG4/python/DD4hep.py @@ -1,4 +1,3 @@ -# $Id: $ #========================================================================== # AIDA Detector description implementation for LCD #-------------------------------------------------------------------------- @@ -43,7 +42,7 @@ def loadDD4hep(): from ROOT import gSystem result = gSystem.Load("libDDCore") if 0 != result: - raise Exception('DDG4.py: Failed to load the Geant4 library libDDCore: '+gSystem.GetErrorStr()) + raise Exception('DD4hep.py: Failed to load the DD4hep library libDDCore: '+gSystem.GetErrorStr()) from ROOT import DD4hep as module return module @@ -67,7 +66,7 @@ try: except Exception,X: import sys print '+--%-100s--+'%(100*'-',) - print '| %-100s |'%('Failed to load DDG4 library:',) + print '| %-100s |'%('Failed to load DD4hep base library:',) print '| %-100s |'%(str(X),) print '+--%-100s--+'%(100*'-',) sys.exit(1) diff --git a/DDG4/python/DDG4.py b/DDG4/python/DDG4.py index e41d01c1d61a946d0bd784eb7b8e1e44a5cea982..9c8c33e19d007881a7d85ebedc38edbef7c37980 100644 --- a/DDG4/python/DDG4.py +++ b/DDG4/python/DDG4.py @@ -1,4 +1,3 @@ -# $Id: $ #========================================================================== # AIDA Detector description implementation for LCD #-------------------------------------------------------------------------- diff --git a/examples/AlignDet/CMakeLists.txt b/examples/AlignDet/CMakeLists.txt index 46c5fe4d88f373848acbf8d4f7252c510986107c..d62a1bf3c96e4f5e3553fce2198b7170b6fdd985 100644 --- a/examples/AlignDet/CMakeLists.txt +++ b/examples/AlignDet/CMakeLists.txt @@ -15,12 +15,12 @@ include ( ${DD4hep_DIR}/cmake/DD4hep.cmake ) dd4hep_configure_output() dd4hep_package ( AlignDet MAJOR 0 MINOR 0 PATCH 1 USES [ROOT REQUIRED COMPONENTS Geom GenVector MathCore] - [DD4hep REQUIRED COMPONENTS DDCore DDAlign] + [DD4hep REQUIRED COMPONENTS DDCore DDCond DDAlign] OPTIONAL XERCESC INCLUDE_DIRS include ) -dd4hep_add_plugin( AlignDet SOURCES src/*.cpp ) +dd4hep_add_plugin( AlignDetExample SOURCES src/*.cpp ) dd4hep_install_dir( compact DESTINATION examples/AlignDet ) dd4hep_configure_scripts( AlignDet DEFAULT_SETUP WITH_TESTS) @@ -29,10 +29,18 @@ dd4hep_configure_scripts( AlignDet DEFAULT_SETUP WITH_TESTS) dd4hep_add_test_reg( test_AlignDet_Telescope_dump_geometry COMMAND "${CMAKE_INSTALL_PREFIX}/bin/run_test_AlignDet.sh" EXEC_ARGS geoPluginRun -volmgr -destroy - -compact file:${CMAKE_CURRENT_SOURCE_DIR}/../AlignDet/compact/Telescope.xml + -compact file:${CMAKE_CURRENT_SOURCE_DIR}/compact/Telescope.xml -plugin DD4hepDetectorDump REGEX_PASS "/world/Telescope/module_9 NumDau\\:1 VolID\\:00000903 Place") # +#---Testing: Load Telescope geometry and read conditions ------------------ +dd4hep_add_test_reg( test_AlignDet_Telescope_dump_alignments + COMMAND "${CMAKE_INSTALL_PREFIX}/bin/run_test_AlignDet.sh" + EXEC_ARGS geoPluginRun -volmgr -destroy -plugin DD4hep_AlignmentExample + -input file:${DD4hep_DIR}/examples/AlignDet/compact/Telescope.xml + -deltas file:${DD4hep_DIR}/examples/Conditions/data/repository.xml + REGEX_PASS "\\[E42813AA\\] -> \\[E42813AA\\] /world/Telescope/module_9/sensor#alignment/Tranformations") +# #---Testing: Load ALEPH TPC geometry -------------------------------------- dd4hep_add_test_reg( test_AlignDet_AlephTPC_load COMMAND "${CMAKE_INSTALL_PREFIX}/bin/run_test_AlignDet.sh" diff --git a/examples/AlignDet/src/AlignmentExample.cpp b/examples/AlignDet/src/AlignmentExample.cpp index 9f0c34fb8a2a0b6d923ac6db918f423537cafb83..e6e76f9bd39b74779551c641a7bf1be98c6715a4 100644 --- a/examples/AlignDet/src/AlignmentExample.cpp +++ b/examples/AlignDet/src/AlignmentExample.cpp @@ -27,10 +27,11 @@ #include "DD4hep/Conditions.h" #include "DD4hep/Alignments.h" #include "DD4hep/DetectorProcessor.h" -#include "DD4hep/AlignedVolumePrinter.h" +#include "DD4hep/AlignmentsPrinter.h" #include "DD4hep/Factories.h" +#include "DD4hep/DetAlign.h" -#include "DDCond/ConditionsManager.h" +#include "DDCond/ConditionsSlice.h" #include "DDAlign/AlignmentsManager.h" #include "DDAlign/DDAlignUpdateCall.h" #include "DDAlign/DDAlignForwardCall.h" @@ -41,13 +42,39 @@ using namespace std; using namespace DD4hep; using namespace DD4hep::Alignments; +// Don't clutter global namespace namespace { + + /// Example how to access the alignment constants from a detector element + /** + * \author M.Frank + * \version 1.0 + * \date 01/04/2016 + */ + struct AlignmentDataAccess : public AlignmentsProcessor { + Conditions::UserPool* pool; + AlignmentDataAccess(Conditions::UserPool* p) : AlignmentsProcessor(0), pool(p) {} + int processElement(DetElement de) { + DetAlign a(de); // Use special facade... + Container container = a.alignments(); + // Let's go for the deltas.... + for(const auto& k : container.keys() ) { + Alignment align = container.get(k.first,*pool); + const Delta& delta = align.data().delta; + if ( delta.hasTranslation() || delta.hasPivot() || delta.hasRotation() ) {} + } + // Keep it simple. To know how to access stuff, + // simply look in DDDCore/src/AlignmentsPrinter.cpp... + printElementPlacement("Example",de,pool); + return 1; + } + }; struct Proc : public Geometry::DetectorProcessor { DetElement::Processor* proc; virtual int operator()(DetElement de, int) { return proc->processElement(de); } template <typename Q> Proc& scan(Q& p, DetElement start) - { proc = &p; this->process(start, 0, true); return *this; } + { Proc obj; obj.proc = &p; obj.process(start, 0, true); return *this; } }; } @@ -99,33 +126,31 @@ static int alignment_example (Geometry::LCDD& lcdd, int argc, char** argv) { if ( 0 == iov_typ ) { except("ConditionsPrepare","++ Unknown IOV type supplied."); } - IOV iov(iov_typ,1500); // IOV goes from run 1000 ... 2000 - dd4hep_ptr<Conditions::UserPool> pool; // Working set up conditions for this IOV - - long num_updated = condMgr.prepare(iov, pool); + IOV req_iov(iov_typ,1500); // IOV goes from run 1000 ... 2000 + dd4hep_ptr<Conditions::ConditionsSlice> slice(Conditions::createSlice(condMgr,*iov_typ)); + dd4hep_ptr<Conditions::UserPool>& pool = slice->pool(); + long num_updated = condMgr.prepare(req_iov,*slice); printout(DEBUG,"Example","Updated %ld conditions of type %s.",num_updated, iov_typ->str().c_str()); + printout(INFO,"Example","Updated %ld [%ld] conditions of type %s.", + num_updated, slice->conditions().size(), iov_typ->str().c_str()); + AlignmentsRegister reg(alignMgr,new DDAlignUpdateCall(),pool.get()); AlignmentsForward fwd(alignMgr,new DDAlignForwardCall(),pool.get()); // Let's register the callbacks to compute dependent conditions/alignments Proc() - .scan(reg,lcdd.world()) - .scan(fwd,lcdd.world()); + .scan(reg,lcdd.world()) // Create dependencies for all deltas found in the conditions + .scan(fwd,lcdd.world()); // Create child dependencies if higher level alignments exist // ++++++++++++++++++++++++ Now the registration is finished. // ++++++++++++++++++++++++ The following has to be done for each new IOV.... - - // Need to compute the conditions sources - num_updated = condMgr.prepare(iov, pool); - printout(DEBUG,"Example","Updated %ld conditions of type %s.",num_updated, iov_typ->str().c_str()); - // Let's compute the tranformation matrices - alignMgr.compute(pool); + alignMgr.compute(*slice); - // What else ? let's print the result - AlignedVolumePrinter printer(pool.get(),"ExamplePrint"); - Proc().scan(printer,lcdd.world()); + // What else ? let's access the data + AlignmentDataAccess access(pool.get()); + Proc().scan(access,lcdd.world()); // All done. return 1; diff --git a/examples/Conditions/CMakeLists.txt b/examples/Conditions/CMakeLists.txt index 3c4d2e756ce262cd387d63f1d6dd05719e34bf35..dc088294369961f103d1f21167bb9a2a60b762b9 100644 --- a/examples/Conditions/CMakeLists.txt +++ b/examples/Conditions/CMakeLists.txt @@ -1,4 +1,3 @@ -# $Id: $ #========================================================================== # AIDA Detector description implementation for LCD #-------------------------------------------------------------------------- @@ -14,10 +13,13 @@ include ( ${DD4hep_DIR}/cmake/DD4hep.cmake ) #-------------------------------------------------------------------------- dd4hep_configure_output () -dd4hep_package ( CLICSiD MAJOR 0 MINOR 0 PATCH 1 - USES [ROOT REQUIRED COMPONENTS Geom] - [DD4hep REQUIRED COMPONENTS DDCore] +dd4hep_package ( Conditions MAJOR 0 MINOR 0 PATCH 1 + USES [ROOT REQUIRED COMPONENTS Geom GenVector] + [DD4hep REQUIRED COMPONENTS DDCore DDCond DDAlign] + OPTIONAL XERCESC ) +#----------------------------------------------------------------------------------- +dd4hep_add_plugin(ConditionsExample SOURCES src/*.cpp) dd4hep_install_dir( xml DESTINATION ${DD4hep_DIR}/examples/Conditions ) dd4hep_install_dir( data DESTINATION ${DD4hep_DIR}/examples/Conditions ) dd4hep_configure_scripts ( Conditions DEFAULT_SETUP WITH_TESTS ) diff --git a/DDCond/src/plugins/ConditionsExample.cpp b/examples/Conditions/src/ConditionsExample.cpp similarity index 99% rename from DDCond/src/plugins/ConditionsExample.cpp rename to examples/Conditions/src/ConditionsExample.cpp index dc4206bc172b45589cc3487c3349db48adfbc8f9..797efba6452e91c87f8d28ff39c8485a811607f2 100644 --- a/DDCond/src/plugins/ConditionsExample.cpp +++ b/examples/Conditions/src/ConditionsExample.cpp @@ -12,7 +12,7 @@ //========================================================================== // Framework include files -#include "DDCond/ConditionsTest.h" +#include "ConditionsTest.h" using namespace std; using namespace DD4hep; @@ -20,7 +20,7 @@ using namespace DD4hep::Conditions; using Geometry::LCDD; using Geometry::Position; using Geometry::DetElement; - +#if 0 namespace { struct _Key : public std::string { @@ -213,3 +213,5 @@ DECLARE_APPLY(DD4hep_Test_ConditionsAccess,example1) DECLARE_APPLY(DD4hep_Test_ConditionsExample3,example3) DECLARE_APPLY(DD4hep_Test_ConditionsTreeDump,example2) DECLARE_APPLY(DD4hep_Test_CallbackInstall,DD4hep_CallbackInstallTest) + +#endif diff --git a/DDCond/src/ConditionsTest.cpp b/examples/Conditions/src/ConditionsTest.cpp similarity index 99% rename from DDCond/src/ConditionsTest.cpp rename to examples/Conditions/src/ConditionsTest.cpp index 64492a28b8aa6431aa8a038c5b926806dd5ebbd7..4ee7fe5a5b9c1fa39860021f4754c2ef03838f0c 100644 --- a/DDCond/src/ConditionsTest.cpp +++ b/examples/Conditions/src/ConditionsTest.cpp @@ -12,9 +12,9 @@ //========================================================================== // Framework include files +#include "ConditionsTest.h" #include "DD4hep/DetConditions.h" #include "DD4hep/DetectorTools.h" -#include "DDCond/ConditionsTest.h" #include "DDCond/ConditionsDataLoader.h" #include "DDCond/ConditionsManager.h" #include "DD4hep/objects/DetectorInterna.h" diff --git a/DDCond/include/DDCond/ConditionsTest.h b/examples/Conditions/src/ConditionsTest.h similarity index 98% rename from DDCond/include/DDCond/ConditionsTest.h rename to examples/Conditions/src/ConditionsTest.h index 44636fe5b9022a37841d184378be11f143f1dce0..4d30d55a9781121fe2a1224afc8ec2445aa4dc20 100644 --- a/DDCond/include/DDCond/ConditionsTest.h +++ b/examples/Conditions/src/ConditionsTest.h @@ -19,6 +19,7 @@ #include "DD4hep/Conditions.h" #include "DD4hep/DetConditions.h" #include "DD4hep/DetFactoryHelper.h" +#include "DD4hep/objects/ConditionsInterna.h" #include "DDCond/ConditionsAccess.h" #include "DDCond/ConditionsIOVPool.h"