Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

Commit

Permalink
Revert to using templates and clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
ariostas committed May 21, 2024
1 parent bb35daf commit 4308182
Show file tree
Hide file tree
Showing 13 changed files with 253 additions and 210 deletions.
14 changes: 7 additions & 7 deletions SDL/EndcapGeometry.cc
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#include "EndcapGeometry.h"

SDL::EndcapGeometry<SDL::Dev, true>::EndcapGeometry(SDL::Dev const& devAccIn,
SDL::QueueAcc& queue,
SDL::EndcapGeometry<SDL::DevHost, false> const& endcapGeometryIn)
SDL::EndcapGeometry<SDL::Dev>::EndcapGeometry(SDL::Dev const& devAccIn,
SDL::QueueAcc& queue,
SDL::EndcapGeometryHost<SDL::Dev> const& endcapGeometryIn)
: geoMapDetId_buf(allocBufWrapper<unsigned int>(devAccIn, endcapGeometryIn.centroid_phis_.size())),
geoMapPhi_buf(allocBufWrapper<float>(devAccIn, endcapGeometryIn.centroid_phis_.size())) {
dxdy_slope_ = endcapGeometryIn.dxdy_slope_;
centroid_phis_ = endcapGeometryIn.centroid_phis_;
fillGeoMapArraysExplicit(queue);
}

