-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Be able to use merged magnetic field interpolation files #38051
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7a1167b
Moved binary_ifstream to public interface
Dr15Jones d0450e0
Allow passing binary_ifstream directly to MFGridFactory
Dr15Jones ea9835f
Added separate InterpolatorBuilder class
Dr15Jones a46c0e2
Added seek interface to binary_ifstream
Dr15Jones 98be07d
Added move interfaces to binanry_ifstream
Dr15Jones 60aed87
Added interpolation field merged file handling
Dr15Jones 03f6cd4
Fix formating in binary_ifstream
Dr15Jones 75ceeb4
Extended GridFileReader to also use index files
Dr15Jones 1e773e6
Added documentation for mergeFileTable
Dr15Jones c00fa60
Added parameter to disable use of merged files for MagField
Dr15Jones File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
// -*- C++ -*- | ||
// | ||
// Package: MagneticField/GeomBuilder | ||
// Class : InterpolatorBuilder | ||
// | ||
// Implementation: | ||
// [Notes on implementation] | ||
// | ||
// Original Author: Christopher Jones | ||
// Created: Tue, 17 May 2022 20:50:21 GMT | ||
// | ||
|
||
// system include files | ||
|
||
// user include files | ||
#include "InterpolatorBuilder.h" | ||
#include "FakeInterpolator.h" | ||
|
||
#include "FWCore/ParameterSet/interface/FileInPath.h" | ||
#include "FWCore/Utilities/interface/Exception.h" | ||
#include "MagneticField/Interpolation/interface/binary_ifstream.h" | ||
#include "MagneticField/Interpolation/interface/MFGridFactory.h" | ||
#include "MagneticField/Interpolation/interface/MFGrid.h" | ||
|
||
#include "DataFormats/Math/interface/angle_units.h" | ||
// | ||
// constants, enums and typedefs | ||
// | ||
|
||
namespace magneticfield { | ||
using namespace angle_units::operators; | ||
|
||
// | ||
// static data member definitions | ||
// | ||
|
||
// | ||
// constructors and destructor | ||
// | ||
InterpolatorBuilder::InterpolatorBuilder(std::string iTableSet, bool useMergeFileIfAvailable) | ||
: tableSet_(std::move(iTableSet)) { | ||
if (not useMergeFileIfAvailable) | ||
return; | ||
auto indexFileName = edm::FileInPath::findFile("MagneticField/Interpolation/data/" + tableSet_ + "/merged.index"); | ||
if (not indexFileName.empty()) { | ||
auto binaryFileName = edm::FileInPath::findFile("MagneticField/Interpolation/data/" + tableSet_ + "/merged.bin"); | ||
if (not binaryFileName.empty()) { | ||
std::ifstream indexFile(indexFileName); | ||
while (indexFile) { | ||
std::string magFile; | ||
unsigned int offset; | ||
indexFile >> magFile >> offset; | ||
offsets_.emplace(std::move(magFile), offset); | ||
} | ||
stream_ = interpolation::binary_ifstream(binaryFileName); | ||
} | ||
} | ||
} | ||
|
||
// | ||
// member functions | ||
// | ||
std::unique_ptr<MagProviderInterpol> InterpolatorBuilder::build(volumeHandle const* vol) { | ||
if (tableSet_ == "fake" || vol->magFile == "fake") { | ||
return std::make_unique<magneticfield::FakeInterpolator>(); | ||
} | ||
|
||
// If the table is in "local" coordinates, must create a reference | ||
// frame that is appropriately rotated along the CMS Z axis. | ||
|
||
GloballyPositioned<float> rf = *(vol->placement()); | ||
|
||
if (vol->masterSector != 1) { | ||
typedef Basic3DVector<float> Vector; | ||
|
||
// Phi of the master sector | ||
double masterSectorPhi = (vol->masterSector - 1) * 1._pi / 6.; | ||
|
||
GloballyPositioned<float>::RotationType rot(Vector(0, 0, 1), -masterSectorPhi); | ||
Vector vpos(vol->placement()->position()); | ||
|
||
rf = GloballyPositioned<float>(GloballyPositioned<float>::PositionType(rot.multiplyInverse(vpos)), | ||
vol->placement()->rotation() * rot); | ||
} | ||
|
||
if (not stream_) { | ||
auto fullPath = edm::FileInPath::findFile("MagneticField/Interpolation/data/" + tableSet_ + "/" + vol->magFile); | ||
if (fullPath.empty()) { | ||
//cause the exception to happen | ||
edm::FileInPath mydata("MagneticField/Interpolation/data/" + tableSet_ + "/" + vol->magFile); | ||
return {}; | ||
} | ||
|
||
magneticfield::interpolation::binary_ifstream strm(fullPath); | ||
return std::unique_ptr<MagProviderInterpol>(MFGridFactory::build(strm, rf)); | ||
} | ||
|
||
auto find = offsets_.find(vol->magFile); | ||
if (find == offsets_.end()) { | ||
throw cms::Exception("MissingMagFileEntry") << vol->magFile << " was not an entry in the index file"; | ||
} | ||
stream_->seekg(find->second); | ||
if (stream_->fail()) { | ||
throw cms::Exception("SeekMagFileEntry") << " failed seekg within merged binary file"; | ||
} | ||
return std::unique_ptr<MagProviderInterpol>(MFGridFactory::build(*stream_, rf)); | ||
} | ||
|
||
// | ||
// const member functions | ||
// | ||
|
||
// | ||
// static member functions | ||
// | ||
} // namespace magneticfield |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This parameter doesn't actually exist in this module.