Belle II Software development
SVDDetectorConfigurationImporter.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9// Own header.
10#include <svd/calibration/SVDDetectorConfigurationImporter.h>
11
12// Map from the online world (FADC id, ADC id, APV ch id)
13// to the offline world (layer, ladder, sensor, view, cell)
14//#include <svd/online/SVDOnlineToOfflineMap.h>
15
16// framework - Database
17#include <framework/database/Database.h>
18#include <framework/database/IntervalOfValidity.h>
19#include <framework/database/DBImportObjPtr.h>
20
21// framework aux
22#include <framework/logging/Logger.h>
23
24#include <framework/utilities/FileSystem.h>
25
26// DB objects
27#include <svd/dbobjects/SVDLocalConfigParameters.h>
28#include <svd/dbobjects/SVDGlobalConfigParameters.h>
29
30#include <boost/property_tree/ptree.hpp>
31#include <boost/property_tree/xml_parser.hpp>
32
33#include <iostream>
34#include <fstream>
35#include <sstream>
36
37using namespace Belle2;
38using boost::property_tree::ptree;
39
40
41void SVDDetectorConfigurationImporter::importSVDGlobalXMLFile(const std::string& fileName)
42{
43
45 const std::string filename = FileSystem::findFile(fileName);
46 B2INFO("Importing the global run configuration xml file " << fileName << "\n");
47
48 const std::string payloadname = "SVDGlobalXMLFile.xml";
49 if (Database::Instance().addPayload(payloadname, filename, iov))
50 B2INFO("Success!");
51 else
52 B2INFO("Failure :( ua uaa uaa uaa uaaaa)");
53}
54
56{
57 // This is the property tree
58 ptree pt;
59
60 // Load the XML file into the property tree. If reading fails
61 // (cannot open file, parse error), an exception is thrown.
62 read_xml(xmlFileName, pt);
63
64 //auxilairy variables to store the XML file values
65 int maskFilter = 0;
66 float zeroSuppression = 0;
67 float latency = 0;
68 std::string systemClock = "";
69 float hv = 0;
70 int relativeTimeShift = 0;
71 int nrFrames = 0;
72
73 for (ptree::value_type const& cfgDocumentChild :
74 pt.get_child("cfg_document")) {
75
76 if (cfgDocumentChild.first == "noise_run") {
77 maskFilter = cfgDocumentChild.second.get<int>("<xmlattr>.mask") ;
78 B2INFO(" masking bitmap = " << maskFilter);
79
80 }
81 if (cfgDocumentChild.first == "hardware_run") {
82 zeroSuppression = cfgDocumentChild.second.get<float>("<xmlattr>.zs_cut") ;
83 B2INFO(" zero suppression cut = " << zeroSuppression);
84
85 }
86
87 if (cfgDocumentChild.first == "i2c") {
88 latency = cfgDocumentChild.second.get<float>("<xmlattr>.lat") ;
89 B2INFO(" latency = " << latency);
90
91 }
92
93 if (cfgDocumentChild.first == "fadc_ctrl") {
94 systemClock = cfgDocumentChild.second.get<std::string>("<xmlattr>.system_clock") ;
95 B2INFO(" APV clock units = " << systemClock);
96 nrFrames = cfgDocumentChild.second.get<int>("<xmlattr>.nr_frames") ;
97 B2INFO(" Number of Frames = " << nrFrames);
98
99 }
100
101 if (cfgDocumentChild.first == "controller") {
102 relativeTimeShift = cfgDocumentChild.second.get<int>("<xmlattr>.mix_trg_delay") ;
103 B2INFO(" delay of 3-sample VS 6-sample in units of APV clock /4 = " << relativeTimeShift);
104 if (relativeTimeShift < 0)
105 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.");
106 else if (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.");
109 }
110 }
111
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);
117 }
118
119 }
120
121 DBImportObjPtr<SVDGlobalConfigParameters> svdGlobalConfig("SVDGlobalConfigParameters");
122
123 svdGlobalConfig.construct(xmlFileName);
124
125 svdGlobalConfig->setZeroSuppression(zeroSuppression);
126 svdGlobalConfig->setLatency(latency);
127 svdGlobalConfig->setMaskFilter(maskFilter);
128 svdGlobalConfig->setAPVClockInRFCUnits(systemClock);
129 svdGlobalConfig->setHV(hv);
130 svdGlobalConfig->setRelativeTimeShift(relativeTimeShift);
131 svdGlobalConfig->setNrFrames(nrFrames);
132
135
136 svdGlobalConfig.import(iov);
137 B2RESULT("SVDGlobalConfigParameters imported to database.");
138
139}
140
142{
143
144 // This is the property tree
145 ptree pt;
146
147 // Load the XML file into the property tree. If reading fails
148 // (cannot open file, parse error), an exception is thrown.
149 read_xml(xmlFileName, pt);
150
151 //auxilairy variables to store the XML file values
152 // TODO: calInjectedCharge is not used! Check if it can be removed.
153 std::string calInjectedCharge;
154 std::string calibTimeUnits = "";
155 std::string calibDate = "";
156
157 for (ptree::value_type const& apvChild :
158 pt.get_child("cfg_document.back_end_layout.fadc.adc.apv25")) {
159
160
161 if (apvChild.first == "cal_peaks") {
162 calInjectedCharge = apvChild.second.get<std::string>("<xmlattr>.units");
163 B2INFO(" injected charge from XML = " << calInjectedCharge << ", but actually set to 22500, hardcoded");
164 }
165
166 if (apvChild.first == "cal_peak_time") {
167 calibTimeUnits = apvChild.second.get<std::string>("<xmlattr>.units");
168 B2INFO(" calibration time units = " << calibTimeUnits);
169
170 }
171 }
172 for (ptree::value_type const& latestRunChild :
173 pt.get_child("cfg_document.latest_runs")) {
174
175 if (latestRunChild.first == "Noise") {
176 calibDate = latestRunChild.second.get<std::string>("<xmlattr>.end_of_run");
177 B2INFO(" calibration date = " << calibDate);
178
179 }
180 }
181
182 DBImportObjPtr<SVDLocalConfigParameters> svdLocalConfig("SVDLocalConfigParameters");
183
184 svdLocalConfig.construct(xmlFileName);
185
186 svdLocalConfig->setCalibrationTimeInRFCUnits(calibTimeUnits);
187 svdLocalConfig->setCalibDate(calibDate);
188 /* Injected charge set is HARDCODED here, by default 22500 electrons
189 */
190 svdLocalConfig->setInjectedCharge(22500);
191
192
195
196 svdLocalConfig.import(iov);
197 B2RESULT("SVDLocalConfigParameters imported to database.");
198
199}
200
201
202
203
204
205
206
207
Class for importing a single object to the database.
static std::string findFile(const std::string &path, bool silent=false)
Search for given file or directory in local or central release directory, and return absolute path if...
Definition: FileSystem.cc:151
A class that describes the interval of experiments/runs for which an object in the database is valid.
void importSVDGlobalConfigParametersFromXML(const std::string &xmlFileName)
This method import to the database the global configuration parameters used during data taking.
void importSVDLocalConfigParametersFromXML(const std::string &xmlFileName)
This method import to the database the local configuration parameters used during data taking.
int m_firstExperiment
The interval of validity coordinates are defined as private members.
static Database & Instance()
Instance of a singleton Database.
Definition: Database.cc:42
Abstract base class for different kinds of events.