DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
ConditionsUserPool.cpp
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : M.Frank
11 //
12 //==========================================================================
13 #ifndef DDCOND_CONDITIONSMAPPEDUSERPOOL_H
14 #define DDCOND_CONDITIONSMAPPEDUSERPOOL_H
15 
16 // Framework include files
17 #include <DDCond/ConditionsPool.h>
18 #include <DD4hep/ConditionsMap.h>
19 
20 // C/C++ include files
21 #include <map>
22 #include <unordered_map>
23 
25 namespace dd4hep {
26 
28  namespace cond {
29 
32 
34 
46  template<typename MAPPING>
48  typedef MAPPING Mapping;
54 
57 
59  bool i_insert(Condition::Object* o);
60 
61  public:
65  virtual ~ConditionsMappedUserPool();
67  virtual void print(const std::string& opt) const override;
69  virtual size_t size() const override;
71  virtual void clear() override;
73  virtual bool exists(Condition::key_type hash) const override;
75  virtual bool exists(const ConditionKey& key) const override;
77  virtual Condition get(Condition::key_type hash) const override;
79  virtual Condition get(const ConditionKey& key) const override;
80 
82  virtual bool remove(Condition::key_type hash_key) override;
84  virtual bool remove(const ConditionKey& key) override;
86  virtual bool registerOne(const IOV& iov, Condition cond) override;
88  virtual size_t registerMany(const IOV& iov, const std::vector<Condition>& values) override;
90  virtual bool insert(Condition cond) override;
91 
93  virtual bool insert(DetElement detector, Condition::itemkey_type key, Condition condition) override;
95  virtual Condition get(DetElement detector, Condition::itemkey_type key) const override;
97  virtual std::vector<Condition> get(DetElement detector,
99  Condition::itemkey_type upper) const override;
101  virtual std::vector<Condition> get(Condition::key_type lower,
102  Condition::key_type upper) const override;
103 
105  virtual void scan(const Condition::Processor& processor) const override;
107  virtual void scan(Condition::key_type lower,
108  Condition::key_type upper,
109  const Condition::Processor& processor) const override;
111  virtual void scan(DetElement detector,
114  const Condition::Processor& processor) const override;
115 
117  virtual ConditionsManager::Result prepare(const IOV& required,
118  ConditionsSlice& slice,
119  ConditionUpdateUserContext* user_param) override;
120 
122  virtual size_t compute(const Dependencies& dependencies,
123  ConditionUpdateUserContext* user_param,
124  bool force) override;
125 
127  virtual ConditionsManager::Result load (const IOV& required,
128  ConditionsSlice& slice,
129  ConditionUpdateUserContext* user_param) override;
131  virtual ConditionsManager::Result compute(const IOV& required,
132  ConditionsSlice& slice,
133  ConditionUpdateUserContext* user_param) override;
134  };
135 
136  } /* End namespace cond */
137 } /* End namespace dd4hep */
138 #endif /* DDCOND_CONDITIONSMAPPEDUSERPOOL_H */
139 
140 //==========================================================================
141 // AIDA Detector description implementation
142 //--------------------------------------------------------------------------
143 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
144 // All rights reserved.
145 //
146 // For the licensing terms see $DD4hepINSTALL/LICENSE.
147 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
148 //
149 // Author : M.Frank
150 //
151 //==========================================================================
152 
153 // Framework include files
154 //#include <DDCond/ConditionsMappedPool.h>
155 #include <DD4hep/Printout.h>
156 #include <DD4hep/Factories.h>
157 #include <DD4hep/InstanceCount.h>
158 
164 
165 // C/C++ include files
166 #include <mutex>
167 
168 using namespace dd4hep::cond;
169 
170 namespace {
171 
172  class SimplePrint : public dd4hep::Condition::Processor {
174  virtual int process(dd4hep::Condition) const override { return 1; }
176  virtual int operator()(dd4hep::Condition) const override { return 1; }
178  virtual int operator()(const std::pair<dd4hep::Condition::key_type,dd4hep::Condition>& i) const override {
179  dd4hep::Condition c = i.second;
180  dd4hep::printout(dd4hep::INFO,"UserPool","++ %16llX/%16llX Val:%s %s",i.first, c->hash, c->value.c_str(), c.str().c_str());
181  return 1;
182  }
183  };
184  template <typename T> struct MapSelector : public dd4hep::ConditionsSelect {
185  T& m;
186  MapSelector(T& o) : m(o) {}
187  bool operator()(dd4hep::Condition::Object* o) const
188  { return m.emplace(o->hash,o).second; }
189  };
190  template <typename T> MapSelector<T> mapSelector(T& container)
191  { return MapSelector<T>(container); }
192 
193  template <typename T> struct Inserter {
194  T& m;
195  dd4hep::IOV* iov;
196  Inserter(T& o, dd4hep::IOV* i=0) : m(o), iov(i) {}
197  void operator()(const dd4hep::Condition& c) {
199  m.emplace(o->hash,o);
200  if ( iov ) iov->iov_intersection(o->iov->key());
201  }
202  void operator()(const std::pair<dd4hep::Condition::key_type,dd4hep::Condition>& e) { (*this)(e.second); }
203  };
204 }
205 
207 template<typename MAPPING>
209  : UserPool(mgr), m_iovPool(pool)
210 {
212  if ( mgr.isValid() ) {
213  if ( m_iovPool ) {
215  m_loader = mgr->loader();
216  if ( m_loader ) return;
217  except("UserPool","The conditions manager is not properly setup. No conditions loader present.");
218  }
219  except("UserPool","FAILED to create mapped user pool. [Invalid IOV pool]");
220  }
221  except("UserPool","FAILED to create mapped user pool. [Invalid conditions manager]");
222 }
223 
225 template<typename MAPPING>
227  clear();
229 }
230 
231 template<typename MAPPING> inline dd4hep::Condition::Object*
233  typename MAPPING::const_iterator i=m_conditions.find(key);
234 #if 0
235  if ( i == m_conditions.end() ) {
236  print("*"); // This causes CTEST to bail out, due too much output!
237  }
238 #endif
239  return i != m_conditions.end() ? (*i).second : 0;
240 }
241 
242 template<typename MAPPING> inline bool
244  int ret = m_conditions.emplace(o->hash,o).second;
245  if ( flags&PRINT_INSERT ) {
246  printout(INFO,"UserPool","++ %s condition [%016llX]"
247 #if defined(DD4HEP_CONDITIONS_HAVE_NAME)
248  ": %s [%s].", ret ? "Successfully inserted" : "FAILED to insert",
249  o->hash, o->GetName(), o->GetTitle());
250 #else
251  , ret ? "Successfully inserted" : "FAILED to insert", o->hash);
252 #endif
253  }
254  return ret;
255 }
256 
258 template<typename MAPPING>
260  return m_conditions.size();
261 }
262 
264 template<typename MAPPING>
265 void ConditionsMappedUserPool<MAPPING>::print(const std::string& opt) const {
266  const IOV* iov = &m_iov;
267  printout(INFO,"UserPool","+++ %s Conditions for USER pool with IOV: %-32s [%4d entries]",
268  opt.c_str(), iov->str().c_str(), size());
269  if ( opt == "*" ) {
270  SimplePrint prt;
271  scan(prt);
272  }
273 }
274 
276 template<typename MAPPING>
278  if ( flags&PRINT_CLEAR ) {
279  printout(INFO,"UserPool","++ Cleared %ld conditions from pool.",m_conditions.size());
280  }
281  m_iov = IOV(0);
282  m_conditions.clear();
283 }
284 
286 template<typename MAPPING>
288  return i_findCondition(hash) != 0;
289 }
290 
292 template<typename MAPPING>
294  return i_findCondition(key.hash) != 0;
295 }
296 
298 template<typename MAPPING>
300  return i_findCondition(hash);
301 }
302 
304 template<typename MAPPING>
306  return i_findCondition(key.hash);
307 }
308 
310 template<typename MAPPING> bool
312  Condition cond) {
313  if ( iov.iovType ) {
314  ConditionsPool* pool = m_manager.registerIOV(*iov.iovType,iov.keyData);
315  if ( pool ) {
316  return m_manager.registerUnlocked(*pool, cond);
317  }
318  except("UserPool","++ Failed to register IOV: %s",iov.str().c_str());
319  }
320  except("UserPool","++ Cannot register conditions with invalid IOV.");
321  return 0;
322 }
323 
325 template<typename MAPPING> std::size_t
327  const std::vector<Condition>& conds) {
328  if ( iov.iovType ) {
329  ConditionsPool* pool = m_manager.registerIOV(*iov.iovType,iov.keyData);
330  if ( pool ) {
331  std::size_t result = m_manager.blockRegister(*pool, conds);
332  if ( result == conds.size() ) {
333  for(auto c : conds) i_insert(c.ptr());
334  return result;
335  }
336  except("UserPool","++ Conditions registration was incomplete: "
337  "registerd only %ld out of %ld conditions.",
338  result, conds.size());
339  }
340  except("UserPool","++ Failed to register IOV: %s",iov.str().c_str());
341  }
342  except("UserPool","++ Cannot register conditions with invalid IOV.");
343  return 0;
344 }
345 
347 template<typename MAPPING>
349  bool result = i_insert(cond.ptr());
350  if ( result ) return true;
351  except("UserPool","++ Attempt to double insert condition: %16llX Name:%s", cond->hash, cond.name());
352  return false;
353 }
354 
356 template<typename MAPPING>
358  unsigned int item_key,
359  Condition cond) {
360  cond->hash = ConditionKey::KeyMaker(detector.key(),item_key).hash;
361  return insert(cond);
362 }
363 
365 template<typename MAPPING>
367  return get(ConditionKey::KeyMaker(detector.key(), item_key).hash);
368 }
369 
371 template<typename MAPPING> std::vector<dd4hep::Condition>
374  Condition::itemkey_type upper) const {
375  Condition::detkey_type det_key = detector.key();
376  return this->get(ConditionKey::KeyMaker(det_key,lower).hash,
377  ConditionKey::KeyMaker(det_key,upper).hash);
378 }
379 
381 template<typename MAPPING> std::vector<dd4hep::Condition>
383  std::vector<Condition> result;
384  if ( !m_conditions.empty() ) {
385  typename MAPPING::const_iterator first = m_conditions.lower_bound(lower);
386  for(; first != m_conditions.end(); ++first ) {
387  if ( (*first).first > upper ) break;
388  result.emplace_back((*first).second);
389  }
390  }
391  return result;
392 }
393 
395 template<typename MAPPING>
397  for( const auto& i : m_conditions )
398  processor(i.second);
399 }
400 
402 template<typename MAPPING>
406  const Condition::Processor& processor) const
407 {
408  Condition::detkey_type det_key = detector.key();
409  scan(ConditionKey::KeyMaker(det_key,lower).hash,
410  ConditionKey::KeyMaker(det_key,upper).hash,
411  processor);
412 }
413 
415 template<typename MAPPING>
417  Condition::key_type upper,
418  const Condition::Processor& processor) const
419 {
420  typename MAPPING::const_iterator first = m_conditions.lower_bound(lower);
421  for(; first != m_conditions.end() && (*first).first <= upper; ++first )
422  processor((*first).second);
423 }
424 
426 template<typename MAPPING>
428  return remove(key.hash);
429 }
430 
432 template<typename MAPPING>
434  typename MAPPING::iterator i = m_conditions.find(hash_key);
435  if ( i != m_conditions.end() ) {
436  m_conditions.erase(i);
437  return true;
438  }
439  return false;
440 }
441 
443 template<typename MAPPING>
445  ConditionUpdateUserContext* user_param,
446  bool force)
447 {
448  if ( !deps.empty() ) {
449  Dependencies missing;
450  // Loop over the dependencies and check if they have to be upgraded
451  for ( const auto& i : deps ) {
452  typename MAPPING::iterator j = m_conditions.find(i.first);
453  if ( j != m_conditions.end() ) {
454  if ( !force ) {
455  Condition::Object* c = (*j).second;
456  // Remeber: key ist first, test is second!
457  if ( !IOV::key_is_contained(m_iov.keyData,c->iov->keyData) ) {
460  m_conditions.erase(j);
461  missing.emplace(i);
462  }
463  continue;
464  }
465  else {
466  m_conditions.erase(j);
467  }
468  }
469  missing.emplace(i);
470  }
471  if ( !missing.empty() ) {
472  ConditionsManagerObject* mgr(m_manager.access());
473  ConditionsDependencyHandler handler(mgr, *this, missing, user_param);
475  handler.compute();
477  handler.resolve();
478  return handler.num_callback;
479  }
480  }
481  return 0;
482 }
483 
484 namespace {
485  struct COMP {
486  typedef std::pair<dd4hep::Condition::key_type,const ConditionDependency*> Dep;
487  typedef std::pair<const dd4hep::Condition::key_type,dd4hep::detail::ConditionObject*> Cond;
488  typedef std::pair<const dd4hep::Condition::key_type,ConditionsLoadInfo* > Info;
489  typedef std::pair<const dd4hep::Condition::key_type,dd4hep::Condition> Cond2;
490 
491  bool operator()(const Dep& a,const Cond& b) const { return a.first < b.first; }
492  bool operator()(const Cond& a,const Dep& b) const { return a.first < b.first; }
493 
494  bool operator()(const Info& a,const Cond& b) const { return a.first < b.first; }
495  bool operator()(const Cond& a,const Info& b) const { return a.first < b.first; }
496 
497  bool operator()(const Info& a,const Cond2& b) const { return a.first < b.first; }
498  bool operator()(const Cond2& a,const Info& b) const { return a.first < b.first; }
499  };
500 }
501 
502 template<typename MAPPING> ConditionsManager::Result
504  ConditionsSlice& slice,
505  ConditionUpdateUserContext* user_param)
506 {
507  typedef std::vector<std::pair<Condition::key_type,ConditionDependency*> > CalcMissing;
508  typedef std::vector<std::pair<Condition::key_type,ConditionsLoadInfo*> > CondMissing;
509  const auto& slice_cond = slice.content->conditions();
510  const auto& slice_calc = slice.content->derived();
511  auto& slice_miss_cond = slice.missingConditions();
512  auto& slice_miss_calc = slice.missingDerivations();
513  bool do_load = m_manager->doLoadConditions();
514  bool do_output_miss = m_manager->doOutputUnloaded();
515  IOV pool_iov(required.iovType);
517 
518  // This is a critical operation, because we have to ensure the
519  // IOV pools are ONLY manipulated by the current thread.
520  // Otherwise the selection and the population are unsafe!
521  static std::mutex lock;
522  std::lock_guard<std::mutex> guard(lock);
523 
524  m_conditions.clear();
525  slice_miss_cond.clear();
526  slice_miss_calc.clear();
527  pool_iov.reset().invert();
528  m_iovPool->select(required, Operators::mapConditionsSelect(m_conditions), pool_iov);
529  m_iov = pool_iov;
530  CondMissing cond_missing(slice_cond.size()+m_conditions.size());
531  CalcMissing calc_missing(slice_calc.size()+m_conditions.size());
532 
533  CondMissing::iterator last_cond = set_difference(begin(slice_cond), end(slice_cond),
534  begin(m_conditions), end(m_conditions),
535  begin(cond_missing), COMP());
536  long num_cond_miss = last_cond-begin(cond_missing);
537  cond_missing.resize(num_cond_miss);
538  printout((flags&PRINT_LOAD) ? INFO : DEBUG,"UserPool",
539  "%ld conditions out of %ld conditions are MISSING.",
540  num_cond_miss, slice_cond.size());
541  CalcMissing::iterator last_calc = set_difference(begin(slice_calc), end(slice_calc),
542  begin(m_conditions), end(m_conditions),
543  begin(calc_missing), COMP());
544  long num_calc_miss = last_calc-begin(calc_missing);
545  calc_missing.resize(num_calc_miss);
546  printout((flags&PRINT_COMPUTE) ? INFO : DEBUG,"UserPool",
547  "%ld derived conditions out of %ld conditions are MISSING.",
548  num_calc_miss, slice_calc.size());
549 
550  result.loaded = 0;
551  result.computed = 0;
552  result.selected = m_conditions.size();
553  result.missing = num_cond_miss+num_calc_miss;
554  //
555  // Now we load the missing conditions from the conditions loader
556  //
557  if ( num_cond_miss > 0 ) {
558  if ( do_load ) {
560  size_t updates = m_loader->load_many(required, cond_missing, loaded, pool_iov);
561  if ( updates > 0 ) {
562  // Need to compute the intersection: All missing entries are required....
563  CondMissing load_missing(cond_missing.size()+loaded.size());
564  // Note: cond_missing is already sorted (doc of 'set_difference'). No need to re-sort....
565  CondMissing::iterator load_last = set_difference(begin(cond_missing), last_cond,
566  begin(loaded), end(loaded),
567  begin(load_missing), COMP());
568  long num_load_miss = load_last-begin(load_missing);
569  printout(num_load_miss==0 ? DEBUG : ERROR,"UserPool",
570  "%ld out of %ld conditions CANNOT be loaded...",
571  num_load_miss, loaded.size());
572  if ( do_output_miss ) {
573  copy(begin(load_missing), load_last, inserter(slice_miss_cond, slice_miss_cond.begin()));
574  for ( const auto& missing : slice_miss_cond ) {
575  printout (ERROR, "TEST", "Unloaded: %s",missing.second->toString().c_str());
576  }
577  }
578  for_each(loaded.begin(),loaded.end(),Inserter<MAPPING>(m_conditions,&m_iov));
579  result.loaded = slice_cond.size()-num_load_miss;
580  result.missing = num_load_miss+num_calc_miss;
581  if ( cond_missing.size() != loaded.size() ) {
582  // ERROR!
583  printout(ERROR,"UserPool","Could not load %ld out of %ld conditions. "
584  "[Unhandled error]",cond_missing.size(), slice_cond.size());
585  }
586  }
587  }
588  else if ( do_output_miss ) {
589  copy(begin(cond_missing), last_cond, inserter(slice_miss_cond, slice_miss_cond.begin()));
590  for ( const auto& missing : slice_miss_cond ) {
591  printout (ERROR, "TEST", "Unloaded: %s",missing.second->toString().c_str());
592  }
593  }
594  }
595  //
596  // Now we update the already existing dependencies, which have expired
597  //
598  if ( num_calc_miss > 0 ) {
599  if ( do_load ) {
600  std::map<Condition::key_type,const ConditionDependency*> deps(calc_missing.begin(),last_calc);
601  ConditionsDependencyHandler handler(m_manager, *this, deps, user_param);
603  handler.compute();
605  handler.resolve();
606 
607  result.computed = handler.num_callback;
608  result.missing -= handler.num_callback;
609  if ( do_output_miss && result.computed < deps.size() ) {
610  // Is this cheaper than an intersection ?
611  for( auto i = calc_missing.begin(); i != last_calc; ++i ) {
612  typename MAPPING::iterator j = m_conditions.find((*i).first);
613  if ( j == m_conditions.end() )
614  slice_miss_calc.emplace(*i);
615  }
616  }
617  }
618  else if ( do_output_miss ) {
619  copy(begin(calc_missing), last_calc, inserter(slice_miss_calc, slice_miss_calc.begin()));
620  }
621  }
622  slice.status = result;
623  slice.used_pools.clear();
624  if ( slice.flags&ConditionsSlice::REF_POOLS ) {
625  m_iovPool->select(required, slice.used_pools);
626  }
627  return result;
628 }
629 
630 template<typename MAPPING> ConditionsManager::Result
632  ConditionsSlice& slice,
633  ConditionUpdateUserContext* /* user_param */)
634 {
635  typedef std::vector<std::pair<Condition::key_type,ConditionsLoadInfo*> > CondMissing;
636  const auto& slice_cond = slice.content->conditions();
637  auto& slice_miss_cond = slice.missingConditions();
638  bool do_load = m_manager->doLoadConditions();
639  bool do_output_miss = m_manager->doOutputUnloaded();
640  IOV pool_iov(required.iovType);
642 
643  // This is a critical operation, because we have to ensure the
644  // IOV pools are ONLY manipulated by the current thread.
645  // Otherwise the selection and the population are unsafe!
646  static std::mutex lock;
647  std::lock_guard<std::mutex> guard(lock);
648 
649  m_conditions.clear();
650  slice_miss_cond.clear();
651  pool_iov.reset().invert();
652  m_iovPool->select(required, Operators::mapConditionsSelect(m_conditions), pool_iov);
653  m_iov = pool_iov;
654  CondMissing cond_missing(slice_cond.size()+m_conditions.size());
655  CondMissing::iterator last_cond = set_difference(begin(slice_cond), end(slice_cond),
656  begin(m_conditions), end(m_conditions),
657  begin(cond_missing), COMP());
658  long num_cond_miss = last_cond-begin(cond_missing);
659  cond_missing.resize(num_cond_miss);
660  printout((flags&PRINT_LOAD) ? INFO : DEBUG,"UserPool",
661  "Found %ld missing conditions out of %ld conditions.",
662  num_cond_miss, slice_cond.size());
663  result.loaded = 0;
664  result.computed = 0;
665  result.missing = num_cond_miss;
666  result.selected = m_conditions.size();
667  //
668  // Now we load the missing conditions from the conditions loader
669  //
670  if ( num_cond_miss > 0 ) {
671  if ( do_load ) {
673  size_t updates = m_loader->load_many(required, cond_missing, loaded, pool_iov);
674  if ( updates > 0 ) {
675  // Need to compute the intersection: All missing entries are required....
676  CondMissing load_missing(cond_missing.size()+loaded.size());
677  // Note: cond_missing is already sorted (doc of 'set_difference'). No need to re-sort....
678  CondMissing::iterator load_last = set_difference(begin(cond_missing), last_cond,
679  begin(loaded), end(loaded),
680  begin(load_missing), COMP());
681  long num_load_miss = load_last-begin(load_missing);
682  printout(num_load_miss==0 ? DEBUG : ERROR,"UserPool",
683  "+++ %ld out of %ld conditions CANNOT be loaded... [Not found by loader]",
684  num_load_miss, loaded.size());
685  if ( do_output_miss ) {
686  copy(begin(load_missing), load_last, inserter(slice_miss_cond, slice_miss_cond.begin()));
687  }
688  for_each(loaded.begin(),loaded.end(),Inserter<MAPPING>(m_conditions,&m_iov));
689  result.loaded = slice_cond.size()-num_load_miss;
690  result.missing = num_load_miss;
691  if ( cond_missing.size() != loaded.size() ) {
692  // ERROR!
693  }
694  }
695  }
696  else if ( do_output_miss ) {
697  copy(begin(cond_missing), last_cond, inserter(slice_miss_cond, slice_miss_cond.begin()));
698  }
699  }
700  slice.status = result;
701  return result;
702 }
703 
704 template<typename MAPPING> ConditionsManager::Result
706  ConditionsSlice& slice,
707  ConditionUpdateUserContext* user_param)
708 {
709  typedef std::vector<std::pair<Condition::key_type,ConditionDependency*> > CalcMissing;
710  const auto& slice_calc = slice.content->derived();
711  auto& slice_miss_calc = slice.missingDerivations();
712  bool do_load = m_manager->doLoadConditions();
713  bool do_output = m_manager->doOutputUnloaded();
714  IOV pool_iov(required.iovType);
716 
717  // This is a critical operation, because we have to ensure the
718  // IOV pools are ONLY manipulated by the current thread.
719  // Otherwise the selection and the population are unsafe!
720  static std::mutex lock;
721  std::lock_guard<std::mutex> guard(lock);
722 
723  slice_miss_calc.clear();
724  CalcMissing calc_missing(slice_calc.size()+m_conditions.size());
725  CalcMissing::iterator last_calc = set_difference(begin(slice_calc), end(slice_calc),
726  begin(m_conditions), end(m_conditions),
727  begin(calc_missing), COMP());
728  long num_calc_miss = last_calc-begin(calc_missing);
729  calc_missing.resize(num_calc_miss);
730  printout((flags&PRINT_COMPUTE) ? INFO : DEBUG,"UserPool",
731  "Found %ld missing derived conditions out of %ld conditions.",
732  num_calc_miss, m_conditions.size());
733 
734  result.loaded = 0;
735  result.computed = 0;
736  result.missing = num_calc_miss;
737  result.selected = m_conditions.size();
738  //
739  // Now we update the already existing dependencies, which have expired
740  //
741  if ( num_calc_miss > 0 ) {
742  if ( do_load ) {
743  std::map<Condition::key_type,const ConditionDependency*> deps(calc_missing.begin(),last_calc);
744  ConditionsDependencyHandler handler(m_manager, *this, deps, user_param);
745 
747  handler.compute();
749  handler.resolve();
750 
751  result.computed = handler.num_callback;
752  result.missing -= handler.num_callback;
753  if ( do_output && result.computed < deps.size() ) {
754  for(auto i=calc_missing.begin(); i != last_calc; ++i) {
755  typename MAPPING::iterator j = m_conditions.find((*i).first);
756  if ( j == m_conditions.end() )
757  slice_miss_calc.emplace(*i);
758  }
759  }
760  }
761  else if ( do_output ) {
762  copy(begin(calc_missing), last_calc, inserter(slice_miss_calc, slice_miss_calc.begin()));
763  }
764  }
765  slice.status += result;
766  slice.used_pools.clear();
767  if ( slice.flags&ConditionsSlice::REF_POOLS ) {
768  m_iovPool->select(required, slice.used_pools);
769  }
770  return result;
771 }
772 
773 
775 namespace dd4hep {
776 
778  namespace cond {
779 
780  typedef std::unordered_map<Condition::key_type,Condition::Object*> umap_t;
781 
783 
785  template<> void
787  Condition::key_type upper,
788  const Condition::Processor& processor) const {
789  for( const auto& e : m_conditions )
790  if ( e.second->hash >= lower && e.second->hash <= upper )
791  processor(e.second);
792  }
794 
796  template<> std::vector<Condition>
798  std::vector<Condition> result;
799  for( const auto& e : m_conditions ) {
800  if ( e.second->hash >= lower && e.second->hash <= upper )
801  result.emplace_back(e.second);
802  }
803  return result;
804  }
805  } /* End namespace cond */
806 } /* End namespace dd4hep */
807 
808 namespace {
809  template <typename MAPPING>
810  void* create_pool(dd4hep::Detector&, int argc, char** argv) {
811  if ( argc > 1 ) {
813  ConditionsIOVPool* p = (ConditionsIOVPool*)argv[1];
815  return pool;
816  }
817  dd4hep::except("ConditionsMappedUserPool","++ Insufficient arguments: arg[0] = ConditionManager!");
818  return 0;
819  }
820 }
821 
822 // Factory for the user pool using a binary tree map
823 void* create_map_user_pool(dd4hep::Detector& description, int argc, char** argv)
824 { return create_pool<std::map<dd4hep::Condition::key_type,dd4hep::Condition::Object*> >(description, argc, argv); }
825 DECLARE_DD4HEP_CONSTRUCTOR(DD4hep_ConditionsMapUserPool, create_map_user_pool)
826 
827 // Factory for the user pool using a binary tree map
828 void* create_unordered_map_user_pool(dd4hep::Detector& description, int argc, char** argv)
829 { return create_pool<std::unordered_map<dd4hep::Condition::key_type,dd4hep::Condition::Object*> >(description, argc, argv); }
830 DECLARE_DD4HEP_CONSTRUCTOR(DD4hep_ConditionsUnorderedMapUserPool, create_map_user_pool)
dd4hep::IOV::iov_intersection
void iov_intersection(const IOV &comparator)
Set the intersection of this IOV with the argument IOV.
Definition: IOV.cpp:99
dd4hep::cond::ConditionsSlice::flags
unsigned long flags
Flag to steer conditions management.
Definition: ConditionsSlice.h:116
dd4hep::cond::ConditionsManager::loader
ConditionsDataLoader & loader() const
Access the conditions loader.
Definition: ConditionsManager.cpp:188
dd4hep::Condition::value
const std::string & value() const
Access the value field of the condition as a string.
Definition: Conditions.cpp:150
dd4hep::cond::umap_t
std::unordered_map< Condition::key_type, Condition::Object * > umap_t
Definition: ConditionsUserPool.cpp:780
ConditionsSelectors.h
dd4hep::cond::ConditionsSlice::used_pools
ContainedPools used_pools
If requested refence the used pools with a shared pointer to inhibit cleanup.
Definition: ConditionsSlice.h:114
cond
AlignmentCondition::Object * cond
Definition: AlignmentsCalculator.cpp:68
dd4hep::cond::ConditionsSlice::REF_POOLS
@ REF_POOLS
Definition: ConditionsSlice.h:64
dd4hep::DetElement::key
unsigned int key() const
Access hash key of this detector element (Only valid once geometry is closed!)
Definition: DetElement.cpp:134
dd4hep::cond::ConditionsMappedUserPool::i_insert
bool i_insert(Condition::Object *o)
Internal insertion helper.
Definition: ConditionsUserPool.cpp:243
dd4hep::detail::ConditionObject::hash
Condition::key_type hash
Hash value of the name.
Definition: ConditionsInterna.h:85
dd4hep::Handle< detail::ConditionObject >::Object
detail::ConditionObject Object
Extern accessible definition of the contained element type.
Definition: Handle.h:88
dd4hep::cond::ConditionsMappedUserPool::prepare
virtual ConditionsManager::Result prepare(const IOV &required, ConditionsSlice &slice, ConditionUpdateUserContext *user_param) override
Prepare user pool for usage (load, fill etc.) according to required IOV.
Definition: ConditionsUserPool.cpp:503
dd4hep::IOV::invert
IOV & invert()
Invert the key values (first=second and second=first)
Definition: IOV.cpp:92
dd4hep::cond::ConditionsMappedUserPool::scan
virtual void scan(const Condition::Processor &processor) const override
ConditionsMap overload: Interface to scan data content of the conditions mapping.
Definition: ConditionsUserPool.cpp:396
ConditionsDataLoader.h
dd4hep::cond::ConditionsMappedUserPool::compute
virtual size_t compute(const Dependencies &dependencies, ConditionUpdateUserContext *user_param, bool force) override
Evaluate and register all derived conditions from the dependency list.
Definition: ConditionsUserPool.cpp:444
dd4hep::cond::ConditionsManager::Result::selected
size_t selected
Definition: ConditionsManager.h:61
dd4hep::cond::ConditionsMappedUserPool::exists
virtual bool exists(Condition::key_type hash) const override
Check a condition for existence.
Definition: ConditionsUserPool.cpp:287
dd4hep::Handle::isValid
bool isValid() const
Check the validity of the object held by the handle.
Definition: Handle.h:128
dd4hep::IOV::str
std::string str() const
Create string representation of the IOV.
Definition: IOV.cpp:141
dd4hep::cond::ConditionsSlice::content
std::shared_ptr< ConditionsContent > content
Container of conditions required by this slice.
Definition: ConditionsSlice.h:109
dd4hep::InstanceCount::increment
static void increment(T *)
Increment count according to type information.
Definition: InstanceCount.h:98
dd4hep::cond::ConditionsManager::Result::loaded
size_t loaded
Definition: ConditionsManager.h:62
dd4hep::ConditionKey
Key definition to optimize ans simplyfy the access to conditions entities.
Definition: Conditions.h:280
Factories.h
dd4hep::cond::ConditionUpdateUserContext
ConditionUpdateUserContext class used by the derived conditions calculation mechanism.
Definition: ConditionDerived.h:49
dd4hep::ConditionKey::KeyMaker
Helper union to interprete conditions keys.
Definition: Conditions.h:295
dd4hep::ConditionsSelect
Conditions selector functor. Default implementation selects everything evaluated.
Definition: Conditions.h:422
dd4hep::cond::ConditionsMappedUserPool::registerMany
virtual size_t registerMany(const IOV &iov, const std::vector< Condition > &values) override
Do block insertions of conditions with identical IOV including registration to the manager.
Definition: ConditionsUserPool.cpp:326
dd4hep::Condition::detkey_type
unsigned int detkey_type
High part of the key identifies the detector element.
Definition: Conditions.h:56
dd4hep::cond::ConditionsManagerObject
Basic conditions manager implementation.
Definition: ConditionsManagerObject.h:54
ConditionsManagerObject.h
dd4hep::Condition
Main condition object handle.
Definition: Conditions.h:51
dd4hep::cond::ConditionsIOVPool::type
const IOVType * type
Reference to the IOV container.
Definition: ConditionsIOVPool.h:48
dd4hep::cond
Namespace for implementation details of the AIDA detector description toolkit.
Definition: ConditionsCleanup.h:23
dd4hep::IOV
Class describing the interval of validty.
Definition: IOV.h:67
dd4hep::DetElement
Handle class describing a detector element.
Definition: DetElement.h:188
dd4hep::cond::ConditionsDependencyHandler::num_callback
size_t num_callback
Number of callbacks to the handler for monitoring.
Definition: ConditionsDependencyHandler.h:110
dd4hep::cond::ConditionsPool
Class implementing the conditions collection for a given IOV type.
Definition: ConditionsPool.h:54
dd4hep::InstanceCount::decrement
static void decrement(T *)
Decrement count according to type information.
Definition: InstanceCount.h:102
dd4hep::cond::ConditionsDependencyHandler::compute
void compute()
Access the conditions created during processing.
Definition: ConditionsDependencyHandler.cpp:94
dd4hep::IOV::keyData
Key keyData
IOV key (if second==first, discrete, otherwise range)
Definition: IOV.h:82
DECLARE_DD4HEP_CONSTRUCTOR
#define DECLARE_DD4HEP_CONSTRUCTOR(name, func)
Definition: Factories.h:291
dd4hep::cond::UserPool::m_iov
IOV m_iov
The pool's interval of validity.
Definition: ConditionsPool.h:141
dd4hep::cond::ConditionsDependencyHandler::resolve
void resolve()
2nd pass: Handler callback for the second turn to resolve missing dependencies
Definition: ConditionsDependencyHandler.cpp:109
dd4hep::cond::ConditionsSlice::missingDerivations
ConditionsContent::Dependencies & missingDerivations()
Access the map of missing computational conditions (only valid after preparation)
Definition: ConditionsSlice.h:159
dd4hep::cond::ConditionsMappedUserPool::load
virtual ConditionsManager::Result load(const IOV &required, ConditionsSlice &slice, ConditionUpdateUserContext *user_param) override
Prepare user pool for usage (load, fill etc.) according to required IOV.
Definition: ConditionsUserPool.cpp:631
dd4hep::Condition::str
std::string str(int with_data=WITH_IOV|WITH_ADDRESS|WITH_DATATYPE) const
Output method.
Definition: Conditions.cpp:95
ConditionsIOVPool.h
dd4hep::cond::ConditionsMappedUserPool::m_loader
ConditionsDataLoader * m_loader
The loader to access non-existing conditions.
Definition: ConditionsUserPool.cpp:53
dd4hep::cond::ConditionsMappedUserPool
Class implementing the conditions user pool for a given IOV type.
Definition: ConditionsUserPool.cpp:47
dd4hep::Condition::itemkey_type
unsigned int itemkey_type
Low part of the key identifies the item identifier.
Definition: Conditions.h:58
dd4hep::cond::ConditionsMappedUserPool::clear
virtual void clear() override
Full cleanup of all managed conditions.
Definition: ConditionsUserPool.cpp:277
dd4hep::cond::ConditionsSlice::status
ConditionsManager::Result status
Store the result of the prepare step.
Definition: ConditionsSlice.h:112
dd4hep::IOV::key_is_contained
static bool key_is_contained(const Key &key, const Key &test)
Check if IOV 'test' is fully contained in IOV 'key'.
Definition: IOV.h:153
dd4hep::cond::ConditionsManager::Result::missing
size_t missing
Definition: ConditionsManager.h:64
dd4hep::cond::ConditionsMappedUserPool::~ConditionsMappedUserPool
virtual ~ConditionsMappedUserPool()
Default destructor.
Definition: ConditionsUserPool.cpp:226
dd4hep::IOV::key
Key key() const
Get the local key of the IOV.
Definition: IOV.h:115
dd4hep::Condition::key_type
unsigned long long int key_type
Forward definition of the key type.
Definition: Conditions.h:54
ConditionsMap.h
dd4hep::detail::ConditionObject
The data class behind a conditions handle.
Definition: ConditionsInterna.h:68
dd4hep::cond::ConditionsManager
Manager class for condition handles.
Definition: ConditionsManager.h:46
dd4hep::cond::ConditionsMappedUserPool::i_findCondition
Condition::Object * i_findCondition(Condition::key_type key) const
Internal helper to find conditions.
Definition: ConditionsUserPool.cpp:232
dd4hep::cond::Operators::mapConditionsSelect
MapConditionsSelect< T > mapConditionsSelect(T &collection)
Helper to create functor to collect conditions using a ConditionsSelect base class.
Definition: ConditionsSelectors.h:231
dd4hep::cond::UserPool
Interface for conditions pool optimized to host conditions updates.
Definition: ConditionsPool.h:134
dd4hep::cond::ConditionsMappedUserPool::Mapping
MAPPING Mapping
Definition: ConditionsUserPool.cpp:48
dd4hep::cond::ConditionsSlice::missingConditions
ConditionsContent::Conditions & missingConditions()
Access the map of missing conditions (only valid after preparation)
Definition: ConditionsSlice.h:157
key
unsigned char key
Definition: AlignmentsCalculator.cpp:69
dd4hep::cond::ConditionsManager::Result
Result of a prepare call to the conditions manager.
Definition: ConditionsManager.h:59
dd4hep::cond::ConditionsDataLoader
Interface for a generic conditions loader.
Definition: ConditionsDataLoader.h:46
ConditionsDependencyHandler.h
dd4hep::Handle::ptr
T * ptr() const
Access to the held object.
Definition: Handle.h:153
dd4hep::IOV::reset
IOV & reset()
Set keys to unphysical values (LONG_MAX, LONG_MIN)
Definition: IOV.cpp:85
dd4hep::cond::ConditionsMappedUserPool::insert
virtual bool insert(Condition cond) override
Register a new condition to this pool.
Definition: ConditionsUserPool.cpp:348
dd4hep::IOV::iovType
const IOVType * iovType
Reference to IOV type.
Definition: IOV.h:80
dd4hep::cond::ConditionsMappedUserPool::ConditionsMappedUserPool
ConditionsMappedUserPool(ConditionsManager mgr, ConditionsIOVPool *pool)
Default constructor.
Definition: ConditionsUserPool.cpp:208
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::cond::ConditionsMappedUserPool::remove
virtual bool remove(Condition::key_type hash_key) override
Remove condition by key from pool.
Definition: ConditionsUserPool.cpp:433
dd4hep::ConditionKey::KeyMaker::hash
Condition::key_type hash
Definition: Conditions.h:296
dd4hep::cond::ConditionsDependencyHandler
Callback handler to update condition dependencies.
Definition: ConditionsDependencyHandler.h:50
dd4hep::sim::hash
unsigned int hash(unsigned int initialSeed, unsigned int eventNumber, unsigned int runNumber)
calculate hash from initialSeed, eventID and runID
Definition: Geant4EventSeed.h:201
dd4hep::Detector
The main interface to the dd4hep detector description package.
Definition: Detector.h:90
ConditionsPool.h
dd4hep::cond::ConditionsManager::Result::computed
size_t computed
Definition: ConditionsManager.h:63
dd4hep::detail::tools::copy
void copy(Alignment from, Alignment to)
Copy alignment object from source object.
Definition: AlignmentTools.cpp:43
dd4hep::cond::ConditionsMappedUserPool::get
virtual Condition get(Condition::key_type hash) const override
Check if a condition exists in the pool and return it to the caller.
Definition: ConditionsUserPool.cpp:299
dd4hep::cond::ConditionsMappedUserPool::registerOne
virtual bool registerOne(const IOV &iov, Condition cond) override
Do single insertion of condition including registration to the manager.
Definition: ConditionsUserPool.cpp:311
InstanceCount.h
dd4hep::cond::ConditionsDataLoader::LoadedItems
std::map< key_type, Condition > LoadedItems
Definition: ConditionsDataLoader.h:53
dd4hep::cond::ConditionsMappedUserPool::print
virtual void print(const std::string &opt) const override
Print pool content.
Definition: ConditionsUserPool.cpp:265
dd4hep::detail::ConditionObject::iov
const IOV * iov
Interval of validity.
Definition: ConditionsInterna.h:83
dd4hep::cond::ConditionsIOVPool
Pool of conditions satisfying one IOV type (epoch, run, fill, etc)
Definition: ConditionsIOVPool.h:38
dd4hep::cond::ConditionsMappedUserPool::m_conditions
Mapping m_conditions
Definition: ConditionsUserPool.cpp:49
dd4hep::Condition::Processor
Abstract base for processing callbacks to conditions objects.
Definition: Conditions.h:112
Printout.h
dd4hep::cond::ConditionsMappedUserPool::m_iovPool
ConditionsIOVPool * m_iovPool
IOV Pool as data source.
Definition: ConditionsUserPool.cpp:51
create_unordered_map_user_pool
void * create_unordered_map_user_pool(dd4hep::Detector &description, int argc, char **argv)
Definition: ConditionsUserPool.cpp:828
dd4hep::cond::UserPool::Dependencies
std::map< Condition::key_type, const ConditionDependency * > Dependencies
Forward definition of the key type.
Definition: ConditionsPool.h:137
dd4hep::cond::ConditionsSlice
Conditions slice object. Defines which conditions should be loaded by the ConditionsManager.
Definition: ConditionsSlice.h:53
dd4hep::cond::ConditionsMappedUserPool::size
virtual size_t size() const override
Total entry count.
Definition: ConditionsUserPool.cpp:259
create_map_user_pool
void * create_map_user_pool(dd4hep::Detector &description, int argc, char **argv)
Definition: ConditionsUserPool.cpp:823