CMS 3D CMS Logo

L1CondDBIOVWriterExt.cc
Go to the documentation of this file.
1 #include <sstream>
2 
5 
10 
12 
14  : m_tscKey(iConfig.getParameter<std::string>("tscKey")),
15  m_rsKey(iConfig.getParameter<std::string>("rsKey")),
16  m_ignoreTriggerKey(iConfig.getParameter<bool>("ignoreTriggerKey")),
17  m_logKeys(iConfig.getParameter<bool>("logKeys")),
18  m_logTransactions(iConfig.getParameter<bool>("logTransactions")),
19  m_forceUpdate(iConfig.getParameter<bool>("forceUpdate")) {
20  //now do what ever initialization is needed
21  typedef std::vector<edm::ParameterSet> ToSave;
22  ToSave toSave = iConfig.getParameter<ToSave>("toPut");
23  for (ToSave::const_iterator it = toSave.begin(); it != toSave.end(); it++) {
24  std::string record = it->getParameter<std::string>("record");
25  std::string type = it->getParameter<std::string>("type");
26  m_recordTypes.push_back(record + "@" + type);
27  }
28 }
29 
31  // do anything here that needs to be done at desctruction time
32  // (e.g. close files, deallocate resources etc.)
33 }
34 
35 // ------------ method called to for each event ------------
37  using namespace edm;
38 
39  // Get L1TriggerKeyListExt
40  L1TriggerKeyListExt keyList;
41  l1t::DataWriterExt dataWriter;
42  if (!dataWriter.fillLastTriggerKeyList(keyList)) {
43  edm::LogError("L1-O2O") << "Problem getting last L1TriggerKeyListExt";
44  }
45 
46  unsigned long long run = iEvent.id().run();
47 
48  L1TriggerKeyExt::RecordToKey recordTypeToKeyMap;
49 
50  bool triggerKeyIOVUpdated = true;
51 
52  // Start log string, convert run number into string
53  std::stringstream ss;
54  ss << run;
55  std::string log = "KEYLOG runNumber=" + ss.str();
56  bool logRecords = true;
57 
58  std::string m_Key = m_tscKey + ":" + m_rsKey;
59 
60  if (!m_ignoreTriggerKey) {
61  if (!m_tscKey.empty() && !m_rsKey.empty()) {
62  edm::LogVerbatim("L1-O2O") << "Object key for L1TriggerKeyExt@L1TriggerKeyExtRcd: " << m_tscKey << " : "
63  << m_rsKey;
64 
65  // Use TSC key and L1TriggerKeyListExt to find next run's
66  // L1TriggerKey token
67  std::string keyToken = keyList.token(m_Key);
68 
69  // Update IOV sequence for this token with since-time = new run
70  triggerKeyIOVUpdated = m_writer.updateIOV("L1TriggerKeyExtRcd", keyToken, run, m_logTransactions);
71 
72  // Read current L1TriggerKeyExt directly from ORCON using token
74  m_writer.readObject(keyToken, key);
75 
76  recordTypeToKeyMap = key.recordToKeyMap();
77 
78  // Replace spaces in key with ?s. Do reverse substitution when
79  // making L1TriggerKeyExt.
80  std::string tmpKey = m_Key;
81  replace(tmpKey.begin(), tmpKey.end(), ' ', '?');
82  log += " tscKey:rsKey=" + tmpKey;
83  logRecords = false;
84  } else {
85  // For use with Run Settings, no corresponding L1TrigerKey in
86  // ORCON.
87 
88  // Get L1TriggerKeyExt from EventSetup
90  iSetup.get<L1TriggerKeyExtRcd>().get(esKey);
91 
92  recordTypeToKeyMap = esKey->recordToKeyMap();
93  }
94  } else {
95  std::vector<std::string>::const_iterator recordTypeItr = m_recordTypes.begin();
96  std::vector<std::string>::const_iterator recordTypeEnd = m_recordTypes.end();
97 
98  for (; recordTypeItr != recordTypeEnd; ++recordTypeItr) {
99  recordTypeToKeyMap.insert(std::make_pair(*recordTypeItr, m_Key));
100  }
101  }
102 
103  // If L1TriggerKeyExt IOV was already up to date, then so are all its
104  // sub-records.
105  bool throwException = false;
106 
107  if (triggerKeyIOVUpdated || m_forceUpdate) {
108  // Loop over record@type in L1TriggerKeyExt
109  L1TriggerKeyExt::RecordToKey::const_iterator itr = recordTypeToKeyMap.begin();
110  L1TriggerKeyExt::RecordToKey::const_iterator end = recordTypeToKeyMap.end();
111 
112  for (; itr != end; ++itr) {
113  std::string recordType = itr->first;
114  std::string objectKey = itr->second;
115 
116  std::string recordName(recordType, 0, recordType.find_first_of('@'));
117 
118  if (logRecords) {
119  // Replace spaces in key with ?s. Do reverse substitution when
120  // making L1TriggerKeyExt.
121  std::string tmpKey = objectKey;
122  replace(tmpKey.begin(), tmpKey.end(), ' ', '?');
123  log += " " + recordName + "Key=" + tmpKey;
124  }
125 
126  // Do nothing if object key is null.
127  if (objectKey == L1TriggerKeyExt::kNullKey) {
128  edm::LogVerbatim("L1-O2O") << "L1CondDBIOVWriterExt: null object key for " << recordType
129  << "; skipping this record.";
130  } else {
131  // Find payload token
132  edm::LogVerbatim("L1-O2O") << "Object key for " << recordType << ": " << objectKey;
133 
134  std::string payloadToken = keyList.token(recordType, objectKey);
135  if (payloadToken.empty()) {
136  edm::LogVerbatim("L1-O2O") << "L1CondDBIOVWriterExt: empty payload token for " + recordType + ", key " +
137  objectKey;
138 
139  throwException = true;
140  } else {
142  }
143  }
144  }
145  }
146 
147  if (m_logKeys) {
148  edm::LogVerbatim("L1-O2O") << log;
149  }
150 
151  if (throwException) {
152  throw cond::Exception("L1CondDBIOVWriterExt: empty payload tokens");
153  }
154 }
155 
156 // ------------ method called once each job just before starting event loop ------------
158 
159 // ------------ method called once each job just after ending the event loop ------------
161 
162 //define this as a plug-in
163 //DEFINE_FWK_MODULE(L1CondDBIOVWriterExt);
DataWriterExt.h
electrons_cff.bool
bool
Definition: electrons_cff.py:393
L1TriggerKeyListExt
Definition: L1TriggerKeyListExt.h:10
L1CondDBIOVWriterExt::m_tscKey
std::string m_tscKey
l1t::DataWriter m_writer ;
Definition: L1CondDBIOVWriterExt.h:30
L1TriggerKeyExt::kNullKey
const static std::string kNullKey
Definition: L1TriggerKeyExt.h:30
edm
HLT enums.
Definition: AlignableModifier.h:19
L1CondDBIOVWriterExt::beginJob
void beginJob() override
Definition: L1CondDBIOVWriterExt.cc:157
align_cfg.recordName
recordName
Definition: align_cfg.py:66
L1CondDBIOVWriterExt::m_ignoreTriggerKey
bool m_ignoreTriggerKey
Definition: L1CondDBIOVWriterExt.h:41
L1TriggerKeyExtRcd
Definition: L1TriggerKeyExtRcd.h:8
GlobalPosition_Frontier_DevDB_cff.record
record
Definition: GlobalPosition_Frontier_DevDB_cff.py:10
L1CondDBIOVWriterExt::m_writer
l1t::DataWriterExt m_writer
Definition: L1CondDBIOVWriterExt.h:27
L1CondDBIOVWriterExt::m_rsKey
std::string m_rsKey
Definition: L1CondDBIOVWriterExt.h:30
L1TriggerKeyExt::RecordToKey
std::map< std::string, std::string > RecordToKey
Definition: L1TriggerKeyExt.h:25
L1TriggerKeyExt::recordToKeyMap
const RecordToKey & recordToKeyMap() const
Definition: L1TriggerKeyExt.h:77
L1CondDBIOVWriterExt::m_forceUpdate
bool m_forceUpdate
Definition: L1CondDBIOVWriterExt.h:47
L1TriggerKeyExtRcd.h
L1TriggerKeyExt.h
L1TriggerKeyListExtRcd.h
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
edm::EventSetup::get
T get() const
Definition: EventSetup.h:80
mps_fire.end
end
Definition: mps_fire.py:242
edm::ESHandle
Definition: DTSurvey.h:22
L1TriggerKeyExt
Definition: L1TriggerKeyExt.h:23
l1t::DataWriterExt::fillLastTriggerKeyList
bool fillLastTriggerKeyList(L1TriggerKeyListExt &output)
Definition: DataWriterExt.cc:148
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ParameterSet
Definition: ParameterSet.h:47
L1CondDBIOVWriterExt.h
Serialization.h
type
type
Definition: SiPixelVCal_PayloadInspector.cc:37
L1CondDBIOVWriterExt::m_logKeys
bool m_logKeys
Definition: L1CondDBIOVWriterExt.h:43
L1CondDBIOVWriterExt::~L1CondDBIOVWriterExt
~L1CondDBIOVWriterExt() override
Definition: L1CondDBIOVWriterExt.cc:30
iEvent
int iEvent
Definition: GenABIO.cc:224
cond::Exception
persistency::Exception Exception
Definition: Exception.h:25
L1CondDBIOVWriterExt::m_logTransactions
bool m_logTransactions
Definition: L1CondDBIOVWriterExt.h:45
edm::EventSetup
Definition: EventSetup.h:57
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
itr
std::vector< std::pair< float, float > >::iterator itr
Definition: HGCDigitizer.cc:29
get
#define get
std
Definition: JetResolutionObject.h:76
writedatasetfile.run
run
Definition: writedatasetfile.py:27
L1CondDBIOVWriterExt::endJob
void endJob() override
Definition: L1CondDBIOVWriterExt.cc:160
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
L1CondDBIOVWriterExt::m_recordTypes
std::vector< std::string > m_recordTypes
Definition: L1CondDBIOVWriterExt.h:34
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
L1TriggerKeyListExt.h
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
L1CondDBIOVWriterExt::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: L1CondDBIOVWriterExt.cc:36
edm::Event
Definition: Event.h:73
crabWrapper.key
key
Definition: crabWrapper.py:19
L1CondDBIOVWriterExt::L1CondDBIOVWriterExt
L1CondDBIOVWriterExt(const edm::ParameterSet &)
Definition: L1CondDBIOVWriterExt.cc:13
l1t::DataWriterExt::updateIOV
bool updateIOV(const std::string &esRecordName, const std::string &payloadToken, edm::RunNumber_t sinceRun, bool logTransactions=false)
Definition: DataWriterExt.cc:73
l1t::DataWriterExt::readObject
void readObject(const std::string &payloadToken, T &outputObject)
Definition: DataWriterExt.h:72
L1TriggerKeyListExt::token
std::string token(const std::string &tscKey) const
Definition: L1TriggerKeyListExt.cc:69
python.rootplot.root2matplotlib.replace
def replace(string, replacements)
Definition: root2matplotlib.py:444
l1t::DataWriterExt
Definition: DataWriterExt.h:35