CMS 3D CMS Logo

scaleGains.cc
Go to the documentation of this file.
1 #include <cstdlib>
2 #include <iostream>
3 #include <fstream>
4 #include <vector>
5 
16 
17 class scaleGains : public edm::one::EDAnalyzer<edm::one::WatchRuns> {
18 
19 public:
20  explicit scaleGains(const edm::ParameterSet&);
21  ~scaleGains() override;
22 
23 private:
24  void beginRun(edm::Run const& iEvent, edm::EventSetup const&) override {}
25  void analyze(edm::Event const&, edm::EventSetup const&) override;
26  void endRun(edm::Run const& iEvent, edm::EventSetup const&) override {}
28  double scale;
29 };
30 
32  fileIn = iConfig.getUntrackedParameter<std::string>("FileIn");
33  fileOut = iConfig.getUntrackedParameter<std::string>("FileOut");
34  scale = iConfig.getUntrackedParameter<double>("Scale");
35 }
36 
38 
39 void scaleGains::analyze(edm::Event const&, edm::EventSetup const& iSetup) {
40 
42  iSetup.get<HcalRecNumberingRecord>().get(htopo);
43  HcalTopology topo = (*htopo);
44 
45  HcalGains gainsIn(&topo);;
46  std::ifstream inStream (fileIn.c_str());
47  HcalDbASCIIIO::getObject (inStream, &gainsIn);
48  inStream.close();
49 
50  HcalGains gainsOut(&topo);;
51  std::vector<DetId> channels = gainsIn.getAllChannels ();
52  for (unsigned i = 0; i < channels.size(); i++) {
53  DetId id = channels[i];
54  HcalGain item(id, gainsIn.getValues(id)->getValue(0) * scale, gainsIn.getValues(id)->getValue(1) * scale,
55  gainsIn.getValues(id)->getValue(2) * scale, gainsIn.getValues(id)->getValue(3) * scale);
56  gainsOut.addValues(item);
57  }
58 
59  std::ofstream outStream (fileOut.c_str());
60  HcalDbASCIIIO::dumpObject (outStream, gainsOut);
61  outStream.close();
62 }
63 
64 //define this as a plug-in
T getUntrackedParameter(std::string const &, T const &) const
void endRun(edm::Run const &iEvent, edm::EventSetup const &) override
Definition: scaleGains.cc:26
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void analyze(edm::Event const &, edm::EventSetup const &) override
Definition: scaleGains.cc:39
const Item * getValues(DetId fId, bool throwOnFail=true) const
float getValue(int fCapId) const
get value for capId = 0..3
Definition: HcalGain.h:22
std::string fileOut
Definition: scaleGains.cc:27
int iEvent
Definition: GenABIO.cc:230
std::vector< DetId > getAllChannels() const
std::string fileIn
Definition: scaleGains.cc:27
scaleGains(const edm::ParameterSet &)
Definition: scaleGains.cc:31
double scale
Definition: scaleGains.cc:28
Definition: DetId.h:18
~scaleGains() override
Definition: scaleGains.cc:37
void beginRun(edm::Run const &iEvent, edm::EventSetup const &) override
Definition: scaleGains.cc:24
bool getObject(std::istream &fInput, HcalPedestals *fObject)
bool dumpObject(std::ostream &fOutput, const HcalPedestals &fObject)
T get() const
Definition: EventSetup.h:62
bool addValues(const Item &myItem)
Definition: Run.h:44