10 #include <svd/calibration/SVDDetectorConfigurationImporter.h>
17 #include <framework/database/Database.h>
18 #include <framework/database/IntervalOfValidity.h>
19 #include <framework/database/DBImportObjPtr.h>
22 #include <framework/logging/Logger.h>
24 #include <framework/utilities/FileSystem.h>
27 #include <svd/dbobjects/SVDLocalConfigParameters.h>
28 #include <svd/dbobjects/SVDGlobalConfigParameters.h>
30 #include <boost/property_tree/ptree.hpp>
31 #include <boost/property_tree/xml_parser.hpp>
39 using boost::property_tree::ptree;
42 void SVDDetectorConfigurationImporter::importSVDGlobalXMLFile(
const std::string& fileName)
46 const std::string filename = FileSystem::findFile(fileName);
47 B2INFO(
"Importing the global run configuration xml file " << fileName <<
"\n");
49 const std::string payloadname =
"SVDGlobalXMLFile.xml";
50 if (Database::Instance().addPayload(payloadname, filename, iov))
53 B2INFO(
"Failure :( ua uaa uaa uaa uaaaa)");
56 void SVDDetectorConfigurationImporter::importSVDGlobalConfigParametersFromXML(
const std::string& xmlFileName)
63 read_xml(xmlFileName, pt);
67 float zeroSuppression = 0;
69 std::string systemClock =
"";
71 int relativeTimeShift = 0;
74 for (ptree::value_type
const& cfgDocumentChild :
75 pt.get_child(
"cfg_document")) {
77 if (cfgDocumentChild.first ==
"noise_run") {
78 maskFilter = cfgDocumentChild.second.get<
int>(
"<xmlattr>.mask") ;
79 B2INFO(
" masking bitmap = " << maskFilter);
82 if (cfgDocumentChild.first ==
"hardware_run") {
83 zeroSuppression = cfgDocumentChild.second.get<
float>(
"<xmlattr>.zs_cut") ;
84 B2INFO(
" zero suppression cut = " << zeroSuppression);
88 if (cfgDocumentChild.first ==
"i2c") {
89 latency = cfgDocumentChild.second.get<
float>(
"<xmlattr>.lat") ;
90 B2INFO(
" latency = " << latency);
94 if (cfgDocumentChild.first ==
"fadc_ctrl") {
95 systemClock = cfgDocumentChild.second.get<std::string>(
"<xmlattr>.system_clock") ;
96 B2INFO(
" APV clock units = " << systemClock);
97 nrFrames = cfgDocumentChild.second.get<
int>(
"<xmlattr>.nr_frames") ;
98 B2INFO(
" Number of Frames = " << nrFrames);
102 if (cfgDocumentChild.first ==
"controller") {
103 relativeTimeShift = cfgDocumentChild.second.get<
int>(
"<xmlattr>.mix_trg_delay") ;
104 B2INFO(
" delay of 3-sample VS 6-sample in units of APV clock /4 = " << relativeTimeShift);
105 if (relativeTimeShift < 0)
106 B2FATAL(
"OOPS!! The relative time shift is negative. This is not allowed. Please check the global xml. For the moment we set it to 0.");
107 else if (relativeTimeShift > 15)
108 B2FATAL(
"OOPS!! The relative time shift = " << relativeTimeShift <<
109 " 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.");
113 for (ptree::value_type
const& cfgDocumentChild :
114 pt.get_child(
"cfg_document.ps_setup.hv_config")) {
115 if (cfgDocumentChild.first ==
"config") {
116 hv = cfgDocumentChild.second.get<
float>(
"<xmlattr>.v_conf") ;
117 B2INFO(
" HV = " << hv);
124 svdGlobalConfig.construct(xmlFileName);
126 svdGlobalConfig->setZeroSuppression(zeroSuppression);
127 svdGlobalConfig->setLatency(latency);
128 svdGlobalConfig->setMaskFilter(maskFilter);
129 svdGlobalConfig->setAPVClockInRFCUnits(systemClock);
130 svdGlobalConfig->setHV(hv);
131 svdGlobalConfig->setRelativeTimeShift(relativeTimeShift);
132 svdGlobalConfig->setNrFrames(nrFrames);
135 m_lastExperiment, m_lastRun);
137 svdGlobalConfig.import(iov);
138 B2RESULT(
"SVDGlobalConfigParameters imported to database.");
142 void SVDDetectorConfigurationImporter::importSVDLocalConfigParametersFromXML(
const std::string& xmlFileName)
150 read_xml(xmlFileName, pt);
154 std::string calInjectedCharge;
155 std::string calibTimeUnits =
"";
156 std::string calibDate =
"";
158 for (ptree::value_type
const& apvChild :
159 pt.get_child(
"cfg_document.back_end_layout.fadc.adc.apv25")) {
162 if (apvChild.first ==
"cal_peaks") {
163 calInjectedCharge = apvChild.second.get<std::string>(
"<xmlattr>.units");
164 B2INFO(
" injected charge from XML = " << calInjectedCharge <<
", but actually set to 22500, hardcoded");
167 if (apvChild.first ==
"cal_peak_time") {
168 calibTimeUnits = apvChild.second.get<std::string>(
"<xmlattr>.units");
169 B2INFO(
" calibration time units = " << calibTimeUnits);
173 for (ptree::value_type
const& latestRunChild :
174 pt.get_child(
"cfg_document.latest_runs")) {
176 if (latestRunChild.first ==
"Noise") {
177 calibDate = latestRunChild.second.get<std::string>(
"<xmlattr>.end_of_run");
178 B2INFO(
" calibration date = " << calibDate);
185 svdLocalConfig.construct(xmlFileName);
187 svdLocalConfig->setCalibrationTimeInRFCUnits(calibTimeUnits);
188 svdLocalConfig->setCalibDate(calibDate);
191 svdLocalConfig->setInjectedCharge(22500);
195 m_lastExperiment, m_lastRun);
197 svdLocalConfig.import(iov);
198 B2RESULT(
"SVDLocalConfigParameters imported to database.");
Class for importing a single object to the database.
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.