ATLAS Offline Software
CscCondDataCollection.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef CSCCONDDATACOLLECTION_H
6 #define CSCCONDDATACOLLECTION_H
7 
17 //#include "AthenaKernel/CLASS_DEF.h"
20 #include <sstream>
21 
22 
23 
24 namespace MuonCalib {
25  //Might be a neater way to do this. For now, this lets the collection name its
26  //type
27  template<typename type> class typeNamer {
28  public:
29  std::string nameType() const {
30  return "unknownType";
31  }
32  };
33 
34  template<> class typeNamer<uint8_t> {
35  public:
36  std::string nameType() const {
37  return "uint8_t";
38  }
39  };
40 
41  template<> class typeNamer<uint16_t> {
42  public:
43  std::string nameType() const {
44  return "uint16_t";
45  }
46  };
47 
48  template<> class typeNamer<uint32_t> {
49  public:
50  std::string nameType() const {
51  return "uint32_t";
52  }
53  };
54 
55  template<> class typeNamer<int> {
56  public:
57  std::string nameType() const {
58  return "int";
59  }
60  };
61 
62  template<> class typeNamer<float> {
63  public:
64  std::string nameType() const {
65  return "float";
66  }
67  };
68 
69  template<> class typeNamer<bool> {
70  public:
71  std::string nameType() const {
72  return "bool";
73  }
74  };
75 
76  template<> class typeNamer<double> {
77  public:
78  std::string nameType() const {
79  return "double";
80  }
81  };
82 
83  template<> class typeNamer<std::string> {
84  public:
85  std::string nameType() const {
86  return "string";
87  }
88  };
89 
90  template <typename data_type>
91  class CscCondDataCollection : public CscCondDataCollectionBase, public DataVector< CscCondData<data_type> > {
92  public:
94  : DataVector<CscCondData<data_type> >(own), m_parDefault(data_type()) {}
96 
97  //Reinitializes internal DataVector to point to empty entries, but
98  //keeps size the same (if size was set with setSize())
99  virtual inline void reset() {
100  this->clear();
101  this->resize(m_size);
102  //std::cout << "Reset " << this->getParName() << ". Value of first index is " << (*this)[0] << std::endl;
103 
104  }
105 
106  //set parameter default from a string
107  virtual void setParDefault(const std::string & parDefault) {
108  std::istringstream ss(parDefault);
109  ss >> m_parDefault;
110 
111 
112  }
113 
114  //virtual void print();
115  virtual std::string getParDataType() const {
116  return m_typeNamer.nameType();
117  }
118 
119 
120  virtual const data_type & getParDefault() const { return m_parDefault;}
121 
122  virtual void setSize(const unsigned int & size) {
123  m_size = size;
124  this->resize(size);
125  }
126  virtual size_t getSize() const { return this->size(); }
127 
128 
129  StatusCode recordFromSS(std::istringstream & ss,const unsigned int &index);
130  StatusCode record(const data_type &, const int & index);
131 
132  //check that there is a non-null pointer at index
133  virtual inline int check(unsigned int & index) const {
134  if(index >= this->size())
135  return 0;
136  //std::cout << "checking index" << index << " of " << this->getParName() << ". have " << (*this)[index] << "\n";
137 
138  if((*this)[index])
139  return 1;
140  else
141  return 0;
142  }
143 
144  private:
146  data_type m_parDefault;
147 
148 
149  };
150 
151 
152  //Retrieves a single word from an istreamstream, stores the value into CscCondDataCollection
153  template <typename data_type>
154  inline StatusCode CscCondDataCollection<data_type>::recordFromSS(std::istringstream & ss, const unsigned int & index) {
155  data_type data;
156  ss >> data;
157  return record(data, index);
158  }
159 
160  //Store a bit of data into CscCondDataCollection
161  template <typename data_type>
162  inline StatusCode CscCondDataCollection<data_type>::record(const data_type & data, const int &index) {
163 
164  //std::cout << "Storing [" << index << "] - " << data << std::endl;
165  //std::cout << "Currently we have pointer to: " << this->at(index) << std::endl;
166 
167  //Check to see if this channel is already used. Don't allow overwriting in order to
168  //catch bugs
169  if(this->at(index))
170  return StatusCode::RECOVERABLE;
171  this->at(index) = new CscCondData<data_type>(data);
172  return StatusCode::SUCCESS;
173  }
174 
175  //CLASS_DEF(MuonCalib::CscCondDataContainer, 1173850174, 1)
176 
177 }//end namespace MuonCalib
178 #endif
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
MuonCalib::typeNamer< int >::nameType
std::string nameType() const
Definition: CscCondDataCollection.h:57
MuonCalib::CscCondDataCollection::getParDefault
virtual const data_type & getParDefault() const
Definition: CscCondDataCollection.h:120
MuonCalib::CscCondDataCollectionBase::m_size
unsigned int m_size
Definition: CscCondDataCollectionBase.h:98
PowhegControl_ttHplus_NLO.ss
ss
Definition: PowhegControl_ttHplus_NLO.py:83
xAOD::uint8_t
uint8_t
Definition: Muon_v1.cxx:557
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
MuonCalib::typeNamer::nameType
std::string nameType() const
Definition: CscCondDataCollection.h:29
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
index
Definition: index.py:1
MuonCalib::CscCondDataCollection::recordFromSS
StatusCode recordFromSS(std::istringstream &ss, const unsigned int &index)
Definition: CscCondDataCollection.h:154
MuonCalib::typeNamer< float >::nameType
std::string nameType() const
Definition: CscCondDataCollection.h:64
MuonCalib::CscCondDataCollectionBase
Definition: CscCondDataCollectionBase.h:25
MuonCalib::CscCondDataCollection::reset
virtual void reset()
Definition: CscCondDataCollection.h:99
CscCondData.h
MuonCalib::CscCondDataCollection::check
virtual int check(unsigned int &index) const
Definition: CscCondDataCollection.h:133
SG::OwnershipPolicy
OwnershipPolicy
describes the possible element ownership policies (see e.g. DataVector)
Definition: OwnershipPolicy.h:16
MuonCalib::typeNamer< uint32_t >::nameType
std::string nameType() const
Definition: CscCondDataCollection.h:50
MuonCalib::CscCondDataCollection::~CscCondDataCollection
virtual ~CscCondDataCollection()
Definition: CscCondDataCollection.h:95
xAOD::uint16_t
setWord1 uint16_t
Definition: eFexEMRoI_v1.cxx:93
SG::OWN_ELEMENTS
@ OWN_ELEMENTS
this data object owns its elements
Definition: OwnershipPolicy.h:17
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
MuonCalib::typeNamer< bool >::nameType
std::string nameType() const
Definition: CscCondDataCollection.h:71
MuonCalib::CscCondDataCollection::setSize
virtual void setSize(const unsigned int &size)
Definition: CscCondDataCollection.h:122
MuonCalib
CscCalcPed - algorithm that finds the Cathode Strip Chamber pedestals from an RDO.
Definition: CscCalcPed.cxx:22
MuonCalib::CscCondDataCollection::record
StatusCode record(const data_type &, const int &index)
Definition: CscCondDataCollection.h:162
xAOD::double
double
Definition: CompositeParticle_v1.cxx:159
MuonCalib::CscCondDataCollection::CscCondDataCollection
CscCondDataCollection(SG::OwnershipPolicy own=SG::OWN_ELEMENTS)
Definition: CscCondDataCollection.h:93
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
MuonCalib::typeNamer< std::string >::nameType
std::string nameType() const
Definition: CscCondDataCollection.h:85
MuonCalib::typeNamer< uint16_t >::nameType
std::string nameType() const
Definition: CscCondDataCollection.h:43
DataVector< CscCondData< data_type > >::clear
void clear()
Erase all the elements in the collection.
DataVector< CscCondData< data_type > >::resize
void resize(size_type sz)
Resizes the collection to the specified number of elements.
MuonCalib::CscCondDataCollection::getParDataType
virtual std::string getParDataType() const
Definition: CscCondDataCollection.h:115
MuonCalib::CscCondDataCollection::m_parDefault
data_type m_parDefault
Definition: CscCondDataCollection.h:146
MuonCalib::CscCondData
Definition: CscCondData.h:20
MuonCalib::typeNamer
Definition: CscCondDataCollection.h:27
MuonCalib::CscCondDataCollection::setParDefault
virtual void setParDefault(const std::string &parDefault)
Definition: CscCondDataCollection.h:107
MuonCalib::typeNamer< uint8_t >::nameType
std::string nameType() const
Definition: CscCondDataCollection.h:36
DataVector.h
An STL vector of pointers that by default owns its pointed-to elements.
MuonCalib::CscCondDataCollection::m_typeNamer
typeNamer< data_type > m_typeNamer
Definition: CscCondDataCollection.h:145
xAOD::bool
setBGCode setTAP setLVL2ErrorBits bool
Definition: TrigDecision_v1.cxx:60
CscCondDataCollectionBase.h
MuonCalib::CscCondDataCollection::getSize
virtual size_t getSize() const
Definition: CscCondDataCollection.h:126
MuonCalib::typeNamer< double >::nameType
std::string nameType() const
Definition: CscCondDataCollection.h:78
DataVector< CscCondData< data_type > >::size
size_type size() const noexcept
Returns the number of elements in the collection.
readCCLHist.float
float
Definition: readCCLHist.py:83
MuonCalib::CscCondDataCollection
Definition: CscCondDataCollection.h:91