Belle II Software  release-05-01-25
SVDDetectorConfigurationImporter.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2017 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Laura Zani *
7  * *
8  * This software is provided "as is" without any warranty. *
9  * WARNING: Do not try to fry it with water. Use only olive oil. *
10  **************************************************************************/
11 
12 // Own include
13 #include <svd/calibration/SVDDetectorConfigurationImporter.h>
14 
15 // Map from the online world (FADC id, ADC id, APV ch id)
16 // to the offline world (layer, ladder, sensor, view, cell)
17 //#include <svd/online/SVDOnlineToOfflineMap.h>
18 
19 // framework - Database
20 #include <framework/database/Database.h>
21 #include <framework/database/IntervalOfValidity.h>
22 #include <framework/database/DBImportObjPtr.h>
23 
24 // framework aux
25 #include <framework/logging/Logger.h>
26 
27 #include <framework/utilities/FileSystem.h>
28 
29 // wrapper objects
30 #include <svd/calibration/SVDDetectorConfiguration.h>
31 
32 #include <boost/property_tree/ptree.hpp>
33 #include <boost/property_tree/xml_parser.hpp>
34 
35 #include <iostream>
36 #include <fstream>
37 #include <sstream>
38 
39 using namespace std;
40 using namespace Belle2;
41 using boost::property_tree::ptree;
42 
43 
44 void SVDDetectorConfigurationImporter::importSVDGlobalXMLFile(const std::string& fileName)
45 {
46 
47  IntervalOfValidity iov(m_firstExperiment, m_firstRun, m_lastExperiment, m_lastRun);
48  const std::string filename = FileSystem::findFile(fileName);
49  B2INFO("Importing the global run configuration xml file " << fileName << "\n");
50 
51  const std::string payloadname = "SVDGlobalXMLFile.xml";
52  if (Database::Instance().addPayload(payloadname, filename, iov))
53  B2INFO("Success!");
54  else
55  B2INFO("Failure :( ua uaa uaa uaa uaaaa)");
56 }
57 
58 void SVDDetectorConfigurationImporter::importSVDGlobalConfigParametersFromXML(const std::string& xmlFileName)
59 {
60  // This is the property tree
61  ptree pt;
62 
63  // Load the XML file into the property tree. If reading fails
64  // (cannot open file, parse error), an exception is thrown.
65  read_xml(xmlFileName, pt);
66 
67  //auxilairy variables to store the XML file values
68  int maskFilter = 0;
69  float zeroSuppression = 0;
70  float latency = 0;
71  std::string systemClock = "";
72  float hv = 0;
73  int relativeTimeShift = 0;
74  int nrFrames = 0;
75 
76  for (ptree::value_type const& cfgDocumentChild :
77  pt.get_child("cfg_document")) {
78 
79  if (cfgDocumentChild.first == "noise_run") {
80  maskFilter = cfgDocumentChild.second.get<int>("<xmlattr>.mask") ;
81  B2INFO(" masking bitmap = " << maskFilter);
82 
83  }
84  if (cfgDocumentChild.first == "hardware_run") {
85  zeroSuppression = cfgDocumentChild.second.get<float>("<xmlattr>.zs_cut") ;
86  B2INFO(" zero suppression cut = " << zeroSuppression);
87 
88  }
89 
90  if (cfgDocumentChild.first == "i2c") {
91  latency = cfgDocumentChild.second.get<float>("<xmlattr>.lat") ;
92  B2INFO(" latency = " << latency);
93 
94  }
95 
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);
101  }
102 
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");
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  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);
125  }
126 
127  }
128 
129 
130  DBImportObjPtr<SVDDetectorConfiguration::t_svdGlobalConfig_payload> svdGlobalConfig(SVDDetectorConfiguration::svdGlobalConfig_name);
131 
132  svdGlobalConfig.construct(xmlFileName);
133 
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);
141 
142  IntervalOfValidity iov(m_firstExperiment, m_firstRun,
143  m_lastExperiment, m_lastRun);
144 
145  svdGlobalConfig.import(iov);
146  B2RESULT("SVDGlobalConfigParameters imported to database.");
147 
148 }
149 
150 void SVDDetectorConfigurationImporter::importSVDLocalConfigParametersFromXML(const std::string& xmlFileName)
151 {
152 
153  // This is the property tree
154  ptree pt;
155 
156  // Load the XML file into the property tree. If reading fails
157  // (cannot open file, parse error), an exception is thrown.
158  read_xml(xmlFileName, pt);
159 
160  //auxilairy variables to store the XML file values
161  // TODO: calInjectedCharge is not used! Check if it can be removed.
162  std::string calInjectedCharge = "";
163  std::string calibTimeUnits = "";
164  std::string calibDate = "";
165 
166  for (ptree::value_type const& apvChild :
167  pt.get_child("cfg_document.back_end_layout.fadc.adc.apv25")) {
168 
169 
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");
173  }
174 
175  if (apvChild.first == "cal_peak_time") {
176  calibTimeUnits = apvChild.second.get<std::string>("<xmlattr>.units");
177  B2INFO(" calibration time units = " << calibTimeUnits);
178 
179  }
180  }
181  for (ptree::value_type const& latestRunChild :
182  pt.get_child("cfg_document.latest_runs")) {
183 
184  if (latestRunChild.first == "Noise") {
185  calibDate = latestRunChild.second.get<std::string>("<xmlattr>.end_of_run");
186  B2INFO(" calibration date = " << calibDate);
187 
188  }
189  }
190 
191  DBImportObjPtr<SVDDetectorConfiguration::t_svdLocalConfig_payload> svdLocalConfig(SVDDetectorConfiguration::svdLocalConfig_name);
192 
193  svdLocalConfig.construct(xmlFileName);
194 
195  svdLocalConfig->setCalibrationTimeInRFCUnits(calibTimeUnits);
196  svdLocalConfig->setCalibDate(calibDate);
197  /* Injected charge set is HARDCODED here, by default 22500 electrons
198  */
199  svdLocalConfig->setInjectedCharge(22500);
200 
201 
202  IntervalOfValidity iov(m_firstExperiment, m_firstRun,
203  m_lastExperiment, m_lastRun);
204 
205  svdLocalConfig.import(iov);
206  B2RESULT("SVDLocalConfigParameters imported to database.");
207 
208 }
209 
210 
211 
212 
213 
214 
215 
216 
Belle2::IntervalOfValidity
A class that describes the interval of experiments/runs for which an object in the database is valid.
Definition: IntervalOfValidity.h:35
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::DBImportObjPtr
Class for importing a single object to the database.
Definition: DBImportObjPtr.h:33
alignment.constraints_generator.filename
filename
File name.
Definition: constraints_generator.py:224