CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
magneticfield::InterpolatorBuilder Class Reference

#include <InterpolatorBuilder.h>

Public Member Functions

std::unique_ptr< MagProviderInterpolbuild (volumeHandle const *)
 
 InterpolatorBuilder (std::string iTableSet, bool useMergeFileIfAvailable=true)
 
 InterpolatorBuilder (const InterpolatorBuilder &)=delete
 
const InterpolatorBuilderoperator= (const InterpolatorBuilder &)=delete
 

Private Attributes

std::unordered_map< std::string, unsigned int > offsets_
 
std::optional< interpolation::binary_ifstreamstream_
 
std::string tableSet_
 

Detailed Description

Definition at line 34 of file InterpolatorBuilder.h.

Constructor & Destructor Documentation

◆ InterpolatorBuilder() [1/2]

InterpolatorBuilder::InterpolatorBuilder ( std::string  iTableSet,
bool  useMergeFileIfAvailable = true 
)

Definition at line 40 of file InterpolatorBuilder.cc.

References edm::FileInPath::findFile(), eostools::move(), hltrates_dqm_sourceclient-live_cfg::offset, offsets_, stream_, AlCaHLTBitMon_QueryRunRegistry::string, and tableSet_.

41  : tableSet_(std::move(iTableSet)) {
42  if (not useMergeFileIfAvailable)
43  return;
44  auto indexFileName = edm::FileInPath::findFile("MagneticField/Interpolation/data/" + tableSet_ + "/merged.index");
45  if (not indexFileName.empty()) {
46  auto binaryFileName = edm::FileInPath::findFile("MagneticField/Interpolation/data/" + tableSet_ + "/merged.bin");
47  if (not binaryFileName.empty()) {
48  std::ifstream indexFile(indexFileName);
49  while (indexFile) {
50  std::string magFile;
51  unsigned int offset;
52  indexFile >> magFile >> offset;
53  offsets_.emplace(std::move(magFile), offset);
54  }
55  stream_ = interpolation::binary_ifstream(binaryFileName);
56  }
57  }
58  }
std::optional< interpolation::binary_ifstream > stream_
std::unordered_map< std::string, unsigned int > offsets_
static std::string findFile(std::string const &)
Definition: FileInPath.cc:452
def move(src, dest)
Definition: eostools.py:511

◆ InterpolatorBuilder() [2/2]

magneticfield::InterpolatorBuilder::InterpolatorBuilder ( const InterpolatorBuilder )
delete

Member Function Documentation

◆ build()

std::unique_ptr< MagProviderInterpol > InterpolatorBuilder::build ( volumeHandle const *  vol)

Definition at line 63 of file InterpolatorBuilder.cc.

References MFGridFactory::build(), Exception, spr::find(), edm::FileInPath::findFile(), contentValuesFiles::fullPath, magneticfield::BaseVolumeHandle::magFile, magneticfield::BaseVolumeHandle::masterSector, offsets_, magneticfield::BaseVolumeHandle::placement(), GloballyPositioned< T >::position(), hcal_runs::rf, makeMuonMisalignmentScenario::rot, GloballyPositioned< T >::rotation(), stream_, and tableSet_.

Referenced by magneticfield::MagGeoBuilder::buildInterpolator().

63  {
64  if (tableSet_ == "fake" || vol->magFile == "fake") {
65  return std::make_unique<magneticfield::FakeInterpolator>();
66  }
67 
68  // If the table is in "local" coordinates, must create a reference
69  // frame that is appropriately rotated along the CMS Z axis.
70 
71  GloballyPositioned<float> rf = *(vol->placement());
72 
73  if (vol->masterSector != 1) {
75 
76  // Phi of the master sector
77  double masterSectorPhi = (vol->masterSector - 1) * 1._pi / 6.;
78 
79  GloballyPositioned<float>::RotationType rot(Vector(0, 0, 1), -masterSectorPhi);
80  Vector vpos(vol->placement()->position());
81 
83  vol->placement()->rotation() * rot);
84  }
85 
86  if (not stream_) {
87  auto fullPath = edm::FileInPath::findFile("MagneticField/Interpolation/data/" + tableSet_ + "/" + vol->magFile);
88  if (fullPath.empty()) {
89  //cause the exception to happen
90  edm::FileInPath mydata("MagneticField/Interpolation/data/" + tableSet_ + "/" + vol->magFile);
91  return {};
92  }
93 
95  return std::unique_ptr<MagProviderInterpol>(MFGridFactory::build(strm, rf));
96  }
97 
98  auto find = offsets_.find(vol->magFile);
99  if (find == offsets_.end()) {
100  throw cms::Exception("MissingMagFileEntry") << vol->magFile << " was not an entry in the index file";
101  }
102  stream_->seekg(find->second);
103  if (stream_->fail()) {
104  throw cms::Exception("SeekMagFileEntry") << " failed seekg within merged binary file";
105  }
106  return std::unique_ptr<MagProviderInterpol>(MFGridFactory::build(*stream_, rf));
107  }
ROOT::Math::Plane3D::Vector Vector
Definition: EcalHitMaker.cc:29
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
std::optional< interpolation::binary_ifstream > stream_
static MFGrid * build(const std::string &name, const GloballyPositioned< float > &vol)
Build interpolator for a binary grid file.
Point3DBase< T, GlobalTag > PositionType
std::unordered_map< std::string, unsigned int > offsets_
static std::string findFile(std::string const &)
Definition: FileInPath.cc:452

◆ operator=()

const InterpolatorBuilder& magneticfield::InterpolatorBuilder::operator= ( const InterpolatorBuilder )
delete

Member Data Documentation

◆ offsets_

std::unordered_map<std::string, unsigned int> magneticfield::InterpolatorBuilder::offsets_
private

Definition at line 51 of file InterpolatorBuilder.h.

Referenced by build(), and InterpolatorBuilder().

◆ stream_

std::optional<interpolation::binary_ifstream> magneticfield::InterpolatorBuilder::stream_
private

Definition at line 52 of file InterpolatorBuilder.h.

Referenced by build(), and InterpolatorBuilder().

◆ tableSet_

std::string magneticfield::InterpolatorBuilder::tableSet_
private

Definition at line 50 of file InterpolatorBuilder.h.

Referenced by build(), and InterpolatorBuilder().