CMS 3D CMS Logo

Classes | Namespaces | Typedefs | Functions
DDLogicalPart.h File Reference
#include <iosfwd>
#include <map>
#include <string>
#include <utility>
#include <vector>
#include "DetectorDescription/Core/interface/Singleton.h"
#include "DetectorDescription/Core/interface/DDBase.h"
#include "DetectorDescription/Core/interface/DDEnums.h"
#include "DetectorDescription/Core/interface/DDName.h"
#include "DetectorDescription/Core/interface/DDsvalues.h"

Go to the source code of this file.

Classes

class  DDLogicalPart
 A DDLogicalPart aggregates information concerning material, solid and sensitveness ... More...
 

Namespaces

 DDI
 

Typedefs

typedef DDI::Singleton< std::map< std::string, std::vector< DDName > > > LPNAMES
 

Functions

void DD_NC (const DDName &)
 
std::pair< bool, std::string > DDIsValid (const std::string &ns, const std::string &name, std::vector< DDLogicalPart > &result, bool doRegex=true)
 
std::ostream & operator<< (std::ostream &, const DDLogicalPart &)
 

Typedef Documentation

typedef DDI::Singleton<std::map<std::string, std::vector<DDName> > > LPNAMES

Definition at line 137 of file DDLogicalPart.h.

Function Documentation

void DD_NC ( const DDName )

Definition at line 14 of file DDLogicalPart.cc.

References DDI::Singleton< I >::instance(), DDName::name(), DDName::ns(), and AlCaHLTBitMon_ParallelJobs::p.

Referenced by DDLogicalPart::DDLogicalPart().

15 {
16  auto & ns = LPNAMES::instance()[n.name()];
17 
18  bool alreadyIn( false );
19  for( const auto& p : ns )
20  {
21  if( p.ns() == n.ns())
22  {
23  alreadyIn = true;
24  break;
25  }
26  }
27  if( !alreadyIn )
28  {
29  ns.emplace_back( n );
30  }
31 }
static value_type & instance()
std::pair<bool, std::string> DDIsValid ( const std::string &  ns,
const std::string &  name,
std::vector< DDLogicalPart > &  result,
bool  doRegex = true 
)

Definition at line 314 of file DDLogicalPart.cc.

References DDBase< DDName, DDI::LogicalPart * >::begin(), objects.IsoTrackAnalyzer::candidates, DDLogicalPart::DDLogicalPart(), DDBase< DDName, DDI::LogicalPart * >::end(), RemoveAddSevLevel::flag, DDI::Singleton< I >::instance(), python.rootplot.argparse::message, mps_update::status, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by DDI::Specific::createPartSelections(), and DDLogicalPart::DDLogicalPart().

