CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
HcalLuttoDB Class Reference

#include <CalibCalorimetry/HcalLuttoDB/src/HcalLuttoDB.cc>

Inheritance diagram for HcalLuttoDB:
edm::EDAnalyzer

Public Member Functions

virtual void analyze (const edm::Event &, const edm::EventSetup &)
 
virtual void beginJob ()
 
virtual void endJob ()
 
 HcalLuttoDB (const edm::ParameterSet &)
 
 ~HcalLuttoDB ()
 
- Public Member Functions inherited from edm::EDAnalyzer
 EDAnalyzer ()
 
std::string workerType () const
 
virtual ~EDAnalyzer ()
 

Private Member Functions

std::vector< unsigned char > extractOutputLut (const CaloTPGTranscoder &coder, HcalTrigTowerDetId chan)
 
std::ostream * openChecksums ()
 
std::ostream * openPerCrate (int crate)
 
std::ostream * openPerLut1 (HcalElectronicsId eid)
 
std::ostream * openPerLut2 (HcalElectronicsId eid)
 
void writeoutlut1 (HcalDetId id, HcalElectronicsId eid, const std::vector< unsigned short > &lut, std::ostream &os)
 
void writeoutlut2 (HcalTrigTowerDetId id, HcalElectronicsId eid, const std::vector< unsigned char > &lut, std::ostream &os)
 

Private Attributes

std::string creationstamp_
 
std::string fileformat_
 
bool filePerCrate_
 
std::ostream * oc_
 

Additional Inherited Members

- Public Types inherited from edm::EDAnalyzer
typedef EDAnalyzer ModuleType
 
typedef WorkerT< EDAnalyzerWorkerType
 
- Static Public Member Functions inherited from edm::EDAnalyzer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::EDAnalyzer
CurrentProcessingContext const * currentContext () const
 

Detailed Description

Description: <one line="" class="" summary>=""> R Implementation: <Notes on="" implementation>="">

Definition at line 57 of file HcalLuttoDB.cc.

Constructor & Destructor Documentation

HcalLuttoDB::HcalLuttoDB ( const edm::ParameterSet iConfig)
explicit

Definition at line 87 of file HcalLuttoDB.cc.

References creationtag_, edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), and targetfirmware_.

