CMS 3D CMS Logo

Classes | Namespaces | Typedefs | Functions
DDLogicalPart.h File Reference
#include <iosfwd>
#include <map>
#include <memory>
#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 135 of file DDLogicalPart.h.

Function Documentation

void DD_NC ( const DDName )

Definition at line 13 of file DDLogicalPart.cc.

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

Referenced by DDLogicalPart::DDLogicalPart().

14 {
15  auto & ns = LPNAMES::instance()[n.name()];
16 
17  bool alreadyIn( false );
18  for( const auto& p : ns )
19  {
20  if( p.ns() == n.ns())
21  {
22  alreadyIn = true;
23  break;
24  }
25  }
26  if( !alreadyIn )
27  {
28  ns.emplace_back( n );
29  }
30 }
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 289 of file DDLogicalPart.cc.

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

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

290 {
291  if( !doRegex )
292  {
293  DDName ddnm( nm, ns );
294  result.emplace_back( DDLogicalPart( ddnm ));
295  return std::make_pair( true, "" );
296  }
298  Regex aRegex( nm );
299  Regex aNsRegex( ns );
300  bool emptyNs = aNsRegex.empty();
301 
302  // THIS IS THE SLOW PART: I have to compare every namespace & name of every
303  // logical part with a regex-comparison .... a linear search always through the
304  // full range of logical parts!!!!
305  /*
306  Algorithm description:
307  x. empty nm and ns argument of method means: use all matching regex ^.*$
308  a. iterate over all logical part names, match against regex for names
309  b. iterate over all namespaces of names found in a & match against regex for namespaces
310  */
311  LPNAMES::value_type::const_iterator bn(LPNAMES::instance().begin()),
312  ed(LPNAMES::instance().end());
313  typedef std::vector< LPNAMES::value_type::const_iterator> Candidates;
314  Candidates candidates;
315  if ( aRegex.notRegex() ) {
316  LPNAMES::value_type::const_iterator it = LPNAMES::instance().find(aRegex.value());
317  if (it!=ed) candidates.emplace_back(it);
318  }
319  else {
320  if ( !aRegex.range().first.empty()) {
321  bn = LPNAMES::instance().lower_bound(aRegex.range().first);
322  ed = LPNAMES::instance().upper_bound(aRegex.range().second);
323  }
324  for (LPNAMES::value_type::const_iterator it=bn; it != ed; ++it)
325  if(aRegex.match(it->first)) candidates.emplace_back(it);
326  }
327  for (const auto & it : candidates) {
328  //if (doit) edm::LogInfo("DDLogicalPart") << "rgx: " << aName << ' ' << it->first << ' ' << doit << std::endl;
329  std::vector<DDName>::size_type sz = it->second.size(); // no of 'compatible' namespaces
330  if ( emptyNs && (sz==1) ) { // accept all logical parts in all the namespaces
331  result.emplace_back(it->second[0]);
332  //std::vector<DDName>::const_iterator nsIt(it->second.begin()), nsEd(it->second.end());
333  //for(; nsIt != nsEd; ++nsIt) {
334  // result.emplace_back(DDLogicalPart(*nsIt));
335  // edm::LogInfo("DDLogicalPart") << "DDD-WARNING: multiple namespaces match (in SpecPars PartSelector): " << *nsIt << std::endl;
336  //}
337  }
338  else if ( !emptyNs ) { // only accept matching namespaces
339  std::vector<DDName>::const_iterator nsit(it->second.begin()), nsed(it->second.end());
340  for (; nsit !=nsed; ++nsit) {
341  //edm::LogInfo("DDLogicalPart") << "comparing " << aNs << " with " << *nsit << std::endl;
342  bool another_doit = aNsRegex.match(nsit->ns());
343  if ( another_doit ) {
344  //temp.emplace_back(std::make_pair(it->first,*nsit));
345  result.emplace_back(DDLogicalPart(*nsit));
346  }
347  }
348  }
349  else { // emtpyNs and sz>1 -> error, too ambigous
350  std::string message = "DDLogicalPart-name \"" + it->first +"\" matching regex \""
351  + nm + "\" has been found at least in following namespaces:\n";
352  std::vector<DDName>::const_iterator vit = it->second.begin();
353  for(; vit != it->second.end(); ++vit) {
354  message += vit->ns();
355  message += " ";
356  }
357  message += "\nQualify the name with a regexp for the namespace, i.e \".*:name-regexp\" !";
358  return std::make_pair(false,message);
359  }
360  }
361  bool flag=true;
362  std::string message;
363 
364  // check whether the found logical-parts are also defined (i.e. have material, solid ...)
365  if (!result.empty()) {
366  std::vector<DDLogicalPart>::const_iterator lpit(result.begin()), lped(result.end());
367  for (; lpit != lped; ++lpit) {
368  // std::cout << "VI- " << std::string(lpit->name()) << std::endl;
369  if (!lpit->isDefined().second) {
370  message = message + "LogicalPart " + lpit->name().fullname() + " not (yet) defined!\n";
371  flag = false;
372  }
373  }
374  }
375  else {
376  flag = false;
377  message = "No regex-match for namespace=" + ns + " name=" + nm + "\n";
378  }
379 
380  return std::make_pair(flag,message);
381 }
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:93
#define end
Definition: vmac.h:39
#define begin
Definition: vmac.h:32
std::ostream& operator<< ( std::ostream &  ,
const DDLogicalPart  
)

Definition at line 33 of file DDLogicalPart.cc.

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

34 {
36  if( defined.first )
37  {
38  os << *(defined.first) << " ";
39  if( defined.second )
40  {
41  part.rep().stream( os );
42  }
43  else
44  {
45  os << "* logicalpart not defined * ";
46  }
47  }
48  else
49  {
50  os << "* logicalpart not declared * ";
51  }
52  return os;
53 }
part
Definition: HCALResponse.h:20
std::pair< const N *, bool > def_type
Definition: DDBase.h:66