CMS 3D CMS Logo

Functions
DDLogicalPart.cc File Reference
#include "DetectorDescription/Core/interface/DDLogicalPart.h"
#include <ostream>
#include "DetectorDescription/Base/interface/Store.h"
#include "DetectorDescription/Core/interface/DDMaterial.h"
#include "DetectorDescription/Core/interface/DDSolid.h"
#include "DetectorDescription/Core/src/LogicalPart.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include <regex.h>
#include <stddef.h>

Go to the source code of this file.

Functions

void DD_NC (const DDName &n)
 
std::pair< bool, std::string > DDIsValid (const std::string &ns, const std::string &nm, std::vector< DDLogicalPart > &result, bool doRegex)
 
std::ostream & operator<< (std::ostream &os, const DDLogicalPart &part)
 

Function Documentation

void DD_NC ( const DDName n)

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  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.push_back( n );
29  }
30 }
const std::string & ns() const
Returns the namespace.
Definition: DDName.cc:104
static value_type & instance()
const std::string & name() const
Returns the name.
Definition: DDName.cc:90
std::pair<bool, std::string> DDIsValid ( const std::string &  ns,
const std::string &  nm,
std::vector< DDLogicalPart > &  result,
bool  doRegex 
)

Definition at line 313 of file DDLogicalPart.cc.

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

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

314 {
315  if( !doRegex )
316  {
317  DDName ddnm( nm, ns );
318  result.push_back( DDLogicalPart( ddnm ));
319  return std::make_pair( true, "" );
320  }
322  Regex aRegex( nm );
323  Regex aNsRegex( ns );
324  bool emptyNs = aNsRegex.empty();
325 
326  // THIS IS THE SLOW PART: I have to compare every namespace & name of every
327  // logical part with a regex-comparison .... a linear search always through the
328  // full range of logical parts!!!!
329  /*
330  Algorithm description:
331  x. empty nm and ns argument of method means: use all matching regex ^.*$
332  a. iterate over all logical part names, match against regex for names
333  b. iterate over all namespaces of names found in a & match against regex for namespaces
334  */
335  LPNAMES::value_type::const_iterator bn(LPNAMES::instance().begin()),
336  ed(LPNAMES::instance().end());
337  typedef std::vector< LPNAMES::value_type::const_iterator> Candidates;
338  Candidates candidates;
339  if ( aRegex.notRegex() ) {
340  LPNAMES::value_type::const_iterator it = LPNAMES::instance().find(aRegex.value());
341  if (it!=ed) candidates.push_back(it);
342  }
343  else {
344  if ( !aRegex.range().first.empty()) {
345  bn = LPNAMES::instance().lower_bound(aRegex.range().first);
346  ed = LPNAMES::instance().upper_bound(aRegex.range().second);
347  }
348  for (LPNAMES::value_type::const_iterator it=bn; it != ed; ++it)
349  if(aRegex.match(it->first)) candidates.push_back(it);
350  }
351  for (int i=0; i<int(candidates.size()); ++i) {
352  LPNAMES::value_type::const_iterator it = candidates[i];
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.push_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.push_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.push_back(std::make_pair(it->first,*nsit));
370  result.push_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.size()) {
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:16
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 &  os,
const DDLogicalPart part 
)

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 }
Definition: DDBase.h:10
const DDI::rep_traits< N, C >::reference rep() const
Definition: DDBase.h:84
def_type isDefined() const
Definition: DDBase.h:110