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 //
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>" << "CastorDbXml" << "</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  CastorText2DetIdConverter 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 CastorPedestalWidth& 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  int i = fChannels.size ();
108  while (--i >= 0) {
109  fOutput << "<DATA_SET id=\"" << i << "\">" << std::endl;
110  dumpRun (fOutput, fRun);
111  fOutput << "<KIND_OF_CONDITION><NAME>" << fKind << "</NAME></KIND_OF_CONDITION>" << std::endl;
112  dumpChannelId (fOutput, fChannels[i]);
113  fOutput << "<VERSION>" << fVersion << "</VERSION>" << std::endl;
114  fOutput << "</DATA_SET>" << std::endl;
115  }
116  // set IOV
117  fOutput << "<IOV id=\"" << IOV_ID << "\">";
118  fOutput << " <INTERVAL_OF_VALIDITY_BEGIN>" << fGMTIOVBegin << "</INTERVAL_OF_VALIDITY_BEGIN>"<< std::endl;
119  fOutput << " <INTERVAL_OF_VALIDITY_END>" << fGMTIOVEnd << "</INTERVAL_OF_VALIDITY_END>"<< std::endl;
120  fOutput << "</IOV>" << std::endl;
121  // set TAG
122  fOutput << "<TAG id=\"" << TAG_ID << "\" mode=\"create\">"<< std::endl;
123  fOutput << " <TAG_NAME>" << fTag << "</TAG_NAME>"<< std::endl;
124  fOutput << " <DETECTOR_NAME>HCAL</DETECTOR_NAME>"<< std::endl;
125  fOutput << " <COMMENT_DESCRIPTION>Automatically created by CastorDbXml</COMMENT_DESCRIPTION>" << std::endl;
126  fOutput << "</TAG>" << std::endl;
127 
128  fOutput << "</ELEMENTS>" << std::endl;
129 
130  // mapping itself
131  fOutput << "<MAPS>" << std::endl;
132  fOutput << "<TAG idref=\"" << TAG_ID << "\">" << std::endl;
133  fOutput << "<IOV idref=\"" << IOV_ID << "\">" << std::endl;
134  i = fChannels.size ();
135  while (--i >= 0) {
136  fOutput << "<DATA_SET idref=\"" << i << "\"/>" << std::endl;
137  }
138  fOutput << "</IOV>" << std::endl;
139  fOutput << "</TAG>" << std::endl;
140  fOutput << "</MAPS>" << std::endl;
141  }
142 }
143 
144 
145 
146 bool CastorDbXml::dumpObject (std::ostream& fOutput,
147  unsigned fRun, unsigned long fGMTIOVBegin, unsigned long fGMTIOVEnd, const std::string& fTag, unsigned fVersion,
148  const CastorPedestals& fObject) {
149  float dummyError = 0.0001;
150  std::cout << "CastorDbXml::dumpObject-> set default errors: 0.0001, 0.0001, 0.0001, 0.0001" << std::endl;
151  CastorPedestalWidths widths(fObject.isADC() );
152  std::vector<DetId> channels = fObject.getAllChannels ();
153  for (std::vector<DetId>::iterator channel = channels.begin ();
154  channel != channels.end ();
155  ++channel) {
156 
157  CastorPedestalWidth item(*channel);
158  for (int iCapId = 1; iCapId <= 4; iCapId++) {
159  item.setSigma (iCapId, iCapId, dummyError*dummyError);
160  }
161  widths.addValues(item);
162 
163  }
164  return dumpObject (fOutput, fRun, fGMTIOVBegin, fGMTIOVEnd, fTag, fVersion, fObject, widths);
165 }
166 
167 bool CastorDbXml::dumpObject (std::ostream& fOutput,
168  unsigned fRun, unsigned long fGMTIOVBegin, unsigned long fGMTIOVEnd, const std::string& fTag, unsigned fVersion,
169  const CastorPedestals& fObject, const CastorPedestalWidths& fError) {
170  const std::string KIND = "HCAL_PEDESTALS_V2";
171 
172  dumpProlog (fOutput);
173  dumpHeader (fOutput, fRun, KIND, KIND);
174 
175  std::vector<DetId> channels = fObject.getAllChannels ();
176  for (std::vector<DetId>::iterator channel = channels.begin ();
177  channel != channels.end ();
178  ++channel) {
179  DetId chId = *channel;
180  const float* values = fObject.getValues (chId)->getValues ();
181  const CastorPedestalWidth* errors = fError.getValues (chId);
182  if (!values) {
183  std::cerr << "CastorDbXml::dumpObject-> Can not get data for channel " << CastorText2DetIdConverter(chId).toString () << std::endl;
184  continue;
185  }
186  if (!errors) {
187  std::cerr << "CastorDbXml::dumpObject-> Can not get errors for channel " << CastorText2DetIdConverter(chId).toString () << ". Use defaults" << std::endl;
188  continue;
189  }
190  dumpDataset (fOutput, fVersion, "", "");
191  dumpChannelId (fOutput,chId);
192  dumpData (fOutput, values, *errors);
193  endDataset (fOutput);
194  }
195  dumpMapping (fOutput, fRun, KIND, fGMTIOVBegin, fGMTIOVEnd, fTag, fVersion, channels);
196 
197  dumpFooter (fOutput);
198  return true;
199 }
200 
201 bool CastorDbXml::dumpObject (std::ostream& fOutput,
202  unsigned fRun, unsigned long fGMTIOVBegin, unsigned long fGMTIOVEnd, const std::string& fTag, unsigned fVersion,
203  const CastorGains& fObject) {
204  float dummyErrors [4] = {0., 0., 0., 0.};
205  std::cout << "CastorDbXml::dumpObject-> set default errors: 4 x 0.0" << std::endl;
206 
207  CastorGainWidths widths;
208  std::vector<DetId> channels = fObject.getAllChannels ();
209  for (std::vector<DetId>::iterator channel = channels.begin (); channel != channels.end (); ++channel)
210  {
211  CastorGainWidth item(*channel,dummyErrors[0],dummyErrors[1],dummyErrors[2],dummyErrors[3]);
212  widths.addValues(item);
213  }
214 
215  return dumpObject (fOutput, fRun, fGMTIOVBegin, fGMTIOVEnd, fTag, fVersion, fObject, widths);
216 }
217 
218 bool CastorDbXml::dumpObject (std::ostream& fOutput,
219  unsigned fRun, unsigned long fGMTIOVBegin, unsigned long fGMTIOVEnd, const std::string& fTag, unsigned fVersion,
220  const CastorGains& fObject, const CastorGainWidths& fError) {
221  const std::string KIND = "HCAL Gains";
222  const std::string TABLE = "HCAL_GAIN_PEDSTL_CALIBRATIONS";
223 
224  dumpProlog (fOutput);
225  dumpHeader (fOutput, fRun, TABLE, KIND);
226 
227  std::vector<DetId> channels = fObject.getAllChannels ();
228  for (std::vector<DetId>::iterator channel = channels.begin ();
229  channel != channels.end ();
230  ++channel) {
231  DetId chId = *channel;
232  const float* values = fObject.getValues (chId)->getValues ();
233  const float* errors = fError.getValues (chId)->getValues ();
234  if (!values) {
235  std::cerr << "CastorDbXml::dumpObject-> Can not get data for channel " << CastorText2DetIdConverter(chId).toString () << std::endl;
236  continue;
237  }
238  if (!errors) {
239  std::cerr << "CastorDbXml::dumpObject-> Can not get errors for channel " << CastorText2DetIdConverter(chId).toString () << ". Use defaults" << std::endl;
240  continue;
241  }
242  dumpDataset (fOutput, fVersion, "", "");
243  dumpChannelId (fOutput,chId);
244  dumpData (fOutput, values, errors);
245  endDataset (fOutput);
246  }
247  dumpMapping (fOutput, fRun, KIND, fGMTIOVBegin, fGMTIOVEnd, fTag, fVersion, channels);
248 
249  dumpFooter (fOutput);
250  return true;
251 }
int i
Definition: DBlmapReader.cc:9
void setSigma(int fCapId1, int fCapId2, float fSigma)
std::vector< DetId > getAllChannels() const
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:167
const Item * getValues(DetId fId, bool throwOnFail=true) const
float getSigma(int fCapId1, int fCapId2) const
get correlation element for capId1/2 = 0..3
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const float * getValues() const
get value for all capId = 0..3
Definition: DetId.h:18
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:145
const float * getValues() const
get value for all capId = 0..3
Definition: CastorGain.h:17