CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions
DDLogicalPart.cc File Reference
#include "DetectorDescription/Core/interface/DDLogicalPart.h"
#include "DetectorDescription/Core/src/LogicalPart.h"
#include "DetectorDescription/Base/interface/DDdebug.h"
#include <ostream>
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include <regex.h>
#include <set>

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 9 of file DDLogicalPart.cc.

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

Referenced by DDLogicalPart::DDLogicalPart().

10 {
11  std::vector<DDName> & ns = LPNAMES::instance()[n.name()];
12  typedef std::vector<DDName>::iterator IT;
13  bool alreadyIn( false );
14  for( IT p = ns.begin(); p != ns.end(); ++p )
15  {
16  if( p->ns() == n.ns())
17  {
18  alreadyIn = true;
19  break;
20  }
21  }
22  if( !alreadyIn )
23  {
24  ns.push_back( n );
25  }
26 }
const std::string & ns() const
Returns the namespace.
Definition: DDName.cc:101
static value_type & instance()
std::vector< LinkConnSpec >::const_iterator IT
const std::string & name() const
Returns the name.
Definition: DDName.cc:87
std::pair<bool, std::string> DDIsValid ( const std::string &  ns,
const std::string &  nm,
std::vector< DDLogicalPart > &  result,
bool  doRegex 
)

Definition at line 311 of file DDLogicalPart.cc.

References begin, end, archive::flag, i, DDI::Singleton< I >::instance(), python.rootplot.argparse::message, ntuplemaker::status, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by DDI::Specific::createPartSelections().

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

Definition at line 29 of file DDLogicalPart.cc.

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

30 {
32  if( defined.first )
33  {
34  os << *(defined.first) << " ";
35  if( defined.second )
36  {
37  part.rep().stream( os );
38  }
39  else
40  {
41  os << "* logicalpart not defined * ";
42  }
43  }
44  else
45  {
46  os << "* logicalpart not declared * ";
47  }
48  return os;
49 }
Definition: DDBase.h:14
const DDI::rep_traits< N, C >::reference rep() const
Definition: DDBase.h:89
def_type isDefined() const
Definition: DDBase.h:115