Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Christian Dziwok
Ph2_ACF
Commits
0d89568b
Commit
0d89568b
authored
Oct 14, 2016
by
Georg Auzinger
Browse files
added easylogging to HWDescription objects
parent
23b836db
Changes
6
Hide whitespace changes
Inline
Side-by-side
HWDescription/BeBoard.cc
View file @
0d89568b
...
...
@@ -15,118 +15,125 @@
#include <sstream>
#include <fstream>
namespace
Ph2_HwDescription
{
// Constructors
BeBoard
::
BeBoard
()
:
fBeId
(
0
)
{}
BeBoard
::
BeBoard
(
uint8_t
pBeId
)
:
fBeId
(
pBeId
)
{
}
BeBoard
::
BeBoard
(
uint8_t
pBeId
,
const
std
::
string
&
filename
)
:
fBeId
(
pBeId
)
{
loadConfigFile
(
filename
);
}
// Public Members:
uint32_t
BeBoard
::
getReg
(
const
std
::
string
&
pReg
)
const
{
BeBoardRegMap
::
const_iterator
i
=
fRegMap
.
find
(
pReg
);
if
(
i
==
fRegMap
.
end
()
)
{
std
::
cout
<<
"The Board object: "
<<
+
fBeId
<<
" doesn't have "
<<
pReg
<<
std
::
endl
;
return
0
;
}
else
return
i
->
second
;
}
void
BeBoard
::
setReg
(
const
std
::
string
&
pReg
,
uint32_t
psetValue
)
{
BeBoardRegMap
::
iterator
i
=
fRegMap
.
find
(
pReg
);
if
(
i
==
fRegMap
.
end
()
)
fRegMap
.
insert
(
{
pReg
,
psetValue
}
);
else
i
->
second
=
psetValue
;
}
bool
BeBoard
::
removeModule
(
uint8_t
pModuleId
)
{
bool
found
=
false
;
std
::
vector
<
Module
*>::
iterator
i
;
for
(
i
=
fModuleVector
.
begin
();
i
!=
fModuleVector
.
end
();
++
i
)
{
if
(
(
*
i
)
->
getModuleId
()
==
pModuleId
)
{
found
=
true
;
break
;
}
}
if
(
found
)
{
fModuleVector
.
erase
(
i
);
return
true
;
}
else
{
std
::
cout
<<
"Error:The BeBoard: "
<<
+
fBeId
<<
" doesn't have the module "
<<
+
pModuleId
<<
std
::
endl
;
return
false
;
}
}
Module
*
BeBoard
::
getModule
(
uint8_t
pModuleId
)
const
{
for
(
Module
*
m
:
fModuleVector
)
{
if
(
m
->
getModuleId
()
==
pModuleId
)
return
m
;
}
return
nullptr
;
}
// Private Members:
void
BeBoard
::
loadConfigFile
(
const
std
::
string
&
filename
)
{
std
::
ifstream
cFile
(
filename
.
c_str
(),
std
::
ios
::
in
);
if
(
!
cFile
)
std
::
cerr
<<
"The BeBoard Settings File "
<<
filename
<<
" could not be opened!"
<<
std
::
endl
;
else
{
fRegMap
.
clear
();
std
::
string
cLine
,
cName
,
cValue
,
cFound
;
while
(
!
(
getline
(
cFile
,
cLine
).
eof
()
)
)
{
if
(
cLine
.
find_first_not_of
(
"
\t
"
)
==
std
::
string
::
npos
)
continue
;
if
(
cLine
.
at
(
0
)
==
'#'
||
cLine
.
at
(
0
)
==
'*'
)
continue
;
if
(
cLine
.
find
(
":"
)
==
std
::
string
::
npos
)
continue
;
std
::
istringstream
input
(
cLine
);
input
>>
cName
>>
cFound
>>
cValue
;
// Here the Reg name sits in cName and the Reg value sits in cValue
if
(
cValue
.
find
(
"0x"
)
!=
std
::
string
::
npos
)
fRegMap
[
cName
]
=
strtol
(
cValue
.
c_str
(),
0
,
16
);
else
fRegMap
[
cName
]
=
strtol
(
cValue
.
c_str
(),
0
,
10
);
}
cFile
.
close
();
}
}
namespace
Ph2_HwDescription
{
// Constructors
BeBoard
::
BeBoard
()
:
fBeId
(
0
)
{}
BeBoard
::
BeBoard
(
uint8_t
pBeId
)
:
fBeId
(
pBeId
)
{
}
BeBoard
::
BeBoard
(
uint8_t
pBeId
,
const
std
::
string
&
filename
)
:
fBeId
(
pBeId
)
{
loadConfigFile
(
filename
);
}
// Public Members:
uint32_t
BeBoard
::
getReg
(
const
std
::
string
&
pReg
)
const
{
BeBoardRegMap
::
const_iterator
i
=
fRegMap
.
find
(
pReg
);
if
(
i
==
fRegMap
.
end
()
)
{
LOG
(
INFO
)
<<
"The Board object: "
<<
+
fBeId
<<
" doesn't have "
<<
pReg
;
return
0
;
}
else
return
i
->
second
;
}
void
BeBoard
::
setReg
(
const
std
::
string
&
pReg
,
uint32_t
psetValue
)
{
BeBoardRegMap
::
iterator
i
=
fRegMap
.
find
(
pReg
);
if
(
i
==
fRegMap
.
end
()
)
fRegMap
.
insert
(
{
pReg
,
psetValue
}
);
else
i
->
second
=
psetValue
;
}
bool
BeBoard
::
removeModule
(
uint8_t
pModuleId
)
{
bool
found
=
false
;
std
::
vector
<
Module
*>::
iterator
i
;
for
(
i
=
fModuleVector
.
begin
();
i
!=
fModuleVector
.
end
();
++
i
)
{
if
(
(
*
i
)
->
getModuleId
()
==
pModuleId
)
{
found
=
true
;
break
;
}
}
if
(
found
)
{
fModuleVector
.
erase
(
i
);
return
true
;
}
else
{
LOG
(
IFNO
)
<<
"Error:The BeBoard: "
<<
+
fBeId
<<
" doesn't have the module "
<<
+
pModuleId
;
return
false
;
}
}
Module
*
BeBoard
::
getModule
(
uint8_t
pModuleId
)
const
{
for
(
Module
*
m
:
fModuleVector
)
{
if
(
m
->
getModuleId
()
==
pModuleId
)
return
m
;
}
return
nullptr
;
}
// Private Members:
void
BeBoard
::
loadConfigFile
(
const
std
::
string
&
filename
)
{
std
::
ifstream
cFile
(
filename
.
c_str
(),
std
::
ios
::
in
);
if
(
!
cFile
)
LOG
(
ERROR
)
<<
"The BeBoard Settings File "
<<
filename
<<
" could not be opened!"
;
else
{
fRegMap
.
clear
();
std
::
string
cLine
,
cName
,
cValue
,
cFound
;
while
(
!
(
getline
(
cFile
,
cLine
).
eof
()
)
)
{
if
(
cLine
.
find_first_not_of
(
"
\t
"
)
==
std
::
string
::
npos
)
continue
;
if
(
cLine
.
at
(
0
)
==
'#'
||
cLine
.
at
(
0
)
==
'*'
)
continue
;
if
(
cLine
.
find
(
":"
)
==
std
::
string
::
npos
)
continue
;
std
::
istringstream
input
(
cLine
);
input
>>
cName
>>
cFound
>>
cValue
;
// Here the Reg name sits in cName and the Reg value sits in cValue
if
(
cValue
.
find
(
"0x"
)
!=
std
::
string
::
npos
)
fRegMap
[
cName
]
=
strtol
(
cValue
.
c_str
(),
0
,
16
);
else
fRegMap
[
cName
]
=
strtol
(
cValue
.
c_str
(),
0
,
10
);
}
cFile
.
close
();
}
}
}
HWDescription/BeBoard.h
View file @
0d89568b
...
...
@@ -15,6 +15,7 @@
#include "Definition.h"
#include "Module.h"
#include "../Utils/Visitor.h"
#include "../Utils/easylogging++.h"
#include <vector>
#include <map>
#include <stdint.h>
...
...
@@ -24,180 +25,194 @@
* \namespace Ph2_HwDescription
* \brief Namespace regrouping all the hardware description
*/
namespace
Ph2_HwDescription
{
using
BeBoardRegMap
=
std
::
map
<
std
::
string
,
uint32_t
>
;
/*!< Map containing the registers of a board */
/*!
* \class BeBoard
* \brief Read/Write BeBoard's registers on a file, handles a register map and handles a vector of Module which are connected to the BeBoard
*/
class
BeBoard
{
public:
// C'tors: the BeBoard only needs to know about which BE it is
/*!
* \brief Default C'tor
*/
BeBoard
();
/*!
* \brief Standard C'tor
* \param pBeId
*/
BeBoard
(
uint8_t
pBeId
);
/*!
* \brief C'tor for a standard BeBoard reading a config file
* \param pBeId
* \param filename of the configuration file
*/
BeBoard
(
uint8_t
pBeId
,
const
std
::
string
&
filename
);
/*!
* \brief Destructor
*/
~
BeBoard
()
{
for
(
auto
&
pModule
:
fModuleVector
)
delete
pModule
;
fModuleVector
.
clear
();
}
// Public Methods
/*!
* \brief acceptor method for HwDescriptionVisitor
* \param pVisitor
*/
void
accept
(
HwDescriptionVisitor
&
pVisitor
)
{
pVisitor
.
visit
(
*
this
);
for
(
auto
&
cFe
:
fModuleVector
)
cFe
->
accept
(
pVisitor
);
}
// void accept( HwDescriptionVisitor& pVisitor ) const {
// pVisitor.visit( *this );
// for ( auto& cFe : fModuleVector )
// cFe.accept( pVisitor );
// }
/*!
* \brief Get the number of modules connected to the BeBoard
* \return The size of the vector
*/
uint8_t
getNFe
()
const
{
return
fModuleVector
.
size
();
}
/*!
* \brief Get any register from the Map
* \param pReg
* \return The value of the register
*/
uint32_t
getReg
(
const
std
::
string
&
pReg
)
const
;
/*!
* \brief Set any register of the Map, if the register is not on the map, it adds it.
* \param pReg
* \param psetValue
*/
void
setReg
(
const
std
::
string
&
pReg
,
uint32_t
psetValue
);
/*!
* \brief Adding a module to the vector
* \param pModule
*/
void
addModule
(
Module
&
pModule
)
{
fModuleVector
.
push_back
(
&
pModule
);
}
void
addModule
(
Module
*
pModule
)
{
fModuleVector
.
push_back
(
pModule
);
}
/*!
* \brief Remove a Module from the vector
* \param pModuleId
* \return a bool which indicate if the removing was successful
*/
bool
removeModule
(
uint8_t
pModuleId
);
/*!
* \brief Get a module from the vector
* \param pModuleId
* \return a pointer of module, so we can manipulate directly the module contained in the vector
*/
Module
*
getModule
(
uint8_t
pModuleId
)
const
;
/*!
* \brief Get the Map of the registers
* \return The map of register
*/
BeBoardRegMap
getBeBoardRegMap
()
const
{
return
fRegMap
;
}
/*!
* \brief Get the BeBoardId of the BeBoard
* \return the BeBoard Id
*/
uint8_t
getBeId
()
const
{
return
fBeId
;
}
/*!
* \brief Get the BeBoardIdentifier
* \return The BeBoardIdentifier
*/
uint32_t
getBeBoardIdentifier
()
const
{
return
fBeId
<<
8
;
}
/*!
* \brief Set the Be Id of the BeBoard
* \param pBeId
*/
void
setBeId
(
uint8_t
pBeId
)
{
fBeId
=
pBeId
;
};
/*!
* \brief Set the Number of CBCs that are used to compute the data blob size of the BeBoard (according to FW version)
* \param pNCbcDataSize
*/
void
setNCbcDataSize
(
uint16_t
pNCbcDataSize
)
{
fNCbcDataSize
=
pNCbcDataSize
;
};
/*!
* \brief Get the Number of CBCs that are used to compute the data blob size of the BeBoard (according to FW version)
*/
uint16_t
getNCbcDataSize
()
const
{
return
fNCbcDataSize
;
};
void
setBoardType
(
const
std
::
string
&
pBoardType
)
{
fBoardType
=
pBoardType
;
namespace
Ph2_HwDescription
{
using
BeBoardRegMap
=
std
::
map
<
std
::
string
,
uint32_t
>
;
/*!< Map containing the registers of a board */
/*!
* \class BeBoard
* \brief Read/Write BeBoard's registers on a file, handles a register map and handles a vector of Module which are connected to the BeBoard
*/
class
BeBoard
{
public:
// C'tors: the BeBoard only needs to know about which BE it is
/*!
* \brief Default C'tor
*/
BeBoard
();
/*!
* \brief Standard C'tor
* \param pBeId
*/
BeBoard
(
uint8_t
pBeId
);
/*!
* \brief C'tor for a standard BeBoard reading a config file
* \param pBeId
* \param filename of the configuration file
*/
BeBoard
(
uint8_t
pBeId
,
const
std
::
string
&
filename
);
/*!
* \brief Destructor
*/
~
BeBoard
()
{
for
(
auto
&
pModule
:
fModuleVector
)
delete
pModule
;
fModuleVector
.
clear
();
}
std
::
string
getBoardType
()
const
{
return
fBoardType
;
// Public Methods
/*!
* \brief acceptor method for HwDescriptionVisitor
* \param pVisitor
*/
void
accept
(
HwDescriptionVisitor
&
pVisitor
)
{
pVisitor
.
visit
(
*
this
);
for
(
auto
&
cFe
:
fModuleVector
)
cFe
->
accept
(
pVisitor
);
}
// void accept( HwDescriptionVisitor& pVisitor ) const {
// pVisitor.visit( *this );
// for ( auto& cFe : fModuleVector )
// cFe.accept( pVisitor );
// }
/*!
* \brief Get the number of modules connected to the BeBoard
* \return The size of the vector
*/
uint8_t
getNFe
()
const
{
return
fModuleVector
.
size
();
}
/*!
* \brief Get any register from the Map
* \param pReg
* \return The value of the register
*/
uint32_t
getReg
(
const
std
::
string
&
pReg
)
const
;
/*!
* \brief Set any register of the Map, if the register is not on the map, it adds it.
* \param pReg
* \param psetValue
*/
void
setReg
(
const
std
::
string
&
pReg
,
uint32_t
psetValue
);
/*!
* \brief Adding a module to the vector
* \param pModule
*/
void
addModule
(
Module
&
pModule
)
{
fModuleVector
.
push_back
(
&
pModule
);
}
void
addModule
(
Module
*
pModule
)
{
fModuleVector
.
push_back
(
pModule
);
}
/*!
* \brief Remove a Module from the vector
* \param pModuleId
* \return a bool which indicate if the removing was successful
*/
bool
removeModule
(
uint8_t
pModuleId
);
/*!
* \brief Get a module from the vector
* \param pModuleId
* \return a pointer of module, so we can manipulate directly the module contained in the vector
*/
Module
*
getModule
(
uint8_t
pModuleId
)
const
;
/*!
* \brief Get the Map of the registers
* \return The map of register
*/
BeBoardRegMap
getBeBoardRegMap
()
const
{
return
fRegMap
;
}
/*!
* \brief Get the BeBoardId of the BeBoard
* \return the BeBoard Id
*/
uint8_t
getBeId
()
const
{
return
fBeId
;
}
/*!
* \brief Get the BeBoardIdentifier
* \return The BeBoardIdentifier
*/
uint32_t
getBeBoardIdentifier
()
const
{
return
fBeId
<<
8
;
}
/*!
* \brief Set the Be Id of the BeBoard
* \param pBeId
*/
void
setBeId
(
uint8_t
pBeId
)
{
fBeId
=
pBeId
;
};
/*!
* \brief Set the Number of CBCs that are used to compute the data blob size of the BeBoard (according to FW version)
* \param pNCbcDataSize
*/
void
setNCbcDataSize
(
uint16_t
pNCbcDataSize
)
{
fNCbcDataSize
=
pNCbcDataSize
;
};
/*!
* \brief Get the Number of CBCs that are used to compute the data blob size of the BeBoard (according to FW version)
*/
uint16_t
getNCbcDataSize
()
const
{
return
fNCbcDataSize
;
};
void
setBoardType
(
const
std
::
string
&
pBoardType
)
{
fBoardType
=
pBoardType
;
}
std
::
string
getBoardType
()
const
{
return
fBoardType
;
}
// Vector of FEModules, each module is supposed to know which FMC slot it is connected to...
std
::
vector
<
Module
*
>
fModuleVector
;
// Vector of FEModules, each module is supposed to know which FMC slot it is connected to...
std
::
vector
<
Module
*
>
fModuleVector
;
protected:
//Connection Members
uint8_t
fBeId
;
uint16_t
fNCbcDataSize
;
protected:
//Connection Members
uint8_t
fBeId
;
uint16_t
fNCbcDataSize
;
std
::
string
fBoardType
;
BeBoardRegMap
fRegMap
;
/*!< Map of BeBoard Register Names vs. Register Values */
BeBoardRegMap
fRegMap
;
/*!< Map of BeBoard Register Names vs. Register Values */
private:
private:
/*!
* \brief Load RegMap from a file
* \param filename
*/
void
loadConfigFile
(
const
std
::
string
&
filename
);
};
/*!
* \brief Load RegMap from a file
* \param filename
*/
void
loadConfigFile
(
const
std
::
string
&
filename
);
};
}
#endif
HWDescription/Cbc.cc
View file @
0d89568b
...
...
@@ -19,167 +19,176 @@
#include "Definition.h"
namespace
Ph2_HwDescription
{
// C'tors with object FE Description
Cbc
::
Cbc
(
const
FrontEndDescription
&
pFeDesc
,
uint8_t
pCbcId
,
const
std
::
string
&
filename
)
:
FrontEndDescription
(
pFeDesc
),
fCbcId
(
pCbcId
)
namespace
Ph2_HwDescription
{
// C'tors with object FE Description
{
loadfRegMap
(
filename
);
}
Cbc
::
Cbc
(
const
FrontEndDescription
&
pFeDesc
,
uint8_t
pCbcId
,
const
std
::
string
&
filename
)
:
FrontEndDescription
(
pFeDesc
),
fCbcId
(
pCbcId
)
// C'tors which take BeId, FMCId, FeID, CbcId
{
loadfRegMap
(
filename
);