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 {
20  public:
22  ~CTPPSOpticalFunctionsESSource() override = default;
23 
24  std::unique_ptr<LHCOpticalFunctionsSetCollection> produce(const CTPPSOpticsRcd &);
26 
27  private:
29 
30  struct FileInfo
31  {
32  double m_xangle;
34  };
35 
36  struct RPInfo
37  {
40  };
41 
42  struct Entry
43  {
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 
61 {
62  for (const auto &entry_pset : conf.getParameter<std::vector<edm::ParameterSet>>("configuration"))
63  {
64  edm::EventRange validityRange = entry_pset.getParameter<edm::EventRange>("validityRange");
65 
66  std::vector<FileInfo> fileInfo;
67  for (const auto &pset : entry_pset.getParameter<std::vector<edm::ParameterSet>>("opticalFunctions"))
68  {
69  const double &xangle = pset.getParameter<double>("xangle");
70  const std::string &fileName = pset.getParameter<edm::FileInPath>("fileName").fullPath();
71  fileInfo.push_back({xangle, fileName});
72  }
73 
74  std::unordered_map<unsigned int, RPInfo> rpInfo;
75  for (const auto &pset : entry_pset.getParameter<std::vector<edm::ParameterSet>>("scoringPlanes"))
76  {
77  const unsigned int rpId = pset.getParameter<unsigned int>("rpId");
78  const std::string dirName = pset.getParameter<std::string>("dirName");
79  const double z = pset.getParameter<double>("z");
80  const RPInfo entry = {dirName, z};
81  rpInfo.emplace(rpId, entry);
82  }
83 
84  m_entries.push_back({validityRange, fileInfo, rpInfo});
85  }
86 
87  setWhatProduced(this);
88  findingRecord<CTPPSOpticsRcd>();
89 }
90 
91 //----------------------------------------------------------------------------------------------------
92 
94  const edm::IOVSyncValue& iosv, edm::ValidityInterval& oValidity)
95 {
96  for (unsigned int idx = 0; idx < m_entries.size(); ++idx)
97  {
98  const auto &entry = m_entries[idx];
99 
100  // is within an entry ?
101  if (edm::contains(entry.m_validityRange, iosv.eventID()))
102  {
103  m_currentEntryValid = true;
105  oValidity = edm::ValidityInterval(edm::IOVSyncValue(entry.m_validityRange.startEventID()), edm::IOVSyncValue(entry.m_validityRange.endEventID()));
106  return;
107  }
108  }
109 
110  // not within any entry
111  m_currentEntryValid = false;
112  m_currentEntry = 0;
113 
114  edm::LogInfo("") << "No configuration entry found for event " << iosv.eventID() << ", no optical functions will be available.";
115 
116  const edm::EventID start(iosv.eventID().run(), iosv.eventID().luminosityBlock(), iosv.eventID().event());
117  const edm::EventID end(iosv.eventID().run(), iosv.eventID().luminosityBlock(), iosv.eventID().event());
119 }
120 
121 //----------------------------------------------------------------------------------------------------
122 
123 std::unique_ptr<LHCOpticalFunctionsSetCollection>
125 {
126  // prepare output, empty by default
127  auto output = std::make_unique<LHCOpticalFunctionsSetCollection>();
128 
129  // fill the output
131  {
132  const auto &entry = m_entries[m_currentEntry];
133 
134  for (const auto &fi : entry.m_fileInfo)
135  {
136  std::unordered_map<unsigned int, LHCOpticalFunctionsSet> xa_data;
137 
138  for (const auto &rpi : entry.m_rpInfo)
139  {
140  LHCOpticalFunctionsSet fcn(fi.m_fileName, rpi.second.m_dirName, rpi.second.m_scoringPlaneZ);
141  xa_data.emplace(rpi.first, std::move(fcn));
142  }
143 
144  output->emplace(fi.m_xangle, xa_data);
145  }
146  }
147 
148  // commit the output
149  return output;
150 }
151 
152 //----------------------------------------------------------------------------------------------------
153 
154 void
156 {
158 
159  edm::ParameterSetDescription config_desc;
160 
161  config_desc.add<edm::EventRange>("validityRange", edm::EventRange())->setComment("interval of validity");
162 
164  of_desc.add<double>("xangle")->setComment("half crossing angle value in urad");
165  of_desc.add<edm::FileInPath>("fileName")->setComment("ROOT file with optical functions");
166  std::vector<edm::ParameterSet> of;
167  config_desc.addVPSet("opticalFunctions", of_desc, of)->setComment("list of optical functions at different crossing angles");
168 
170  sp_desc.add<unsigned int>("rpId")->setComment("associated detector DetId");
171  sp_desc.add<std::string>("dirName")->setComment("associated path to the optical functions file");
172  sp_desc.add<double>("z")->setComment("longitudinal position at scoring plane/detector");
173  std::vector<edm::ParameterSet> sp;
174  config_desc.addVPSet("scoringPlanes", sp_desc, sp)->setComment("list of sensitive planes/detectors stations");
175 
176  std::vector<edm::ParameterSet> config;
177  desc.addVPSet("configuration", config_desc, sp)->setComment("list of configuration blocks");
178 
179  descriptions.add("ctppsOpticalFunctionsESSource", desc);
180 }
181 
182 //----------------------------------------------------------------------------------------------------
183 
185 
RunNumber_t run() const
Definition: EventID.h:39
Definition: start.py:1
T getParameter(std::string const &) const
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:124
EventNumber_t event() const
Definition: EventID.h:41
void setComment(std::string const &value)
ParameterDescriptionBase * addVPSet(U const &iLabel, ParameterSetDescription const &validator, std::vector< ParameterSet > const &defaults)
bool contains(EventRange const &lh, EventID const &rh)
Definition: EventRange.cc:38
Loads optical functions from ROOT files.
const EventID & eventID() const
Definition: IOVSyncValue.h:40
std::pair< Time_t, Time_t > ValidityInterval
Definition: Time.h:19
LuminosityBlockNumber_t luminosityBlock() const
Definition: EventID.h:40
config
Definition: looper.py:291
~CTPPSOpticalFunctionsESSource() override=default
#define end
Definition: vmac.h:39
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &) override
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)
std::unordered_map< unsigned int, RPInfo > m_rpInfo
std::unique_ptr< LHCOpticalFunctionsSetCollection > produce(const CTPPSOpticsRcd &)
CTPPSOpticalFunctionsESSource(const edm::ParameterSet &)
static void fillDescriptions(edm::ConfigurationDescriptions &)
#define DEFINE_FWK_EVENTSETUP_SOURCE(type)
Definition: SourceFactory.h:91
def move(src, dest)
Definition: eostools.py:511