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 134 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 296 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(), mps_update::status, and AlCaHLTBitMon_QueryRunRegistry::string.

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

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