315 {
316  if( !doRegex )
317  {
318  DDName ddnm( nm, ns );
319  result.emplace_back( DDLogicalPart( ddnm ));
320  return std::make_pair( true, "" );
321  }
323  Regex aRegex( nm );
324  Regex aNsRegex( ns );
325  bool emptyNs = aNsRegex.empty();
326 
327  // THIS IS THE SLOW PART: I have to compare every namespace & name of every
328  // logical part with a regex-comparison .... a linear search always through the
329  // full range of logical parts!!!!
330  /*
331  Algorithm description:
332  x. empty nm and ns argument of method means: use all matching regex ^.*$
333  a. iterate over all logical part names, match against regex for names
334  b. iterate over all namespaces of names found in a & match against regex for namespaces
335  */
336  LPNAMES::value_type::const_iterator bn(LPNAMES::instance().begin()),
337  ed(LPNAMES::instance().end());
338  typedef std::vector< LPNAMES::value_type::const_iterator> Candidates;
339  Candidates candidates;
340  if ( aRegex.notRegex() ) {
341  LPNAMES::value_type::const_iterator it = LPNAMES::instance().find(aRegex.value());
342  if (it!=ed) candidates.emplace_back(it);
343  }
344  else {
345  if ( !aRegex.range().first.empty()) {
346  bn = LPNAMES::instance().lower_bound(aRegex.range().first);
347  ed = LPNAMES::instance().upper_bound(aRegex.range().second);
348  }
349  for (LPNAMES::value_type::const_iterator it=bn; it != ed; ++it)
350  if(aRegex.match(it->first)) candidates.emplace_back(it);
351  }
352  for (const auto & it : candidates) {
353  //if (doit) edm::LogInfo("DDLogicalPart") << "rgx: " << aName << ' ' << it->first << ' ' << doit << std::endl;
354  std::vector<DDName>::size_type sz = it->second.size(); // no of 'compatible' namespaces
355  if ( emptyNs && (sz==1) ) { // accept all logical parts in all the namespaces
356  result.emplace_back(it->second[0]);
357  //std::vector<DDName>::const_iterator nsIt(it->second.begin()), nsEd(it->second.end());
358  //for(; nsIt != nsEd; ++nsIt) {
359  // result.emplace_back(DDLogicalPart(*nsIt));
360  // edm::LogInfo("DDLogicalPart") << "DDD-WARNING: multiple namespaces match (in SpecPars PartSelector): " << *nsIt << std::endl;
361  //}
362  }
363  else if ( !emptyNs ) { // only accept matching namespaces
364  std::vector<DDName>::const_iterator nsit(it->second.begin()), nsed(it->second.end());
365  for (; nsit !=nsed; ++nsit) {
366  //edm::LogInfo("DDLogicalPart") << "comparing " << aNs << " with " << *nsit << std::endl;
367  bool another_doit = aNsRegex.match(nsit->ns());
368  if ( another_doit ) {
369  //temp.emplace_back(std::make_pair(it->first,*nsit));
370  result.emplace_back(DDLogicalPart(*nsit));
371  }
372  }
373  }
374  else { // emtpyNs and sz>1 -> error, too ambigous
375  std::string message = "DDLogicalPart-name \"" + it->first +"\" matching regex \""
376  + nm + "\" has been found at least in following namespaces:\n";
377  std::vector<DDName>::const_iterator vit = it->second.begin();
378  for(; vit != it->second.end(); ++vit) {
379  message += vit->ns();
380  message += " ";
381  }
382  message += "\nQualify the name with a regexp for the namespace, i.e \".*:name-regexp\" !";
383  return std::make_pair(false,message);
384  }
385  }
386  bool flag=true;
388 
389  // check whether the found logical-parts are also defined (i.e. have material, solid ...)
390  if (!result.empty()) {
391  std::vector<DDLogicalPart>::const_iterator lpit(result.begin()), lped(result.end());
392  for (; lpit != lped; ++lpit) {
393  // std::cout << "VI- " << std::string(lpit->name()) << std::endl;
394  if (!lpit->isDefined().second) {
395  message = message + "LogicalPart " + lpit->name().fullname() + " not (yet) defined!\n";
396  flag = false;
397  }
398  }
399  }
400  else {
401  flag = false;
402  message = "No regex-match for namespace=" + ns + " name=" + nm + "\n";
403  }
404 
405  return std::make_pair(flag,message);
406 }
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:15
uint16_t size_type
static value_type & instance()
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
Definition: DDLogicalPart.h:92
#define end
Definition: vmac.h:37
#define begin
Definition: vmac.h:30
std::ostream& operator<< ( std::ostream &  ,
const DDLogicalPart  
)

Definition at line 34 of file DDLogicalPart.cc.

References DDBase< N, C >::isDefined(), and DDBase< N, C >::rep().

35 {
37  if( defined.first )
38  {
39  os << *(defined.first) << " ";
40  if( defined.second )
41  {
42  part.rep().stream( os );
43  }
44  else
45  {
46  os << "* logicalpart not defined * ";
47  }
48  }
49  else
50  {
51  os << "* logicalpart not declared * ";
52  }
53  return os;
54 }
Definition: DDBase.h:10
const DDI::rep_traits< N, C >::reference rep() const
Definition: DDBase.h:84
part
Definition: HCALResponse.h:20