ATLAS Offline Software
TBMWPCContCnv_p1.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 #include "TBEvent/TBMWPCCont.h"
7 #include "Identifier/Identifier.h"
9 
10 
11 
12 void
14  TBMWPCCont* trans, MsgStream &/*log*/) const
15 {
16 
17  const unsigned nTBMWPCs = pers->m_cPos.size();
18 
19  // clear the trans contained and reserve space for the new MWPCs
20  trans->clear();
21  trans->reserve(nTBMWPCs);
22 
23  // copy all the MWPCs from the pers to the trans
24  for (unsigned nTBMWPCNow=0; nTBMWPCNow<nTBMWPCs; nTBMWPCNow++) {
25  TBMWPC * MWPC = new TBMWPC();
26 
27  MWPC -> setCPos( pers->m_cPos[nTBMWPCNow] );
28  MWPC -> setCErr( pers->m_cErr[nTBMWPCNow] );
29  MWPC -> setXchambers( pers->m_isX[nTBMWPCNow] );
30  MWPC -> setClusterSizeC( pers->m_clusterSize_c[nTBMWPCNow] );
31 
32 
33 
34 
35  // ------------------------------------------------------------------------------------------------
36  // for some reason a stright forward definition of m_cPosOverflow as
37  // std::vector < std::vector<bool> > m_cPosOverflow;
38  // does not work. perhaps due to the fact that std::vector<bool> is nonconforming (not
39  // really a vector of bool). instead we defined
40  // std::vector < std::vector<unsigned> > m_cPosOverflow;
41  // and now need to convert the bool constituents of the vectors to unsigned
42  // ------------------------------------------------------------------------------------------------
43  unsigned nBools = pers->m_cPosOverflow[nTBMWPCNow].size(); //length of the vector of bool in TBMWPC
44  std::vector<bool> cPosOverflowNow; //defines length
45  cPosOverflowNow.reserve(nBools);
46 
47  for (unsigned nBoolNow=0; nBoolNow<nBools; nBoolNow++) {
48  if(pers->m_cPosOverflow[nTBMWPCNow][nBoolNow])
49  cPosOverflowNow.push_back(true);
50  else
51  cPosOverflowNow.push_back(false);
52  }
53  MWPC -> setCPosOverflow( cPosOverflowNow );
54  // ------------------------------------------------------------------------------------------------
55 
56 
57 
58  MWPC -> setDetectorName( pers->m_tbDetectorName[nTBMWPCNow] );
59  MWPC -> setOverflow( pers->m_overflow[nTBMWPCNow] );
60 
61  // fill the container with the MWPC object
62  trans->push_back(MWPC);
63  }
64 
65 }
66 
67 
68 void
70  TBMWPCCont_p1* pers, MsgStream &/*log*/) const
71 {
72 
73  const unsigned nTBMWPCs = trans->size();
74 
75  pers -> m_cPos.reserve(nTBMWPCs);
76  pers -> m_cErr.reserve(nTBMWPCs);
77  pers -> m_isX.reserve(nTBMWPCs);
78  pers -> m_clusterSize_c.reserve(nTBMWPCs);
79  pers -> m_cPosOverflow.reserve(nTBMWPCs);
80  pers -> m_tbDetectorName.reserve(nTBMWPCs);
81  pers -> m_overflow.reserve(nTBMWPCs);
82 
83 
84  // iterators for the container
85  TBMWPCCont::const_iterator MWPCIt = trans->begin();
86  TBMWPCCont::const_iterator MWPCIt_e = trans->end();
87 
88  // copy all the MWPCs from the trans to the pers
89  for (; MWPCIt!=MWPCIt_e; ++MWPCIt) {
90  const TBMWPC * MWPC = * MWPCIt;
91 
92  // fill in the MWPC properties
93  pers -> m_cPos.push_back( MWPC->getCPos() );
94  pers -> m_cErr.push_back( MWPC->getCErr() );
95  pers -> m_isX.push_back( MWPC->isX() );
96  pers -> m_clusterSize_c.push_back( MWPC->getClusterSizeC() );
97 
98  // ------------------------------------------------------------------------------------------------
99  // for some reason a stright forward definition of m_cPosOverflow as
100  // std::vector < std::vector<bool> > m_cPosOverflow;
101  // does not work. perhaps due to the fact that std::vector<bool> is nonconforming (not
102  // really a vector of bool variables, but some ). instead we defined
103  // std::vector < std::vector<unsigned> > m_cPosOverflow;
104  // and now need to convert the bool constituents of the vectors to unsigned
105  // ------------------------------------------------------------------------------------------------
106  unsigned nBools = MWPC->isCPosOverflow().size(); //length of the vector of bool in TBMWPC
107  std::vector<unsigned> cPosOverflowNow(nBools); //defines length and initializes to zero
108 
109  for (unsigned nBoolNow=0; nBoolNow<nBools; nBoolNow++) {
110  if(MWPC->isCPosOverflow()[nBoolNow])
111  cPosOverflowNow[nBoolNow] = 1;
112  }
113  pers -> m_cPosOverflow.push_back( cPosOverflowNow );
114  // ------------------------------------------------------------------------------------------------
115 
116  pers -> m_tbDetectorName.push_back( MWPC->getDetectorName() );
117  pers -> m_overflow.push_back( MWPC->isOverflow() );
118  }
119 
120 }
121 
DataVector::reserve
void reserve(size_type n)
Attempt to preallocate enough memory for a specified number of elements.
TBBeamDetector::getDetectorName
std::string getDetectorName() const
Definition: TBBeamDetector.h:61
DataModel_detail::const_iterator
Const iterator class for DataVector/DataList.
Definition: DVLIterator.h:82
TBMWPC::isX
bool isX() const
Definition: TBMWPC.h:69
TBMWPCCont_p1.h
TBMWPCCont_p1
Definition: TBMWPCCont_p1.h:15
TBMWPCCont_p1::m_overflow
std::vector< bool > m_overflow
Definition: TBMWPCCont_p1.h:41
TBMWPCCont_p1::m_tbDetectorName
std::vector< std::string > m_tbDetectorName
Definition: TBMWPCCont_p1.h:40
TBMWPCContCnv_p1::transToPers
virtual void transToPers(const TBMWPCCont *trans, TBMWPCCont_p1 *pers, MsgStream &log) const override
Definition: TBMWPCContCnv_p1.cxx:69
TBMWPC::getCErr
std::vector< float > getCErr() const
Definition: TBMWPC.h:67
TBMWPCContCnv_p1.h
TBMWPCCont
Definition: TBMWPCCont.h:17
DataVector::clear
void clear()
Erase all the elements in the collection.
TBMWPC::getCPos
std::vector< float > getCPos() const
Definition: TBMWPC.h:65
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
TBMWPC
Definition: TBMWPC.h:30
TBMWPCCont_p1::m_clusterSize_c
std::vector< std::vector< float > > m_clusterSize_c
Definition: TBMWPCCont_p1.h:26
TBMWPC::isCPosOverflow
std::vector< bool > isCPosOverflow() const
Definition: TBMWPC.h:78
TBBeamDetector::isOverflow
bool isOverflow() const
Definition: TBBeamDetector.h:64
TBMWPCCont.h
TBMWPCCont_p1::m_cErr
std::vector< std::vector< float > > m_cErr
Definition: TBMWPCCont_p1.h:21
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
TBMWPCContCnv_p1::persToTrans
virtual void persToTrans(const TBMWPCCont_p1 *pers, TBMWPCCont *trans, MsgStream &log) const override
Definition: TBMWPCContCnv_p1.cxx:13
TBMWPC::getClusterSizeC
std::vector< float > getClusterSizeC() const
Get cluster size for c-direction.
Definition: TBMWPC.h:74
TBMWPCCont_p1::m_cPosOverflow
std::vector< std::vector< unsigned > > m_cPosOverflow
Definition: TBMWPCCont_p1.h:37
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
TBMWPCCont_p1::m_cPos
std::vector< std::vector< float > > m_cPos
Definition: TBMWPCCont_p1.h:20
TBMWPCCont_p1::m_isX
std::vector< bool > m_isX
Definition: TBMWPCCont_p1.h:23