CMS 3D CMS Logo

HcalLuttoDB.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: HcalLuttoDB
4 // Class: HcalLuttoDB
5 //
13 //
14 // Original Author: Michael Weinberger
15 // Created: Mon Mar 19 11:53:56 CDT 2007
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 
22 // user include files
28 
30 
39 
44 
45 using namespace edm;
46 using namespace std;
47 #include <iostream>
48 #include <fstream>
49 #include "md5.h"
50 
51 //
52 // class decleration
53 //
54 
55 class HcalLuttoDB : public edm::EDAnalyzer {
56 public:
57  explicit HcalLuttoDB(const edm::ParameterSet&);
58  ~HcalLuttoDB() override;
59 
60  void beginJob() override;
61  void analyze(const edm::Event&, const edm::EventSetup&) override;
62  void endJob() override;
63 
64 private:
65  void writeoutlut1(HcalDetId id, HcalElectronicsId eid, const std::vector<unsigned short>& lut, std::ostream& os);
66  std::vector<unsigned char> extractOutputLut(const CaloTPGTranscoder& coder, HcalTrigTowerDetId chan);
67  void writeoutlut2(HcalTrigTowerDetId id,
69  const std::vector<unsigned char>& lut,
70  std::ostream& os);
74  std::ostream* openPerCrate(int crate);
75  std::ostream* openPerLut1(HcalElectronicsId eid);
76  std::ostream* openPerLut2(HcalElectronicsId eid);
77  std::ostream* openChecksums();
78  std::ostream* oc_;
79 };
80 // ----------member data ---------------------------
81 
84 static const int formatRevision_ = 1;
85 
86 // constructors and destructor
87 //
89  creationtag_ = iConfig.getParameter<std::string>("creationtag");
90  targetfirmware_ = iConfig.getParameter<std::string>("targetfirmware");
91  filePerCrate_ = iConfig.getUntrackedParameter<bool>("filePerCrate", true);
92  fileformat_ = iConfig.getParameter<std::string>("filePrefix");
93 }
94 
96 
97 //
98 // member functions
99 //
100 
101 std::ostream* HcalLuttoDB::openChecksums() {
102  char fname[1024];
103  snprintf(fname, 1024, "%s_checksums.xml", fileformat_.c_str());
104  std::ostream* os = new std::ofstream(fname);
105  (*os) << "<?xml version=\"1.0\"?>\n<CFGBrick>\n";
106  return os;
107 }
108 
109 std::ostream* HcalLuttoDB::openPerCrate(int crate) {
110  char fname[1024];
111  snprintf(fname, 1024, "%s_%d.xml", fileformat_.c_str(), crate);
112  std::ostream* os = new std::ofstream(fname);
113  (*os) << "<?xml version=\"1.0\"?>\n<CFGBrickSet>\n";
114  return os;
115 }
116 
118  char fname[1024];
119  snprintf(fname,
120  1024,
121  "%s_%d_%d%c_%d_%d_1.xml",
122  fileformat_.c_str(),
123  eid.readoutVMECrateId(),
124  eid.htrSlot(),
125  ((eid.htrTopBottom()) ? ('t') : ('b')),
126  eid.fiberIndex(),
127  eid.fiberChanId());
128  std::ostream* os = new std::ofstream(fname);
129  (*os) << "<?xml version=\"1.0\"?>\n";
130  return os;
131 }
132 
134  char fname[1024];
135  snprintf(fname,
136  1024,
137  "%s_%d_%d%c_%d_%d_2.xml",
138  fileformat_.c_str(),
139  eid.readoutVMECrateId(),
140  eid.htrSlot(),
141  ((eid.htrTopBottom()) ? ('t') : ('b')),
142  eid.slbSiteNumber(),
143  eid.slbChannelIndex());
144  std::ostream* os = new std::ofstream(fname);
145  (*os) << "<?xml version=\"1.0\"?>\n";
146  return os;
147 }
148 
151  const std::vector<unsigned short>& lut,
152  std::ostream& os) {
153  os << "<CFGBrick> " << std::endl;
154  os << " <Parameter name='IETA' type='int'>" << id.ieta() << "</Parameter>" << std::endl;
155  os << " <Parameter name='IPHI' type='int'>" << id.iphi() << "</Parameter>" << std::endl;
156  os << " <Parameter name='DEPTH' type='int'>" << id.depth() << "</Parameter>" << std::endl;
157  os << " <Parameter name='CRATE' type='int'>" << eid.readoutVMECrateId() << "</Parameter>" << std::endl;
158  os << " <Parameter name='SLOT' type='int'>" << eid.htrSlot() << "</Parameter>" << std::endl;
159  os << " <Parameter name='TOPBOTTOM' type='int'>" << eid.htrTopBottom() << "</Parameter>" << std::endl;
160  os << " <Parameter name='FIBER' type='int'>" << eid.fiberIndex() << "</Parameter>" << std::endl;
161  os << " <Parameter name='FIBERCHAN' type='int'>" << eid.fiberChanId() << "</Parameter>" << std::endl;
162  os << " <Parameter name='LUT_TYPE' type='int'>1</Parameter>" << std::endl;
163  os << " <Parameter name='CREATIONTAG' type='string'>" << creationtag_ << "</Parameter>" << std::endl;
164  os << " <Parameter name='CREATIONSTAMP' type='string'>" << creationstamp_ << "</Parameter>" << std::endl;
165  os << " <Parameter name='FORMATREVISION' type='string'>" << formatRevision_ << "</Parameter>" << std::endl;
166  os << " <Parameter name='TARGETFIRMWARE' type='string'>" << targetfirmware_ << "</Parameter>" << std::endl;
167  int generalizedIndex = id.ietaAbs() + 1000 * id.depth() + 10000 * id.iphi() + ((id.ieta() < 0) ? (0) : (100)) +
168  ((id.subdet() == HcalForward && id.ietaAbs() == 29) ? (4 * 10000) : (0));
169 
170  os << " <Parameter name='GENERALIZEDINDEX' type='int'>" << generalizedIndex << "</Parameter>" << std::endl;
171  // do checksum
172  md5_state_t md5er;
173  md5_byte_t digest[16];
174  unsigned char tool[2];
175  md5_init(&md5er);
176  for (int i = 0; i < 128; i++) {
177  tool[0] = lut[i] & 0xFF;
178  tool[1] = (lut[i] >> 8) & 0xFF;
179  md5_append(&md5er, tool, 2);
180  }
181  md5_finish(&md5er, digest);
182  os << " <Parameter name='CHECKSUM' type='string'>";
183  for (int i = 0; i < 16; i++)
184  os << std::hex << (((int)(digest[i])) & 0xFF);
185  os << "</Parameter>\n";
186 
187  *oc_ << " <Data crate='" << eid.readoutVMECrateId() << "' slot='" << eid.htrSlot() << "' fpga='"
188  << eid.htrTopBottom() << "' fiber='" << eid.fiberIndex() << "' fiberchan='" << eid.fiberChanId()
189  << "' luttype='1' elements='1' encoding='hex'>";
190  for (int i = 0; i < 16; i++)
191  *oc_ << std::hex << (((int)(digest[i])) & 0xFF);
192  *oc_ << "</Data>\n";
193 
194  os << " <Data elements='128' encoding='hex'> " << std::endl;
195  os << std::hex;
196  for (int initr2 = 0; initr2 < 128; initr2++) {
197  os << lut[initr2] << " ";
198  }
199  os << std::dec;
200  os << std::endl;
201  os << " </Data> " << std::endl;
202  os << "</CFGBrick> " << std::endl;
203 }
204 
207  const std::vector<unsigned char>& lut,
208  std::ostream& os) {
209  os << "<CFGBrick> " << std::endl;
210  os << " <Parameter name='IETA' type='int'>" << id.ieta() << "</Parameter>" << std::endl;
211  os << " <Parameter name='IPHI' type='int'>" << id.iphi() << "</Parameter>" << std::endl;
212  os << " <Parameter name='CRATE' type='int'>" << eid.readoutVMECrateId() << "</Parameter>" << std::endl;
213  os << " <Parameter name='SLOT' type='int'>" << eid.htrSlot() << "</Parameter>" << std::endl;
214  os << " <Parameter name='TOPBOTTOM' type='int'>" << eid.htrTopBottom() << "</Parameter>" << std::endl;
215  os << " <Parameter name='SLB' type='int'>" << eid.slbSiteNumber() << "</Parameter>" << std::endl;
216  os << " <Parameter name='SLBCHAN' type='int'>" << eid.slbChannelIndex() << "</Parameter>" << std::endl;
217  os << " <Parameter name='LUT_TYPE' type='int'>2</Parameter>" << std::endl;
218  os << " <Parameter name='CREATIONTAG' type='string'>" << creationtag_ << "</Parameter>" << std::endl;
219  os << " <Parameter name='CREATIONSTAMP' type='string'>" << creationstamp_ << "</Parameter>" << std::endl;
220  os << " <Parameter name='FORMATREVISION' type='string'>" << formatRevision_ << "</Parameter>" << std::endl;
221  os << " <Parameter name='TARGETFIRMWARE' type='string'>" << targetfirmware_ << "</Parameter>" << std::endl;
222  int generalizedIndex = id.ietaAbs() + 10000 * id.iphi() + ((id.ieta() < 0) ? (0) : (100));
223 
224  os << " <Parameter name='GENERALIZEDINDEX' type='int'>" << generalizedIndex << "</Parameter>" << std::endl;
225 
226  // do checksum
227  md5_state_t md5er;
228  md5_byte_t digest[16];
229  md5_init(&md5er);
230  md5_append(&md5er, &(lut[0]), 1024);
231  md5_finish(&md5er, digest);
232  os << " <Parameter name='CHECKSUM' type='string'>";
233  for (int i = 0; i < 16; i++)
234  os << std::hex << (((int)(digest[i])) & 0xFF);
235  os << "</Parameter>\n";
236 
237  *oc_ << " <Data crate='" << eid.readoutVMECrateId() << "' slot='" << eid.htrSlot() << "' fpga='"
238  << eid.htrTopBottom() << "' slb='" << eid.slbSiteNumber() << "' slbchan='" << eid.slbChannelIndex()
239  << "' luttype='2' elements='1' encoding='hex'>";
240  for (int i = 0; i < 16; i++)
241  *oc_ << std::hex << (((int)(digest[i])) & 0xFF);
242  *oc_ << "</Data>\n";
243 
244  os << " <Data elements='1024' encoding='hex'> " << std::endl;
245  os << std::hex;
246  for (int initr2 = 0; initr2 < 1024; initr2++) {
247  os << (int(lut[initr2]) & 0xFF) << " ";
248  }
249  os << std::dec;
250  os << std::endl;
251  os << " </Data> " << std::endl;
252  os << "</CFGBrick> " << std::endl;
253 }
254 
255 std::vector<unsigned char> HcalLuttoDB::extractOutputLut(const CaloTPGTranscoder& coder, HcalTrigTowerDetId chan) {
256  std::vector<unsigned char> lut;
257  for (int i = 0; i < 1024; i++) {
259  lut.push_back(s.compressedEt());
260  }
261  return lut;
262 }
263 
264 // ------------ method called to produce the data ------------
266  //using namespace edm;
267  //using namespace std;
268 
269  edm::LogInfo("Hcal") << "Beginning dump of Hcal TPG LUTS (this may take a minute or two)";
270 
271  const HcalElectronicsMap* Map_;
273  iSetup.get<HcalDbRecord>().get(pSetup);
274  Map_ = pSetup->getHcalMapping();
275  // get the conditions, for the decoding
276  edm::ESHandle<HcalTPGCoder> inputCoder;
277  iSetup.get<HcalTPGRecord>().get(inputCoder);
278  edm::ESHandle<CaloTPGTranscoder> outTranscoder;
279  iSetup.get<CaloTPGRecord>().get(outTranscoder);
280 
281  std::vector<HcalElectronicsId> allEID = Map_->allElectronicsId();
282  std::vector<HcalElectronicsId>::iterator itreid;
283 
284  std::ostream* pfile = nullptr;
285  oc_ = openChecksums();
286 
287  for (int crate = 0; crate < 20; crate++) {
288  edm::LogInfo("Hcal") << "Beginning crate " << crate;
289  for (itreid = allEID.begin(); itreid != allEID.end(); ++itreid) {
290  if (itreid->readoutVMECrateId() != crate)
291  continue;
292  if (itreid->isTriggerChainId()) { // lut2
293  HcalTrigTowerDetId tid = Map_->lookupTrigger(*itreid);
294  if (tid.null())
295  continue;
296 
297  if (filePerCrate_ && pfile == nullptr)
298  pfile = openPerCrate(crate);
299  else if (pfile == nullptr)
300  pfile = openPerLut2(*itreid);
301 
302  std::vector<unsigned char> lut = extractOutputLut(*outTranscoder, tid);
303  writeoutlut2(tid, *itreid, lut, *pfile);
304  if (!filePerCrate_) {
305  delete pfile;
306  pfile = nullptr;
307  }
308  } else { // lut1
309  HcalGenericDetId gid = Map_->lookup(*itreid);
310  if (gid.null() || !(gid.genericSubdet() == HcalGenericDetId::HcalGenBarrel ||
313  continue;
314 
315  if (filePerCrate_ && pfile == nullptr)
316  pfile = openPerCrate(crate);
317  else if (pfile == nullptr)
318  pfile = openPerLut1(*itreid);
319 
320  std::vector<unsigned short> lut = inputCoder->getLinearizationLUT(HcalDetId(gid));
321  writeoutlut1(HcalDetId(gid), *itreid, lut, *pfile);
322  if (!filePerCrate_) {
323  delete pfile;
324  pfile = nullptr;
325  }
326  }
327  }
328  if (pfile != nullptr) {
329  if (filePerCrate_)
330  *pfile << "</CFGBrickSet>\n";
331  delete pfile;
332  pfile = nullptr;
333  }
334  }
335  *oc_ << "</CFGBrick>\n";
336  delete oc_;
337 }
338 
339 // ------------ method called once each job just before starting event loop ------------
341  char buffer[120];
342  time_t now = time(nullptr);
343  struct tm* tm = localtime(&now);
344  strftime(buffer, 120, "%F %T", tm);
345  creationstamp_ = buffer;
346 }
347 
348 // ------------ method called once each job just after ending the event loop ------------
350 
351 //define this as a plug-in
HcalElectronicsMap.h
CaloTPGTranscoder
Definition: CaloTPGTranscoder.h:24
HcalLuttoDB::writeoutlut1
void writeoutlut1(HcalDetId id, HcalElectronicsId eid, const std::vector< unsigned short > &lut, std::ostream &os)
Definition: HcalLuttoDB.cc:149
bk::beginJob
void beginJob()
Definition: Breakpoints.cc:14
HcalLuttoDB::filePerCrate_
bool filePerCrate_
Definition: HcalLuttoDB.cc:71
mps_fire.i
i
Definition: mps_fire.py:355
HcalLuttoDB
Definition: HcalLuttoDB.cc:55
ESHandle.h
HcalElectronicsMap::allElectronicsId
std::vector< HcalElectronicsId > allElectronicsId() const
Definition: HcalElectronicsMap.cc:110
HcalGenericDetId
Definition: HcalGenericDetId.h:15
HcalLuttoDB::openPerLut2
std::ostream * openPerLut2(HcalElectronicsId eid)
Definition: HcalLuttoDB.cc:133
HcalTriggerPrimitiveSample
Definition: HcalTriggerPrimitiveSample.h:11
edm
HLT enums.
Definition: AlignableModifier.h:19
HcalTPGRecord
Definition: HcalTPGRecord.h:25
edm::LogInfo
Definition: MessageLogger.h:254
HcalLuttoDB::endJob
void endJob() override
Definition: HcalLuttoDB.cc:349
HcalTPGCoder::getLinearizationLUT
virtual std::vector< unsigned short > getLinearizationLUT(HcalDetId id) const
Get the full linearization LUT (128 elements). Default implementation just uses adc2Linear to get all...
Definition: HcalTPGCoder.cc:3
HcalLuttoDB::HcalLuttoDB
HcalLuttoDB(const edm::ParameterSet &)
Definition: HcalLuttoDB.cc:88
HcalGenericDetId::HcalGenEndcap
Definition: HcalGenericDetId.h:20
HcalGenericDetId.h
DetId::null
constexpr bool null() const
is this a null id ?
Definition: DetId.h:59
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
EDAnalyzer.h
creationtag_
std::string creationtag_
Definition: HcalLuttoDB.cc:82
CaloTPGTranscoder.h
HcalLuttoDB::~HcalLuttoDB
~HcalLuttoDB() override
Definition: HcalLuttoDB.cc:95
HcalTPGRecord.h
HcalDbService::getHcalMapping
const HcalElectronicsMap * getHcalMapping() const
Definition: HcalDbService.cc:343
HcalLuttoDB::openChecksums
std::ostream * openChecksums()
Definition: HcalLuttoDB.cc:101
edm::EDAnalyzer
Definition: EDAnalyzer.h:29
edmScanValgrind.buffer
buffer
Definition: edmScanValgrind.py:171
HcalElectronicsMap::lookupTrigger
const DetId lookupTrigger(HcalElectronicsId fId) const
brief lookup the trigger logical detid associated with the given electronics id
Definition: HcalElectronicsMap.cc:80
fileCollector.now
now
Definition: fileCollector.py:207
MakerMacros.h
alignCSCRings.s
s
Definition: alignCSCRings.py:92
edm::EventSetup::get
T get() const
Definition: EventSetup.h:73
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
HcalLuttoDB::writeoutlut2
void writeoutlut2(HcalTrigTowerDetId id, HcalElectronicsId eid, const std::vector< unsigned char > &lut, std::ostream &os)
Definition: HcalLuttoDB.cc:205
edm::ESHandle< HcalDbService >
HcalElectronicsId
Readout chain identification for Hcal.
Definition: HcalElectronicsId.h:32
HcalLuttoDB::openPerCrate
std::ostream * openPerCrate(int crate)
Definition: HcalLuttoDB.cc:109
HcalDbRecord.h
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
HcalTrigTowerDetId.h
HcalLuttoDB::beginJob
void beginJob() override
Definition: HcalLuttoDB.cc:340
edm::ParameterSet
Definition: ParameterSet.h:36
CaloTPGRecord
Definition: CaloTPGRecord.h:26
HcalLuttoDB::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: HcalLuttoDB.cc:265
HcalDetId.h
edm::get
T const & get(Event const &event, InputTag const &tag) noexcept(false)
Definition: Event.h:669
HcalLuttoDB::openPerLut1
std::ostream * openPerLut1(HcalElectronicsId eid)
Definition: HcalLuttoDB.cc:117
HcalDetId
Definition: HcalDetId.h:12
createfilelist.int
int
Definition: createfilelist.py:10
iEvent
int iEvent
Definition: GenABIO.cc:224
runTauDisplay.eid
eid
Definition: runTauDisplay.py:298
formatRevision_
static const int formatRevision_
Definition: HcalLuttoDB.cc:84
analyze
example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
HcalGenericDetId::HcalGenBarrel
Definition: HcalGenericDetId.h:19
edm::EventSetup
Definition: EventSetup.h:57
HcalSubdetector.h
CaloTPGRecord.h
HcalElectronicsId.h
HcalLuttoDB::oc_
std::ostream * oc_
Definition: HcalLuttoDB.cc:78
HcalElectronicsMap
Definition: HcalElectronicsMap.h:31
HcalForward
Definition: HcalAssistant.h:36
alignmentValidation.fname
string fname
main script
Definition: alignmentValidation.py:959
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
std
Definition: JetResolutionObject.h:76
targetfirmware_
std::string targetfirmware_
Definition: HcalLuttoDB.cc:83
HcalElectronicsMap::lookup
const DetId lookup(HcalElectronicsId fId) const
lookup the logical detid associated with the given electronics id
Definition: HcalElectronicsMap.cc:70
DetId.h
officialStyle.chan
chan
lumi = TPaveText(lowX+0.38, lowY+0.061, lowX+0.45, lowY+0.161, "NDC") lumi.SetBorderSize( 0 ) lumi....
Definition: officialStyle.py:106
HcalGenericDetId::genericSubdet
HcalGenericSubdetector genericSubdet() const
Definition: HcalGenericDetId.cc:21
HcalLuttoDB::fileformat_
std::string fileformat_
Definition: HcalLuttoDB.cc:73
EventSetup.h
HcalLuttoDB::creationstamp_
std::string creationstamp_
Definition: HcalLuttoDB.cc:72
HcalLuttoDB::extractOutputLut
std::vector< unsigned char > extractOutputLut(const CaloTPGTranscoder &coder, HcalTrigTowerDetId chan)
Definition: HcalLuttoDB.cc:255
HcalDbService.h
CaloTPGTranscoder::hcalCompress
virtual HcalTriggerPrimitiveSample hcalCompress(const HcalTrigTowerDetId &id, unsigned int sample, int fineGrain) const =0
Compression from linear samples+fine grain in the HTR.
HcalDbRecord
Definition: HcalDbRecord.h:30
ParameterSet.h
ntuplemaker.time
time
Definition: ntuplemaker.py:310
edm::Event
Definition: Event.h:73
HcalGenericDetId::HcalGenForward
Definition: HcalGenericDetId.h:22
TauDecayModes.dec
dec
Definition: TauDecayModes.py:143
HcalTPGCoder.h
HcalTrigTowerDetId
Definition: HcalTrigTowerDetId.h:14