10 #include <svd/calibration/SVDLocalCalibrationsImporter.h>
14 #include <svd/online/SVDOnlineToOfflineMap.h>
17 #include <framework/database/Database.h>
18 #include <framework/database/DBObjPtr.h>
19 #include <framework/database/PayloadFile.h>
20 #include <framework/database/IntervalOfValidity.h>
21 #include <framework/database/DBImportObjPtr.h>
24 #include <framework/logging/Logger.h>
26 #include <framework/utilities/FileSystem.h>
29 #include <svd/calibration/SVDNoiseCalibrations.h>
30 #include <svd/calibration/SVDPedestalCalibrations.h>
31 #include <svd/calibration/SVDPulseShapeCalibrations.h>
32 #include <svd/calibration/SVDHotStripsCalibrations.h>
33 #include <svd/calibration/SVDFADCMaskedStrips.h>
35 #include <vxd/dataobjects/VxdID.h>
37 #include <boost/property_tree/ptree.hpp>
38 #include <boost/property_tree/xml_parser.hpp>
44 using boost::property_tree::ptree;
46 void SVDLocalCalibrationsImporter::importSVDChannelMapping(
const std::string& fileName)
50 const std::string filename = FileSystem::findFile(fileName);
51 B2INFO(
"Importing the svd online -> offline map " << fileName <<
"\n");
53 const std::string payloadname =
"SVDChannelMapping.xml";
54 if (Database::Instance().addPayload(payloadname, filename, iov))
57 B2INFO(
"Failure :( ua uaa uaa uaa uaaaa)");
61 void SVDLocalCalibrationsImporter::importSVDNoiseCalibrationsFromXML(
const std::string& xmlFileName,
bool errorTollerant)
70 importSVDCalibrationsFromXML< SVDNoiseCalibrations::t_payload >(SVDNoiseCalibrations::name,
71 xmlFileName,
"noises",
72 -1.0, errorTollerant);
75 void SVDLocalCalibrationsImporter::importSVDPedestalCalibrationsFromXML(
const std::string& xmlFileName,
bool errorTollerant)
77 importSVDCalibrationsFromXML< SVDPedestalCalibrations::t_payload >(SVDPedestalCalibrations::name,
78 xmlFileName,
"pedestals",
79 -1.0, errorTollerant);
82 void SVDLocalCalibrationsImporter::importSVDHotStripsCalibrationsFromXML(
const std::string& xmlFileName,
bool errorTollerant)
84 importSVDCalibrationsFromXML< SVDHotStripsCalibrations::t_payload >(SVDHotStripsCalibrations::name,
85 xmlFileName,
"hot_strips",
86 false, errorTollerant);
89 void SVDLocalCalibrationsImporter::importSVDFADCMaskedStripsFromXML(
const std::string& xmlFileName,
bool errorTollerant)
91 importSVDCalibrationsFromXML< SVDFADCMaskedStrips::t_payload >(SVDFADCMaskedStrips::name,
93 false, errorTollerant);
99 template<
class SVDcalibration >
100 void SVDLocalCalibrationsImporter::importSVDCalibrationsFromXML(
const std::string& condDbname,
101 const std::string& xmlFileName,
102 const std::string& xmlTag,
103 typename SVDcalibration::t_perSideContainer::calibrationType defaultValue,
110 OnlineToOfflineMapFileName.hasChanged();
112 unique_ptr<SVDOnlineToOfflineMap> map =
113 make_unique<SVDOnlineToOfflineMap>(OnlineToOfflineMapFileName->getFileName());
115 payload.construct(defaultValue, xmlFileName);
122 read_xml(xmlFileName, pt);
124 for (ptree::value_type
const& backEndLayoutChild :
125 pt.get_child(
"cfg_document.back_end_layout")) {
127 if (backEndLayoutChild.first ==
"fadc") {
129 string FADCidString = backEndLayoutChild.second.get<
string>(
"<xmlattr>.id");
131 ss << std::hex << FADCidString;
134 for (ptree::value_type
const& fadcChild : backEndLayoutChild.second.get_child(
"")) {
135 if (fadcChild.first ==
"adc") {
136 int ADCid = fadcChild.second.get<
int>(
"<xmlattr>.id") ;
137 B2DEBUG(1,
" ADC id = " << ADCid);
139 int layerId = fadcChild.second.get<
int>(
"<xmlattr>.layer_id");
140 B2DEBUG(1,
" layer_id = " << layerId);
142 int ladderId = fadcChild.second.get<
int>(
"<xmlattr>.ladder_id") ;
143 B2DEBUG(1,
" ladder_id = " << ladderId);
145 int hybridId = fadcChild.second.get<
int>(
"<xmlattr>.hybrid_id");
146 B2DEBUG(1,
" hybrid_id = " << hybridId);
148 B2DEBUG(1,
" delay25 = " <<
149 fadcChild.second.get<
int>(
"<xmlattr>.delay25"));
151 for (ptree::value_type
const& apvChild : fadcChild.second.get_child(
"")) {
152 if (apvChild.first ==
"apv25") {
153 int apv25ADCid = apvChild.second.get<
int>(
"<xmlattr>.id");
154 string valuesString = apvChild.second.get<
string>(xmlTag) ;
155 B2DEBUG(10, xmlTag <<
" APV25ID" << apv25ADCid <<
" "
156 << valuesString <<
"\n~~~~~~~~\n");
161 for (
int apvChannel = 0 ; apvChannel < 128; apvChannel ++) {
164 map->getSensorInfo(FADCid, ADCid * 6 + apv25ADCid);
166 short strip = map->getStripNumber(apvChannel, info);
167 int side = info.m_uSide ?
168 SVDcalibration::Uindex :
169 SVDcalibration::Vindex ;
170 int layer = info.m_sensorID.getLayerNumber();
171 int ladder = info.m_sensorID.getLadderNumber();
172 int sensor = info.m_sensorID.getSensorNumber();
173 if (apvChannel % 127 == 0)
174 B2DEBUG(100, layer <<
"_" << ladder <<
"_" <<
175 sensor <<
"_" << side <<
"_" << strip <<
"( " <<
176 apvChannel <<
") " << value);
177 if (errorTollerant || layer != layerId || ladder != ladderId
181 B2FATAL(
"Inconsistency among maps: xml files tells \n" <<
182 "layer " << layerId <<
" ladder " << ladderId <<
183 " hybridID " << hybridId <<
"\n" <<
184 "while the basf2 map tells \n" <<
185 "layer " << layer <<
" ladder " << ladder <<
186 " sensor " << sensor <<
"\n");
189 payload->set(layer, ladder, sensor, side, strip, value);
201 m_lastExperiment, m_lastRun);
205 B2RESULT(
"Imported to database.");
212 void SVDLocalCalibrationsImporter::importSVDCalAmpCalibrationsFromXML(
const std::string& xmlFileName,
bool errorTollerant)
219 OnlineToOfflineMapFileName.hasChanged();
221 unique_ptr<SVDOnlineToOfflineMap> map =
222 make_unique<SVDOnlineToOfflineMap>(OnlineToOfflineMapFileName->getFileName());
231 read_xml(xmlFileName, pt);
233 for (ptree::value_type
const& backEndLayoutChild :
234 pt.get_child(
"cfg_document.back_end_layout")) {
236 if (backEndLayoutChild.first ==
"fadc") {
238 string FADCidString = backEndLayoutChild.second.get<
string>(
"<xmlattr>.id");
240 ss << std::hex << FADCidString;
243 for (ptree::value_type
const& fadcChild : backEndLayoutChild.second.get_child(
"")) {
244 if (fadcChild.first ==
"adc") {
245 int ADCid = fadcChild.second.get<
int>(
"<xmlattr>.id") ;
246 B2DEBUG(1,
" ADC id = " << ADCid);
248 int layerId = fadcChild.second.get<
int>(
"<xmlattr>.layer_id");
249 B2DEBUG(1,
" layer_id = " << layerId);
251 int ladderId = fadcChild.second.get<
int>(
"<xmlattr>.ladder_id") ;
252 B2DEBUG(1,
" ladder_id = " << ladderId);
254 int hybridId = fadcChild.second.get<
int>(
"<xmlattr>.hybrid_id");
255 B2DEBUG(1,
" hybrid_id = " << hybridId);
257 B2DEBUG(1,
" delay25 = " << fadcChild.second.get<
int>(
"<xmlattr>.delay25"));
259 for (ptree::value_type
const& apvChild : fadcChild.second.get_child(
"")) {
260 if (apvChild.first ==
"apv25") {
261 int apv25ADCid = apvChild.second.get<
int>(
"<xmlattr>.id");
262 string ampString = apvChild.second.get<
string>(
"cal_peaks") ;
263 string widthString = apvChild.second.get<
string>(
"cal_width") ;
264 string peakTimeString = apvChild.second.get<
string>(
"cal_peak_time") ;
269 stringstream ssWidth;
270 ssWidth << widthString;
273 ssPeak << peakTimeString;
275 double amp, width, peakTime;
276 for (
int apvChannel = 0 ; apvChannel < 128; apvChannel ++) {
283 short strip = map->getStripNumber(apvChannel, info);
284 int side = info.m_uSide ?
285 SVDPulseShapeCalibrations::t_calAmp_payload::Uindex :
286 SVDPulseShapeCalibrations::t_calAmp_payload::Vindex;
288 int layer = info.m_sensorID.getLayerNumber();
289 int ladder = info.m_sensorID.getLadderNumber();
290 int sensor = info.m_sensorID.getSensorNumber();
291 if (errorTollerant || layer != layerId || ladder != ladderId
294 B2ERROR(
"Inconsistency among maps: xml files tels \n" <<
295 "layer " << layerId <<
" ladder " << ladderId <<
" hybridID " << hybridId <<
"\n" <<
296 "while the basf2 map tels \n" <<
297 "layer " << layer <<
" ladder " << ladder <<
" sensor " << sensor <<
"\n");
301 stripCalAmp.
gain = amp / 22500.;
302 stripCalAmp.
peakTime = peakTime * 31.44 / 8;
304 pulseShapes->set(layer, ladder, sensor, side, strip, stripCalAmp);
317 m_lastExperiment, m_lastRun);
319 pulseShapes.import(iov);
321 B2RESULT(
"Imported to database.");
Class for importing a single object to the database.
Specialization of DBObjPtr in case of PayloadFiles.
A class that describes the interval of experiments/runs for which an object in the database is valid.
Abstract base class for different kinds of events.
Struct to hold data about a sensor.
contains the parameter of the APV pulse
float pulseWidth
pulseWidth (in ns) is the width of the shaper output TO BE CLARIFIED: how this width is defined?
float peakTime
peakTimes (in ns) is the time at wich the shaper output reach the maximum.
float gain
gain is expressed in ADC counts / # electrons injected in the channel