test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HtrXmlPatternTool.cc
Go to the documentation of this file.
1 #include "HtrXmlPatternTool.h"
3 #include "HtrXmlPatternSet.h"
4 #include "HtrXmlPatternWriter.h"
5 #include "TFile.h"
6 #include "TH1.h"
7 #include <iostream>
8 #include <fstream>
9 #include "boost/filesystem/operations.hpp"
10 
12  m_params = params;
13 
14  //slotsOn array index corresponds to physical number (e.g., slotsOn[1] for slot 1)
15  int slotsOn [ChannelPattern::NUM_SLOTS];
16  int cratesOn[ChannelPattern::NUM_CRATES];
17 
18  //turn off all slots
19  for (int i=0; i<ChannelPattern::NUM_SLOTS; i++) slotsOn[i]=0;
20  //turn on slots 2,3,4,5,6,7,8
21  for (int i=2; i<9; i++) slotsOn[i]=1;
22  //turn on slots 13,14,15,16,17,18
23  for (int i=13; i<19; i++) slotsOn[i]=1;
24 
25  //turn on all crates
26  for (int i=0; i<ChannelPattern::NUM_CRATES; i++) cratesOn[i]=1;
27  //turn off two unused crates
28  cratesOn[ 8] = 0;
29  cratesOn[16] = 0;
30 
31  m_patternSet=new HtrXmlPatternSet(cratesOn,slotsOn);
33 
34 }
35 
37  delete m_patternSet;
38 }
39 
42  HalfHtrData* hd=0;
43  ChannelPattern* cp=0;
44 
45  if (cd) {
46  hd=cd->getHalfHtrData(HEID.htrSlot(),HEID.htrTopBottom());
47  if (hd) {
48  hd->setSpigot(HEID.spigot());
49  hd->setDCC(HEID.dccid());
50 
51  cp=hd->getPattern(HEID.htrChanId());
52  if (cp) cp->Fill(m_params,data);
53  else if(m_params->m_show_errors) std::cerr << "Bad (crate,slot,channel): ("
54  << HEID.readoutVMECrateId() << ","
55  << HEID.htrSlot() << ","
56  << HEID.htrChanId() << ")" << std::endl;
57  }
58  else if(m_params->m_show_errors) std::cerr << "Bad (crate,slot): ("
59  << HEID.readoutVMECrateId() << ","
60  << HEID.htrSlot() << ")" << std::endl;
61  }
62  else if(m_params->m_show_errors) std::cerr << "Bad (crate): (" << HEID.readoutVMECrateId() << ")" << std::endl;
63 }
64 
67  HalfHtrData* hd=0;
68  ChannelPattern* cp=0;
69 
70  if (cd) {
71  hd=cd->getHalfHtrData(HEID.htrSlot(),HEID.htrTopBottom());
72  if (hd) {
73  hd->setSpigot(HEID.spigot());
74  hd->setDCC(HEID.dccid());
75 
76  cp=hd->getPattern(HEID.htrChanId());
77  if (cp) cp->Fill(m_params,data);
78  else if(m_params->m_show_errors) std::cerr << "Bad (crate,slot,channel): ("
79  << HEID.readoutVMECrateId() << ","
80  << HEID.htrSlot() << ","
81  << HEID.htrChanId() << ")" << std::endl;
82  }
83  else if(m_params->m_show_errors) std::cerr << "Bad (crate,slot): ("
84  << HEID.readoutVMECrateId() << ","
85  << HEID.htrSlot() << ")" << std::endl;
86  }
87  else if(m_params->m_show_errors) std::cerr << "Bad (crate): (" << HEID.readoutVMECrateId() << ")" << std::endl;
88 }
89 
92  HalfHtrData* hd=0;
93  ChannelPattern* cp=0;
94 
95  if (cd) {
96  hd=cd->getHalfHtrData(HEID.htrSlot(),HEID.htrTopBottom());
97  if (hd) {
98  hd->setSpigot(HEID.spigot());
99  hd->setDCC(HEID.dccid());
100 
101  cp=hd->getPattern(HEID.htrChanId());
102  if (cp) cp->Fill(m_params,data);
103  else if(m_params->m_show_errors) std::cerr << "Bad (crate,slot,channel): ("
104  << HEID.readoutVMECrateId() << ","
105  << HEID.htrSlot() << ","
106  << HEID.htrChanId() << ")" << std::endl;
107  }
108  else if(m_params->m_show_errors) std::cerr << "Bad (crate,slot): ("
109  << HEID.readoutVMECrateId() << ","
110  << HEID.htrSlot() << ")" << std::endl;
111  }
112  else if(m_params->m_show_errors) std::cerr << "Bad (crate): (" << HEID.readoutVMECrateId() << ")" << std::endl;
113 }
114 
116  boost::filesystem::create_directory(m_params->m_output_directory);
117 }
118 
120  std::cout << "Writing XML..." << std::endl;
121  std::ofstream* of=0;
122 
123  if (m_params->m_XML_file_mode==1) {
125  of=new std::ofstream(name.c_str(),std::ios_base::out|std::ios_base::trunc);
126  if (!of->good()) {
127  std::cerr << "XML output file " << name << " is bad." << std::endl;
128  return;
129  }
130  (*of) << "<?xml version='1.0' encoding='UTF-8'?>" << std::endl;
131  (*of) << "<CFGBrickSet name='" << m_params->m_file_tag << "'>" << std::endl;
132  }
133 
134  for (int crate=0; crate<ChannelPattern::NUM_CRATES; crate++) {
135  CrateData* cd=m_patternSet->getCrate(crate);
136  if (cd==0) continue;
137 
138  if (m_params->m_XML_file_mode==2) {
140  char cr_name[256];
141  snprintf(cr_name,256,"_crate_%d.xml",crate);
142  name += cr_name;
143  of=new std::ofstream(name.c_str(),std::ios_base::out|std::ios_base::trunc);
144  if (!of->good()) {
145  std::cerr << "XML output file " << name << " is bad." << std::endl;
146  return;
147  }
148  (*of) << "<?xml version='1.0' encoding='UTF-8'?>" << std::endl;
149  (*of) << "<CFGBrickSet name='" << m_params->m_file_tag << "'>" << std::endl;
150  }
151 
152  for (int slot=0; slot<ChannelPattern::NUM_SLOTS; slot++) {
153  for (int tb=0; tb<=1; tb++) {
154  HalfHtrData* hd=cd->getHalfHtrData(slot,tb);
155  if (hd==0) continue;
156  for (int fiber=1; fiber<=8; fiber++) {
157 
158  if (m_params->m_XML_file_mode==3) {
160  char cr_name[256];
161  snprintf(cr_name,256,"_crate_%d_slot_%d_tb_%d_fiber_%d.xml",crate,slot,tb,fiber);
162  name += cr_name;
163  of=new std::ofstream(name.c_str(),std::ios_base::out|std::ios_base::trunc);
164  if (!of->good()) {
165  std::cerr << "XML output file " << name << " is bad." << std::endl;
166  return;
167  }
168  (*of) << "<?xml version='1.0' encoding='UTF-8'?>" << std::endl;
169  }
170  m_xmlWriter.writePattern(hd,fiber,*of,1);
171  if (m_params->m_XML_file_mode==3) {
172  of->close();
173  delete of;
174  of=0;
175  }
176 
177  } //end fiber loop
178  } // end tb loop
179  } //end slot loop
180 
181  if (m_params->m_XML_file_mode==2) {
182  (*of) << "</CFGBrickSet>" << std::endl;
183  of->close();
184  delete of;
185  of=0;
186  }
187 
188  } //end crate loop
189 
190  if (m_params->m_XML_file_mode==1) {
191  (*of) << "</CFGBrickSet>" << std::endl;
192  of->close();
193  delete of;
194  of=0;
195  }
196 }
197 
199  std::cout << "Writing root file..." << std::endl;
201  TFile of(name.c_str(),"RECREATE");
202  if (of.IsZombie()) {
203  std::cerr << "root output file " << name << " is bad." << std::endl;
204  return;
205  }
206 
207  of.mkdir("adc");
208 
209  for (int crate=0; crate<ChannelPattern::NUM_CRATES; crate++) {
210  CrateData* cd=m_patternSet->getCrate(crate);
211  if (cd==0) continue;
212  for (int slot=0; slot<ChannelPattern::NUM_SLOTS; slot++) {
213  for (int tb=0; tb<=1; tb++) {
214  HalfHtrData* hd=cd->getHalfHtrData(slot,tb);
215  if (hd==0) continue;
216  for (int chan=1; chan<=24; chan++) {
217  ChannelPattern* cp=hd->getPattern(chan);
218  char hname[128];
219  sprintf(hname,"Exact fC Cr%d,%d%s-%d",crate,slot,
220  ((tb==1)?("t"):("b")),chan);
221  TH1* hp=new TH1F(hname,hname,ChannelPattern::SAMPLES,-0.5,ChannelPattern::SAMPLES-0.5);
222  hp->SetDirectory(0);
223  sprintf(hname,"Quantized fC Cr%d,%d%s-%d",crate,slot,
224  ((tb==1)?("t"):("b")),chan);
225  TH1* hq=new TH1F(hname,hname,ChannelPattern::SAMPLES,-0.5,ChannelPattern::SAMPLES-0.5);
226  hp->SetDirectory(0);
227  sprintf(hname,"Encoded fC Cr%d,%d%s-%d",crate,slot,
228  ((tb==1)?("t"):("b")),chan);
229  TH1* ha=new TH1F(hname,hname,ChannelPattern::SAMPLES,-0.5,ChannelPattern::SAMPLES-0.5);
230  ha->SetDirectory(0);
231  for (int i=0; i<ChannelPattern::SAMPLES; i++) {
232  hp->Fill(i*1.0,(*cp)[i]);
233  hq->Fill(i*1.0,cp->getQuantized(i));
234  ha->Fill(i*1.0,cp->getCoded(i));
235  }
236  //of.cd("perfect"); hp->Write();
237  //of.cd("quantized"); hq->Write();
238  of.cd("adc"); ha->Write();
239  delete hp;
240  delete hq;
241  delete ha;
242  }
243  }
244  }
245  }
246  of.Close();
247 }
int i
Definition: DBlmapReader.cc:9
int getCoded(int bc) const
int htrSlot() const
get the htr slot
std::vector< HBHEDataFrame >::const_iterator const_iterator
void setTagName(std::string tn)
HtrXmlPatternToolParameters * m_params
int readoutVMECrateId() const
get the readout VME crate number
static const int NUM_CRATES
HtrXmlPatternWriter m_xmlWriter
void Fill(HtrXmlPatternToolParameters *params, HBHEDigiCollection::const_iterator data)
static const int SAMPLES
int htrTopBottom() const
get the htr top/bottom (1=top/0=bottom), valid for VME
HtrXmlPatternTool(HtrXmlPatternToolParameters *m_params)
ChannelPattern * getPattern(int chan)
susybsm::HSCParticleRefProd hp
Definition: classes.h:27
int htrChanId() const
get the HTR channel id (1-24)
int dccid() const
get the (Hcal local) DCC id for VME, crate number for uTCA
static const int NUM_SLOTS
HtrXmlPatternSet * m_patternSet
int spigot() const
get the spigot (input number on DCC, AMC card number for uTCA)
double getQuantized(int bc) const
void Fill(const HcalElectronicsId HEID, HBHEDigiCollection::const_iterator data)
HalfHtrData * getHalfHtrData(int slot, int one_two_tb)
CrateData * getCrate(int crate)
void setSpigot(int spigot)
void writePattern(HalfHtrData *spigotData, int fiber, std::ostream &os, int level=0)
tuple cout
Definition: gather_cfg.py:145
void setDCC(int dcc)
Readout chain identification for Hcal.