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

Remove global variables #401

Merged
merged 24 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
329 changes: 150 additions & 179 deletions SDL/Event.cc

Large diffs are not rendered by default.

37 changes: 35 additions & 2 deletions SDL/Event.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,34 @@ namespace SDL {
int* superbinCPU;
int8_t* pixelTypeCPU;

// Stuff that used to be global
uint16_t nModules;
uint16_t nLowerModules;
std::shared_ptr<modulesBuffer<Dev>> modulesBuffers;
std::shared_ptr<pixelMap> pixelMapping;
std::shared_ptr<EndcapGeometry<Dev>> endcapGeometry;
std::shared_ptr<ModuleConnectionMap> moduleConnectionMap;

public:
// Constructor used for CMSSW integration. Uses an external queue.
template <typename TQueue>
Event(bool verbose, TQueue const& q) : queue(q), devAcc(alpaka::getDev(q)), devHost(cms::alpakatools::host()) {
Event(bool verbose,
TQueue const& q,
uint16_t nModulesIn,
uint16_t nLowerModulesIn,
std::shared_ptr<SDL::modulesBuffer<SDL::Dev>> modulesBuffersIn,
std::shared_ptr<SDL::pixelMap> pixelMappingIn,
std::shared_ptr<SDL::EndcapGeometry<SDL::Dev>> endcapGeometryIn,
std::shared_ptr<SDL::ModuleConnectionMap> moduleConnectionMapIn)
: queue(q),
devAcc(alpaka::getDev(q)),
devHost(cms::alpakatools::host()),
nModules(nModulesIn),
nLowerModules(nLowerModulesIn),
modulesBuffers(modulesBuffersIn),
pixelMapping(pixelMappingIn),
endcapGeometry(endcapGeometryIn),
moduleConnectionMap(moduleConnectionMapIn) {
init(verbose);
}
void resetEvent();
Expand Down Expand Up @@ -185,7 +209,16 @@ namespace SDL {
modulesBuffer<alpaka::DevCpu>* getModules(bool isFull = false);

//read from file and init
static void initModules(QueueAcc& queue, const MapPLStoLayer& pLStoLayer, const char* moduleMetaDataFilePath);
static void initModules(QueueAcc& queue,
const MapPLStoLayer& pLStoLayer,
const char* moduleMetaDataFilePath,
uint16_t& nModules,
uint16_t& nLowerModules,
struct modulesBuffer<SDL::Dev>* modulesBuf,
struct pixelMap* pixelMapping,
EndcapGeometry<SDL::Dev>* endcapGeometry,
TiltedGeometry* tiltedGeometry,
ModuleConnectionMap* moduleConnectionMap);
};

} // namespace SDL
Expand Down
27 changes: 0 additions & 27 deletions SDL/Globals.cc

This file was deleted.

38 changes: 0 additions & 38 deletions SDL/Globals.h

This file was deleted.

84 changes: 51 additions & 33 deletions SDL/LST.cc
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
#ifdef LST_IS_CMSSW_PACKAGE

Check notice on line 1 in SDL/LST.cc

View workflow job for this annotation

GitHub Actions / linter

Run clang-format on SDL/LST.cc

File SDL/LST.cc does not conform to Custom style guidelines. (lines 133, 134, 135, 136, 137, 138, 139)
#include "RecoTracker/LSTCore/interface/alpaka/LST.h"
#else
#include "LST.h"
#endif

#include "Event.h"
#include "Globals.h"

#include "Math/Vector3D.h"
using XYZVector = ROOT::Math::XYZVector;

namespace {
std::string trackLooperDir() {
const char* path = std::getenv("LST_BASE");
const char* path_lst_base = std::getenv("LST_BASE");
const char* path_tracklooperdir = std::getenv("TRACKLOOPERDIR");
std::string path_str;
if (path != nullptr) {
path_str = path;
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
Expand All @@ -34,23 +36,24 @@
return fullpath.string();
}

void loadMaps(SDL::Dev const& devAccIn, SDL::QueueAcc& queue, SDL::MapPLStoLayer& pLStoLayer) {
void loadMaps(SDL::Dev const& devAccIn,
SDL::QueueAcc& queue,
SDL::MapPLStoLayer& pLStoLayer,
std::shared_ptr<SDL::EndcapGeometry<SDL::Dev>> 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");
if (SDL::Globals<SDL::Dev>::endcapGeometry == nullptr) {
SDL::Globals<SDL::Dev>::endcapGeometry =
new SDL::EndcapGeometry<SDL::Dev>(devAccIn, queue, endcap_geom); // centroid values added to the map
}

SDL::Globals<SDL::Dev>::tiltedGeometry.load(tilted_geom);

// 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");
SDL::Globals<SDL::Dev>::moduleConnectionMap.load(mappath);

endcapGeometry->load(queue, 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{
Expand All @@ -62,42 +65,51 @@
auto connectData = connects[i].data();

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

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

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

} // namespace

void SDL::LST<SDL::Acc>::loadAndFillES(SDL::QueueAcc& queue, struct modulesBuffer<SDL::Dev>* modules) {
void SDL::LST<SDL::Acc>::loadAndFillES(SDL::QueueAcc& queue,
uint16_t& nModules,
uint16_t& nLowerModules,
std::shared_ptr<SDL::modulesBuffer<SDL::Dev>> modulesBuf,
std::shared_ptr<SDL::pixelMap> pixelMapping,
std::shared_ptr<SDL::EndcapGeometry<SDL::Dev>> endcapGeometry,
std::shared_ptr<SDL::TiltedGeometry> tiltedGeometry,
std::shared_ptr<SDL::ModuleConnectionMap> moduleConnectionMap) {
SDL::MapPLStoLayer pLStoLayer;
SDL::Dev const& devAccIn = alpaka::getDev(queue);
::loadMaps(devAccIn, queue, pLStoLayer);
::loadMaps(devAccIn, queue, pLStoLayer, endcapGeometry, tiltedGeometry, moduleConnectionMap);

auto path =
get_absolute_path_after_check_file_exists(trackLooperDir() + "/data/OT800_IT615_pt0.8/sensor_centroids.bin");
if (SDL::Globals<SDL::Dev>::modulesBuffers == nullptr) {
SDL::Globals<SDL::Dev>::modulesBuffers = new SDL::modulesBuffer<SDL::Dev>(devAccIn);
}
if (SDL::Globals<SDL::Dev>::pixelMapping == nullptr) {
SDL::Globals<SDL::Dev>::pixelMapping = std::make_shared<SDL::pixelMap>();
}
SDL::loadModulesFromFile(modules,
SDL::Globals<SDL::Dev>::nModules,
SDL::Globals<SDL::Dev>::nLowerModules,
*SDL::Globals<SDL::Dev>::pixelMapping,
queue,
SDL::loadModulesFromFile(queue,
pLStoLayer,
path.c_str(),
pLStoLayer);
nModules,
nLowerModules,
modulesBuf.get(),
pixelMapping.get(),
endcapGeometry.get(),
tiltedGeometry.get(),
moduleConnectionMap.get());
}

void SDL::LST<SDL::Acc>::run(SDL::QueueAcc& queue,
const SDL::modulesBuffer<SDL::Dev>* modules,
uint16_t nModules,
uint16_t nLowerModules,
std::shared_ptr<SDL::modulesBuffer<SDL::Dev>> modulesBuffers,
std::shared_ptr<SDL::pixelMap> pixelMapping,
std::shared_ptr<SDL::EndcapGeometry<SDL::Dev>> endcapGeometry,
std::shared_ptr<SDL::ModuleConnectionMap> moduleConnectionMap,
bool verbose,
const std::vector<float> see_px,
const std::vector<float> see_py,
Expand All @@ -118,8 +130,14 @@
const std::vector<float> ph2_x,
const std::vector<float> ph2_y,
const std::vector<float> ph2_z) {
SDL::Globals<SDL::Dev>::modulesBuffersES = modules;
auto event = SDL::Event<Acc>(verbose, queue);
auto event = SDL::Event<Acc>(verbose,
queue,
nModules,
nLowerModules,
modulesBuffers,
pixelMapping,
endcapGeometry,
moduleConnectionMap);
prepareInput(see_px,
see_py,
see_pz,
Expand Down
25 changes: 23 additions & 2 deletions SDL/LST.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ namespace SDL {
template <typename>
struct modulesBuffer;

struct pixelMap;

template <typename>
class EndcapGeometry;

class TiltedGeometry;

class ModuleConnectionMap;

template <typename>
class LST;

Expand All @@ -28,10 +37,22 @@ namespace SDL {
public:
LST() = default;

static void loadAndFillES(SDL::QueueAcc& queue, struct modulesBuffer<SDL::Dev>* modules);
static void loadAndFillES(SDL::QueueAcc& queue,
uint16_t& nModules,
uint16_t& nLowerModules,
std::shared_ptr<SDL::modulesBuffer<SDL::Dev>> modulesBuffers,
std::shared_ptr<SDL::pixelMap> pixelMapping,
std::shared_ptr<SDL::EndcapGeometry<SDL::Dev>> endcapGeometry,
std::shared_ptr<SDL::TiltedGeometry> tiltedGeometry,
std::shared_ptr<SDL::ModuleConnectionMap> moduleConnectionMap);

void run(SDL::QueueAcc& queue,
const SDL::modulesBuffer<SDL::Dev>* modules,
uint16_t nModules,
uint16_t nLowerModules,
std::shared_ptr<SDL::modulesBuffer<SDL::Dev>> modulesBuffers,
std::shared_ptr<SDL::pixelMap> pixelMapping,
std::shared_ptr<SDL::EndcapGeometry<SDL::Dev>> endcapGeometry,
std::shared_ptr<SDL::ModuleConnectionMap> moduleConnectionMap,
bool verbose,
const std::vector<float> see_px,
const std::vector<float> see_py,
Expand Down
16 changes: 8 additions & 8 deletions SDL/ModuleConnectionMap.cc
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#include "ModuleConnectionMap.h"

SDL::ModuleConnectionMap<SDL::Dev>::ModuleConnectionMap() {}
SDL::ModuleConnectionMap::ModuleConnectionMap() {}

SDL::ModuleConnectionMap<SDL::Dev>::ModuleConnectionMap(std::string filename) { load(filename); }
SDL::ModuleConnectionMap::ModuleConnectionMap(std::string filename) { load(filename); }

SDL::ModuleConnectionMap<SDL::Dev>::~ModuleConnectionMap() {}
SDL::ModuleConnectionMap::~ModuleConnectionMap() {}

void SDL::ModuleConnectionMap<SDL::Dev>::load(std::string filename) {
void SDL::ModuleConnectionMap::load(std::string filename) {
moduleConnections_.clear();

std::ifstream ifile(filename, std::ios::binary);
Expand Down Expand Up @@ -49,7 +49,7 @@ void SDL::ModuleConnectionMap<SDL::Dev>::load(std::string filename) {
}
}

void SDL::ModuleConnectionMap<SDL::Dev>::add(std::string filename) {
void SDL::ModuleConnectionMap::add(std::string filename) {
std::ifstream ifile;
ifile.open(filename.c_str());
std::string line;
Expand Down Expand Up @@ -81,7 +81,7 @@ void SDL::ModuleConnectionMap<SDL::Dev>::add(std::string filename) {
}
}

void SDL::ModuleConnectionMap<SDL::Dev>::print() {
void SDL::ModuleConnectionMap::print() {
std::cout << "Printing ModuleConnectionMap" << std::endl;
for (auto& pair : moduleConnections_) {
unsigned int detid = pair.first;
Expand All @@ -93,9 +93,9 @@ void SDL::ModuleConnectionMap<SDL::Dev>::print() {
}
}

const std::vector<unsigned int>& SDL::ModuleConnectionMap<SDL::Dev>::getConnectedModuleDetIds(unsigned int detid) const {
const std::vector<unsigned int>& SDL::ModuleConnectionMap::getConnectedModuleDetIds(unsigned int detid) const {
static const std::vector<unsigned int> dummy;
auto const mList = moduleConnections_.find(detid);
return mList != moduleConnections_.end() ? mList->second : dummy;
}
int SDL::ModuleConnectionMap<SDL::Dev>::size() const { return moduleConnections_.size(); }
int SDL::ModuleConnectionMap::size() const { return moduleConnections_.size(); }
8 changes: 2 additions & 6 deletions SDL/ModuleConnectionMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@
#endif

namespace SDL {
//FIXME: move to non-alpaka single arch build
template <typename>
class ModuleConnectionMap;
template <>
class ModuleConnectionMap<SDL::Dev> {
class ModuleConnectionMap {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the FIXME was here for a reason

private:
std::map<unsigned int, std::vector<unsigned int>> moduleConnections_;

Expand All @@ -36,7 +32,7 @@ namespace SDL {
int size() const;
};

using MapPLStoLayer = std::array<std::array<ModuleConnectionMap<SDL::Dev>, 4>, 3>;
using MapPLStoLayer = std::array<std::array<ModuleConnectionMap, 4>, 3>;
} // namespace SDL

#endif
Loading
Loading