CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
L1CondDBIOVWriter.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: L1CondDBIOVWriter
4 // Class: L1CondDBIOVWriter
5 //
13 //
14 // Original Author: Werner Man-Li Sun
15 // Created: Sun Mar 2 20:09:46 CET 2008
16 // $Id: L1CondDBIOVWriter.cc,v 1.19 2010/02/16 21:59:24 wsun Exp $
17 //
18 //
19 
20 // system include files
21 #include <sstream>
22 
23 // user include files
26 
31 
33 
34 //
35 // class declaration
36 //
37 
38 //
39 // constants, enums and typedefs
40 //
41 
42 //
43 // static data member definitions
44 //
45 
46 //
47 // constructors and destructor
48 //
50  : m_tscKey(iConfig.getParameter<std::string>("tscKey")),
51  m_ignoreTriggerKey(iConfig.getParameter<bool>("ignoreTriggerKey")),
52  m_logKeys(iConfig.getParameter<bool>("logKeys")),
53  m_logTransactions(iConfig.getParameter<bool>("logTransactions")),
54  m_forceUpdate(iConfig.getParameter<bool>("forceUpdate")) {
55  //now do what ever initialization is needed
56  typedef std::vector<edm::ParameterSet> ToSave;
57  ToSave toSave = iConfig.getParameter<ToSave>("toPut");
58  for (ToSave::const_iterator it = toSave.begin(); it != toSave.end(); it++) {
59  std::string record = it->getParameter<std::string>("record");
60  std::string type = it->getParameter<std::string>("type");
61  m_recordTypes.push_back(record + "@" + type);
62  }
64 }
65 
67  // do anything here that needs to be done at desctruction time
68  // (e.g. close files, deallocate resources etc.)
69 }
70 
71 //
72 // member functions
73 //
74 
75 // ------------ method called to for each event ------------
77  using namespace edm;
78 
79  // Get L1TriggerKeyList
80  L1TriggerKeyList keyList;
81  l1t::DataWriter dataWriter;
82  if (!dataWriter.fillLastTriggerKeyList(keyList)) {
83  edm::LogError("L1-O2O") << "Problem getting last L1TriggerKeyList";
84  }
85 
86  unsigned long long run = iEvent.id().run();
87 
88  L1TriggerKey::RecordToKey recordTypeToKeyMap;
89 
90  bool triggerKeyIOVUpdated = true;
91 
92  // Start log string, convert run number into string
93  std::stringstream ss;
94  ss << run;
95  std::string log = "KEYLOG runNumber=" + ss.str();
96  bool logRecords = true;
97 
98  if (!m_ignoreTriggerKey) {
99  if (!m_tscKey.empty()) {
100  edm::LogVerbatim("L1-O2O") << "Object key for L1TriggerKey@L1TriggerKeyRcd: " << m_tscKey;
101 
102  // Use TSC key and L1TriggerKeyList to find next run's
103  // L1TriggerKey token
104  std::string keyToken = keyList.token(m_tscKey);
105 
106  // Update IOV sequence for this token with since-time = new run
107  triggerKeyIOVUpdated = m_writer.updateIOV("L1TriggerKeyRcd", keyToken, run, m_logTransactions);
108 
109  // Read current L1TriggerKey directly from ORCON using token
111  m_writer.readObject(keyToken, key);
112 
113  recordTypeToKeyMap = key.recordToKeyMap();
114 
115  // Replace spaces in key with ?s. Do reverse substitution when
116  // making L1TriggerKey.
117  std::string tmpKey = m_tscKey;
118  replace(tmpKey.begin(), tmpKey.end(), ' ', '?');
119  log += " tscKey=" + tmpKey;
120  logRecords = false;
121  } else {
122  // For use with Run Settings, no corresponding L1TrigerKey in
123  // ORCON.
124 
125  // Get L1TriggerKey from EventSetup
126  auto esKey = iSetup.getHandle(l1TriggerKeyToken_);
127  recordTypeToKeyMap = esKey->recordToKeyMap();
128  }
129  } else {
130  std::vector<std::string>::const_iterator recordTypeItr = m_recordTypes.begin();
131  std::vector<std::string>::const_iterator recordTypeEnd = m_recordTypes.end();
132 
133  for (; recordTypeItr != recordTypeEnd; ++recordTypeItr) {
134  recordTypeToKeyMap.insert(std::make_pair(*recordTypeItr, m_tscKey));
135  }
136  }
137 
138  // If L1TriggerKey IOV was already up to date, then so are all its
139  // sub-records.
140  bool throwException = false;
141 
142  if (triggerKeyIOVUpdated || m_forceUpdate) {
143  // Loop over record@type in L1TriggerKey
144  L1TriggerKey::RecordToKey::const_iterator itr = recordTypeToKeyMap.begin();
145  L1TriggerKey::RecordToKey::const_iterator end = recordTypeToKeyMap.end();
146 
147  for (; itr != end; ++itr) {
148  std::string recordType = itr->first;
149  std::string objectKey = itr->second;
150 
151  std::string recordName(recordType, 0, recordType.find_first_of('@'));
152 
153  if (logRecords) {
154  // Replace spaces in key with ?s. Do reverse substitution when
155  // making L1TriggerKey.
156  std::string tmpKey = objectKey;
157  replace(tmpKey.begin(), tmpKey.end(), ' ', '?');
158  log += " " + recordName + "Key=" + tmpKey;
159  }
160 
161  // Do nothing if object key is null.
162  if (objectKey == L1TriggerKey::kNullKey) {
163  edm::LogVerbatim("L1-O2O") << "L1CondDBIOVWriter: null object key for " << recordType
164  << "; skipping this record.";
165  } else {
166  // Find payload token
167  edm::LogVerbatim("L1-O2O") << "Object key for " << recordType << ": " << objectKey;
168 
169  std::string payloadToken = keyList.token(recordType, objectKey);
170  if (payloadToken.empty()) {
171  edm::LogVerbatim("L1-O2O") << "L1CondDBIOVWriter: empty payload token for " + recordType + ", key " +
172  objectKey;
173 
174  throwException = true;
175  } else {
177  }
178  }
179  }
180  }
181 
182  if (m_logKeys) {
183  edm::LogVerbatim("L1-O2O") << log;
184  }
185 
186  if (throwException) {
187  throw cond::Exception("L1CondDBIOVWriter: empty payload tokens");
188  }
189 }
190 
191 // ------------ method called once each job just before starting event loop ------------
193 
194 // ------------ method called once each job just after ending the event loop ------------
196 
197 //define this as a plug-in
198 //DEFINE_FWK_MODULE(L1CondDBIOVWriter);
RunNumber_t run() const
Definition: EventID.h:38
persistency::Exception Exception
Definition: Exception.h:25
Log< level::Info, true > LogVerbatim
l1t::DataWriter m_writer
std::vector< std::string > m_recordTypes
static std::vector< std::string > checklist log
std::map< std::string, std::string > RecordToKey
Definition: L1TriggerKey.h:25
static const std::string kNullKey
Definition: L1TriggerKey.h:30
edm::ESGetToken< L1TriggerKey, L1TriggerKeyRcd > l1TriggerKeyToken_
tuple recordName
Definition: align_cfg.py:66
Log< level::Error, false > LogError
void beginJob() override
~L1CondDBIOVWriter() override
int iEvent
Definition: GenABIO.cc:224
const RecordToKey & recordToKeyMap() const
Definition: L1TriggerKey.h:76
tuple key
prepare the HTCondor submission files and eventually submit them
L1CondDBIOVWriter(const edm::ParameterSet &)
void readObject(const std::string &payloadToken, T &outputObject)
Definition: DataWriter.h:72
void endJob() override
void analyze(const edm::Event &, const edm::EventSetup &) override
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::EventID id() const
Definition: EventBase.h:59
string end
Definition: dataset.py:937
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:151
bool updateIOV(const std::string &esRecordName, const std::string &payloadToken, edm::RunNumber_t sinceRun, bool logTransactions=false)
Definition: DataWriter.cc:72
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:12