CMS 3D CMS Logo

GeometryInterface.h
Go to the documentation of this file.
1 #ifndef SiPixel_GeometryInterface_h
2 #define SiPixel_GeometryInterface_h
3 // -*- C++ -*-
4 //
5 // Package: SiPixelPhase1Common
6 // Class: GeometryInterface
7 //
8 // The histogram manager uses this class to gather information about a sample.
9 // All geometry dependence goes here.
10 //
11 // Original Author: Marcel Schneider
12 //
13 
19 
28 
29 #include <functional>
30 #include <map>
31 #include <string>
32 #include <array>
33 
35 public:
36  // an ID is produced by interning a string name.
37  typedef int ID;
38  // A column could have multiple IDs if it is a or-form.
39  // Not used atm, makes many things much easier.
40  typedef ID Column;
41  typedef double Value;
42  static const Value UNDEFINED;
43 
44  // Essentially a map backed by a vector (for the small counts here
45  // this should always be faster). Most ops turned out to be not needed.
46  typedef std::vector<std::pair<Column, Value>> Values;
47 
51 
52  bool loaded() { return is_loaded; };
53 
54  // The hard work happens here.
55  void load(edm::EventSetup const& iSetup);
56 
58  // in this order the struct should fit 2 64bit words and is cheap to copy.
59  const edm::Event* sourceEvent = nullptr;
61  int16_t col = 0;
62  int16_t row = 0;
63  };
64 
65  // This has to be fast, _should_ not malloc.
66  void extractColumns(std::vector<Column> const& names, InterestingQuantities const& iq, Values& out) {
67  out.clear();
68  for (Column const& col : names) {
69  auto val = extract(col, iq);
70  out.push_back(val);
71  }
72  }
73 
74  // the pair return value is historical; it is only really needed with or-columns.
75  // But it is cleaner to carry it around.
76  std::pair<Column, Value> extract(Column const& col, InterestingQuantities const& iq) {
77  assert(col != 0 || !"Extracting invalid column.");
78  ID id = col;
79  assert(ID(extractors.size()) > id || !"extractors vector too small!");
80  auto& ex = extractors[id];
81  if (!ex) { // we have never heard about this. This is a typo for sure.
82  edm::LogError("GeometryInterface") << "Undefined column used: " << unintern(id) << ". Check your spelling.\n";
83  } else {
84  auto val = ex(iq);
85  if (val != UNDEFINED) {
86  return std::make_pair(Column{id}, val);
87  }
88  }
89  return std::make_pair(col, UNDEFINED);
90  }
91 
92  Value extract(ID id, DetId did, edm::Event* ev = nullptr, int16_t col = 0, int16_t row = 0) {
93  InterestingQuantities iq = {ev, did, col, row};
94  return extractors[id](iq);
95  }
96 
97  // TODO: for Phase0 (and maybe also Phase2) this should include the 4 corners
98  // of each ROC (or the *correct* corners of the respective modules).
99  std::vector<InterestingQuantities> const& allModules() { return all_modules; }
100 
101  Value maxValue(ID id) { return max_value[id]; };
102  Value minValue(ID id) { return min_value[id]; };
103  Value binWidth(ID id) { return bin_width[id]; };
104 
105  // turn string into an ID, adding it if needed.
106  ID intern(std::string const& id) {
107  auto it = ids.find(id);
108  if (it == ids.end()) {
109  ids[id] = ++max_id;
110  extractors.resize(max_id + 1);
111  }
112  return ids[id];
113  };
114 
115  // turn an ID back into a string. Only for pretty output (including histo
116  // labels), so it can be slow (though intern() does not have to be fast
117  // either).
119  for (auto& e : ids)
120  if (e.second == id)
121  return e.first;
122  return "INVALID";
123  }
124 
126 
128 
129 private:
132  const TrackerTopology&,
133  const SiPixelFedCablingMap&,
134  const edm::ParameterSet&);
138 
140 
143  // When converting this module to use esConsumes I preserved the previous behavior.
144  // In one place a configurable label is allowed when getting SiPixelFedCablingMap
145  // and in another place it always assumes an empty label. I am not sure if this is
146  // actually correct (seems strange). Maybe it does not matter as in all the configurations
147  // I could find in the repository the parameter was an empty string... An expert who
148  // understands this might want to fix this or eliminate this comment if the behavior is
149  // correct.
153 
154  bool is_loaded = false;
155 
156  // This holds closures that compute the column values in step1.
157  // can be a Vector since ids are dense.
159  // quantity range if it is known. Can be UNDEFINED, in this case booking will
160  // determine the range. Map for ease of use.
161  std::map<ID, Value> max_value;
162  std::map<ID, Value> min_value;
163  std::map<ID, Value> bin_width;
164 
165  // cache of pre-formatted values. Can be pre-populated while loading
166  // (used for Pixel*Name)
167  std::map<std::pair<Column, Value>, std::string> format_value;
168 
169  void addExtractor(ID id,
171  Value min = UNDEFINED,
172  Value max = UNDEFINED,
173  Value binwidth = 1) {
174  max_value[id] = max;
175  min_value[id] = min;
176  bin_width[id] = binwidth;
177  extractors[id] = func;
178  }
179 
180  std::vector<InterestingQuantities> all_modules;
181 
182  // interning table. Maps string IDs to a dense set of integer IDs
183  std::map<std::string, ID> ids{std::make_pair(std::string("INVALID"), ID(0))};
184  ID max_id = 0;
185 };
186 
187 #endif
GeometryInterface::max_value
std::map< ID, Value > max_value
Definition: GeometryInterface.h:161
MessageLogger.h
TrackerGeometry.h
GeometryInterface::InterestingQuantities::sourceModule
DetId sourceModule
Definition: GeometryInterface.h:60
GeometryInterface::cablingMapLabel_
std::string cablingMapLabel_
Definition: GeometryInterface.h:152
GeometryInterface::InterestingQuantities::col
int16_t col
Definition: GeometryInterface.h:61
GeometryInterface::loaded
bool loaded()
Definition: GeometryInterface.h:52
min
T min(T a, T b)
Definition: MathUtil.h:58
GeometryInterface::ids
std::map< std::string, ID > ids
Definition: GeometryInterface.h:183
TrackerTopology
Definition: TrackerTopology.h:16
cuy.col
col
Definition: cuy.py:1009
GeometryInterface::format_value
std::map< std::pair< Column, Value >, std::string > format_value
Definition: GeometryInterface.h:167
cms::cuda::assert
assert(be >=bs)
SiPixelFedCablingMap.h
GeometryInterface::GeometryInterface
GeometryInterface(const edm::ParameterSet &, edm::ConsumesCollector &&, edm::Transition transition=edm::Transition::BeginRun)
Definition: GeometryInterface.cc:34
GeometryInterface::loadFromTopology
void loadFromTopology(const TrackerGeometry &, const TrackerTopology &, const edm::ParameterSet &)
Definition: GeometryInterface.cc:86
GeometryInterface::pretty
std::string pretty(Column col)
Definition: GeometryInterface.h:125
Column
ESGetToken.h
GeometryInterface::binWidth
Value binWidth(ID id)
Definition: GeometryInterface.h:103
GeometryInterface::load
void load(edm::EventSetup const &iSetup)
Definition: GeometryInterface.cc:62
GeometryInterface::Value
double Value
Definition: GeometryInterface.h:41
DetId
Definition: DetId.h:17
TrackerTopology.h
GeometryInterface::addExtractor
void addExtractor(ID id, std::function< Value(InterestingQuantities const &iq)> func, Value min=UNDEFINED, Value max=UNDEFINED, Value binwidth=1)
Definition: GeometryInterface.h:169
GeometryInterface::formatValue
std::string formatValue(Column, Value)
Definition: GeometryInterface.cc:485
TrackerTopologyRcd.h
GeometryInterface::bin_width
std::map< ID, Value > bin_width
Definition: GeometryInterface.h:163
names
const std::string names[nVars_]
Definition: PhotonIDValueMapProducer.cc:124
GeometryInterface::labeledSiPixelFedCablingMapToken_
edm::ESGetToken< SiPixelFedCablingMap, SiPixelFedCablingMapRcd > labeledSiPixelFedCablingMapToken_
Definition: GeometryInterface.h:151
GeometryInterface::trackerTopologyToken_
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > trackerTopologyToken_
Definition: GeometryInterface.h:142
Transition.h
GeometryInterface::maxValue
Value maxValue(ID id)
Definition: GeometryInterface.h:101
GeometryInterface::loadModuleLevel
void loadModuleLevel(const edm::ParameterSet &iConfig)
Definition: GeometryInterface.cc:439
GeometryInterface::ID
int ID
Definition: GeometryInterface.h:37
GeometryInterface::InterestingQuantities::sourceEvent
const edm::Event * sourceEvent
Definition: GeometryInterface.h:59
GeometryInterface::unintern
std::string unintern(ID id)
Definition: GeometryInterface.h:118
GeometryInterface::extractColumns
void extractColumns(std::vector< Column > const &names, InterestingQuantities const &iq, Values &out)
Definition: GeometryInterface.h:66
TrackerDigiGeometryRecord.h
GeometryInterface::max_id
ID max_id
Definition: GeometryInterface.h:184
edm::ParameterSet
Definition: ParameterSet.h:47
edm::Transition
Transition
Definition: Transition.h:12
Event.h
SiPixelFedCablingMapRcd.h
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
GeometryInterface::is_loaded
bool is_loaded
Definition: GeometryInterface.h:154
GeometryInterface::UNDEFINED
static const Value UNDEFINED
Definition: GeometryInterface.h:42
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
GeometryInterface::loadFromSiPixelCoordinates
void loadFromSiPixelCoordinates(const TrackerGeometry &, const TrackerTopology &, const SiPixelFedCablingMap &, const edm::ParameterSet &)
Definition: GeometryInterface.cc:197
edm::EventSetup
Definition: EventSetup.h:58
GeometryInterface::Values
std::vector< std::pair< Column, Value > > Values
Definition: GeometryInterface.h:46
GeometryInterface::iConfig
const edm::ParameterSet iConfig
Definition: GeometryInterface.h:139
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
GeometryInterface::all_modules
std::vector< InterestingQuantities > all_modules
Definition: GeometryInterface.h:180
TrackCollections2monitor_cff.func
func
Definition: TrackCollections2monitor_cff.py:359
GeometryInterface::Column
ID Column
Definition: GeometryInterface.h:40
edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord >
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
GeometryInterface::trackerGeometryToken_
edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > trackerGeometryToken_
Definition: GeometryInterface.h:141
SiPixelFedCablingMap
Definition: SiPixelFedCablingMap.h:19
GeometryInterface::loadTimebased
void loadTimebased(const edm::ParameterSet &iConfig)
Definition: GeometryInterface.cc:388
GeometryInterface::minValue
Value minValue(ID id)
Definition: GeometryInterface.h:102
heppy_batch.val
val
Definition: heppy_batch.py:351
GeometryInterface::loadFEDCabling
void loadFEDCabling(const SiPixelFedCablingMap *)
Definition: GeometryInterface.cc:453
GeometryInterface::intern
ID intern(std::string const &id)
Definition: GeometryInterface.h:106
GeometryInterface::extract
std::pair< Column, Value > extract(Column const &col, InterestingQuantities const &iq)
Definition: GeometryInterface.h:76
DetId.h
GeometryInterface::extractors
std::vector< std::function< Value(InterestingQuantities const &iq)> > extractors
Definition: GeometryInterface.h:158
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:29
edm::Transition::BeginRun
ev
bool ev
Definition: Hydjet2Hadronizer.cc:97
GeometryInterface::extract
Value extract(ID id, DetId did, edm::Event *ev=nullptr, int16_t col=0, int16_t row=0)
Definition: GeometryInterface.h:92
HiBiasedCentrality_cfi.function
function
Definition: HiBiasedCentrality_cfi.py:4
GeometryInterface::InterestingQuantities::row
int16_t row
Definition: GeometryInterface.h:62
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
GeometryInterface::InterestingQuantities
Definition: GeometryInterface.h:57
ConsumesCollector.h
GeometryInterface
Definition: GeometryInterface.h:34
ParameterSet.h
edm::Event
Definition: Event.h:73
GeometryInterface::min_value
std::map< ID, Value > min_value
Definition: GeometryInterface.h:162
GeometryInterface::siPixelFedCablingMapToken_
edm::ESGetToken< SiPixelFedCablingMap, SiPixelFedCablingMapRcd > siPixelFedCablingMapToken_
Definition: GeometryInterface.h:150
edm::ConsumesCollector
Definition: ConsumesCollector.h:45
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
TrackerGeometry
Definition: TrackerGeometry.h:14
GeometryInterface::allModules
std::vector< InterestingQuantities > const & allModules()
Definition: GeometryInterface.h:99