CMS 3D CMS Logo

EcalSRCondTools.cc
Go to the documentation of this file.
1 //emacs settings:-*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil -*-
2 /*
3  *
4  * author: Ph Gras. June, 2010
5  */
6 
8 
15 
21 
24 
25 #include <fstream>
26 #include <iostream>
27 #include <algorithm>
28 
29 namespace module {
31  //methods
32  public:
37 
40  ~EcalSRCondTools() override;
41 
46  void analyze(const edm::Event& evt, const edm::EventSetup& es) override;
47 
48  //fields
49  private:
51 
54  bool done_;
55 
58  };
59 
60  using namespace std;
61  using namespace ecalsrcondtools;
62 
64  : ps_(ps), mode_(ps.getParameter<string>("mode")), iomode_write_(true), done_(false) {
65  if (mode_ == "read") {
66  iomode_write_ = false;
69  }
70  }
71 
73 
75  if (done_)
76  return;
77  EcalSRSettings sr;
78 
79  if (mode_ == "online_config" || mode_ == "combine_config") {
80  string fname = ps_.getParameter<string>("onlineSrpConfigFile");
81  ifstream f(fname.c_str());
82  if (!f.good()) {
83  throw cms::Exception("EcalSRCondTools") << "Failed to open file " << fname;
84  }
85  importSrpConfigFile(sr, f, true);
86  }
87 
88  if (mode_ == "python_config" || mode_ == "combine_config") {
90  }
91 
92  if (!(mode_ == "python_config" || mode_ == "online_config" || mode_ == "combine_config" || (mode_ == "read"))) {
93  throw cms::Exception("Config") << "Invalid value," << mode_ << ", for parameter mode. "
94  << "Valid values: online_config, python_config, combine_config, read";
95  }
96 
97  if (iomode_write_) {
98  sr.bxGlobalOffset_ = ps_.getParameter<int>("bxGlobalOffset");
99  sr.automaticSrpSelect_ = ps_.getParameter<int>("automaticSrpSelect");
100  sr.automaticMasks_ = ps_.getParameter<int>("automaticMasks");
101 
103  if (!db.isAvailable()) {
104  throw cms::Exception("CondDBAccess") << "Failed to connect to PoolDBOutputService\n";
105  }
106  //fillup DB
107  //create new infinite IOV
108  cond::Time_t firstSinceTime = db->beginOfTime();
109  db->writeOneIOV(sr, firstSinceTime, "EcalSRSettingsRcd");
110  done_ = true;
111  } else { //read mode
113  if (!hSr.isValid()) {
114  cout << "EcalSRSettings record not found. Check the Cond DB Global tag.\n";
115  } else {
116  const EcalSRSettings* ssr = hSr.product();
117  cout << "ECAL Seletive readout settings:\n";
118  cout << *ssr << "\n" << endl;
119  }
120 
121  //trigger tower thresholds (from FENIX configuration):
123  if (!hTp.isValid()) {
124  cout << "EcalTPGPhysicsConst record not found. Check the Cond DB Global tag.\n";
125  } else {
126  const EcalTPGPhysicsConst* tp = hTp.product();
127  const EcalTPGPhysicsConstMap& mymap = tp->getMap();
128  if (mymap.size() != 2) {
129  cout << "Error: TPG physics record is of unexpected size: " << mymap.size()
130  << " elements instead of two (one for EB, one for EE)\n";
131  } else {
132  EcalTPGPhysicsConstMap::const_iterator it = mymap.begin();
133  cout << "----------------------------------------------------------------------\n"
134  "Trigger tower Et thresholds extracted from TPG configuration \n"
135  "(EcalSRCondTools modules supports only read mode for these parameters):\n\n";
136  cout << "EB: "
137  << "LT = " << it->second.ttf_threshold_Low << " GeV "
138  << "HT = " << it->second.ttf_threshold_High << " GeV\n";
139  ++it;
140  cout << "EE: "
141  << "LT = " << it->second.ttf_threshold_Low << " GeV "
142  << "HT = " << it->second.ttf_threshold_High << " GeV\n";
143  }
144  }
145  }
146  }
147 } // namespace module
148 
149 using namespace module;
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
void analyze(const edm::Event &evt, const edm::EventSetup &es) override
EcalSRCondTools(const edm::ParameterSet &)
const edm::ParameterSet ps_
T const * product() const
Definition: ESHandle.h:86
unsigned long long Time_t
Definition: Time.h:14
double f[11][100]
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const std::string mode_
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:130
bool isValid() const
Definition: ESHandle.h:44
edm::ESGetToken< EcalSRSettings, EcalSRSettingsRcd > hSrToken_
string fname
main script
void importSrpConfigFile(EcalSRSettings &sr, std::istream &f, bool debug=false)
std::map< uint32_t, EcalTPGPhysicsConst::Item > EcalTPGPhysicsConstMap
void importParameterSet(EcalSRSettings &sr, const edm::ParameterSet &ps)
Definition: event.py:1
edm::ESGetToken< EcalTPGPhysicsConst, EcalTPGPhysicsConstRcd > tpgPhysicsConstToken_