void SDL::EndcapGeometry<SDL::DevHost, false>::load(std::string filename) {
void SDL::EndcapGeometryHost<SDL::Dev>::load(std::string filename) {
dxdy_slope_.clear();
centroid_phis_.clear();

Expand Down Expand Up @@ -40,7 +40,7 @@ void SDL::EndcapGeometry<SDL::DevHost, false>::load(std::string filename) {
}
}

void SDL::EndcapGeometry<SDL::Dev, true>::fillGeoMapArraysExplicit(SDL::QueueAcc& queue) {
void SDL::EndcapGeometry<SDL::Dev>::fillGeoMapArraysExplicit(SDL::QueueAcc& queue) {
unsigned int phi_size = centroid_phis_.size();

// Allocate buffers on host
Expand Down Expand Up @@ -69,14 +69,14 @@ void SDL::EndcapGeometry<SDL::Dev, true>::fillGeoMapArraysExplicit(SDL::QueueAcc
alpaka::wait(queue);
}

float SDL::EndcapGeometry<SDL::Dev, true>::getdxdy_slope(unsigned int detid) const {
float SDL::EndcapGeometry<SDL::Dev>::getdxdy_slope(unsigned int detid) const {
if (dxdy_slope_.find(detid) != dxdy_slope_.end()) {
return dxdy_slope_.at(detid);
} else {
return 0;
}
}
float SDL::EndcapGeometry<SDL::DevHost, false>::getdxdy_slope(unsigned int detid) const {
float SDL::EndcapGeometryHost<SDL::Dev>::getdxdy_slope(unsigned int detid) const {
if (dxdy_slope_.find(detid) != dxdy_slope_.end()) {
return dxdy_slope_.at(detid);
} else {
Expand Down
24 changes: 14 additions & 10 deletions SDL/EndcapGeometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,40 @@

namespace SDL {

// Only the full one contains alpaka buffers
template <typename TDev, bool full>
class EndcapGeometry;
// FIXME: Need to separate this better into host and device classes
// This is only needed for host, but we template it to avoid symbol conflicts
template <typename TDev>
class EndcapGeometryHost;

template <>
class EndcapGeometry<DevHost, false> {
class EndcapGeometryHost<Dev> {
public:
std::map<unsigned int, float> dxdy_slope_; // dx/dy slope
std::map<unsigned int, float> centroid_phis_; // centroid phi

EndcapGeometry() = default;
~EndcapGeometry() = default;
EndcapGeometryHost() = default;
~EndcapGeometryHost() = default;

void load(std::string);
float getdxdy_slope(unsigned int detid) const;
};

template <typename TDev>
class EndcapGeometry;

template <>
class EndcapGeometry<Dev, true> {
class EndcapGeometry<Dev> {
private:
std::map<unsigned int, float> dxdy_slope_; // dx/dy slope
std::map<unsigned int, float> centroid_phis_; // centroid phi

public:
Buf<Dev, unsigned int> geoMapDetId_buf;
Buf<Dev, float> geoMapPhi_buf;
Buf<SDL::Dev, unsigned int> geoMapDetId_buf;
Buf<SDL::Dev, float> geoMapPhi_buf;

unsigned int nEndCapMap;

EndcapGeometry(Dev const& devAccIn, QueueAcc& queue, SDL::EndcapGeometry<DevHost, false> const& endcapGeometryIn);
EndcapGeometry(Dev const& devAccIn, QueueAcc& queue, SDL::EndcapGeometryHost<Dev> const& endcapGeometryIn);
~EndcapGeometry() = default;

void fillGeoMapArraysExplicit(QueueAcc& queue);
Expand Down
2 changes: 1 addition & 1 deletion SDL/Event.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ namespace SDL {
const unsigned int nPixels_;
const std::shared_ptr<const modulesBuffer<Dev>> modulesBuffers_;
const std::shared_ptr<const pixelMap> pixelMapping_;
const std::shared_ptr<const EndcapGeometry<Dev, true>> endcapGeometry_;
const std::shared_ptr<const EndcapGeometry<Dev>> endcapGeometry_;

public:
// Constructor used for CMSSW integration. Uses an external queue.
Expand Down
103 changes: 0 additions & 103 deletions SDL/LST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,109 +9,6 @@
#include "Math/Vector3D.h"
using XYZVector = ROOT::Math::XYZVector;

namespace {
std::string trackLooperDir() {
const char* path_lst_base = std::getenv("LST_BASE");
const char* path_tracklooperdir = std::getenv("TRACKLOOPERDIR");
std::string path_str;
if (path_lst_base != nullptr) {
path_str = path_lst_base;
} else if (path_tracklooperdir != nullptr) {
path_str = path_tracklooperdir;
} else {
// FIXME: temporary solution, will need to pass a value from FileInPath or CMSSW search path
// in the `LSTProducer` or a related ES producer
path_str = std::getenv("CMSSW_BASE");
path_str += "/src/RecoTracker/LSTCore/TrackLooper";
}
return path_str;
}

std::string get_absolute_path_after_check_file_exists(const std::string name) {
std::filesystem::path fullpath = std::filesystem::absolute(name.c_str());
if (not std::filesystem::exists(fullpath)) {
std::cout << "ERROR: Could not find the file = " << fullpath << std::endl;
exit(2);
}
return fullpath.string();
}

void loadMapsHost(SDL::MapPLStoLayer& pLStoLayer,
std::shared_ptr<SDL::EndcapGeometry<SDL::DevHost, false>> endcapGeometry,
std::shared_ptr<SDL::TiltedGeometry> tiltedGeometry,
std::shared_ptr<SDL::ModuleConnectionMap> moduleConnectionMap) {
// Module orientation information (DrDz or phi angles)
auto endcap_geom =
get_absolute_path_after_check_file_exists(trackLooperDir() + "/data/OT800_IT615_pt0.8/endcap_orientation.bin");
auto tilted_geom = get_absolute_path_after_check_file_exists(
trackLooperDir() + "/data/OT800_IT615_pt0.8/tilted_barrel_orientation.bin");
// Module connection map (for line segment building)
auto mappath = get_absolute_path_after_check_file_exists(
trackLooperDir() + "/data/OT800_IT615_pt0.8/module_connection_tracing_merged.bin");

endcapGeometry->load(endcap_geom);
tiltedGeometry->load(tilted_geom);
moduleConnectionMap->load(mappath);

auto pLSMapDir = trackLooperDir() + "/data/OT800_IT615_pt0.8/pixelmap/pLS_map";
const std::array<std::string, 4> connects{
{"_layer1_subdet5", "_layer2_subdet5", "_layer1_subdet4", "_layer2_subdet4"}};
std::string path;

static_assert(connects.size() == std::tuple_size<std::decay_t<decltype(pLStoLayer[0])>>{});
for (unsigned int i = 0; i < connects.size(); i++) {
auto connectData = connects[i].data();

path = pLSMapDir + connectData + ".bin";
pLStoLayer[0][i] = SDL::ModuleConnectionMap(get_absolute_path_after_check_file_exists(path));

path = pLSMapDir + "_pos" + connectData + ".bin";
pLStoLayer[1][i] = SDL::ModuleConnectionMap(get_absolute_path_after_check_file_exists(path));

path = pLSMapDir + "_neg" + connectData + ".bin";
pLStoLayer[2][i] = SDL::ModuleConnectionMap(get_absolute_path_after_check_file_exists(path));
}
}

} // namespace

std::unique_ptr<SDL::LSTESHostData> SDL::loadAndFillESHost() {
auto pLStoLayer = std::make_shared<SDL::MapPLStoLayer>();
auto endcapGeometry = std::make_shared<SDL::EndcapGeometry<SDL::DevHost, false>>();
auto tiltedGeometry = std::make_shared<SDL::TiltedGeometry>();
auto moduleConnectionMap = std::make_shared<SDL::ModuleConnectionMap>();
::loadMapsHost(*pLStoLayer, endcapGeometry, tiltedGeometry, moduleConnectionMap);
return std::make_unique<LSTESHostData>(pLStoLayer, endcapGeometry, tiltedGeometry, moduleConnectionMap);
}

std::unique_ptr<SDL::LSTESDeviceData<SDL::Dev>> SDL::loadAndFillESDevice(SDL::QueueAcc& queue,
const LSTESHostData* hostData) {
SDL::Dev const& devAccIn = alpaka::getDev(queue);
uint16_t nModules;
uint16_t nLowerModules;
unsigned int nPixels;
std::shared_ptr<SDL::modulesBuffer<SDL::Dev>> modulesBuffers = nullptr;
auto endcapGeometry =
std::make_shared<SDL::EndcapGeometry<SDL::Dev, true>>(devAccIn, queue, *hostData->endcapGeometry);
auto pixelMapping = std::make_shared<SDL::pixelMap>();
auto moduleConnectionMap = hostData->moduleConnectionMap;

auto path =
get_absolute_path_after_check_file_exists(trackLooperDir() + "/data/OT800_IT615_pt0.8/sensor_centroids.bin");
SDL::loadModulesFromFile(queue,
hostData->mapPLStoLayer.get(),
path.c_str(),
nModules,
nLowerModules,
nPixels,
modulesBuffers,
pixelMapping.get(),
endcapGeometry.get(),
hostData->tiltedGeometry.get(),
moduleConnectionMap.get());
return std::make_unique<LSTESDeviceData<SDL::Dev>>(
nModules, nLowerModules, nPixels, modulesBuffers, endcapGeometry, pixelMapping);
}

void SDL::LST<SDL::Acc>::run(SDL::QueueAcc& queue,
bool verbose,
Expand Down
71 changes: 2 additions & 69 deletions SDL/LST.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
#ifndef LST_H
#define LST_H

#include "HeterogeneousCore/AlpakaInterface/interface/CopyToDevice.h"

#ifdef LST_IS_CMSSW_PACKAGE
#include "RecoTracker/LSTCore/interface/alpaka/Constants.h"
#include "RecoTracker/LSTCore/interface/alpaka/LSTESData.h"
#else
#include "Constants.h"
#include "LSTESData.h"
#endif

#include <filesystem>
#include <cstdlib>
#include <numeric>
#include <mutex>
Expand All @@ -19,65 +18,9 @@ namespace SDL {
template <typename>
class Event;

struct pixelMap;
class TiltedGeometry;
class ModuleConnectionMap;
using MapPLStoLayer = std::array<std::array<ModuleConnectionMap, 4>, 3>;

template <typename>
struct modulesBuffer;

template <typename, bool>
class EndcapGeometry;

struct LSTESHostData {
const std::shared_ptr<const MapPLStoLayer> mapPLStoLayer;
const std::shared_ptr<const EndcapGeometry<DevHost, false>> endcapGeometry;
const std::shared_ptr<const TiltedGeometry> tiltedGeometry;
const std::shared_ptr<const ModuleConnectionMap> moduleConnectionMap;

LSTESHostData(std::shared_ptr<MapPLStoLayer> mapPLStoLayerIn,
std::shared_ptr<EndcapGeometry<DevHost, false>> endcapGeometryIn,
std::shared_ptr<TiltedGeometry> tiltedGeometryIn,
std::shared_ptr<ModuleConnectionMap> moduleConnectionMapIn)
: mapPLStoLayer(std::const_pointer_cast<const MapPLStoLayer>(mapPLStoLayerIn)),
endcapGeometry(std::const_pointer_cast<const EndcapGeometry<DevHost, false>>(endcapGeometryIn)),
tiltedGeometry(std::const_pointer_cast<const TiltedGeometry>(tiltedGeometryIn)),
moduleConnectionMap(std::const_pointer_cast<const ModuleConnectionMap>(moduleConnectionMapIn)) {}
};

template <typename TDev>
struct LSTESDeviceData {
const uint16_t nModules;
const uint16_t nLowerModules;
const unsigned int nPixels;
const std::shared_ptr<const modulesBuffer<TDev>> modulesBuffers;
const std::shared_ptr<const EndcapGeometry<TDev, true>> endcapGeometry;
const std::shared_ptr<const pixelMap> pixelMapping;

LSTESDeviceData(uint16_t nModulesIn,
uint16_t nLowerModulesIn,
unsigned int nPixelsIn,
std::shared_ptr<modulesBuffer<TDev>> modulesBuffersIn,
std::shared_ptr<EndcapGeometry<TDev, true>> endcapGeometryIn,
std::shared_ptr<pixelMap> pixelMappingIn)
: nModules(nModulesIn),
nLowerModules(nLowerModulesIn),
nPixels(nPixelsIn),
modulesBuffers(std::const_pointer_cast<const modulesBuffer<TDev>>(modulesBuffersIn)),
endcapGeometry(std::const_pointer_cast<const EndcapGeometry<TDev, true>>(endcapGeometryIn)),
pixelMapping(std::const_pointer_cast<const pixelMap>(pixelMappingIn)) {}
};

std::unique_ptr<LSTESHostData> loadAndFillESHost();
std::unique_ptr<LSTESDeviceData<Dev>> loadAndFillESDevice(SDL::QueueAcc& queue, const LSTESHostData* hostData);

template <typename>
class LST;

template <>
class LST<SDL::DevHost> {};

template <>
class LST<SDL::Acc> {
public:
Expand Down Expand Up @@ -169,14 +112,4 @@ namespace SDL {

} // namespace SDL

namespace cms::alpakatools {
template <>
struct CopyToDevice<SDL::LSTESHostData> {
template <typename TQueue>
static auto copyAsync(TQueue& queue, SDL::LSTESHostData const& hostData) {
return std::make_unique<SDL::LSTESHostData>(hostData);
}
};
}

#endif
Loading

0 comments on commit 4308182

Please sign in to comment.