ATLAS Offline Software
RtDataFromFile.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 #include <TString.h> // for Form
8 
9 #include <string>
10 
11 
12 namespace {
13  constexpr int M_MAX_RTS = 100000;
14 }
15 
16 namespace MuonCalib {
17 
18  std::istream& RtDataFromFile::read(std::istream& is) {
19  std::string version;
20  std::string rts_str;
21 
22  // read number of rts in file
23  is >> version >> rts_str;
24 
25  unsigned long int pos = 0;
26  std::string::size_type start = rts_str.find_first_not_of(' ', pos);
27  if (start == std::string::npos)
28  throw std::runtime_error(
29  Form("File: %s, Line: %d\nRtDataFromFile::read() - problems extracting m_rts, exiting", __FILE__, __LINE__));
30 
31  std::string::size_type stop = rts_str.find_first_of(' ', start + 1);
32  if (stop == std::string::npos) stop = rts_str.size();
33  m_rts = std::stoi(rts_str.substr(start, stop - start), nullptr);
34 
35  m_rts = (m_rts > M_MAX_RTS) ? M_MAX_RTS : m_rts;
36  for (unsigned int i = 0; i < m_rts; ++i) {
37  if (version != "v0.0") {
38  // read in additional information
39  RtFullInfo fi;
40  is >> fi;
41  }
42  // create empty rt
43  RtRelation* rt = new RtRelation();
44 
45  // read rt from file
46  is >> *rt;
47 
48  // store rt
49  m_rtRelations.push_back(rt);
50  }
51 
52  return is;
53  }
54 
55  std::ostream& RtDataFromFile::write(std::ostream& os, int region) const {
56  if (m_rts != m_rtRelations.size()) {
57  MsgStream log(Athena::getMessageSvc(), "RtDataFromFile");
58  log << MSG::WARNING << "write() <inconsistent rt count>" << endmsg;
59  }
60  if (region >= static_cast<int>(m_rts)) {
61  MsgStream log(Athena::getMessageSvc(), "RtDataFromFile");
62  log << MSG::WARNING << "write() <requested not existent region>" << endmsg;
63  }
64  os << "v" << m_major_version << "." << m_minor_version << " 1"; // full info added
65 
66  if (m_fullInfo[region]) os << *(m_fullInfo[region]);
67  if (m_rtRelations[region]) os << *(m_rtRelations[region]);
68  return os;
69  }
70 
71  std::ostream& RtDataFromFile::write(std::ostream& os) const {
72  if (m_rts != m_rtRelations.size()) {
73  MsgStream log(Athena::getMessageSvc(), "RtDataFromFile");
74  log << MSG::WARNING << "write() <inconsistent rt count>" << endmsg;
75  }
76 
77  os << "v1.0 " << m_rts; // full info added
78 
79  for (unsigned int i = 0; i < m_rtRelations.size(); ++i) {
80  if (m_fullInfo[i]) os << *(m_fullInfo[i]);
81  if (m_rtRelations[i]) os << *(m_rtRelations[i]);
82  }
83  return os;
84  }
85 
86  void RtDataFromFile::write_forDB(FILE* frt, FILE* frtt, FILE* frtr, FILE* frts, int region) const {
87  if (m_rts != m_rtRelations.size()) {
88  MsgStream log(Athena::getMessageSvc(), "RtDataFromFile");
89  log << MSG::WARNING << "write_forDB() <inconsistent rt count>" << endmsg;
90  }
91  if (region >= static_cast<int>(m_rts)) {
92  MsgStream log(Athena::getMessageSvc(), "RtDataFromFile");
93  log << MSG::WARNING << "write_forDB() <requested not existent region>" << endmsg;
94  }
95  if (m_fullInfo[region]) { (m_fullInfo[region])->write_forDB(frt); }
96  if (m_rtRelations[region]) { (m_rtRelations[region])->write_forDB(frtt, frtr, frts); }
97  return;
98  }
99 
100  void RtDataFromFile::write_forDB(FILE* frt, FILE* frtt, FILE* frtr, FILE* frts) const {
101  if (m_rts != m_rtRelations.size()) {
102  MsgStream log(Athena::getMessageSvc(), "RtDataFromFile");
103  log << MSG::WARNING << "write_forDB() <inconsistent rt count>" << endmsg;
104  }
105 
106  for (unsigned int i = 0; i < m_rtRelations.size(); ++i) {
107  if (m_rtRelations[i]) { (m_rtRelations[i])->write_forDB(frtt, frtr, frts); }
108  if (m_fullInfo[i]) { (m_fullInfo[i])->write_forDB(frt); }
109  }
110  return;
111  }
112 
113 } // namespace MuonCalib
114 
115 std::istream& operator>>(std::istream& is, MuonCalib::RtDataFromFile& data) { return data.read(is); }
116 
117 std::ostream& operator<<(std::ostream& os, const MuonCalib::RtDataFromFile& data) { return data.write(os); }
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
MuonCalib::RtDataFromFile::RtRelation
RtData_t_r_reso RtRelation
Definition: RtDataFromFile.h:23
MuonCalib::RtDataFromFile::write
std::ostream & write(std::ostream &os, int region) const
Definition: RtDataFromFile.cxx:55
mergePhysValFiles.start
start
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:14
MuonCalib::RtDataFromFile
Manages the I/O of the Rt realtions from/to file.
Definition: RtDataFromFile.h:21
MuonCalib::RtDataFromFile::m_major_version
int m_major_version
format version
Definition: RtDataFromFile.h:90
operator>>
std::istream & operator>>(std::istream &is, MuonCalib::RtDataFromFile &data)
Definition: RtDataFromFile.cxx:115
PixelModuleFeMask_create_db.stop
int stop
Definition: PixelModuleFeMask_create_db.py:76
operator<<
std::ostream & operator<<(std::ostream &os, const MuonCalib::RtDataFromFile &data)
Definition: RtDataFromFile.cxx:117
Athena::getMessageSvc
IMessageSvc * getMessageSvc(bool quiet=false)
Definition: getMessageSvc.cxx:20
lumiFormat.i
int i
Definition: lumiFormat.py:85
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
MuonCalib::RtDataFromFile::m_rtRelations
RtRelations m_rtRelations
rt relations
Definition: RtDataFromFile.h:87
MuonCalib
CscCalcPed - algorithm that finds the Cathode Strip Chamber pedestals from an RDO.
Definition: CscCalcPed.cxx:22
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
MuonCalib::RtFullInfo
addiitonal information used in validation of a rt-relation
Definition: RtFullInfo.h:15
MuonCalib::RtDataFromFile::m_rts
unsigned int m_rts
total number of regions
Definition: RtDataFromFile.h:84
MuonCalib::RtDataFromFile::m_minor_version
int m_minor_version
Definition: RtDataFromFile.h:90
MuonCalib::RtDataFromFile::write_forDB
void write_forDB(FILE *frt, FILE *frtt, FILE *frtr, FILE *frts, int region) const
Definition: RtDataFromFile.cxx:86
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
get_generator_info.version
version
Definition: get_generator_info.py:33
MuonCalib::RtDataFromFile::read
std::istream & read(std::istream &is)
Definition: RtDataFromFile.cxx:18
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
checkFileSG.fi
fi
Definition: checkFileSG.py:65
MuonCalib::RtDataFromFile::m_fullInfo
std::vector< const RtFullInfo * > m_fullInfo
Definition: RtDataFromFile.h:88
MuonCalib::RtData_t_r_reso
Represents an Rt relation in the form of a set of (time,radius,resolution) points.
Definition: RtData_t_r_reso.h:16
RtDataFromFile.h