CMS 3D CMS Logo

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  }
63 }
64 
66  // do anything here that needs to be done at desctruction time
67  // (e.g. close files, deallocate resources etc.)
68 }
69 
70 //
71 // member functions
72 //
73 
74 // ------------ method called to for each event ------------
76  using namespace edm;
77 
78  // Get L1TriggerKeyList
79  L1TriggerKeyList keyList;
80  l1t::DataWriter dataWriter;
81  if (!dataWriter.fillLastTriggerKeyList(keyList)) {
82  edm::LogError("L1-O2O") << "Problem getting last L1TriggerKeyList";
83  }
84 
85  unsigned long long run = iEvent.id().run();
86 
87  L1TriggerKey::RecordToKey recordTypeToKeyMap;
88 
89  bool triggerKeyIOVUpdated = true;
90 
91  // Start log string, convert run number into string
92  std::stringstream ss;
93  ss << run;
94  std::string log = "KEYLOG runNumber=" + ss.str();
95  bool logRecords = true;
96 
97  if (!m_ignoreTriggerKey) {
98  if (!m_tscKey.empty()) {
99  edm::LogVerbatim("L1-O2O") << "Object key for L1TriggerKey@L1TriggerKeyRcd: " << m_tscKey;
100 
101  // Use TSC key and L1TriggerKeyList to find next run's
102  // L1TriggerKey token
103  std::string keyToken = keyList.token(m_tscKey);
104 
105  // Update IOV sequence for this token with since-time = new run
106  triggerKeyIOVUpdated = m_writer.updateIOV("L1TriggerKeyRcd", keyToken, run, m_logTransactions);
107 
108  // Read current L1TriggerKey directly from ORCON using token
110  m_writer.readObject(keyToken, key);
111 
112  recordTypeToKeyMap = key.recordToKeyMap();
113 
114  // Replace spaces in key with ?s. Do reverse substitution when
115  // making L1TriggerKey.
116  std::string tmpKey = m_tscKey;
117  replace(tmpKey.begin(), tmpKey.end(), ' ', '?');
118  log += " tscKey=" + tmpKey;
119  logRecords = false;
120  } else {
121  // For use with Run Settings, no corresponding L1TrigerKey in
122  // ORCON.
123 
124  // Get L1TriggerKey from EventSetup
126  iSetup.get<L1TriggerKeyRcd>().get(esKey);
127 
128  recordTypeToKeyMap = esKey->recordToKeyMap();
129  }
130  } else {
131  std::vector<std::string>::const_iterator recordTypeItr = m_recordTypes.begin();
132  std::vector<std::string>::const_iterator recordTypeEnd = m_recordTypes.end();
133 
134  for (; recordTypeItr != recordTypeEnd; ++recordTypeItr) {
135  recordTypeToKeyMap.insert(std::make_pair(*recordTypeItr, m_tscKey));
136  }
137  }
138 
139  // If L1TriggerKey IOV was already up to date, then so are all its
140  // sub-records.
141  bool throwException = false;
142 
143  if (triggerKeyIOVUpdated || m_forceUpdate) {
144  // Loop over record@type in L1TriggerKey
145  L1TriggerKey::RecordToKey::const_iterator itr = recordTypeToKeyMap.begin();
146  L1TriggerKey::RecordToKey::const_iterator end = recordTypeToKeyMap.end();
147 
148  for (; itr != end; ++itr) {
149  std::string recordType = itr->first;
150  std::string objectKey = itr->second;
151 
152  std::string recordName(recordType, 0, recordType.find_first_of('@'));
153 
154  if (logRecords) {
155  // Replace spaces in key with ?s. Do reverse substitution when
156  // making L1TriggerKey.
157  std::string tmpKey = objectKey;
158  replace(tmpKey.begin(), tmpKey.end(), ' ', '?');
159  log += " " + recordName + "Key=" + tmpKey;
160  }
161 
162  // Do nothing if object key is null.
163  if (objectKey == L1TriggerKey::kNullKey) {
164  edm::LogVerbatim("L1-O2O") << "L1CondDBIOVWriter: null object key for " << recordType
165  << "; skipping this record.";
166  } else {
167  // Find payload token
168  edm::LogVerbatim("L1-O2O") << "Object key for " << recordType << ": " << objectKey;
169 
170  std::string payloadToken = keyList.token(recordType, objectKey);
171  if (payloadToken.empty()) {
172  edm::LogVerbatim("L1-O2O") << "L1CondDBIOVWriter: empty payload token for " + recordType + ", key " +
173  objectKey;
174 
175  throwException = true;
176  } else {
178  }
179  }
180  }
181  }
182 
183  if (m_logKeys) {
184  edm::LogVerbatim("L1-O2O") << log;
185  }
186 
187  if (throwException) {
188  throw cond::Exception("L1CondDBIOVWriter: empty payload tokens");
189  }
190 }
191 
192 // ------------ method called once each job just before starting event loop ------------
194 
195 // ------------ method called once each job just after ending the event loop ------------
197 
198 //define this as a plug-in
199 //DEFINE_FWK_MODULE(L1CondDBIOVWriter);
L1CondDBIOVWriter::m_ignoreTriggerKey
bool m_ignoreTriggerKey
Definition: L1CondDBIOVWriter.h:61
DataWriter.h
electrons_cff.bool
bool
Definition: electrons_cff.py:366
l1t::DataWriter::updateIOV
bool updateIOV(const std::string &esRecordName, const std::string &payloadToken, edm::RunNumber_t sinceRun, bool logTransactions=false)
Definition: DataWriter.cc:72
L1TriggerKeyRcd
Definition: L1TriggerKeyRcd.h:30
edm
HLT enums.
Definition: AlignableModifier.h:19
align_cfg.recordName
recordName
Definition: align_cfg.py:66
L1CondDBIOVWriter::~L1CondDBIOVWriter
~L1CondDBIOVWriter() override
Definition: L1CondDBIOVWriter.cc:65
L1CondDBIOVWriter::m_recordTypes
std::vector< std::string > m_recordTypes
Definition: L1CondDBIOVWriter.h:54
L1CondDBIOVWriter::m_logKeys
bool m_logKeys
Definition: L1CondDBIOVWriter.h:63
L1TriggerKey::RecordToKey
std::map< std::string, std::string > RecordToKey
Definition: L1TriggerKey.h:25
L1TriggerKey
Definition: L1TriggerKey.h:23
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
L1TriggerKey::kNullKey
const static std::string kNullKey
Definition: L1TriggerKey.h:30
edm::EventSetup::get
T get() const
Definition: EventSetup.h:87
L1TriggerKey.h
mps_fire.end
end
Definition: mps_fire.py:242
edm::ESHandle
Definition: DTSurvey.h:22
L1CondDBIOVWriter::beginJob
void beginJob() override
Definition: L1CondDBIOVWriter.cc:193
L1TriggerKey::recordToKeyMap
const RecordToKey & recordToKeyMap() const
Definition: L1TriggerKey.h:76
L1CondDBIOVWriter::L1CondDBIOVWriter
L1CondDBIOVWriter(const edm::ParameterSet &)
Definition: L1CondDBIOVWriter.cc:49
L1TriggerKeyList
Definition: L1TriggerKeyList.h:32
L1CondDBIOVWriter::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: L1CondDBIOVWriter.cc:75
edm::ParameterSet
Definition: ParameterSet.h:47
Serialization.h
type
type
Definition: SiPixelVCal_PayloadInspector.cc:39
iEvent
int iEvent
Definition: GenABIO.cc:224
L1CondDBIOVWriter::endJob
void endJob() override
Definition: L1CondDBIOVWriter.cc:196
L1TriggerKeyList.h
cond::Exception
persistency::Exception Exception
Definition: Exception.h:25
edm::EventSetup
Definition: EventSetup.h:58
AlCaHarvesting_cff.record
record
Definition: AlCaHarvesting_cff.py:42
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
L1CondDBIOVWriter::m_forceUpdate
bool m_forceUpdate
Definition: L1CondDBIOVWriter.h:67
L1CondDBIOVWriter::m_logTransactions
bool m_logTransactions
Definition: L1CondDBIOVWriter.h:65
get
#define get
L1TriggerKeyRcd.h
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
l1t::DataWriter::readObject
void readObject(const std::string &payloadToken, T &outputObject)
Definition: DataWriter.h:72
l1t::DataWriter::fillLastTriggerKeyList
bool fillLastTriggerKeyList(L1TriggerKeyList &output)
Definition: DataWriter.cc:147
std
Definition: JetResolutionObject.h:76
writedatasetfile.run
run
Definition: writedatasetfile.py:27
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
dqm-mbProfile.log
log
Definition: dqm-mbProfile.py:17
cond::persistency::throwException
void throwException(const std::string &message, const std::string &methodName)
Definition: Exception.cc:12
l1t::DataWriter
Definition: DataWriter.h:35
L1CondDBIOVWriter.h
L1CondDBIOVWriter::m_tscKey
std::string m_tscKey
Definition: L1CondDBIOVWriter.h:50
L1TriggerKeyList::token
std::string token(const std::string &tscKey) const
Definition: L1TriggerKeyList.cc:96
edm::Event
Definition: Event.h:73
crabWrapper.key
key
Definition: crabWrapper.py:19
L1CondDBIOVWriter::m_writer
l1t::DataWriter m_writer
Definition: L1CondDBIOVWriter.h:49
L1TriggerKeyListRcd.h
python.rootplot.root2matplotlib.replace
def replace(string, replacements)
Definition: root2matplotlib.py:444