13 #include <svd/calibration/SVDLocalCalibrationsImporter.h>
17 #include <svd/online/SVDOnlineToOfflineMap.h>
20 #include <framework/database/Database.h>
21 #include <framework/database/DBObjPtr.h>
22 #include <framework/database/PayloadFile.h>
23 #include <framework/database/IntervalOfValidity.h>
24 #include <framework/database/DBImportObjPtr.h>
27 #include <framework/logging/Logger.h>
29 #include <framework/utilities/FileSystem.h>
32 #include <svd/calibration/SVDNoiseCalibrations.h>
33 #include <svd/calibration/SVDPedestalCalibrations.h>
34 #include <svd/calibration/SVDPulseShapeCalibrations.h>
35 #include <svd/calibration/SVDHotStripsCalibrations.h>
36 #include <svd/calibration/SVDFADCMaskedStrips.h>
38 #include <vxd/dataobjects/VxdID.h>
40 #include <boost/property_tree/ptree.hpp>
41 #include <boost/property_tree/xml_parser.hpp>
47 using boost::property_tree::ptree;
49 void SVDLocalCalibrationsImporter::importSVDChannelMapping(
const std::string& fileName)
53 const std::string
filename = FileSystem::findFile(fileName);
54 B2INFO(
"Importing the svd online -> offline map " << fileName <<
"\n");
56 const std::string payloadname =
"SVDChannelMapping.xml";
57 if (Database::Instance().addPayload(payloadname, filename, iov))
60 B2INFO(
"Failure :( ua uaa uaa uaa uaaaa)");
64 void SVDLocalCalibrationsImporter::importSVDNoiseCalibrationsFromXML(
const std::string& xmlFileName,
bool errorTollerant)
73 importSVDCalibrationsFromXML< SVDNoiseCalibrations::t_payload >(SVDNoiseCalibrations::name,
74 xmlFileName,
"noises",
75 -1.0, errorTollerant);
78 void SVDLocalCalibrationsImporter::importSVDPedestalCalibrationsFromXML(
const std::string& xmlFileName,
bool errorTollerant)
80 importSVDCalibrationsFromXML< SVDPedestalCalibrations::t_payload >(SVDPedestalCalibrations::name,
81 xmlFileName,
"pedestals",
82 -1.0, errorTollerant);
85 void SVDLocalCalibrationsImporter::importSVDHotStripsCalibrationsFromXML(
const std::string& xmlFileName,
bool errorTollerant)
87 importSVDCalibrationsFromXML< SVDHotStripsCalibrations::t_payload >(SVDHotStripsCalibrations::name,
88 xmlFileName,
"hot_strips",
89 false, errorTollerant);
92 void SVDLocalCalibrationsImporter::importSVDFADCMaskedStripsFromXML(
const std::string& xmlFileName,
bool errorTollerant)
94 importSVDCalibrationsFromXML< SVDFADCMaskedStrips::t_payload >(SVDFADCMaskedStrips::name,
96 false, errorTollerant);
102 template<
class SVDcalibration >
103 void SVDLocalCalibrationsImporter::importSVDCalibrationsFromXML(
const std::string& condDbname,
104 const std::string& xmlFileName,
105 const std::string& xmlTag,
106 typename SVDcalibration::t_perSideContainer::calibrationType defaultValue,
113 OnlineToOfflineMapFileName.hasChanged();
115 unique_ptr<SVDOnlineToOfflineMap> map =
116 make_unique<SVDOnlineToOfflineMap>(OnlineToOfflineMapFileName->getFileName());
118 payload.construct(defaultValue , xmlFileName);
125 read_xml(xmlFileName, pt);
127 for (ptree::value_type
const& backEndLayoutChild :
128 pt.get_child(
"cfg_document.back_end_layout")) {
130 if (backEndLayoutChild.first ==
"fadc") {
132 string FADCidString = backEndLayoutChild.second.get<
string>(
"<xmlattr>.id");
134 ss << std::hex << FADCidString;
137 for (ptree::value_type
const& fadcChild : backEndLayoutChild.second.get_child(
"")) {
138 if (fadcChild.first ==
"adc") {
139 int ADCid = fadcChild.second.get<
int>(
"<xmlattr>.id") ;
140 B2DEBUG(1,
" ADC id = " << ADCid);
142 int layerId = fadcChild.second.get<
int>(
"<xmlattr>.layer_id");
143 B2DEBUG(1,
" layer_id = " << layerId);
145 int ladderId = fadcChild.second.get<
int>(
"<xmlattr>.ladder_id") ;
146 B2DEBUG(1,
" ladder_id = " << ladderId);
148 int hybridId = fadcChild.second.get<
int>(
"<xmlattr>.hybrid_id");
149 B2DEBUG(1,
" hybrid_id = " << hybridId);
151 B2DEBUG(1,
" delay25 = " <<
152 fadcChild.second.get<
int>(
"<xmlattr>.delay25"));
154 for (ptree::value_type
const& apvChild : fadcChild.second.get_child(
"")) {
155 if (apvChild.first ==
"apv25") {
156 int apv25ADCid = apvChild.second.get<
int>(
"<xmlattr>.id");
157 string valuesString = apvChild.second.get<
string>(xmlTag) ;
158 B2DEBUG(10, xmlTag <<
" APV25ID" << apv25ADCid <<
" "
159 << valuesString <<
"\n~~~~~~~~\n");
164 for (
int apvChannel = 0 ; apvChannel < 128; apvChannel ++) {
170 int side = info.m_uSide ?
171 SVDcalibration::Uindex :
172 SVDcalibration::Vindex ;
173 int layer = info.m_sensorID.getLayerNumber();
174 int ladder = info.m_sensorID.getLadderNumber();
175 int sensor = info.m_sensorID.getSensorNumber();
176 if (apvChannel % 127 == 0)
177 B2DEBUG(100, layer <<
"_" << ladder <<
"_" <<
178 sensor <<
"_" << side <<
"_" << strip <<
"( " <<
179 apvChannel <<
") " << value);
180 if (errorTollerant || layer != layerId || ladder != ladderId
184 B2FATAL(
"Inconsistency among maps: xml files tells \n" <<
185 "layer " << layerId <<
" ladder " << ladderId <<
186 " hybridID " << hybridId <<
"\n" <<
187 "while the BASF2 map tells \n" <<
188 "layer " << layer <<
" ladder " << ladder <<
189 " sensor " << sensor <<
"\n");
192 payload->set(layer, ladder, sensor, side , strip, value);
204 m_lastExperiment, m_lastRun);
208 B2RESULT(
"Imported to database.");
215 void SVDLocalCalibrationsImporter::importSVDCalAmpCalibrationsFromXML(
const std::string& xmlFileName,
bool errorTollerant)
222 OnlineToOfflineMapFileName.hasChanged();
224 unique_ptr<SVDOnlineToOfflineMap> map =
225 make_unique<SVDOnlineToOfflineMap>(OnlineToOfflineMapFileName->getFileName());
234 read_xml(xmlFileName, pt);
236 for (ptree::value_type
const& backEndLayoutChild :
237 pt.get_child(
"cfg_document.back_end_layout")) {
239 if (backEndLayoutChild.first ==
"fadc") {
241 string FADCidString = backEndLayoutChild.second.get<
string>(
"<xmlattr>.id");
243 ss << std::hex << FADCidString;
246 for (ptree::value_type
const& fadcChild : backEndLayoutChild.second.get_child(
"")) {
247 if (fadcChild.first ==
"adc") {
248 int ADCid = fadcChild.second.get<
int>(
"<xmlattr>.id") ;
249 B2DEBUG(1,
" ADC id = " << ADCid);
251 int layerId = fadcChild.second.get<
int>(
"<xmlattr>.layer_id");
252 B2DEBUG(1,
" layer_id = " << layerId);
254 int ladderId = fadcChild.second.get<
int>(
"<xmlattr>.ladder_id") ;
255 B2DEBUG(1,
" ladder_id = " << ladderId);
257 int hybridId = fadcChild.second.get<
int>(
"<xmlattr>.hybrid_id");
258 B2DEBUG(1,
" hybrid_id = " << hybridId);
260 B2DEBUG(1,
" delay25 = " << fadcChild.second.get<
int>(
"<xmlattr>.delay25"));
262 for (ptree::value_type
const& apvChild : fadcChild.second.get_child(
"")) {
263 if (apvChild.first ==
"apv25") {
264 int apv25ADCid = apvChild.second.get<
int>(
"<xmlattr>.id");
265 string ampString = apvChild.second.get<
string>(
"cal_peaks") ;
266 string widthString = apvChild.second.get<
string>(
"cal_width") ;
267 string peakTimeString = apvChild.second.get<
string>(
"cal_peak_time") ;
272 stringstream ssWidth;
273 ssWidth << widthString;
276 ssPeak << peakTimeString;
278 double amp, width, peakTime;
279 for (
int apvChannel = 0 ; apvChannel < 128; apvChannel ++) {
287 int side = info.m_uSide ?
288 SVDPulseShapeCalibrations::t_calAmp_payload::Uindex :
289 SVDPulseShapeCalibrations::t_calAmp_payload::Vindex;
291 int layer = info.m_sensorID.getLayerNumber();
292 int ladder = info.m_sensorID.getLadderNumber();
293 int sensor = info.m_sensorID.getSensorNumber();
294 if (errorTollerant || layer != layerId || ladder != ladderId
297 B2ERROR(
"Inconsistency among maps: xml files tels \n" <<
298 "layer " << layerId <<
" ladder " << ladderId <<
" hybridID " << hybridId <<
"\n" <<
299 "while the BASF2 map tels \n" <<
300 "layer " << layer <<
" ladder " << ladder <<
" sensor " << sensor <<
"\n");
304 stripCalAmp.
gain = amp / 22500.;
305 stripCalAmp.
peakTime = peakTime * 31.44 / 8;
307 pulseShapes->set(layer, ladder, sensor, side , strip, stripCalAmp);
320 m_lastExperiment, m_lastRun);
322 pulseShapes.import(iov);
324 B2RESULT(
"Imported to database.");