CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CastorDbXml.cc
Go to the documentation of this file.
1 // F.Ratnikov (UMd), Oct 28, 2005
2 // Modified by S. Won 6 May 2008
3 // $Id: CastorDbXml.cc,v 1.2 2009/12/10 10:29:00 elmer Exp $
4 //
5 #include <vector>
6 #include <string>
7 
8 
10 
13 
14 namespace {
15  void dumpProlog (std::ostream& fOutput) {
16  fOutput << "<?xml version='1.0' encoding='UTF-8'?>" << std::endl;
17  fOutput << "<!DOCTYPE root []>" << std::endl;
18  fOutput << "<ROOT>" << std::endl;
19  }
20 
21  void dumpRun (std::ostream& fOutput, unsigned fRun) {
22  fOutput << "<RUN>"<< std::endl;
23  fOutput << " <RUN_TYPE>" << "CastorDbXml" << "</RUN_TYPE>"<< std::endl;
24  fOutput << " <RUN_NUMBER>" << fRun << "</RUN_NUMBER>"<< std::endl;
25  fOutput << "</RUN>" << std::endl;
26  }
27 
28  void dumpHeader (std::ostream& fOutput, unsigned fRun, const std::string& fTableName, const std::string& fTypeName) {
29  fOutput << " <HEADER>" << std::endl;
30  fOutput << " <TYPE>" << std::endl;
31  fOutput << " <EXTENSION_TABLE_NAME>" << fTableName << "</EXTENSION_TABLE_NAME>" << std::endl;
32  fOutput << " <NAME>" << fTypeName << "</NAME>" << std::endl;
33  fOutput << " </TYPE>" << std::endl;
34  dumpRun (fOutput, fRun);
35  fOutput << " </HEADER>" << std::endl;
36  }
37 
38  void dumpFooter (std::ostream& fOutput) {
39  fOutput << "</ROOT>" << std::endl;
40  }
41 
42  void dumpChannelId (std::ostream& fOutput, DetId fChannel) {
43  CastorText2DetIdConverter converter (fChannel);
44  fOutput << "<CHANNEL> "<< std::endl;
45  fOutput << " <EXTENSION_TABLE_NAME>HCAL_CHANNELS</EXTENSION_TABLE_NAME> "<< std::endl;
46  fOutput << " <ETA>" << abs (converter.getField (1)) << "</ETA>"<< std::endl;
47  fOutput << " <PHI>" << converter.getField (2) << "</PHI> "<< std::endl;
48  fOutput << " <DEPTH>" << converter.getField (3) << "</DEPTH> "<< std::endl;
49  fOutput << " <Z>" << (converter.getField (1) > 0 ? "1" : "-1") << "</Z> "<< std::endl;
50  fOutput << " <DETECTOR_NAME>" << converter.getFlavor () << "</DETECTOR_NAME> "<< std::endl;
51  fOutput << " <HCAL_CHANNEL_ID>" << converter.getId().rawId () << "</HCAL_CHANNEL_ID> "<< std::endl;
52  fOutput << "</CHANNEL>"<< std::endl;
53  fOutput << std::endl;
54  }
55 
56  void dumpData (std::ostream& fOutput, const float* fValues, const CastorPedestalWidth& fErrors) {
57  fOutput << "<DATA> "<< std::endl;
58  fOutput << " <CAPACITOR_0_VALUE>" << fValues [0] << "</CAPACITOR_0_VALUE> "<< std::endl;
59  fOutput << " <CAPACITOR_1_VALUE>" << fValues [1] << "</CAPACITOR_1_VALUE> "<< std::endl;
60  fOutput << " <CAPACITOR_2_VALUE>" << fValues [2] << "</CAPACITOR_2_VALUE> "<< std::endl;
61  fOutput << " <CAPACITOR_3_VALUE>" << fValues [3] << "</CAPACITOR_3_VALUE> "<< std::endl;
62  fOutput << " <SIGMA_0_0>" << fErrors.getSigma (0,0) << "</SIGMA_0_0> "<< std::endl;
63  fOutput << " <SIGMA_1_1>" << fErrors.getSigma (1,1) << "</SIGMA_1_1> "<< std::endl;
64  fOutput << " <SIGMA_2_2>" << fErrors.getSigma (2,2) << "</SIGMA_2_2> "<< std::endl;
65  fOutput << " <SIGMA_3_3>" << fErrors.getSigma (3,3) << "</SIGMA_3_3> "<< std::endl;
66  fOutput << " <SIGMA_0_1>" << fErrors.getSigma (1,0) << "</SIGMA_0_1> "<< std::endl;
67  fOutput << " <SIGMA_0_2>" << fErrors.getSigma (2,0) << "</SIGMA_0_2> "<< std::endl;
68  fOutput << " <SIGMA_0_3>" << fErrors.getSigma (3,0) << "</SIGMA_0_3> "<< std::endl;
69  fOutput << " <SIGMA_1_2>" << fErrors.getSigma (2,1) << "</SIGMA_1_2> "<< std::endl;
70  fOutput << " <SIGMA_1_3>" << fErrors.getSigma (3,1) << "</SIGMA_1_3> "<< std::endl;
71  fOutput << " <SIGMA_2_3>" << fErrors.getSigma (3,2) << "</SIGMA_2_3> "<< std::endl;
72  fOutput << "</DATA> " << std::endl;
73  }
74 
75  void dumpData (std::ostream& fOutput, const float* fValues, const float* fErrors) {
76  fOutput << "<DATA> "<< std::endl;
77  fOutput << " <CAPACITOR_0_VALUE>" << fValues [0] << "</CAPACITOR_0_VALUE> "<< std::endl;
78  fOutput << " <CAPACITOR_1_VALUE>" << fValues [1] << "</CAPACITOR_1_VALUE> "<< std::endl;
79  fOutput << " <CAPACITOR_2_VALUE>" << fValues [2] << "</CAPACITOR_2_VALUE> "<< std::endl;
80  fOutput << " <CAPACITOR_3_VALUE>" << fValues [3] << "</CAPACITOR_3_VALUE> "<< std::endl;
81  fOutput << " <CAPACITOR_0_ERROR>" << fErrors [0] << "</CAPACITOR_0_ERROR> "<< std::endl;
82  fOutput << " <CAPACITOR_1_ERROR>" << fErrors [1] << "</CAPACITOR_1_ERROR> "<< std::endl;
83  fOutput << " <CAPACITOR_2_ERROR>" << fErrors [2] << "</CAPACITOR_2_ERROR> "<< std::endl;
84  fOutput << " <CAPACITOR_3_ERROR>" << fErrors [3] << "</CAPACITOR_3_ERROR> "<< std::endl;
85  fOutput << "</DATA> " << std::endl;
86  }
87 
88  void dumpDataset (std::ostream& fOutput, unsigned fVersion = 0, const std::string& fFileName = "", const std::string& fDescription = "") {
89  fOutput << "<DATA_SET>" << std::endl;
90  fOutput << " <VERSION>" << fVersion << "</VERSION>" << std::endl;
91  if (!fFileName.empty ())
92  fOutput << " <DATA_FILE_NAME>" << fFileName << "</DATA_FILE_NAME>" << std::endl;
93  if (!fDescription.empty ())
94  fOutput << " <COMMENT_DESCRIPTION>" << fDescription << "</COMMENT_DESCRIPTION>" << std::endl;
95  }
96 
97  void endDataset (std::ostream& fOutput) {
98  fOutput << "</DATA_SET>" << std::endl;
99  }
100 
101  void dumpMapping (std::ostream& fOutput, unsigned fRun, const std::string& fKind,
102  unsigned long fGMTIOVBegin, unsigned long fGMTIOVEnd,
103  const std::string& fTag, unsigned fVersion, const std::vector<DetId>& fChannels) {
104  const std::string IOV_ID = "IOV_ID";
105  const std::string TAG_ID = "TAG_ID";
106  fOutput << "<ELEMENTS>" << std::endl;
107  // set channels affected
108  int i = fChannels.size ();
109  while (--i >= 0) {
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 CastorDbXml</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 >= 0) {
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 CastorDbXml::dumpObject (std::ostream& fOutput,
148  unsigned fRun, unsigned long fGMTIOVBegin, unsigned long fGMTIOVEnd, const std::string& fTag, unsigned fVersion,
149  const CastorPedestals& fObject) {
150  float dummyError = 0.0001;
151  std::cout << "CastorDbXml::dumpObject-> set default errors: 0.0001, 0.0001, 0.0001, 0.0001" << std::endl;
152  CastorPedestalWidths widths(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  CastorPedestalWidth 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 CastorDbXml::dumpObject (std::ostream& fOutput,
169  unsigned fRun, unsigned long fGMTIOVBegin, unsigned long fGMTIOVEnd, const std::string& fTag, unsigned fVersion,
170  const CastorPedestals& fObject, const CastorPedestalWidths& 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 CastorPedestalWidth* errors = fError.getValues (chId);
183  if (!values) {
184  std::cerr << "CastorDbXml::dumpObject-> Can not get data for channel " << CastorText2DetIdConverter(chId).toString () << std::endl;
185  continue;
186  }
187  if (!errors) {
188  std::cerr << "CastorDbXml::dumpObject-> Can not get errors for channel " << CastorText2DetIdConverter(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 CastorDbXml::dumpObject (std::ostream& fOutput,
203  unsigned fRun, unsigned long fGMTIOVBegin, unsigned long fGMTIOVEnd, const std::string& fTag, unsigned fVersion,
204  const CastorGains& fObject) {
205  float dummyErrors [4] = {0., 0., 0., 0.};
206  std::cout << "CastorDbXml::dumpObject-> set default errors: 4 x 0.0" << std::endl;
207 
208  CastorGainWidths widths;
209  std::vector<DetId> channels = fObject.getAllChannels ();
210  for (std::vector<DetId>::iterator channel = channels.begin (); channel != channels.end (); channel++)
211  {
212  CastorGainWidth 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 CastorDbXml::dumpObject (std::ostream& fOutput,
220  unsigned fRun, unsigned long fGMTIOVBegin, unsigned long fGMTIOVEnd, const std::string& fTag, unsigned fVersion,
221  const CastorGains& fObject, const CastorGainWidths& 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 << "CastorDbXml::dumpObject-> Can not get data for channel " << CastorText2DetIdConverter(chId).toString () << std::endl;
237  continue;
238  }
239  if (!errors) {
240  std::cerr << "CastorDbXml::dumpObject-> Can not get errors for channel " << CastorText2DetIdConverter(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
void setSigma(int fCapId1, int fCapId2, float fSigma)
std::vector< DetId > getAllChannels() const
#define abs(x)
Definition: mlp_lapack.h:159
bool dumpObject(std::ostream &fOutput, unsigned fRun, unsigned long fGMTIOVBegin, unsigned long fGMTIOVEnd, const std::string &fTag, unsigned fVersion, const CastorPedestals &fObject, const CastorPedestalWidths &fError)
Definition: CastorDbXml.cc:168
float getSigma(int fCapId1, int fCapId2) const
get correlation element for capId1/2 = 0..3
const float * getValues() const
get value for all capId = 0..3
const Item * getValues(DetId fId) const
Definition: DetId.h:20
bool dumpObject(std::ostream &fOutput, const CastorPedestals &fObject)
bool isADC() const
bool addValues(const Item &myItem)
const float * getValues() const
get value for all capId = 0..3
tuple cout
Definition: gather_cfg.py:121
const float * getValues() const
get value for all capId = 0..3
Definition: CastorGain.h:15