ATLAS Offline Software
Loading...
Searching...
No Matches
MuonCalibDbCalibrationSource.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3*/
4
5// this
7
13
14// coral
15#include "CoralBase/Attribute.h"
16#include "CoralBase/AttributeList.h"
17
18// MuonCalibIdentifier//MuonCalibIdentifier
21
22// MuonCalibMath
23#include "GaudiKernel/IMessageSvc.h"
24#include "GaudiKernel/MsgStream.h"
26// MuonCalibStandALoneBase
29// c - c++
30#include "exception"
31#include "iostream"
32#include "sstream"
33
34namespace MuonCalib {
36 MuonCalibDbCalibrationSource::MuonCalibDbCalibrationSource(const std::string& t, const std::string& n, const IInterface* p) :
38 declareInterface<IMuonCalibConditionsSource>(this);
39 declareProperty("SiteName", m_site_name);
40 declareProperty("HeadId", m_head_id);
41 declareProperty("ConnectionString", m_calib_connection_string);
43 declareProperty("UserName", m_username);
44 declareProperty("Password", m_password);
46 m_mdt_tube_cols.push_back(std::string("TUBE_ID"));
47 m_mdt_tube_cols.push_back(std::string("P4"));
48 m_mdt_tube_cols.push_back(std::string("VALIDFLAG"));
49 m_mdt_tube_cols.push_back(std::string("ADC_1"));
50 m_store_t0 = true;
51 m_store_rt = true;
52 declareProperty("StoreT0", m_store_t0);
53 declareProperty("StoreRT", m_store_rt);
54 m_t0_offset = 0.0;
55 declareProperty("DriftTimeOffsetsVsR", m_drift_time_offsets);
56 declareProperty("T0Offset", m_t0_offset);
58 declareProperty("TimeSlewingApplied", m_time_slewing_applied);
60 declareProperty("BFieldCorrectionApplied", m_b_field_correction_applied);
62 }
63
65 // process region
67 if (!m_region) {
68 ATH_MSG_FATAL("Error initializing RegionSelectorBase::GetRegion with region string: '" << m_region_str);
69 return StatusCode::FAILURE;
70 }
71 // open conneciton to calibration db
72 m_connection = std::make_unique<CalibDbConnection>(m_calib_connection_string, m_calib_working_schema);
74 if (!m_connection->OpenConnection()) {
75 ATH_MSG_FATAL("Cannot open connection to calibration database!");
76 return StatusCode::FAILURE;
77 }
78 m_head_ops = std::make_unique<CalibHeadOperations>(*m_connection);
79 int lowrun, uprun, lowtime, uptime;
80 if (!m_head_ops->GetHeadInfo(m_head_id, lowrun, uprun, lowtime, uptime)) {
81 ATH_MSG_FATAL("Cannot get header " << m_head_id << "from calib datbase");
82 return StatusCode::FAILURE;
83 }
84 m_iov_start = lowrun;
85 m_iov_end = uprun;
86 m_iov_end++;
87 m_data_connection.reset(m_head_ops->GetDataConnection(m_head_id, false));
88 if (!m_data_connection) {
89 ATH_MSG_FATAL("Cannot open data connection!");
90 return StatusCode::FAILURE;
91 }
92 if (!m_data_connection->OpenConnection()) {
93 ATH_MSG_FATAL("Cannot open data connection!");
94 return StatusCode::FAILURE;
95 }
99 return StatusCode::SUCCESS;
100 }
101
102 bool MuonCalibDbCalibrationSource::StoreT0Chamber(const int& chamber, const std::map<TubeId, coral::AttributeList>& rows) {
103 MuonFixedId id(chamber);
104 if (!m_region->Result(id)) { return true; }
105 NtupleStationId sid(id);
106 sid.SetMultilayer(0);
107 std::string data_string;
108 std::ostringstream f;
109 f << chamber << m_site_name << m_head_id;
110 if (!m_inserter->StartT0Chamber(sid)) {
111 ATH_MSG_WARNING("Cannot insert chamber " << chamber);
112 return true;
113 }
114 for (const auto & row : rows) {
115 if (!m_inserter->AppendT0(row.second["P4"].data<float>() + m_t0_offset, row.second["VALIDFLAG"].data<short>(),
116 row.second["ADC_1"].data<float>())) {
117 ATH_MSG_WARNING("Wrong number of tubes in database for " << sid.regionId() << "!");
118 break;
119 }
120 }
121 m_inserter->StoreT0Chamber(sid, f.str(), m_creation_flags);
122 return true;
123 }
124
125 bool MuonCalibDbCalibrationSource::StoreRtChamber(const int& chamber, const std::map<int, SamplePoint>& points) {
126 MuonFixedId id(chamber);
127 if (!m_region->Result(id)) { return true; }
128 NtupleStationId sid(id);
129 sid.SetMultilayer(0);
130 std::ostringstream f;
131 f << chamber << m_site_name << m_head_id;
132 if (m_drift_time_offsets.size()) {
133 float slice_width = 14.6 / static_cast<float>(m_drift_time_offsets.size());
134 std::map<int, SamplePoint> points_cp(points);
135 for (auto & it : points_cp) {
136 int slice_number = static_cast<int>(std::floor(it.second.x2() / slice_width));
137 if (slice_number < 0) slice_number = 0;
138 if (slice_number >= static_cast<int>(m_drift_time_offsets.size()))
139 slice_number = static_cast<int>(m_drift_time_offsets.size()) - 1;
140 it.second.set_x1(it.second.x1() + m_drift_time_offsets[slice_number]);
141 }
142 m_inserter->StoreRtChamber(sid, points_cp, f.str(), m_creation_flags);
143 } else {
144 m_inserter->StoreRtChamber(sid, points, f.str(), m_creation_flags);
145 }
146 return true;
147 }
148
149 bool MuonCalibDbCalibrationSource::insert_calibration(bool store_t0, bool store_rt) {
150 try {
151 if (store_t0 && m_store_t0) {
153 if (!t0_op.ReadForConditions(m_site_name, m_head_id, *this)) {
154 ATH_MSG_WARNING("T0 insert failed!");
155 return false;
156 }
157 }
158 if (store_rt && m_store_rt) {
160 if (!rt_op.ReadForConditions(m_site_name, m_head_id, *this)) {
161 ATH_MSG_WARNING("RT insert failed!");
162 return false;
163 }
164 }
165 } // try
166 catch (const std::exception& e) {
167 ATH_MSG_FATAL("Exception: " << e.what());
168 return false;
169 }
170 return true;
171 }
172
173} // namespace MuonCalib
#define ATH_MSG_FATAL(x)
#define ATH_MSG_WARNING(x)
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
bool ReadForConditions(const std::string &, int head_id, IConditionsStorage &storage)
bool ReadForConditions(const std::string &site_name, int head_id, IConditionsStorage &storage)
std::unique_ptr< CalibHeadOperations > m_head_ops
bool StoreRtChamber(const int &chamber, const std::map< int, SamplePoint > &points)
bool StoreT0Chamber(const int &chamber, const std::map< TubeId, coral::AttributeList > &rows)
call back for t0
std::unique_ptr< CalibDbConnection > m_connection
std::unique_ptr< RegionSelectorBase > m_region
std::unique_ptr< CalibDbConnection > m_data_connection
bool insert_calibration(bool store_t0, bool store_rt)
insert calibration
MuonCalibDbCalibrationSource(const std::string &t, const std::string &n, const IInterface *p)
constructor
Implements fixed identifiers not dependent upon Athena Identifier for internal use in the calibration...
Definition MuonFixedId.h:50
Station Identifier for sorting calibration data.
void SetMultilayer(const int &ml)
std::string regionId() const
return the region id string
static std::unique_ptr< RegionSelectorBase > GetRegion(const std::string &input)
create a region from a string
CscCalcPed - algorithm that finds the Cathode Strip Chamber pedestals from an RDO.