CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalDbXml.cc
Go to the documentation of this file.
1 // F.Ratnikov (UMd), Oct 28, 2005
2 // Modified by S. Won 6 May 2008
3 //
4 #include <vector>
5 #include <string>
6 
7 
9 
12 
13 namespace {
14  void dumpProlog (std::ostream& fOutput) {
15  fOutput << "<?xml version='1.0' encoding='UTF-8'?>" << std::endl;
16  fOutput << "<!DOCTYPE root []>" << std::endl;
17  fOutput << "<ROOT>" << std::endl;
18  }
19 
20  void dumpRun (std::ostream& fOutput, unsigned fRun) {
21  fOutput << "<RUN>"<< std::endl;
22  fOutput << " <RUN_TYPE>" << "HcalDbXml" << "</RUN_TYPE>"<< std::endl;
23  fOutput << " <RUN_NUMBER>" << fRun << "</RUN_NUMBER>"<< std::endl;
24  fOutput << "</RUN>" << std::endl;
25  }
26 
27  void dumpHeader (std::ostream& fOutput, unsigned fRun, const std::string& fTableName, const std::string& fTypeName) {
28  fOutput << " <HEADER>" << std::endl;
29  fOutput << " <TYPE>" << std::endl;
30  fOutput << " <EXTENSION_TABLE_NAME>" << fTableName << "</EXTENSION_TABLE_NAME>" << std::endl;
31  fOutput << " <NAME>" << fTypeName << "</NAME>" << std::endl;
32  fOutput << " </TYPE>" << std::endl;
33  dumpRun (fOutput, fRun);
34  fOutput << " </HEADER>" << std::endl;
35  }
36 
37  void dumpFooter (std::ostream& fOutput) {
38  fOutput << "</ROOT>" << std::endl;
39  }
40 
41  void dumpChannelId (std::ostream& fOutput, DetId fChannel) {
42  HcalText2DetIdConverter converter (fChannel);
43  fOutput << "<CHANNEL> "<< std::endl;
44  fOutput << " <EXTENSION_TABLE_NAME>HCAL_CHANNELS</EXTENSION_TABLE_NAME> "<< std::endl;
45  fOutput << " <ETA>" << abs (converter.getField (1)) << "</ETA>"<< std::endl;
46  fOutput << " <PHI>" << converter.getField (2) << "</PHI> "<< std::endl;
47  fOutput << " <DEPTH>" << converter.getField (3) << "</DEPTH> "<< std::endl;
48  fOutput << " <Z>" << (converter.getField (1) > 0 ? "1" : "-1") << "</Z> "<< std::endl;
49  fOutput << " <DETECTOR_NAME>" << converter.getFlavor () << "</DETECTOR_NAME> "<< std::endl;
50  fOutput << " <HCAL_CHANNEL_ID>" << converter.getId().rawId () << "</HCAL_CHANNEL_ID> "<< std::endl;
51  fOutput << "</CHANNEL>"<< std::endl;
52  fOutput << std::endl;
53  }
54 
55  void dumpData (std::ostream& fOutput, const float* fValues, const HcalPedestalWidth& fErrors) {
56  fOutput << "<DATA> "<< std::endl;
57  fOutput << " <CAPACITOR_0_VALUE>" << fValues [0] << "</CAPACITOR_0_VALUE> "<< std::endl;
58  fOutput << " <CAPACITOR_1_VALUE>" << fValues [1] << "</CAPACITOR_1_VALUE> "<< std::endl;
59  fOutput << " <CAPACITOR_2_VALUE>" << fValues [2] << "</CAPACITOR_2_VALUE> "<< std::endl;
60  fOutput << " <CAPACITOR_3_VALUE>" << fValues [3] << "</CAPACITOR_3_VALUE> "<< std::endl;
61  fOutput << " <SIGMA_0_0>" << fErrors.getSigma (0,0) << "</SIGMA_0_0> "<< std::endl;
62  fOutput << " <SIGMA_1_1>" << fErrors.getSigma (1,1) << "</SIGMA_1_1> "<< std::endl;
63  fOutput << " <SIGMA_2_2>" << fErrors.getSigma (2,2) << "</SIGMA_2_2> "<< std::endl;
64  fOutput << " <SIGMA_3_3>" << fErrors.getSigma (3,3) << "</SIGMA_3_3> "<< std::endl;
65  fOutput << " <SIGMA_0_1>" << fErrors.getSigma (1,0) << "</SIGMA_0_1> "<< std::endl;
66  fOutput << " <SIGMA_0_2>" << fErrors.getSigma (2,0) << "</SIGMA_0_2> "<< std::endl;
67  fOutput << " <SIGMA_0_3>" << fErrors.getSigma (3,0) << "</SIGMA_0_3> "<< std::endl;
68  fOutput << " <SIGMA_1_2>" << fErrors.getSigma (2,1) << "</SIGMA_1_2> "<< std::endl;
69  fOutput << " <SIGMA_1_3>" << fErrors.getSigma (3,1) << "</SIGMA_1_3> "<< std::endl;
70  fOutput << " <SIGMA_2_3>" << fErrors.getSigma (3,2) << "</SIGMA_2_3> "<< std::endl;
71  fOutput << "</DATA> " << std::endl;
72  }
73 
74  void dumpData (std::ostream& fOutput, const float* fValues, const float* fErrors) {
75  fOutput << "<DATA> "<< std::endl;
76  fOutput << " <CAPACITOR_0_VALUE>" << fValues [0] << "</CAPACITOR_0_VALUE> "<< std::endl;
77  fOutput << " <CAPACITOR_1_VALUE>" << fValues [1] << "</CAPACITOR_1_VALUE> "<< std::endl;
78  fOutput << " <CAPACITOR_2_VALUE>" << fValues [2] << "</CAPACITOR_2_VALUE> "<< std::endl;
79  fOutput << " <CAPACITOR_3_VALUE>" << fValues [3] << "</CAPACITOR_3_VALUE> "<< std::endl;
80  fOutput << " <CAPACITOR_0_ERROR>" << fErrors [0] << "</CAPACITOR_0_ERROR> "<< std::endl;
81  fOutput << " <CAPACITOR_1_ERROR>" << fErrors [1] << "</CAPACITOR_1_ERROR> "<< std::endl;
82  fOutput << " <CAPACITOR_2_ERROR>" << fErrors [2] << "</CAPACITOR_2_ERROR> "<< std::endl;
83  fOutput << " <CAPACITOR_3_ERROR>" << fErrors [3] << "</CAPACITOR_3_ERROR> "<< std::endl;
84  fOutput << "</DATA> " << std::endl;
85  }
86 
87  void dumpDataset (std::ostream& fOutput, unsigned fVersion = 0, const std::string& fFileName = "", const std::string& fDescription = "") {
88  fOutput << "<DATA_SET>" << std::endl;
89  fOutput << " <VERSION>" << fVersion << "</VERSION>" << std::endl;
90  if (!fFileName.empty ())
91  fOutput << " <DATA_FILE_NAME>" << fFileName << "</DATA_FILE_NAME>" << std::endl;
92  if (!fDescription.empty ())
93  fOutput << " <COMMENT_DESCRIPTION>" << fDescription << "</COMMENT_DESCRIPTION>" << std::endl;
94  }
95 
96  void endDataset (std::ostream& fOutput) {
97  fOutput << "</DATA_SET>" << std::endl;
98  }
99 
100  void dumpMapping (std::ostream& fOutput, unsigned fRun, const std::string& fKind,
101  unsigned long fGMTIOVBegin, unsigned long fGMTIOVEnd,
102  const std::string& fTag, unsigned fVersion, const std::vector<DetId>& fChannels) {
103  const std::string IOV_ID = "IOV_ID";
104  const std::string TAG_ID = "TAG_ID";
105  fOutput << "<ELEMENTS>" << std::endl;
106  // set channels affected
107  unsigned int i = fChannels.size ();
108  unsigned int iend = 0;
109  while (--i >= iend) {
110  fOutput << "<DATA_SET id=\"" << i << "\">" << std::endl;
111  dumpRun (fOutput, fRun);
112  fOutput << "<KIND_OF_CONDITION><NAME>" << fKind << "</NAME></KIND_OF_CONDITION>" << std::endl;
113  dumpChannelId (fOutput, fChannels[i]);
114  fOutput << "<VERSION>" << fVersion << "</VERSION>" << std::endl;
115  fOutput << "</DATA_SET>" << std::endl;
116  }
117  // set IOV
118  fOutput << "<IOV id=\"" << IOV_ID << "\">";
119  fOutput << " <INTERVAL_OF_VALIDITY_BEGIN>" << fGMTIOVBegin << "</INTERVAL_OF_VALIDITY_BEGIN>"<< std::endl;
120  fOutput << " <INTERVAL_OF_VALIDITY_END>" << fGMTIOVEnd << "</INTERVAL_OF_VALIDITY_END>"<< std::endl;
121  fOutput << "</IOV>" << std::endl;
122  // set TAG
123  fOutput << "<TAG id=\"" << TAG_ID << "\" mode=\"create\">"<< std::endl;
124  fOutput << " <TAG_NAME>" << fTag << "</TAG_NAME>"<< std::endl;
125  fOutput << " <DETECTOR_NAME>HCAL</DETECTOR_NAME>"<< std::endl;
126  fOutput << " <COMMENT_DESCRIPTION>Automatically created by HcalDbXml</COMMENT_DESCRIPTION>" << std::endl;
127  fOutput << "</TAG>" << std::endl;
128 
129  fOutput << "</ELEMENTS>" << std::endl;
130 
131  // mapping itself
132  fOutput << "<MAPS>" << std::endl;
133  fOutput << "<TAG idref=\"" << TAG_ID << "\">" << std::endl;
134  fOutput << "<IOV idref=\"" << IOV_ID << "\">" << std::endl;
135  i = fChannels.size ();
136  while (--i >= iend) {
137  fOutput << "<DATA_SET idref=\"" << i << "\"/>" << std::endl;
138  }
139  fOutput << "</IOV>" << std::endl;
140  fOutput << "</TAG>" << std::endl;
141  fOutput << "</MAPS>" << std::endl;
142  }
143 }
144 
145 
146 
147 bool HcalDbXml::dumpObject (std::ostream& fOutput,
148  unsigned fRun, unsigned long fGMTIOVBegin, unsigned long fGMTIOVEnd, const std::string& fTag, unsigned fVersion,
149  const HcalPedestals& fObject) {
150  float dummyError = 0.0001;
151  std::cout << "HcalDbXml::dumpObject-> set default errors: 0.0001, 0.0001, 0.0001, 0.0001" << std::endl;
152  HcalPedestalWidths widths(fObject.topo(),fObject.isADC() );
153  std::vector<DetId> channels = fObject.getAllChannels ();
154  for (std::vector<DetId>::iterator channel = channels.begin ();
155  channel != channels.end ();
156  ++channel) {
157 
158  HcalPedestalWidth item(*channel);
159  for (int iCapId = 1; iCapId <= 4; iCapId++) {
160  item.setSigma (iCapId, iCapId, dummyError*dummyError);
161  }
162  widths.addValues(item);
163 
164  }
165  return dumpObject (fOutput, fRun, fGMTIOVBegin, fGMTIOVEnd, fTag, fVersion, fObject, widths);
166 }
167 
168 bool HcalDbXml::dumpObject (std::ostream& fOutput,
169  unsigned fRun, unsigned long fGMTIOVBegin, unsigned long fGMTIOVEnd, const std::string& fTag, unsigned fVersion,
170  const HcalPedestals& fObject, const HcalPedestalWidths& fError) {
171  const std::string KIND = "HCAL_PEDESTALS_V2";
172 
173  dumpProlog (fOutput);
174  dumpHeader (fOutput, fRun, KIND, KIND);
175 
176  std::vector<DetId> channels = fObject.getAllChannels ();
177  for (std::vector<DetId>::iterator channel = channels.begin ();
178  channel != channels.end ();
179  ++channel) {
180  DetId chId = *channel;
181  const float* values = fObject.getValues (chId)->getValues ();
182  const HcalPedestalWidth* errors = fError.getValues (chId);
183  if (!values) {
184  std::cerr << "HcalDbXml::dumpObject-> Can not get data for channel " << HcalText2DetIdConverter(chId).toString () << std::endl;
185  continue;
186  }
187  if (!errors) {
188  std::cerr << "HcalDbXml::dumpObject-> Can not get errors for channel " << HcalText2DetIdConverter(chId).toString () << ". Use defaults" << std::endl;
189  continue;
190  }
191  dumpDataset (fOutput, fVersion, "", "");
192  dumpChannelId (fOutput,chId);
193  dumpData (fOutput, values, *errors);
194  endDataset (fOutput);
195  }
196  dumpMapping (fOutput, fRun, KIND, fGMTIOVBegin, fGMTIOVEnd, fTag, fVersion, channels);
197 
198  dumpFooter (fOutput);
199  return true;
200 }
201 
202 bool HcalDbXml::dumpObject (std::ostream& fOutput,
203  unsigned fRun, unsigned long fGMTIOVBegin, unsigned long fGMTIOVEnd, const std::string& fTag, unsigned fVersion,
204  const HcalGains& fObject) {
205  float dummyErrors [4] = {0., 0., 0., 0.};
206  std::cout << "HcalDbXml::dumpObject-> set default errors: 4 x 0.0" << std::endl;
207 
208  HcalGainWidths widths(fObject.topo());
209  std::vector<DetId> channels = fObject.getAllChannels ();
210  for (std::vector<DetId>::iterator channel = channels.begin (); channel != channels.end (); ++channel)
211  {
212  HcalGainWidth item(*channel,dummyErrors[0],dummyErrors[1],dummyErrors[2],dummyErrors[3]);
213  widths.addValues(item);
214  }
215 
216  return dumpObject (fOutput, fRun, fGMTIOVBegin, fGMTIOVEnd, fTag, fVersion, fObject, widths);
217 }
218 
219 bool HcalDbXml::dumpObject (std::ostream& fOutput,
220  unsigned fRun, unsigned long fGMTIOVBegin, unsigned long fGMTIOVEnd, const std::string& fTag, unsigned fVersion,
221  const HcalGains& fObject, const HcalGainWidths& fError) {
222  const std::string KIND = "HCAL Gains";
223  const std::string TABLE = "HCAL_GAIN_PEDSTL_CALIBRATIONS";
224 
225  dumpProlog (fOutput);
226  dumpHeader (fOutput, fRun, TABLE, KIND);
227 
228  std::vector<DetId> channels = fObject.getAllChannels ();
229  for (std::vector<DetId>::iterator channel = channels.begin ();
230  channel != channels.end ();
231  ++channel) {
232  DetId chId = *channel;
233  const float* values = fObject.getValues (chId)->getValues ();
234  const float* errors = fError.getValues (chId)->getValues ();
235  if (!values) {
236  std::cerr << "HcalDbXml::dumpObject-> Can not get data for channel " << HcalText2DetIdConverter(chId).toString () << std::endl;
237  continue;
238  }
239  if (!errors) {
240  std::cerr << "HcalDbXml::dumpObject-> Can not get errors for channel " << HcalText2DetIdConverter(chId).toString () << ". Use defaults" << std::endl;
241  continue;
242  }
243  dumpDataset (fOutput, fVersion, "", "");
244  dumpChannelId (fOutput,chId);
245  dumpData (fOutput, values, errors);
246  endDataset (fOutput);
247  }
248  dumpMapping (fOutput, fRun, KIND, fGMTIOVBegin, fGMTIOVEnd, fTag, fVersion, channels);
249 
250  dumpFooter (fOutput);
251  return true;
252 }
int i
Definition: DBlmapReader.cc:9
bool isADC() const
Definition: HcalPedestals.h:28
float getSigma(int fCapId1, int fCapId2) const
get correlation element for capId1/2 = 0..3
bool dumpObject(std::ostream &fOutput, unsigned fRun, unsigned long fGMTIOVBegin, unsigned long fGMTIOVEnd, const std::string &fTag, unsigned fVersion, const HcalPedestals &fObject, const HcalPedestalWidths &fError)
Definition: HcalDbXml.cc:168
const Item * getValues(DetId fId, bool throwOnFail=true) const
const float * getValues() const
get value for all capId = 0..3
Definition: HcalGainWidth.h:19
std::vector< DetId > getAllChannels() const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const float * getValues() const
get value for all capId = 0..3
Definition: HcalGain.h:20
Definition: DetId.h:18
bool dumpObject(std::ostream &fOutput, const CastorPedestals &fObject)
const float * getValues() const
get value for all capId = 0..3
Definition: HcalPedestal.h:19
tuple cout
Definition: gather_cfg.py:121
void setSigma(int fCapId1, int fCapId2, float fSigma)
const HcalTopology * topo() const