File indexing completed on 2024-04-06 12:21:02
0001 #include "FWCore/Framework/interface/Event.h"
0002 #include "FWCore/Framework/interface/EventSetup.h"
0003 #include "FWCore/Framework/interface/ConsumesCollector.h"
0004 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0005
0006 #include "L1Trigger/L1TMuon/interface/GeometryTranslator.h"
0007
0008 #include "L1Trigger/L1TMuonEndCapPhase2/interface/EMTFConfiguration.h"
0009 #include "L1Trigger/L1TMuonEndCapPhase2/interface/EMTFContext.h"
0010
0011 using namespace emtf::phase2;
0012
0013 EMTFContext::EMTFContext(const edm::ParameterSet& pset, edm::ConsumesCollector i_consumes_collector)
0014 :
0015 geometry_translator_(i_consumes_collector),
0016
0017
0018 config_(pset),
0019 model_(*this),
0020
0021
0022 prompt_graph_ptr_(nullptr),
0023 prompt_session_ptr_(nullptr),
0024
0025
0026 disp_graph_ptr_(nullptr),
0027 disp_session_ptr_(nullptr),
0028
0029
0030 site_lut_(),
0031 host_lut_(),
0032 zone_lut_(),
0033 timezone_lut_(),
0034 activation_lut_(),
0035
0036
0037 hitmap_building_layer_(*this),
0038 pattern_matching_layer_(*this),
0039 road_sorting_layer_(*this),
0040 track_building_layer_(*this),
0041 duplicate_removal_layer_(*this),
0042 parameter_assignment_layer_(*this),
0043 output_layer_(*this) {
0044
0045 }
0046
0047 EMTFContext::~EMTFContext() {
0048
0049 if (prompt_session_ptr_ != nullptr) {
0050 tensorflow::closeSession(prompt_session_ptr_);
0051 delete prompt_session_ptr_;
0052 }
0053
0054 if (prompt_graph_ptr_ != nullptr) {
0055 delete prompt_graph_ptr_;
0056 }
0057
0058
0059 if (disp_session_ptr_ != nullptr) {
0060 tensorflow::closeSession(disp_session_ptr_);
0061 delete disp_session_ptr_;
0062 }
0063
0064 if (disp_graph_ptr_ != nullptr) {
0065 delete disp_graph_ptr_;
0066 }
0067 }
0068
0069 void EMTFContext::update(const edm::Event& i_event, const edm::EventSetup& i_event_setup) {
0070
0071 geometry_translator_.checkAndUpdateGeometry(i_event_setup);
0072
0073
0074 config_.update(i_event, i_event_setup);
0075
0076
0077 if (prompt_session_ptr_ != nullptr) {
0078 delete prompt_session_ptr_;
0079 }
0080
0081 if (prompt_graph_ptr_ != nullptr) {
0082 delete prompt_graph_ptr_;
0083 }
0084
0085 prompt_graph_ptr_ = tensorflow::loadGraphDef(edm::FileInPath(config_.prompt_graph_path_).fullPath());
0086
0087 prompt_session_ptr_ = tensorflow::createSession(prompt_graph_ptr_);
0088
0089
0090 if (disp_session_ptr_ != nullptr) {
0091 delete disp_session_ptr_;
0092 }
0093
0094 if (disp_graph_ptr_ != nullptr) {
0095 delete disp_graph_ptr_;
0096 }
0097
0098 disp_graph_ptr_ = tensorflow::loadGraphDef(edm::FileInPath(config_.displ_graph_path_).fullPath());
0099
0100 disp_session_ptr_ = tensorflow::createSession(disp_graph_ptr_);
0101
0102
0103 site_lut_.update(i_event, i_event_setup);
0104 host_lut_.update(i_event, i_event_setup);
0105 zone_lut_.update(i_event, i_event_setup);
0106 timezone_lut_.update(i_event, i_event_setup);
0107 activation_lut_.update(i_event, i_event_setup);
0108 }