diff --git a/DDCond/src/plugins/ConditionsPlugins.cpp b/DDCond/src/plugins/ConditionsPlugins.cpp index 8bf081549a73cbf4ee73051621dd4f7284b77fcb..e85bde274be2dbd7091b8df20b22ede560f74b5c 100644 --- a/DDCond/src/plugins/ConditionsPlugins.cpp +++ b/DDCond/src/plugins/ConditionsPlugins.cpp @@ -1,4 +1,3 @@ -// $Id$ //========================================================================== // AIDA Detector description implementation for LCD //-------------------------------------------------------------------------- @@ -16,7 +15,6 @@ #include "DD4hep/LCDD.h" #include "DD4hep/Printout.h" #include "DD4hep/Conditions.h" -#include "DD4hep/DetConditions.h" #include "DD4hep/DetFactoryHelper.h" #include "DD4hep/ConditionsPrinter.h" @@ -59,8 +57,9 @@ static int ddcond_install_cond_mgr (LCDD& lcdd, int argc, char** argv) { return 1; } DECLARE_APPLY(DD4hep_ConditionsManagerInstaller,ddcond_install_cond_mgr) -// ====================================================================================== + +// ====================================================================================== /// Plugin function: Dump of all Conditions pool with or without conditions /** * Factory: DD4hep_ConditionsPoolDump: Dump pools only @@ -70,18 +69,17 @@ DECLARE_APPLY(DD4hep_ConditionsManagerInstaller,ddcond_install_cond_mgr) * \version 1.0 * \date 01/04/2016 */ -static int ddcond_dump_conditions_functor(lcdd_t& lcdd, bool print_conditions, int argc, char** argv) { +static int ddcond_conditions_pool_processor(lcdd_t& lcdd, bool process_pool, bool process_conditions, int argc, char** argv) { typedef std::vector<const IOVType*> _T; typedef ConditionsIOVPool::Elements _E; typedef RangeConditions _R; ConditionsManager manager = ConditionsManager::from(lcdd); - ConditionsPrinter default_printer(""); - Condition::Processor* printer = &default_printer; - if ( argc > 0 ) { - printer = (Condition::Processor*) argv[0]; + if ( argc < 1 ) { + except("CondPoolProcessor","++ No processor functor given!"); } + Condition::Processor* processor = (Condition::Processor*)argv[0]; const _T types = manager.iovTypesUsed(); for( _T::const_iterator i = types.begin(); i != types.end(); ++i ) { const IOVType* type = *i; @@ -89,42 +87,66 @@ static int ddcond_dump_conditions_functor(lcdd_t& lcdd, bool print_conditions, i ConditionsIOVPool* pool = manager.iovPool(*type); if ( pool ) { const _E& e = pool->elements; - printout(INFO,"CondPoolDump","+++ ConditionsIOVPool for type %s [%d IOV element%s]", - type->str().c_str(), int(e.size()),e.size()==1 ? "" : "s"); + if ( process_pool ) { + printout(INFO,"CondPoolProcessor","+++ ConditionsIOVPool for type %s [%d IOV element%s]", + type->str().c_str(), int(e.size()),e.size()==1 ? "" : "s"); + } for (_E::const_iterator j=e.begin(); j != e.end(); ++j) { ConditionsPool* cp = (*j).second; - cp->print(""); - if ( print_conditions ) { + if ( process_pool ) { + cp->print(""); + } + if ( process_conditions ) { _R rc; cp->select_all(rc); for(_R::const_iterator ic=rc.begin(); ic!=rc.end(); ++ic) { - if ( printer ) { (*printer)(*ic); } - else { - /* print_conditions<void>(rc); */ - } + if ( processor ) { (*processor)(*ic); } } } } } } } - printout(INFO,"CondPoolDump","SUCCESS: +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); - printout(INFO,"CondPoolDump","SUCCESS: +++ Conditions pools successfully dumped"); - printout(INFO,"CondPoolDump","SUCCESS: +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); return 1; } +static int ddcond_conditions_pool_process(LCDD& lcdd, int argc, char** argv) { + return ddcond_conditions_pool_processor(lcdd,true,true,argc, argv); +} +DECLARE_APPLY(DD4hep_ConditionsPoolProcessor,ddcond_conditions_pool_process) + +// ====================================================================================== +/// Plugin function: Dump of all Conditions pool with or without conditions +/** + * Factory: DD4hep_ConditionsPoolDump: Dump pools only + * Factory: DD4hep_ConditionsDump: Dump pools and conditions + * + * \author M.Frank + * \version 1.0 + * \date 01/04/2016 + */ +static int ddcond_conditions_pool_print(lcdd_t& lcdd, bool print_conditions, int argc, char** argv) { + ConditionsPrinter default_printer(""); + Condition::Processor* printer = &default_printer; + if ( argc > 0 ) { + for(int i=0; i<argc; ++i) { + printout(INFO,"","arg[%d]=%s",i,argv[i]); + } + //printer = (Condition::Processor*)argv[0]; + } + const void* args[] = {printer,0}; + return ddcond_conditions_pool_processor(lcdd,true,print_conditions,1,(char**)args); +} static int ddcond_dump_pools(LCDD& lcdd, int argc, char** argv) { - return ddcond_dump_conditions_functor(lcdd,false, argc, argv); + return ddcond_conditions_pool_print(lcdd,false, argc, argv); } static int ddcond_dump_conditions(LCDD& lcdd, int argc, char** argv) { - return ddcond_dump_conditions_functor(lcdd,true, argc, argv); + return ddcond_conditions_pool_print(lcdd,true, argc, argv); } DECLARE_APPLY(DD4hep_ConditionsPoolDump,ddcond_dump_pools) DECLARE_APPLY(DD4hep_ConditionsDump,ddcond_dump_conditions) // ====================================================================================== - /// Plugin function: Dump of all Conditions associated to the detector elements /** * Factory: DD4hep_DetElementConditionsDump @@ -135,11 +157,11 @@ DECLARE_APPLY(DD4hep_ConditionsDump,ddcond_dump_conditions) */ static int ddcond_detelement_dump(LCDD& lcdd, int /* argc */, char** /* argv */) { struct Actor { - ConditionsManager manager; - ConditionsPrinter printer; - dd4hep_ptr<UserPool> user_pool; - const IOVType* iov_type; - + ConditionsManager manager; + ConditionsPrinter printer; + dd4hep_ptr<UserPool> user_pool; + const IOVType* iov_type; + /// Standard constructor Actor(ConditionsManager m) : manager(m) { iov_type = manager.iovType("run"); @@ -167,14 +189,9 @@ static int ddcond_detelement_dump(LCDD& lcdd, int /* argc */, char** /* argv */) ::snprintf(fmt,sizeof(fmt),"%03d %%-%ds %%s #Dau:%%d VolID:%%08X %%c",level+1,2*level+1); printout(INFO,"DetectorDump",fmt,"",de.path().c_str(),int(children.size()), (unsigned long)de.volumeID(), sens); + printer.setName(string(tmp)+de.name()); if ( de.hasConditions() ) { - DetConditions conds(de); - Container cont = conds.conditions(); - printer.setName(string(tmp)+de.name()); - for(const auto& k : cont->keys ) { - Condition c = cont.get(k.first,*(user_pool.get())); - (printer)(c); - } + (printer)(de, user_pool.get(), false); } for (const auto& c : de.children() ) dump(c.second,level+1); @@ -186,7 +203,64 @@ static int ddcond_detelement_dump(LCDD& lcdd, int /* argc */, char** /* argv */) DECLARE_APPLY(DD4hep_DetElementConditionsDump,ddcond_detelement_dump) // ====================================================================================== +/// Plugin function: Dump of all Conditions associated to the detector elements +/** + * Factory: DD4hep_DetElementConditionsDump + * + * \author M.Frank + * \version 1.0 + * \date 01/04/2016 + */ +static int ddcond_detelement_processor(LCDD& lcdd, int /* argc */, char** /* argv */) { + struct Actor { + ConditionsManager manager; + ConditionsPrinter printer; + dd4hep_ptr<UserPool> user_pool; + const IOVType* iov_type; + + /// 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"); + } + /// Default destructor + ~Actor() { + manager.clean(iov_type, 20); + user_pool->clear(); + user_pool.release(); + } + /// Dump method. + long dump(DetElement de,int level) { + const DetElement::Children& children = de.children(); + + PlacedVolume place = de.placement(); + char sens = place.volume().isSensitive() ? 'S' : ' '; + char fmt[128], tmp[32]; + ::snprintf(tmp,sizeof(tmp),"%03d/",level+1); + ::snprintf(fmt,sizeof(fmt),"%03d %%-%ds %%s #Dau:%%d VolID:%%08X %%c",level+1,2*level+1); + printout(INFO,"DetectorDump",fmt,"",de.path().c_str(),int(children.size()), + (unsigned long)de.volumeID(), sens); + printer.setName(string(tmp)+de.name()); + if ( de.hasConditions() ) { + (printer)(de, user_pool.get(), false); + } + for (const auto& c : de.children() ) + dump(c.second,level+1); + return 1; + } + }; + return Actor(ConditionsManager::from(lcdd)).dump(lcdd.world(),0); +} +DECLARE_APPLY(DD4hep_DetElementConditionsProcessor,ddcond_detelement_processor) + +// ====================================================================================== /// Plugin entry point: Synchronize conditions according to new IOV value /** * Factory: DD4hep_ConditionsSynchronize @@ -229,8 +303,8 @@ static long ddcond_synchronize_conditions(lcdd_t& lcdd, int argc, char** argv) { return 0; } DECLARE_APPLY(DD4hep_ConditionsSynchronize,ddcond_synchronize_conditions) -// ====================================================================================== +// ====================================================================================== /// Plugin entry point: Clean conditions reposiory according to maximum age /** * Factory: DD4hep_ConditionsClean @@ -255,8 +329,8 @@ static long ddcond_clean_conditions(lcdd_t& lcdd, int argc, char** argv) { return 0; } DECLARE_APPLY(DD4hep_ConditionsClean,ddcond_clean_conditions) -// ====================================================================================== +// ====================================================================================== /// Plugin entry point: Create repository csv file from loaded conditions /** * Factory: DD4hep_ConditionsCreateRepository @@ -278,8 +352,8 @@ static long ddcond_create_repository(lcdd_t& lcdd, int argc, char** argv) { return 0; } DECLARE_APPLY(DD4hep_ConditionsCreateRepository,ddcond_create_repository) -// ====================================================================================== +// ====================================================================================== /// Plugin entry point: Dump conditions repository csv file /** * Factory: DD4hep_ConditionsDumpRepository @@ -312,8 +386,8 @@ static long ddcond_dump_repository(lcdd_t& lcdd, int argc, char** argv) { return 0; } DECLARE_APPLY(DD4hep_ConditionsDumpRepository,ddcond_dump_repository) -// ====================================================================================== +// ====================================================================================== /// Plugin entry point: Load conditions repository csv file into conditions manager /** * Factory: DD4hep_ConditionsDumpRepository diff --git a/DDCore/include/DD4hep/Conditions.h b/DDCore/include/DD4hep/Conditions.h index 97c1d385fba5b6c9a3dd584a95855a17d798ddf7..b397b5a71abf23fab38fef085f3e3fbe1b5a34a6 100644 --- a/DDCore/include/DD4hep/Conditions.h +++ b/DDCore/include/DD4hep/Conditions.h @@ -101,7 +101,7 @@ namespace DD4hep { USER_FLAGS_LAST = 1<<31 }; - /// Abstract base for processing callbacks + /// Abstract base for processing callbacks to conditions objects /** * \author M.Frank * \version 1.0 @@ -200,12 +200,28 @@ namespace DD4hep { */ class Container : public Handle<Interna::ConditionContainer> { public: + /// Abstract base for processing callbacks to container objects + /** + * \author M.Frank + * \version 1.0 + * \ingroup DD4HEP_CONDITIONS + */ + class Processor { + public: + /// Container callback for object processing + virtual int operator()(Container container, UserPool* pool) = 0; + }; + /// Standard object type - typedef Interna::ConditionContainer Object; + typedef Interna::ConditionContainer Object; /// Forward definition of the key type - typedef Condition::key_type key_type; + typedef Condition::key_type key_type; /// Forward definition of the iov type - typedef Condition::iov_type iov_type; + typedef Condition::iov_type iov_type; + /// Forward definition of the mapping type + typedef std::pair<key_type, std::string> key_value; + /// Definition of the keys + typedef std::map<key_type, key_value> Keys; public: /// Default constructor @@ -222,6 +238,9 @@ namespace DD4hep { /// Access the number of conditons keys available for this detector element size_t numKeys() const; + /// Known keys of conditions in this container + const Keys& keys() const; + /// Access to condition objects by key and IOV. Condition get(const std::string& condition_key, const iov_type& iov); @@ -229,10 +248,10 @@ namespace DD4hep { Condition get(key_type condition_key, const iov_type& iov); /// Access to condition objects. Only conditions in the pool are accessed. - Condition get(const std::string& condition_key, const UserPool& iov); + Condition get(const std::string& condition_key, const UserPool& pool); /// Access to condition objects. Only conditions in the pool are accessed. - Condition get(key_type condition_key, const UserPool& iov); + Condition get(key_type condition_key, const UserPool& pool); }; /// Key definition to optimize ans simplyfy the access to conditions entities diff --git a/DDCore/include/DD4hep/ConditionsPrinter.h b/DDCore/include/DD4hep/ConditionsPrinter.h index 16d03146f0867a759e6afcd13e951f77c7b3e597..ad49991b4463255dfccd2935588b11ff5fe0c7ec 100644 --- a/DDCore/include/DD4hep/ConditionsPrinter.h +++ b/DDCore/include/DD4hep/ConditionsPrinter.h @@ -24,12 +24,19 @@ namespace DD4hep { /// Generic Conditions data dumper. /** + * Please note that the principle of locality applies: + * The object is designed for stack allocation and configuration. + * It may NOT be shared across threads! + * * \author M.Frank * \version 1.0 * \date 31/03/2016 * \ingroup DD4HEP_DDDB */ - class ConditionsPrinter : public Condition::Processor { + class ConditionsPrinter : + public Condition::Processor, + public Container::Processor + { public: std::string name; std::string prefix; @@ -37,17 +44,21 @@ namespace DD4hep { int m_flag; public: - typedef Conditions::Condition Cond; + typedef Conditions::Container Container; /// Initializing constructor ConditionsPrinter(const std::string& prefix="", - int flag=Cond::NO_NAME|Cond::WITH_IOV|Cond::WITH_ADDRESS); + int flag=Condition::NO_NAME|Condition::WITH_IOV|Condition::WITH_ADDRESS); /// Set name for printouts void setName(const std::string& value) { name = value; } /// Set prefix for printouts void setPrefix(const std::string& value) { prefix = value; } /// Callback to output conditions information virtual int operator()(Condition cond); + /// Container callback for object processing + virtual int operator()(Container container, UserPool* pool); + /// Callback to output conditions information of an entire DetElement + virtual int operator()(DetElement de, UserPool* user_pool, bool recurse); }; } /* End namespace Conditions */ diff --git a/DDCore/src/Conditions.cpp b/DDCore/src/Conditions.cpp index e16486183643999b2ffe7295dba3dcc633b1c53e..0aaef83fc28d6481b1d03dd0ec7e866df0f586e1 100644 --- a/DDCore/src/Conditions.cpp +++ b/DDCore/src/Conditions.cpp @@ -173,6 +173,15 @@ size_t Container::numKeys() const { return o->keys.size(); } +/// Known keys of conditions in this container +const Container::Keys& Container::keys() const { + Object* o = ptr(); + if ( !o ) { + invalidHandleError<Container>(); + } + return o->keys; +} + /// Access to condition objects Condition Container::get(const string& condition_key, const iov_type& iov) { Object* o = ptr(); diff --git a/DDCore/src/ConditionsPrinter.cpp b/DDCore/src/ConditionsPrinter.cpp index 9b52b3762da0fcc545025e46b3fd7feec75ff709..0a33532cc566d7fdf7a96e9bbb4e96a584d377c4 100644 --- a/DDCore/src/ConditionsPrinter.cpp +++ b/DDCore/src/ConditionsPrinter.cpp @@ -13,8 +13,10 @@ // Framework includes #include "DD4hep/Printout.h" +#include "DD4hep/DetConditions.h" #include "DD4hep/ConditionsPrinter.h" +using std::string; using namespace DD4hep; using namespace DD4hep::Conditions; @@ -43,3 +45,39 @@ int ConditionsPrinter::operator()(Condition cond) { } return 1; } + +/// Container callback for object processing +int ConditionsPrinter::operator()(Container container, UserPool* pool) { + if ( pool ) { + for(const auto& k : container.keys() ) { + Condition c = container.get(k.first,*pool); + string cn = c.name().substr(c.name().find('#')+1); + Condition::key_type key = ConditionKey::hashCode(cn); + printout(INFO,name,"++ %s %s %s [%08X] -> %s [%08X]", + prefix.c_str(), "Condition:", cn.c_str(), key==k.first ? key : k.first, + c.name().c_str(), k.second.first); + (*this)(c); + } + return 1; + } + except(name,"Cannot dump conditions container without user-pool."); + return 0; +} + +/// Callback to output conditions information of an entire DetElement +int ConditionsPrinter::operator()(DetElement de, UserPool* pool, bool recurse) { + if ( de.isValid() ) { + if ( pool ) { + DetConditions conds(de); + (*this)(conds.conditions(), pool); + if ( recurse ) { + for (const auto& c : de.children() ) + (*this)(c.second, pool, recurse); + } + return 1; + } + except(name,"Cannot dump conditions from %s without pool",de.name()); + } + except(name,"Cannot dump conditions of an invalid detector element"); + return 0; +} diff --git a/examples/Conditions/data/Modules_run-1000...2000.xml b/examples/Conditions/data/Modules_run-1000...2000.xml index cac8e81dfaa19360b42de01396dc8eef56665dfd..636ae6368fc574aa7c8c83eb013c327e0f612df6 100644 --- a/examples/Conditions/data/Modules_run-1000...2000.xml +++ b/examples/Conditions/data/Modules_run-1000...2000.xml @@ -3,28 +3,16 @@ <!--- Created : 2016-11-07 --> <conditions> - <detelement path="/world/Telescope/module_1" ref="default_module.xml"> - <alignment> - <position x="0" y="0" z="290.0*mm"/> - <rotation x="0" y="pi/2" z="0"/> - </alignment> + <detelement path="/world/Telescope/module_1"> </detelement> - <detelement path="/world/Telescope/module_2" ref="default_module.xml"> - <alignment> - <position x="0" y="0" z="290.0*mm"/> - <rotation x="0" y="pi/2" z="0"/> - </alignment> + <detelement path="/world/Telescope/module_2"> </detelement> - <detelement path="/world/Telescope/module_3" ref="default_module.xml"> - <alignment> - <position x="0" y="0" z="290.0*mm"/> - <rotation x="0" y="pi/2" z="0"/> - </alignment> + <detelement path="/world/Telescope/module_3"> </detelement> - <detelement path="/world/Telescope/module_4" ref="default_module.xml"> + <detelement path="/world/Telescope/module_4"> </detelement> <detelement path="/world/Telescope/module_5" ref="default_module.xml"> @@ -51,7 +39,7 @@ </alignment> </detelement> - <detelement path="/world/Telescope/module_9"> + <detelement path="/world/Telescope/module_9" ref="default_module.xml"> <alignment> <position x="0" y="0" z="290.0*mm"/> <rotation x="0" y="pi/2" z="0"/>