CMS 3D CMS Logo

ConfigurableAPVCyclePhaseProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: SiStripTools
4 // Class: ConfigurableAPVCyclePhaseProducer
5 //
13 //
14 // Original Author: Andrea Venturi
15 // Created: Mon Jan 12 09:05:45 CET 2009
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 
22 // user include files
25 
29 
31 
34 
35 #include <map>
36 #include <string>
37 
39 
40 //
41 // class decleration
42 //
43 
44 class ConfigurableAPVCyclePhaseProducer : public edm::global::EDProducer<edm::RunCache<APVCyclePhaseCollection>> {
45 public:
48 
49 private:
50  std::shared_ptr<APVCyclePhaseCollection> globalBeginRun(const edm::Run&, const edm::EventSetup&) const override;
51  void produce(edm::StreamID, edm::Event&, const edm::EventSetup&) const override;
52  void globalEndRun(edm::Run const&, edm::EventSetup const&) const override {}
53 
54  // ----------member data ---------------------------
55 
56  const std::vector<std::string> _defpartnames;
57  const std::vector<int> _defphases;
58 
59  std::map<int, std::vector<std::string>> _runpartnames;
60  std::map<int, std::vector<int>> _runphases;
61 };
62 
63 //
64 // constants, enums and typedefs
65 //
66 
67 //
68 // static data member definitions
69 //
70 
71 //
72 // constructors and destructor
73 //
75  : _defpartnames(iConfig.getParameter<std::vector<std::string>>("defaultPartitionNames")),
76  _defphases(iConfig.getParameter<std::vector<int>>("defaultPhases")) {
77  produces<APVCyclePhaseCollection, edm::InEvent>();
78 
79  //now do what ever other initialization is needed
80 
81  if (_defphases.size() < _defpartnames.size()) {
82  // throw exception
83  throw cms::Exception("InvalidAPVCyclePhases")
84  << " Inconsistent default phases/partitions vector sizes: " << _defphases.size() << " " << _defpartnames.size();
85  }
86 
87  std::vector<edm::ParameterSet> vps(iConfig.getParameter<std::vector<edm::ParameterSet>>("runPhases"));
88 
89  for (std::vector<edm::ParameterSet>::const_iterator ps = vps.begin(); ps != vps.end(); ps++) {
90  _runphases[ps->getParameter<int>("runNumber")] = ps->getUntrackedParameter<std::vector<int>>("phases", _defphases);
91  _runpartnames[ps->getParameter<int>("runNumber")] =
92  ps->getUntrackedParameter<std::vector<std::string>>("partitions", _defpartnames);
93 
94  if (_runphases[ps->getParameter<int>("runNumber")].size() <
95  _runpartnames[ps->getParameter<int>("runNumber")].size()) {
96  // throw exception
97  throw cms::Exception("InvalidAPVCyclePhases")
98  << " Inconsistent run " << ps->getParameter<int>("runNumber")
99  << " phases/partitions vector sizes: " << _runphases[ps->getParameter<int>("runNumber")].size() << " "
100  << _runpartnames[ps->getParameter<int>("runNumber")].size();
101  }
102  }
103 }
104 
106  // do anything here that needs to be done at desctruction time
107  // (e.g. close files, deallocate resources etc.)
108 }
109 
110 //
111 // member functions
112 //
113 
114 // ------------ method called to produce the data ------------
115 std::shared_ptr<APVCyclePhaseCollection> ConfigurableAPVCyclePhaseProducer::globalBeginRun(
116  const edm::Run& iRun, const edm::EventSetup& iSetup) const {
117  using namespace edm;
118 
119  auto currapvphases = std::make_shared<APVCyclePhaseCollection>();
120 
121  // fill phase map
122 
123  const std::map<int, std::vector<std::string>>& _crunpartnames = _runpartnames;
124  const std::map<int, std::vector<int>>& _crunphases = _runphases;
125 
126  std::map<int, std::vector<int>>::const_iterator trphases = _crunphases.find(iRun.run());
127  std::map<int, std::vector<std::string>>::const_iterator trpartnames = _crunpartnames.find(iRun.run());
128 
129  std::vector<int> phases = _defphases;
130  std::vector<std::string> partnames = _defpartnames;
131 
132  if (trphases != _crunphases.end()) {
133  phases = trphases->second;
134  }
135  if (trpartnames != _crunpartnames.end()) {
136  partnames = trpartnames->second;
137  }
138 
139  if (phases.size() < partnames.size()) {
140  // throw exception
141  throw cms::Exception("InvalidAPVCyclePhases")
142  << " Inconsistent phases/partitions vector sizes: " << phases.size() << " " << partnames.size();
143  }
144 
145  for (unsigned int ipart = 0; ipart < partnames.size(); ++ipart) {
146  if (phases[ipart] >= 0) {
147  currapvphases->get()[partnames[ipart]] = phases[ipart];
148  }
149  }
150 
151  for (std::map<std::string, int>::const_iterator it = currapvphases->get().begin(); it != currapvphases->get().end();
152  it++) {
153  edm::LogInfo("APVCyclePhaseProducerDebug") << "partition " << it->first << " phase " << it->second;
154  }
155  return currapvphases;
156 }
157 
160  const edm::EventSetup& iSetup) const {
161  using namespace edm;
162 
163  std::unique_ptr<APVCyclePhaseCollection> apvphases =
164  std::make_unique<APVCyclePhaseCollection>(*runCache(iEvent.getRun().index()));
165 
166  iEvent.put(std::move(apvphases));
167 }
168 
169 //define this as a plug-in
size
Write out results.
void globalEndRun(edm::Run const &, edm::EventSetup const &) const override
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
std::map< int, std::vector< int > > _runphases
std::map< int, std::vector< std::string > > _runpartnames
int iEvent
Definition: GenABIO.cc:224
RunNumber_t run() const
Definition: RunBase.h:40
ConfigurableAPVCyclePhaseProducer(const edm::ParameterSet &)
const std::vector< std::string > _defpartnames
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Log< level::Info, false > LogInfo
HLT enums.
std::shared_ptr< APVCyclePhaseCollection > globalBeginRun(const edm::Run &, const edm::EventSetup &) const override
void produce(edm::StreamID, edm::Event &, const edm::EventSetup &) const override
def move(src, dest)
Definition: eostools.py:511
Definition: Run.h:45