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 
20 // system include files
21 #include <memory>
22 
23 // user include files
26 
30 
32 
35 
36 #include <map>
37 #include <string>
38 
40 
41 //
42 // class decleration
43 //
44 
46  public:
49 
50 private:
51  void beginJob() override ;
52  void beginRun(const edm::Run&, const edm::EventSetup&) override;
53  void produce(edm::Event&, const edm::EventSetup&) override;
54  void endJob() override ;
55 
56  // ----------member data ---------------------------
57 
58  const std::vector<std::string> _defpartnames;
59  const std::vector<int> _defphases;
60 
61  std::map<int,std::vector<std::string> > _runpartnames;
62  std::map<int,std::vector<int> > _runphases;
63 
65 };
66 
67 //
68 // constants, enums and typedefs
69 //
70 
71 
72 //
73 // static data member definitions
74 //
75 
76 //
77 // constructors and destructor
78 //
80  _defpartnames(iConfig.getParameter<std::vector<std::string> >("defaultPartitionNames")),
81  _defphases(iConfig.getParameter<std::vector<int> >("defaultPhases")),
83 {
84 
85  produces<APVCyclePhaseCollection,edm::InEvent>();
86 
87  //now do what ever other initialization is needed
88 
89  if(_defphases.size() < _defpartnames.size() ) {
90  // throw exception
91  throw cms::Exception("InvalidAPVCyclePhases") << " Inconsistent default phases/partitions vector sizes: "
92  << _defphases.size() << " "
93  << _defpartnames.size();
94  }
95 
96  std::vector<edm::ParameterSet> vps(iConfig.getParameter<std::vector<edm::ParameterSet> >("runPhases"));
97 
98  for(std::vector<edm::ParameterSet>::const_iterator ps = vps.begin();ps!=vps.end();ps++) {
99  _runphases[ps->getParameter<int>("runNumber")] = ps->getUntrackedParameter<std::vector<int> >("phases",_defphases);
100  _runpartnames[ps->getParameter<int>("runNumber")] = ps->getUntrackedParameter<std::vector<std::string> >("partitions",_defpartnames);
101 
102  if(_runphases[ps->getParameter<int>("runNumber")].size() < _runpartnames[ps->getParameter<int>("runNumber")].size() ) {
103  // throw exception
104  throw cms::Exception("InvalidAPVCyclePhases") << " Inconsistent run " << ps->getParameter<int>("runNumber")
105  << " phases/partitions vector sizes: "
106  << _runphases[ps->getParameter<int>("runNumber")].size() << " "
107  << _runpartnames[ps->getParameter<int>("runNumber")].size();
108  }
109 
110  }
111 
112 }
113 
114 
116 {
117 
118  // do anything here that needs to be done at desctruction time
119  // (e.g. close files, deallocate resources etc.)
120 
121 }
122 
123 
124 //
125 // member functions
126 //
127 
128 // ------------ method called to produce the data ------------
129 void
131 {
132 
133  using namespace edm;
134 
135  _currapvphases.get().clear();
136 
137  // fill phase map
138 
139  const std::map<int,std::vector<std::string> >& _crunpartnames = _runpartnames;
140  const std::map<int,std::vector<int> >& _crunphases = _runphases;
141 
142  std::map<int,std::vector<int> >::const_iterator trphases = _crunphases.find(iRun.run());
143  std::map<int,std::vector<std::string> >::const_iterator trpartnames = _crunpartnames.find(iRun.run());
144 
145  std::vector<int> phases = _defphases;
146  std::vector<std::string> partnames = _defpartnames;
147 
148  if(trphases != _crunphases.end()) {
149  phases = trphases->second;
150  }
151  if(trpartnames != _crunpartnames.end()) {
152  partnames = trpartnames->second;
153  }
154 
155  if(phases.size() < partnames.size() ) {
156  // throw exception
157  throw cms::Exception("InvalidAPVCyclePhases") << " Inconsistent phases/partitions vector sizes: "
158  << phases.size() << " "
159  << partnames.size();
160  }
161 
162  for(unsigned int ipart=0;ipart<partnames.size();++ipart) {
163  if(phases[ipart]>=0) {
164  _currapvphases.get()[partnames[ipart]] = phases[ipart];
165  }
166  }
167 
168 
169  for(std::map<std::string,int>::const_iterator it=_currapvphases.get().begin(); it!=_currapvphases.get().end();it++) {
170 
171  edm::LogInfo("APVCyclePhaseProducerDebug") << "partition " << it->first << " phase " << it->second;
172 
173  }
174 
175 }
176 
177 void
179 {
180 
181  using namespace edm;
182 
183  std::unique_ptr<APVCyclePhaseCollection> apvphases(new APVCyclePhaseCollection(_currapvphases) );
184 
185  iEvent.put(std::move(apvphases));
186 
187 }
188 
189 // ------------ method called once each job just before starting event loop ------------
190 void
192 {
193 }
194 
195 // ------------ method called once each job just after ending the event loop ------------
196 void
198 }
199 
200 //define this as a plug-in
void produce(edm::Event &, const edm::EventSetup &) override
size
Write out results.
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:127
RunNumber_t run() const
Definition: RunBase.h:40
std::map< int, std::vector< std::string > > _runpartnames
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
const std::map< std::string, int > & get() const
int iEvent
Definition: GenABIO.cc:230
void beginRun(const edm::Run &, const edm::EventSetup &) override
ConfigurableAPVCyclePhaseProducer(const edm::ParameterSet &)
const std::vector< std::string > _defpartnames
std::vector< int > phases
HLT enums.
std::map< int, std::vector< int > > _runphases
def move(src, dest)
Definition: eostools.py:510
Definition: Run.h:43