CMS 3D CMS Logo

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

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

◆ DD_NC()

void DD_NC ( const DDName n)

Definition at line 12 of file DDLogicalPart.cc.

References DDI::Singleton< I >::instance(), dqmiodumpmetadata::n, and AlCaHLTBitMon_ParallelJobs::p.

Referenced by DDLogicalPart::DDLogicalPart().

12  {
13  auto& ns = LPNAMES::instance()[n.name()];
14 
15  bool alreadyIn(false);
16  for (const auto& p : ns) {
17  if (p.ns() == n.ns()) {
18  alreadyIn = true;
19  break;
20  }
21  }
22  if (!alreadyIn) {
23  ns.emplace_back(n);
24  }
25 }
static value_type & instance()

◆ DDIsValid()

std::pair<bool, std::string> DDIsValid ( const std::string &  ns,
const std::string &  nm,
std::vector< DDLogicalPart > &  result,
bool  doRegex 
)

Definition at line 248 of file DDLogicalPart.cc.

References HLT_2023v11_cff::candidates, mps_fire::end, RemoveAddSevLevel::flag, DDI::Singleton< I >::instance(), mps_fire::result, mps_update::status, and AlCaHLTBitMon_QueryRunRegistry::string.

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

251  {
252  if (!doRegex) {
253  DDName ddnm(nm, ns);
254  result.emplace_back(DDLogicalPart(ddnm));
255  return std::make_pair(true, "");
256  }
258  Regex aRegex(nm);
259  Regex aNsRegex(ns);
260  bool emptyNs = aNsRegex.empty();
261 
262  // THIS IS THE SLOW PART: I have to compare every namespace & name of every
263  // logical part with a regex-comparison .... a linear search always through the
264  // full range of logical parts!!!!
265  /*
266  Algorithm description:
267  x. empty nm and ns argument of method means: use all matching regex ^.*$
268  a. iterate over all logical part names, match against regex for names
269  b. iterate over all namespaces of names found in a & match against regex for namespaces
270  */
271  LPNAMES::value_type::const_iterator bn(LPNAMES::instance().begin()), ed(LPNAMES::instance().end());
272  typedef std::vector<LPNAMES::value_type::const_iterator> Candidates;
273  Candidates candidates;
274  if (aRegex.notRegex()) {
275  LPNAMES::value_type::const_iterator it = LPNAMES::instance().find(aRegex.value());
276  if (it != ed)
277  candidates.emplace_back(it);
278  } else {
279  if (!aRegex.range().first.empty()) {
280  bn = LPNAMES::instance().lower_bound(aRegex.range().first);
281  ed = LPNAMES::instance().upper_bound(aRegex.range().second);
282  }
283  for (LPNAMES::value_type::const_iterator it = bn; it != ed; ++it)
284  if (aRegex.match(it->first))
285  candidates.emplace_back(it);
286  }
287  for (const auto& it : candidates) {
288  //if (doit) edm::LogInfo("DDLogicalPart") << "rgx: " << aName << ' ' << it->first << ' ' << doit << std::endl;
289  std::vector<DDName>::size_type sz = it->second.size(); // no of 'compatible' namespaces
290  if (emptyNs && (sz == 1)) { // accept all logical parts in all the namespaces
291  result.emplace_back(it->second[0]);
292  //std::vector<DDName>::const_iterator nsIt(it->second.begin()), nsEd(it->second.end());
293  //for(; nsIt != nsEd; ++nsIt) {
294  // result.emplace_back(DDLogicalPart(*nsIt));
295  // edm::LogInfo("DDLogicalPart") << "DDD-WARNING: multiple namespaces match (in SpecPars PartSelector): " << *nsIt << std::endl;
296  //}
297  } else if (!emptyNs) { // only accept matching namespaces
298  std::vector<DDName>::const_iterator nsit(it->second.begin()), nsed(it->second.end());
299  for (; nsit != nsed; ++nsit) {
300  //edm::LogInfo("DDLogicalPart") << "comparing " << aNs << " with " << *nsit << std::endl;
301  bool another_doit = aNsRegex.match(nsit->ns());
302  if (another_doit) {
303  //temp.emplace_back(std::make_pair(it->first,*nsit));
304  result.emplace_back(DDLogicalPart(*nsit));
305  }
306  }
307  } else { // emtpyNs and sz>1 -> error, too ambigous
308  std::string message = "DDLogicalPart-name \"" + it->first + "\" matching regex \"" + nm +
309  "\" has been found at least in following namespaces:\n";
310  std::vector<DDName>::const_iterator vit = it->second.begin();
311  for (; vit != it->second.end(); ++vit) {
312  message += vit->ns();
313  message += " ";
314  }
315  message += "\nQualify the name with a regexp for the namespace, i.e \".*:name-regexp\" !";
316  return std::make_pair(false, message);
317  }
318  }
319  bool flag = true;
320  std::string message;
321 
322  // check whether the found logical-parts are also defined (i.e. have material, solid ...)
323  if (!result.empty()) {
324  std::vector<DDLogicalPart>::const_iterator lpit(result.begin()), lped(result.end());
325  for (; lpit != lped; ++lpit) {
326  // std::cout << "VI- " << std::string(lpit->name()) << std::endl;
327  if (!lpit->isDefined().second) {
328  message = message + "LogicalPart " + lpit->name().fullname() + " not (yet) defined!\n";
329  flag = false;
330  }
331  }
332  } else {
333  flag = false;
334  message = "No regex-match for namespace=" + ns + " name=" + nm + "\n";
335  }
336 
337  return std::make_pair(flag, message);
338 }
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:17
uint16_t size_type
static value_type & instance()
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
Definition: DDLogicalPart.h:93

◆ operator<<()

std::ostream& operator<< ( std::ostream &  os,
const DDLogicalPart part 
)

Definition at line 27 of file DDLogicalPart.cc.

27  {
29  if (defined.first) {
30  os << *(defined.first) << " ";
31  if (defined.second) {
32  part.rep().stream(os);
33  } else {
34  os << "* logicalpart not defined * ";
35  }
36  } else {
37  os << "* logicalpart not declared * ";
38  }
39  return os;
40 }
part
Definition: HCALResponse.h:20
std::pair< const N *, bool > def_type
Definition: DDBase.h:51