13 #include <svd/calibration/SVDDetectorConfigurationImporter.h>
20 #include <framework/database/Database.h>
21 #include <framework/database/IntervalOfValidity.h>
22 #include <framework/database/DBImportObjPtr.h>
25 #include <framework/logging/Logger.h>
27 #include <framework/utilities/FileSystem.h>
30 #include <svd/calibration/SVDDetectorConfiguration.h>
32 #include <boost/property_tree/ptree.hpp>
33 #include <boost/property_tree/xml_parser.hpp>
41 using boost::property_tree::ptree;
44 void SVDDetectorConfigurationImporter::importSVDGlobalXMLFile(
const std::string& fileName)
48 const std::string
filename = FileSystem::findFile(fileName);
49 B2INFO(
"Importing the global run configuration xml file " << fileName <<
"\n");
51 const std::string payloadname =
"SVDGlobalXMLFile.xml";
52 if (Database::Instance().addPayload(payloadname, filename, iov))
55 B2INFO(
"Failure :( ua uaa uaa uaa uaaaa)");
58 void SVDDetectorConfigurationImporter::importSVDGlobalConfigParametersFromXML(
const std::string& xmlFileName)
65 read_xml(xmlFileName, pt);
69 float zeroSuppression = 0;
71 std::string systemClock =
"";
73 int relativeTimeShift = 0;
76 for (ptree::value_type
const& cfgDocumentChild :
77 pt.get_child(
"cfg_document")) {
79 if (cfgDocumentChild.first ==
"noise_run") {
80 maskFilter = cfgDocumentChild.second.get<
int>(
"<xmlattr>.mask") ;
81 B2INFO(
" masking bitmap = " << maskFilter);
84 if (cfgDocumentChild.first ==
"hardware_run") {
85 zeroSuppression = cfgDocumentChild.second.get<
float>(
"<xmlattr>.zs_cut") ;
86 B2INFO(
" zero suppression cut = " << zeroSuppression);
90 if (cfgDocumentChild.first ==
"i2c") {
91 latency = cfgDocumentChild.second.get<
float>(
"<xmlattr>.lat") ;
92 B2INFO(
" latency = " << latency);
96 if (cfgDocumentChild.first ==
"fadc_ctrl") {
97 systemClock = cfgDocumentChild.second.get<std::string>(
"<xmlattr>.system_clock") ;
98 B2INFO(
" APV clock units = " << systemClock);
99 nrFrames = cfgDocumentChild.second.get<
int>(
"<xmlattr>.nr_frames") ;
100 B2INFO(
" Number of Frames = " << nrFrames);
103 if (cfgDocumentChild.first ==
"controller") {
104 relativeTimeShift = cfgDocumentChild.second.get<
int>(
"<xmlattr>.mix_trg_delay") ;
105 B2INFO(
" delay of 3-sample VS 6-sample in units of APV clock /4 = " << relativeTimeShift);
106 if ((relativeTimeShift < 0) || (relativeTimeShift > 15))
107 B2FATAL(
"OOPS!! the relative time shift = " << relativeTimeShift <<
108 " is not allowed! It must be an int between 0 and 15 included. Please check the global xml. For the moment we set it to 0");
112 for (ptree::value_type
const& cfgDocumentChild :
113 pt.get_child(
"cfg_document.ps_setup.hv_config")) {
114 if (cfgDocumentChild.first ==
"config") {
115 hv = cfgDocumentChild.second.get<
float>(
"<xmlattr>.v_conf") ;
116 B2INFO(
" HV = " << hv);
120 for (ptree::value_type
const& cfgDocumentChild :
121 pt.get_child(
"cfg_document.ps_setup.hv_config")) {
122 if (cfgDocumentChild.first ==
"config") {
123 hv = cfgDocumentChild.second.get<
float>(
"<xmlattr>.v_conf") ;
124 B2INFO(
" HV = " << hv);
132 svdGlobalConfig.construct(xmlFileName);
134 svdGlobalConfig->setZeroSuppression(zeroSuppression);
135 svdGlobalConfig->setLatency(latency);
136 svdGlobalConfig->setMaskFilter(maskFilter);
137 svdGlobalConfig->setAPVClockInRFCUnits(systemClock);
138 svdGlobalConfig->setHV(hv);
139 svdGlobalConfig->setRelativeTimeShift(relativeTimeShift);
140 svdGlobalConfig->setNrFrames(nrFrames);
143 m_lastExperiment, m_lastRun);
145 svdGlobalConfig.import(iov);
146 B2RESULT(
"SVDGlobalConfigParameters imported to database.");
150 void SVDDetectorConfigurationImporter::importSVDLocalConfigParametersFromXML(
const std::string& xmlFileName)
158 read_xml(xmlFileName, pt);
162 std::string calInjectedCharge =
"";
163 std::string calibTimeUnits =
"";
164 std::string calibDate =
"";
166 for (ptree::value_type
const& apvChild :
167 pt.get_child(
"cfg_document.back_end_layout.fadc.adc.apv25")) {
170 if (apvChild.first ==
"cal_peaks") {
171 calInjectedCharge = apvChild.second.get<std::string>(
"<xmlattr>.units");
172 B2INFO(
" injected charge from XML = " << calInjectedCharge <<
", but actually set to 22500, hardcoded");
175 if (apvChild.first ==
"cal_peak_time") {
176 calibTimeUnits = apvChild.second.get<std::string>(
"<xmlattr>.units");
177 B2INFO(
" calibration time units = " << calibTimeUnits);
181 for (ptree::value_type
const& latestRunChild :
182 pt.get_child(
"cfg_document.latest_runs")) {
184 if (latestRunChild.first ==
"Noise") {
185 calibDate = latestRunChild.second.get<std::string>(
"<xmlattr>.end_of_run");
186 B2INFO(
" calibration date = " << calibDate);
193 svdLocalConfig.construct(xmlFileName);
195 svdLocalConfig->setCalibrationTimeInRFCUnits(calibTimeUnits);
196 svdLocalConfig->setCalibDate(calibDate);
199 svdLocalConfig->setInjectedCharge(22500);
203 m_lastExperiment, m_lastRun);
205 svdLocalConfig.import(iov);
206 B2RESULT(
"SVDLocalConfigParameters imported to database.");