ATLAS Offline Software
Loading...
Searching...
No Matches
PrescaleSet.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
3*/
4
5
6
9#include <iostream>
10#include <iomanip>
11#include <math.h>
12
13using namespace std;
14using namespace TrigConf;
15
16//const unsigned int PrescaleSet::N_PRESCALES = 256;
17
18const int32_t PrescaleSet::maxPrescaleCut = 0xFFFFFF; //2**24 - 1
19
32int32_t
34 int32_t sign = prescale<0 ? -1 : 1;
35 double uprescale = fabs(prescale);
36 return sign * ( 0x1000000 - int32_t(0xFFFFFF/uprescale));
37}
38
51double
53 double sign = cut<0 ? -1 : 1;
54 uint32_t ucut = abs(cut);
55 return (sign * 0xFFFFFF ) / ( 0x1000000 - ucut );
56}
57
58
70
72 for(auto& x: m_Prescales) x=-1;
73 for(auto& x: m_Prescales_ctp) x=-1;
74 for(auto& x: m_Prescales_float) x=-1;
75 for(auto& x: m_Cuts) x=-maxPrescaleCut;
76 m_null = true;
77}
78
79void
81 m_Prescales.resize(size,-1);
82 m_Prescales_ctp.resize(size,-1);
83 m_Prescales_float.resize(size,-1);
84 m_Cuts.resize(size,2<<10);
85 //m_Cuts.resize(size,-maxPrescaleCut);
86}
87
88void
89TrigConf::PrescaleSet::setCuts(const std::vector<int32_t>& cuts) {
90 for(unsigned int ctpid = 0; ctpid < cuts.size(); ++ctpid )
91 setCut(ctpid, cuts[ctpid]);
92}
93
94
95void
96TrigConf::PrescaleSet::setCut(unsigned int ctpid, int32_t cut) {
97 m_Cuts[ctpid] = cut;
98
99 const float ps_f = getPrescaleFromCut(cut);
100 m_Prescales_float[ctpid] = ps_f;
101
102 const int sign = ps_f<0 ? -1 : 1;
103 int ps = sign * static_cast<int>(fabs(ps_f)+0.5);
104
105 m_Prescales[ctpid] = ps;
106
107 m_null = false;
108}
109
110
114void
115TrigConf::PrescaleSet::setPrescales(const std::vector<int64_t>& prescales) {
118 unsigned int i(0);
119 for (auto ps: m_Prescales_ctp) {
120 l1ps = TrigConf::L1PSNumber(ps);
121 m_Prescales[i] = l1ps.getInt32();
123 i++;
124 }
125 m_null = false;
126}
127
131void
132TrigConf::PrescaleSet::setPrescales(const int64_t p[], const unsigned int size) {
134 for (unsigned int i = 0; i < size; ++i) {
135 m_Prescales_ctp[i] = p[i];
136 l1ps = TrigConf::L1PSNumber(p[i]);
137 m_Prescales[i] = l1ps.getInt32();
139 }
140 m_null = false;
141}
142
143
149void TrigConf::PrescaleSet::setPrescales(const int p[], const unsigned int size) {
151 for (unsigned int i = 0; i < size; i++) {
152 m_Prescales_ctp[i] = (int64_t) p[i];
153 l1ps = TrigConf::L1PSNumber((int64_t)p[i]);
154 m_Prescales[i] = l1ps.getInt32();
156 }
157 m_null = false;
158}
159
165void
166TrigConf::PrescaleSet::setPrescale(unsigned int num, int64_t prescaleValue) {
167 TrigConf::L1PSNumber l1ps = TrigConf::L1PSNumber(prescaleValue);
168 m_Prescales[num] = l1ps.getInt32();
169 m_Prescales_ctp[num] = prescaleValue;
171 m_null = false;
172}
173
177void
178TrigConf::PrescaleSet::setPrescale(unsigned int num, int prescaleValue) {
179 m_Prescales_ctp[num] = (int64_t) prescaleValue;
180 TrigConf::L1PSNumber l1ps = TrigConf::L1PSNumber((int64_t)prescaleValue);
181 m_Prescales[num] = l1ps.getInt32();
182 m_Prescales_float[num] = l1ps.getFloatPrescale();
183 m_null = false;
184}
185
186void
187TrigConf::PrescaleSet::setPrescale(unsigned int num, float prescaleValue) {
188 int32_t cut = getCutFromPrescale(prescaleValue);
189 m_Prescales[num] = cut;
190 m_Prescales_ctp[num] = cut;
191 m_Prescales_float[num] = prescaleValue;
192 m_null = false;
193}
194
195
196void
197TrigConf::PrescaleSet::print(const std::string& indent, unsigned int detail) const {
198 if(detail>=1) {
199 cout << indent << "PrescaleSet ";
200 printNameIdV("");
201 if(detail>=3) {
202 int i(0);
203 for( auto ps: m_Prescales_float)
204 cout << indent << " ctpid=" << i++ << ": " << " prescale=" << ps << endl;
205 }
206 }
207}
208
212void
213TrigConf::PrescaleSet::writeXML(std::ostream & xmlfile, int indentLevel, int indentWidth) const {
214 L1PSNumber psOut;
215 indent(xmlfile, indentLevel, indentWidth)
216 << "<PrescaleSet"
217 << " name=\"" << name() << "\""
218 << " type=\"" << type() << "\""
219 << " menuPartition=\"" << partition() << "\">"
220 << endl;
221
222 if(newPrescaleStyle()) {
223 int ctpid(0);
224 for (int32_t cut: m_Cuts) {
225 indent(xmlfile, indentLevel + 1, indentWidth)
226 << "<Prescale ctpid=\"" << ctpid++
227 << "\" cut=\"" << (cut<0?"-":"") << hex << setfill('0') << setw(6) << abs(cut) << setfill(' ') << dec
228 << "\" value=\"" << getPrescaleFromCut(cut)
229 << "\"/>" << endl;
230 }
231 } else {
232 int i(0);
233 for (auto& ps: m_Prescales_ctp) {
234 psOut = L1PSNumber(ps);
235 indent(xmlfile, indentLevel + 1, indentWidth)
236 << "<Prescale ctpid=\"" << i++ << "\" ps=\"" << psOut.write() << "\"/>" << endl;
237 }
238 }
239 indent(xmlfile, indentLevel, indentWidth)
240 << "</PrescaleSet>" << endl;
241}
int sign(int a)
#define x
std::string write()
Writes nicely the ps value.
int getInt32() const
Definition L1PSNumber.h:78
float getFloatPrescale() const
Definition L1PSNumber.h:76
static int32_t getCutFromPrescale(double prescale)
calculate cut value for hardware configuration cut = 2*24/prescale - 1
const std::string & type() const
Definition PrescaleSet.h:39
void setPrescale(unsigned int num, int64_t prescaleValue) __attribute__((deprecated))
Set the prescale NUM from the int64 value prescaleValue.
void setCuts(const std::vector< int32_t > &cuts)
bool newPrescaleStyle() const
Definition PrescaleSet.h:38
const std::vector< int > & prescales() const __attribute__((deprecated))
Definition PrescaleSet.h:41
virtual void print(const std::string &indent="", unsigned int detail=1) const override
void setPrescales(const std::vector< int64_t > &) __attribute__((deprecated))
DEPRECATED.
void setCut(unsigned int num, int32_t cut)
const std::vector< int32_t > & cuts() const
Definition PrescaleSet.h:44
static double getPrescaleFromCut(int32_t cut)
prescale = 2*24/(cut+1.)
static const int32_t maxPrescaleCut
Definition PrescaleSet.h:27
std::vector< int32_t > m_Cuts
Definition PrescaleSet.h:79
void writeXML(std::ostream &xmlfile, int indentLevel=0, int indentWidth=2) const
Writes the Prescale item to the XML file.
unsigned int m_Partition
Definition PrescaleSet.h:75
std::vector< float > m_Prescales_float
Definition PrescaleSet.h:78
void resize(size_t size)
std::vector< int > m_Prescales
Definition PrescaleSet.h:76
std::vector< int64_t > m_Prescales_ctp
Definition PrescaleSet.h:77
std::ostream & indent(std::ostream &o, int lvl, int size) const
void printNameIdV(const std::string &indent="") const
static std::vector< std::string > xmlfile
Definition iLumiCalc.h:29
Forward iterator to traverse the main components of the trigger configuration.
Definition Config.h:22
STL namespace.
DataModel_detail::iterator< DVL > partition(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end, Predicate pred)
Specialization of partition for DataVector/List.