CMS 3D CMS Logo

CTPPSOpticalFunctionsESSource.cc
Go to the documentation of this file.
1 // Original Author: Jan Kašpar
2 
9 
12 
13 //----------------------------------------------------------------------------------------------------
14 
19 public:
21  ~CTPPSOpticalFunctionsESSource() override = default;
22 
23  std::unique_ptr<LHCOpticalFunctionsSetCollection> produce(const CTPPSOpticsRcd &);
25 
26 private:
28  const edm::IOVSyncValue &,
29  edm::ValidityInterval &) override;
30 
32 
33  struct FileInfo {
34  double m_xangle;
36  };
37 
38  struct RPInfo {
41  };
42 
43  struct Entry {
45  std::vector<FileInfo> m_fileInfo;
46  std::unordered_map<unsigned int, RPInfo> m_rpInfo;
47  };
48 
49  std::vector<Entry> m_entries;
50 
52  unsigned int m_currentEntry;
53 };
54 
55 //----------------------------------------------------------------------------------------------------
56 //----------------------------------------------------------------------------------------------------
57 
59  : m_label(conf.getParameter<std::string>("label")), m_currentEntryValid(false), m_currentEntry(0) {
60  for (const auto &entry_pset : conf.getParameter<std::vector<edm::ParameterSet>>("configuration")) {
61  edm::EventRange validityRange = entry_pset.getParameter<edm::EventRange>("validityRange");
62 
63  std::vector<FileInfo> fileInfo;
64  for (const auto &pset : entry_pset.getParameter<std::vector<edm::ParameterSet>>("opticalFunctions")) {
65  fileInfo.emplace_back(pset.getParameter<double>("xangle"),
66  pset.getParameter<edm::FileInPath>("fileName").fullPath());
67  }
68 
69  std::unordered_map<unsigned int, RPInfo> rpInfo;
70  for (const auto &pset : entry_pset.getParameter<std::vector<edm::ParameterSet>>("scoringPlanes")) {
71  rpInfo.emplace(pset.getParameter<unsigned int>("rpId"),
72  RPInfo{pset.getParameter<std::string>("dirName"), pset.getParameter<double>("z")});
73  }
74 
75  m_entries.push_back({validityRange, fileInfo, rpInfo});
76  }
77 
78  setWhatProduced(this, m_label);
79  findingRecord<CTPPSOpticsRcd>();
80 }
81 
82 //----------------------------------------------------------------------------------------------------
83 
85  const edm::IOVSyncValue &iosv,
86  edm::ValidityInterval &oValidity) {
87  for (unsigned int idx = 0; idx < m_entries.size(); ++idx) {
88  const auto &entry = m_entries[idx];
89 
90  // is within an entry ?
91  if (edm::contains(entry.m_validityRange, iosv.eventID())) {
92  m_currentEntryValid = true;
94  oValidity = edm::ValidityInterval(edm::IOVSyncValue(entry.m_validityRange.startEventID()),
95  edm::IOVSyncValue(entry.m_validityRange.endEventID()));
96  return;
97  }
98  }
99 
100  // not within any entry
101  m_currentEntryValid = false;
102  m_currentEntry = 0;
103 
104  edm::LogInfo("") << "No configuration entry found for event " << iosv.eventID()
105  << ", no optical functions will be available.";
106 
107  const edm::EventID start(iosv.eventID().run(), iosv.eventID().luminosityBlock(), iosv.eventID().event());
108  const edm::EventID end(iosv.eventID().run(), iosv.eventID().luminosityBlock(), iosv.eventID().event());
110 }
111 
112 //----------------------------------------------------------------------------------------------------
113 
114 std::unique_ptr<LHCOpticalFunctionsSetCollection> CTPPSOpticalFunctionsESSource::produce(const CTPPSOpticsRcd &) {
115  // prepare output, empty by default
116  auto output = std::make_unique<LHCOpticalFunctionsSetCollection>();
117 
118  // fill the output
119  if (m_currentEntryValid) {
120  const auto &entry = m_entries[m_currentEntry];
121 
122  for (const auto &fi : entry.m_fileInfo) {
123  std::unordered_map<unsigned int, LHCOpticalFunctionsSet> xa_data;
124 
125  for (const auto &rpi : entry.m_rpInfo) {
126  LHCOpticalFunctionsSet fcn(fi.m_fileName, rpi.second.m_dirName, rpi.second.m_scoringPlaneZ);
127  xa_data.emplace(rpi.first, std::move(fcn));
128  }
129 
130  output->emplace(fi.m_xangle, xa_data);
131  }
132  }
133 
134  // commit the output
135  return output;
136 }
137 
138 //----------------------------------------------------------------------------------------------------
139 
142 
143  desc.add<std::string>("label", "")->setComment("label of the optics record");
144 
145  edm::ParameterSetDescription config_desc;
146 
147  config_desc.add<edm::EventRange>("validityRange", edm::EventRange())->setComment("interval of validity");
148 
150  of_desc.add<double>("xangle")->setComment("half crossing angle value in urad");
151  of_desc.add<edm::FileInPath>("fileName")->setComment("ROOT file with optical functions");
152  std::vector<edm::ParameterSet> of;
153  config_desc.addVPSet("opticalFunctions", of_desc, of)
154  ->setComment("list of optical functions at different crossing angles");
155 
157  sp_desc.add<unsigned int>("rpId")->setComment("associated detector DetId");
158  sp_desc.add<std::string>("dirName")->setComment("associated path to the optical functions file");
159  sp_desc.add<double>("z")->setComment("longitudinal position at scoring plane/detector");
160  std::vector<edm::ParameterSet> sp;
161  config_desc.addVPSet("scoringPlanes", sp_desc, sp)->setComment("list of sensitive planes/detectors stations");
162 
163  std::vector<edm::ParameterSet> config;
164  desc.addVPSet("configuration", config_desc, sp)->setComment("list of configuration blocks");
165 
166  descriptions.add("ctppsOpticalFunctionsESSource", desc);
167 }
168 
169 //----------------------------------------------------------------------------------------------------
170 
Definition: start.py:1
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:166
void setComment(std::string const &value)
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
ParameterDescriptionBase * addVPSet(U const &iLabel, ParameterSetDescription const &validator, std::vector< ParameterSet > const &defaults)
bool contains(EventRange const &lh, EventID const &rh)
Definition: EventRange.cc:37
Loads optical functions from ROOT files.
std::pair< Time_t, Time_t > ValidityInterval
Definition: Time.h:17
LuminosityBlockNumber_t luminosityBlock() const
Definition: EventID.h:39
~CTPPSOpticalFunctionsESSource() override=default
key
prepare the HTCondor submission files and eventually submit them
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &) override
Log< level::Info, false > LogInfo
RunNumber_t run() const
Definition: EventID.h:38
#define DEFINE_FWK_EVENTSETUP_SOURCE(type)
Definition: SourceFactory.h:92
Set of optical functions corresponding to one scoring plane along LHC.
void fcn(int &, double *, double &, double *, int)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
const EventID & eventID() const
Definition: IOVSyncValue.h:40
std::unordered_map< unsigned int, RPInfo > m_rpInfo
std::unique_ptr< LHCOpticalFunctionsSetCollection > produce(const CTPPSOpticsRcd &)
CTPPSOpticalFunctionsESSource(const edm::ParameterSet &)
static void fillDescriptions(edm::ConfigurationDescriptions &)
dictionary config
Read in AllInOne config in JSON format.
Definition: DiMuonV_cfg.py:30
const std::string & fullPath() const
Definition: FileInPath.cc:144
Definition: output.py:1
def move(src, dest)
Definition: eostools.py:511
EventNumber_t event() const
Definition: EventID.h:40