88 {
89 
90  creationtag_ = iConfig.getParameter<std::string>("creationtag");
91  targetfirmware_ = iConfig.getParameter<std::string>("targetfirmware");
92  filePerCrate_ = iConfig.getUntrackedParameter<bool>("filePerCrate",true);
93  fileformat_=iConfig.getParameter<std::string>("filePrefix");
94 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
bool filePerCrate_
Definition: HcalLuttoDB.cc:70
std::string targetfirmware_
Definition: HcalLuttoDB.cc:82
std::string fileformat_
Definition: HcalLuttoDB.cc:72
std::string creationtag_
Definition: HcalLuttoDB.cc:81
HcalLuttoDB::~HcalLuttoDB ( )

Definition at line 96 of file HcalLuttoDB.cc.

97 {
98 }

Member Function Documentation

void HcalLuttoDB::analyze ( const edm::Event iEvent,
const edm::EventSetup iSetup 
)
virtual

Implements edm::EDAnalyzer.

Definition at line 262 of file HcalLuttoDB.cc.

References HcalElectronicsMap::allElectronicsId(), HcalGenericDetId::genericSubdet(), edm::EventSetup::get(), HcalGenericDetId::HcalGenBarrel, HcalGenericDetId::HcalGenEndcap, HcalGenericDetId::HcalGenForward, CaloTPGTranscoder::HcalTPG, HcalElectronicsMap::lookup(), HcalElectronicsMap::lookupTrigger(), and DetId::null().

263 {
264  //using namespace edm;
265  //using namespace std;
266 
267  edm::LogInfo("Hcal") << "Beginning dump of Hcal TPG LUTS (this may take a minute or two)";
268 
269  const HcalElectronicsMap* Map_;
271  iSetup.get<HcalDbRecord>().get( pSetup );
272  Map_=pSetup->getHcalMapping();
273  // get the conditions, for the decoding
274  edm::ESHandle<HcalTPGCoder> inputCoder;
275  iSetup.get<HcalTPGRecord>().get(inputCoder);
276  edm::ESHandle<CaloTPGTranscoder> outTranscoder;
277  iSetup.get<CaloTPGRecord>().get(outTranscoder);
278  outTranscoder->setup(iSetup,CaloTPGTranscoder::HcalTPG);
279 
280  std::vector<HcalElectronicsId> allEID = Map_->allElectronicsId();
281  std::vector<HcalElectronicsId>::iterator itreid;
282 
283  std::ostream* pfile=0;
284  oc_=openChecksums();
285 
286  for (int crate=0; crate<20; crate++) {
287  edm::LogInfo("Hcal") << "Beginning crate " << crate;
288  for(itreid = allEID.begin(); itreid != allEID.end(); itreid++)
289  {
290  if (itreid->readoutVMECrateId()!=crate) continue;
291  if (itreid->isTriggerChainId()) { // lut2
292  HcalTrigTowerDetId tid=Map_->lookupTrigger(*itreid);
293  if (tid.null()) continue;
294 
295  if (filePerCrate_ && pfile==0) pfile=openPerCrate(crate);
296  else if (pfile==0) pfile=openPerLut2(*itreid);
297 
298  std::vector<unsigned char> lut=extractOutputLut(*outTranscoder,tid);
299  writeoutlut2(tid,*itreid,lut,*pfile);
300  if (!filePerCrate_) { delete pfile; pfile=0; }
301  } else { // lut1
302  HcalGenericDetId gid=Map_->lookup(*itreid);
304 
305  if (filePerCrate_ && pfile==0) pfile=openPerCrate(crate);
306  else if (pfile==0) pfile=openPerLut1(*itreid);
307 
308  std::vector<unsigned short> lut=inputCoder->getLinearizationLUT(HcalDetId(gid));
309  writeoutlut1(HcalDetId(gid),*itreid,lut,*pfile);
310  if (!filePerCrate_) { delete pfile; pfile=0; }
311  }
312  }
313  if (pfile!=0) {
314  if (filePerCrate_) *pfile << "</CFGBrickSet>\n";
315  delete pfile;
316  pfile=0;
317  }
318  }
319  *oc_ << "</CFGBrick>\n";
320  delete oc_;
321 
322  outTranscoder->releaseSetup();
323 }
std::ostream * openPerLut2(HcalElectronicsId eid)
Definition: HcalLuttoDB.cc:130
bool filePerCrate_
Definition: HcalLuttoDB.cc:70
std::ostream * openChecksums()
Definition: HcalLuttoDB.cc:105
void writeoutlut2(HcalTrigTowerDetId id, HcalElectronicsId eid, const std::vector< unsigned char > &lut, std::ostream &os)
Definition: HcalLuttoDB.cc:198
std::ostream * oc_
Definition: HcalLuttoDB.cc:77
std::ostream * openPerCrate(int crate)
Definition: HcalLuttoDB.cc:113
std::vector< HcalElectronicsId > allElectronicsId() const
const T & get() const
Definition: EventSetup.h:55
bool null() const
is this a null id ?
Definition: DetId.h:47
std::ostream * openPerLut1(HcalElectronicsId eid)
Definition: HcalLuttoDB.cc:121
const DetId lookupTrigger(HcalElectronicsId fId) const
brief lookup the trigger logical detid associated with the given electronics id
void writeoutlut1(HcalDetId id, HcalElectronicsId eid, const std::vector< unsigned short > &lut, std::ostream &os)
Definition: HcalLuttoDB.cc:141
HcalGenericSubdetector genericSubdet() const
std::vector< unsigned char > extractOutputLut(const CaloTPGTranscoder &coder, HcalTrigTowerDetId chan)
Definition: HcalLuttoDB.cc:251
const DetId lookup(HcalElectronicsId fId) const
lookup the logical detid associated with the given electronics id
void HcalLuttoDB::beginJob ( void  )
virtual

Reimplemented from edm::EDAnalyzer.

Definition at line 329 of file HcalLuttoDB.cc.

References cmsPerfSuiteHarvest::now, and cond::rpcobgas::time.

330 {
331  char buffer[120];
332  time_t now=time(0);
333  struct tm* tm=localtime(&now);
334  strftime(buffer,120,"%F %T",tm);
335  creationstamp_ = buffer;
336 }
std::string creationstamp_
Definition: HcalLuttoDB.cc:71
void HcalLuttoDB::endJob ( void  )
virtual

Reimplemented from edm::EDAnalyzer.

Definition at line 340 of file HcalLuttoDB.cc.

340  {
341 }
std::vector< unsigned char > HcalLuttoDB::extractOutputLut ( const CaloTPGTranscoder coder,
HcalTrigTowerDetId  chan 
)
private

Definition at line 251 of file HcalLuttoDB.cc.

References HcalTriggerPrimitiveSample::compressedEt(), CaloTPGTranscoder::hcalCompress(), i, and asciidump::s.

251  {
252  std::vector<unsigned char> lut;
253  for (int i=0; i<1024; i++) {
254  HcalTriggerPrimitiveSample s=coder.hcalCompress(chan,i,false);
255  lut.push_back(s.compressedEt());
256  }
257  return lut;
258 }
int i
Definition: DBlmapReader.cc:9
virtual HcalTriggerPrimitiveSample hcalCompress(const HcalTrigTowerDetId &id, unsigned int sample, bool fineGrain) const =0
Compression from linear samples+fine grain in the HTR.
int compressedEt() const
get the encoded/compressed Et
string s
Definition: asciidump.py:422
std::ostream * HcalLuttoDB::openChecksums ( )
private

Definition at line 105 of file HcalLuttoDB.cc.

References alignmentValidation::fname.

105  {
106  char fname[1024];
107  snprintf(fname,1024,"%s_checksums.xml",fileformat_.c_str());
108  std::ostream* os=new std::ofstream(fname);
109  (*os) << "<?xml version=\"1.0\"?>\n<CFGBrick>\n";
110  return os;
111 }
std::string fileformat_
Definition: HcalLuttoDB.cc:72
string fname
main script
std::ostream * HcalLuttoDB::openPerCrate ( int  crate)
private

Definition at line 113 of file HcalLuttoDB.cc.

References alignmentValidation::fname.

113  {
114  char fname[1024];
115  snprintf(fname,1024,"%s_%d.xml",fileformat_.c_str(),crate);
116  std::ostream* os=new std::ofstream(fname);
117  (*os) << "<?xml version=\"1.0\"?>\n<CFGBrickSet>\n";
118  return os;
119 }
std::string fileformat_
Definition: HcalLuttoDB.cc:72
string fname
main script
std::ostream * HcalLuttoDB::openPerLut1 ( HcalElectronicsId  eid)
private

Definition at line 121 of file HcalLuttoDB.cc.

References HcalElectronicsId::fiberChanId(), HcalElectronicsId::fiberIndex(), alignmentValidation::fname, HcalElectronicsId::htrSlot(), HcalElectronicsId::htrTopBottom(), and HcalElectronicsId::readoutVMECrateId().

121  {
122  char fname[1024];
123  snprintf(fname,1024,"%s_%d_%d%c_%d_%d_1.xml",fileformat_.c_str(),eid.readoutVMECrateId(),
124  eid.htrSlot(),((eid.htrTopBottom())?('t'):('b')),eid.fiberIndex(),eid.fiberChanId());
125  std::ostream* os=new std::ofstream(fname);
126  (*os) << "<?xml version=\"1.0\"?>\n";
127  return os;
128 }
int fiberIndex() const
get the fiber index [1-8] (which of eight fibers carried by a spigot) (valid only for non-trigger-cha...
int htrSlot() const
get the htr slot
int readoutVMECrateId() const
get the readout VME crate number
int htrTopBottom() const
get the htr top/bottom (1=top/0=bottom)
int fiberChanId() const
get the fiber channel id (which of three channels on a readout fiber) (valid only for non-trigger-cha...
std::string fileformat_
Definition: HcalLuttoDB.cc:72
string fname
main script
std::ostream * HcalLuttoDB::openPerLut2 ( HcalElectronicsId  eid)
private

Definition at line 130 of file HcalLuttoDB.cc.

References alignmentValidation::fname, HcalElectronicsId::htrSlot(), HcalElectronicsId::htrTopBottom(), HcalElectronicsId::readoutVMECrateId(), HcalElectronicsId::slbChannelIndex(), and HcalElectronicsId::slbSiteNumber().

130  {
131  char fname[1024];
132  snprintf(fname,1024,"%s_%d_%d%c_%d_%d_2.xml",fileformat_.c_str(),eid.readoutVMECrateId(),
133  eid.htrSlot(),((eid.htrTopBottom())?('t'):('b')),eid.slbSiteNumber(),eid.slbChannelIndex());
134  std::ostream* os=new std::ofstream(fname);
135  (*os) << "<?xml version=\"1.0\"?>\n";
136  return os;
137 }
int htrSlot() const
get the htr slot
int readoutVMECrateId() const
get the readout VME crate number
int htrTopBottom() const
get the htr top/bottom (1=top/0=bottom)
int slbChannelIndex() const
get the SLB channel index (valid only for trigger-chain ids)
std::string fileformat_
Definition: HcalLuttoDB.cc:72
string fname
main script
int slbSiteNumber() const
get the SLB site number (valid only for trigger-chain ids)
void HcalLuttoDB::writeoutlut1 ( HcalDetId  id,
HcalElectronicsId  eid,
const std::vector< unsigned short > &  lut,
std::ostream &  os 
)
private

Definition at line 141 of file HcalLuttoDB.cc.

References creationtag_, HcalElectronicsId::fiberChanId(), HcalElectronicsId::fiberIndex(), formatRevision_, HcalForward, HcalElectronicsId::htrSlot(), HcalElectronicsId::htrTopBottom(), i, md5_append(), md5_finish(), md5_init(), HcalElectronicsId::readoutVMECrateId(), and targetfirmware_.

141  {
142 
143  os <<"<CFGBrick> "<<std::endl;
144  os <<" <Parameter name='IETA' type='int'>"<<id.ieta()<<"</Parameter>"<<std::endl;
145  os <<" <Parameter name='IPHI' type='int'>"<<id.iphi()<<"</Parameter>"<<std::endl;
146  os <<" <Parameter name='DEPTH' type='int'>"<<id.depth()<<"</Parameter>"<<std::endl;
147  os <<" <Parameter name='CRATE' type='int'>"<<eid.readoutVMECrateId()<<"</Parameter>"<<std::endl;
148  os <<" <Parameter name='SLOT' type='int'>"<<eid.htrSlot()<<"</Parameter>"<<std::endl;
149  os <<" <Parameter name='TOPBOTTOM' type='int'>"<<eid.htrTopBottom()<<"</Parameter>"<<std::endl;
150  os <<" <Parameter name='FIBER' type='int'>"<<eid.fiberIndex()<<"</Parameter>"<<std::endl;
151  os <<" <Parameter name='FIBERCHAN' type='int'>"<<eid.fiberChanId()<<"</Parameter>"<<std::endl;
152  os <<" <Parameter name='LUT_TYPE' type='int'>1</Parameter>"<<std::endl;
153  os <<" <Parameter name='CREATIONTAG' type='string'>"<<creationtag_<<"</Parameter>"<<std::endl;
154  os <<" <Parameter name='CREATIONSTAMP' type='string'>"<<creationstamp_<<"</Parameter>"<<std::endl;
155  os <<" <Parameter name='FORMATREVISION' type='string'>"<<formatRevision_<<"</Parameter>"<<std::endl;
156  os <<" <Parameter name='TARGETFIRMWARE' type='string'>"<<targetfirmware_<<"</Parameter>"<<std::endl;
157  int generalizedIndex=id.ietaAbs()+1000*id.depth()+10000*id.iphi()+
158  ((id.ieta()<0)?(0):(100))+((id.subdet()==HcalForward && id.ietaAbs()==29)?(4*10000):(0));
159 
160  os <<" <Parameter name='GENERALIZEDINDEX' type='int'>"<<generalizedIndex<<"</Parameter>"<<std::endl;
161  // do checksum
162  md5_state_t md5er;
163  md5_byte_t digest[16];
164  unsigned char tool[2];
165  md5_init(&md5er);
166  for (int i=0; i<128; i++) {
167  tool[0]=lut[i]&0xFF;
168  tool[1]=(lut[i]>>8)&0xFF;
169  md5_append(&md5er,tool,2);
170  }
171  md5_finish(&md5er,digest);
172  os <<" <Parameter name='CHECKSUM' type='string'>";
173  for (int i=0; i<16; i++) os << std::hex << (((int)(digest[i]))&0xFF);
174  os << "</Parameter>\n";
175 
176  *oc_ << " <Data crate='" << eid.readoutVMECrateId()
177  << "' slot='" << eid.htrSlot()
178  << "' fpga='" << eid.htrTopBottom()
179  << "' fiber='" << eid.fiberIndex()
180  << "' fiberchan='" << eid.fiberChanId()
181  << "' luttype='1' elements='1' encoding='hex'>";
182  for (int i=0; i<16; i++) *oc_ << std::hex << (((int)(digest[i]))&0xFF);
183  *oc_ << "</Data>\n";
184 
185  os <<" <Data elements='128' encoding='hex'> "<<std::endl;
186  os << std::hex;
187  for(int initr2 = 0; initr2 < 128; initr2++){
188  os<<lut[initr2]<<" ";
189  }
190  os << std::dec;
191  os<<std::endl;
192  os <<" </Data> "<<std::endl;
193  os <<"</CFGBrick> "<<std::endl;
194 
195 }
void md5_init(md5_state_t *pms)
int i
Definition: DBlmapReader.cc:9
int fiberIndex() const
get the fiber index [1-8] (which of eight fibers carried by a spigot) (valid only for non-trigger-cha...
int htrSlot() const
get the htr slot
int readoutVMECrateId() const
get the readout VME crate number
std::string targetfirmware_
Definition: HcalLuttoDB.cc:82
void md5_finish(md5_state_t *pms, md5_byte_t digest[16])
int htrTopBottom() const
get the htr top/bottom (1=top/0=bottom)
std::ostream * oc_
Definition: HcalLuttoDB.cc:77
int fiberChanId() const
get the fiber channel id (which of three channels on a readout fiber) (valid only for non-trigger-cha...
unsigned char md5_byte_t
Definition: md5.h:63
void md5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes)
std::string creationstamp_
Definition: HcalLuttoDB.cc:71
std::string creationtag_
Definition: HcalLuttoDB.cc:81
static const int formatRevision_
Definition: HcalLuttoDB.cc:83
void HcalLuttoDB::writeoutlut2 ( HcalTrigTowerDetId  id,
HcalElectronicsId  eid,
const std::vector< unsigned char > &  lut,
std::ostream &  os 
)
private

Definition at line 198 of file HcalLuttoDB.cc.

References creationtag_, formatRevision_, HcalElectronicsId::htrSlot(), HcalElectronicsId::htrTopBottom(), i, md5_append(), md5_finish(), md5_init(), HcalElectronicsId::readoutVMECrateId(), HcalElectronicsId::slbChannelIndex(), HcalElectronicsId::slbSiteNumber(), and targetfirmware_.

198  {
199 
200  os <<"<CFGBrick> "<<std::endl;
201  os <<" <Parameter name='IETA' type='int'>"<<id.ieta()<<"</Parameter>"<<std::endl;
202  os <<" <Parameter name='IPHI' type='int'>"<<id.iphi()<<"</Parameter>"<<std::endl;
203  os <<" <Parameter name='CRATE' type='int'>"<<eid.readoutVMECrateId()<<"</Parameter>"<<std::endl;
204  os <<" <Parameter name='SLOT' type='int'>"<<eid.htrSlot()<<"</Parameter>"<<std::endl;
205  os <<" <Parameter name='TOPBOTTOM' type='int'>"<<eid.htrTopBottom()<<"</Parameter>"<<std::endl;
206  os <<" <Parameter name='SLB' type='int'>"<<eid.slbSiteNumber()<<"</Parameter>"<<std::endl;
207  os <<" <Parameter name='SLBCHAN' type='int'>"<<eid.slbChannelIndex()<<"</Parameter>"<<std::endl;
208  os <<" <Parameter name='LUT_TYPE' type='int'>2</Parameter>"<<std::endl;
209  os <<" <Parameter name='CREATIONTAG' type='string'>"<<creationtag_<<"</Parameter>"<<std::endl;
210  os <<" <Parameter name='CREATIONSTAMP' type='string'>"<<creationstamp_<<"</Parameter>"<<std::endl;
211  os <<" <Parameter name='FORMATREVISION' type='string'>"<<formatRevision_<<"</Parameter>"<<std::endl;
212  os <<" <Parameter name='TARGETFIRMWARE' type='string'>"<<targetfirmware_<<"</Parameter>"<<std::endl;
213  int generalizedIndex=id.ietaAbs()+10000*id.iphi()+
214  ((id.ieta()<0)?(0):(100));
215 
216 
217  os <<" <Parameter name='GENERALIZEDINDEX' type='int'>"<<generalizedIndex<<"</Parameter>"<<std::endl;
218 
219 
220 // do checksum
221  md5_state_t md5er;
222  md5_byte_t digest[16];
223  md5_init(&md5er);
224  md5_append(&md5er,&(lut[0]),1024);
225  md5_finish(&md5er,digest);
226  os <<" <Parameter name='CHECKSUM' type='string'>";
227  for (int i=0; i<16; i++) os << std::hex << (((int)(digest[i]))&0xFF);
228  os << "</Parameter>\n";
229 
230  *oc_ << " <Data crate='" << eid.readoutVMECrateId()
231  << "' slot='" << eid.htrSlot()
232  << "' fpga='" << eid.htrTopBottom()
233  << "' slb='" << eid.slbSiteNumber()
234  << "' slbchan='" << eid.slbChannelIndex()
235  << "' luttype='2' elements='1' encoding='hex'>";
236  for (int i=0; i<16; i++) *oc_ << std::hex << (((int)(digest[i]))&0xFF);
237  *oc_ << "</Data>\n";
238 
239  os <<" <Data elements='1024' encoding='hex'> "<<std::endl;
240  os << std::hex;
241  for(int initr2 = 0; initr2 < 1024; initr2++){
242  os<< (int(lut[initr2])&0xFF)<<" ";
243  }
244  os << std::dec;
245  os<<std::endl;
246  os <<" </Data> "<<std::endl;
247  os <<"</CFGBrick> "<<std::endl;
248 
249 }
void md5_init(md5_state_t *pms)
int i
Definition: DBlmapReader.cc:9
int htrSlot() const
get the htr slot
int readoutVMECrateId() const
get the readout VME crate number
std::string targetfirmware_
Definition: HcalLuttoDB.cc:82
void md5_finish(md5_state_t *pms, md5_byte_t digest[16])
int htrTopBottom() const
get the htr top/bottom (1=top/0=bottom)
std::ostream * oc_
Definition: HcalLuttoDB.cc:77
int slbChannelIndex() const
get the SLB channel index (valid only for trigger-chain ids)
unsigned char md5_byte_t
Definition: md5.h:63
void md5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes)
std::string creationstamp_
Definition: HcalLuttoDB.cc:71
int slbSiteNumber() const
get the SLB site number (valid only for trigger-chain ids)
std::string creationtag_
Definition: HcalLuttoDB.cc:81
static const int formatRevision_
Definition: HcalLuttoDB.cc:83

Member Data Documentation

std::string HcalLuttoDB::creationstamp_
private

Definition at line 71 of file HcalLuttoDB.cc.

std::string HcalLuttoDB::fileformat_
private

Definition at line 72 of file HcalLuttoDB.cc.

bool HcalLuttoDB::filePerCrate_
private

Definition at line 70 of file HcalLuttoDB.cc.

std::ostream* HcalLuttoDB::oc_
private

Definition at line 77 of file HcalLuttoDB.cc.