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 
45 public:
48 
49 private:
50  void beginJob() override;
51  void beginRun(const edm::Run&, const edm::EventSetup&) override;
52  void produce(edm::Event&, const edm::EventSetup&) override;
53  void endJob() override;
54 
55  // ----------member data ---------------------------
56 
57  const std::vector<std::string> _defpartnames;
58  const std::vector<int> _defphases;
59 
60  std::map<int, std::vector<std::string> > _runpartnames;
61  std::map<int, std::vector<int> > _runphases;
62 
64 };
65 
66 //
67 // constants, enums and typedefs
68 //
69 
70 //
71 // static data member definitions
72 //
73 
74 //
75 // constructors and destructor
76 //
78  : _defpartnames(iConfig.getParameter<std::vector<std::string> >("defaultPartitionNames")),
79  _defphases(iConfig.getParameter<std::vector<int> >("defaultPhases")),
80  _currapvphases() {
81  produces<APVCyclePhaseCollection, edm::InEvent>();
82 
83  //now do what ever other initialization is needed
84 
85  if (_defphases.size() < _defpartnames.size()) {
86  // throw exception
87  throw cms::Exception("InvalidAPVCyclePhases")
88  << " Inconsistent default phases/partitions vector sizes: " << _defphases.size() << " " << _defpartnames.size();
89  }
90 
91  std::vector<edm::ParameterSet> vps(iConfig.getParameter<std::vector<edm::ParameterSet> >("runPhases"));
92 
93  for (std::vector<edm::ParameterSet>::const_iterator ps = vps.begin(); ps != vps.end(); ps++) {
94  _runphases[ps->getParameter<int>("runNumber")] = ps->getUntrackedParameter<std::vector<int> >("phases", _defphases);
95  _runpartnames[ps->getParameter<int>("runNumber")] =
96  ps->getUntrackedParameter<std::vector<std::string> >("partitions", _defpartnames);
97 
98  if (_runphases[ps->getParameter<int>("runNumber")].size() <
99  _runpartnames[ps->getParameter<int>("runNumber")].size()) {
100  // throw exception
101  throw cms::Exception("InvalidAPVCyclePhases")
102  << " Inconsistent run " << ps->getParameter<int>("runNumber")
103  << " phases/partitions vector sizes: " << _runphases[ps->getParameter<int>("runNumber")].size() << " "
104  << _runpartnames[ps->getParameter<int>("runNumber")].size();
105  }
106  }
107 }
108 
110  // do anything here that needs to be done at desctruction time
111  // (e.g. close files, deallocate resources etc.)
112 }
113 
114 //
115 // member functions
116 //
117 
118 // ------------ method called to produce the data ------------
120  using namespace edm;
121 
122  _currapvphases.get().clear();
123 
124  // fill phase map
125 
126  const std::map<int, std::vector<std::string> >& _crunpartnames = _runpartnames;
127  const std::map<int, std::vector<int> >& _crunphases = _runphases;
128 
129  std::map<int, std::vector<int> >::const_iterator trphases = _crunphases.find(iRun.run());
130  std::map<int, std::vector<std::string> >::const_iterator trpartnames = _crunpartnames.find(iRun.run());
131 
132  std::vector<int> phases = _defphases;
133  std::vector<std::string> partnames = _defpartnames;
134 
135  if (trphases != _crunphases.end()) {
136  phases = trphases->second;
137  }
138  if (trpartnames != _crunpartnames.end()) {
139  partnames = trpartnames->second;
140  }
141 
142  if (phases.size() < partnames.size()) {
143  // throw exception
144  throw cms::Exception("InvalidAPVCyclePhases")
145  << " Inconsistent phases/partitions vector sizes: " << phases.size() << " " << partnames.size();
146  }
147 
148  for (unsigned int ipart = 0; ipart < partnames.size(); ++ipart) {
149  if (phases[ipart] >= 0) {
150  _currapvphases.get()[partnames[ipart]] = phases[ipart];
151  }
152  }
153 
154  for (std::map<std::string, int>::const_iterator it = _currapvphases.get().begin(); it != _currapvphases.get().end();
155  it++) {
156  edm::LogInfo("APVCyclePhaseProducerDebug") << "partition " << it->first << " phase " << it->second;
157  }
158 }
159 
161  using namespace edm;
162 
163  std::unique_ptr<APVCyclePhaseCollection> apvphases(new APVCyclePhaseCollection(_currapvphases));
164 
165  iEvent.put(std::move(apvphases));
166 }
167 
168 // ------------ method called once each job just before starting event loop ------------
170 
171 // ------------ method called once each job just after ending the event loop ------------
173 
174 //define this as a plug-in
ConfigurableAPVCyclePhaseProducer::_defpartnames
const std::vector< std::string > _defpartnames
Definition: ConfigurableAPVCyclePhaseProducer.cc:57
MessageLogger.h
ConfigurableAPVCyclePhaseProducer::produce
void produce(edm::Event &, const edm::EventSetup &) override
Definition: ConfigurableAPVCyclePhaseProducer.cc:160
EDProducer.h
edm::Run
Definition: Run.h:45
phases
std::vector< int > phases
Definition: compareAlignments.cc:30
edm
HLT enums.
Definition: AlignableModifier.h:19
ConfigurableAPVCyclePhaseProducer::_defphases
const std::vector< int > _defphases
Definition: ConfigurableAPVCyclePhaseProducer.cc:58
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
edm::RunBase::run
RunNumber_t run() const
Definition: RunBase.h:40
ConfigurableAPVCyclePhaseProducer::beginJob
void beginJob() override
Definition: ConfigurableAPVCyclePhaseProducer.cc:169
ConfigurableAPVCyclePhaseProducer::beginRun
void beginRun(const edm::Run &, const edm::EventSetup &) override
Definition: ConfigurableAPVCyclePhaseProducer.cc:119
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
ConfigurableAPVCyclePhaseProducer::_runphases
std::map< int, std::vector< int > > _runphases
Definition: ConfigurableAPVCyclePhaseProducer.cc:61
APVCyclePhaseCollection
Definition: APVCyclePhaseCollection.h:8
Run.h
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
APVCyclePhaseCollection::get
const std::map< std::string, int > & get() const
Definition: APVCyclePhaseCollection.h:13
ConfigurableAPVCyclePhaseProducer::_currapvphases
APVCyclePhaseCollection _currapvphases
Definition: ConfigurableAPVCyclePhaseProducer.cc:63
edm::ParameterSet
Definition: ParameterSet.h:47
Event.h
ConfigurableAPVCyclePhaseProducer::~ConfigurableAPVCyclePhaseProducer
~ConfigurableAPVCyclePhaseProducer() override
Definition: ConfigurableAPVCyclePhaseProducer.cc:109
APVCyclePhaseCollection.h
createfilelist.int
int
Definition: createfilelist.py:10
iEvent
int iEvent
Definition: GenABIO.cc:224
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
edm::EventSetup
Definition: EventSetup.h:57
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
ConfigurableAPVCyclePhaseProducer::ConfigurableAPVCyclePhaseProducer
ConfigurableAPVCyclePhaseProducer(const edm::ParameterSet &)
Definition: ConfigurableAPVCyclePhaseProducer.cc:77
Frameworkfwd.h
Exception
Definition: hltDiff.cc:246
edm::EDProducer
Definition: EDProducer.h:35
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
Exception.h
ConfigurableAPVCyclePhaseProducer::endJob
void endJob() override
Definition: ConfigurableAPVCyclePhaseProducer.cc:172
ConfigurableAPVCyclePhaseProducer
Definition: ConfigurableAPVCyclePhaseProducer.cc:44
ParameterSet.h
edm::Event
Definition: Event.h:73
ConfigurableAPVCyclePhaseProducer::_runpartnames
std::map< int, std::vector< std::string > > _runpartnames
Definition: ConfigurableAPVCyclePhaseProducer.cc:60
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443