Skip to content

Commit

Permalink
add BX info to GlobalObjectMap (L1uGT emulation)
Browse files Browse the repository at this point in the history
  • Loading branch information
missirol committed Dec 28, 2024
1 parent 5db9511 commit 052da05
Show file tree
Hide file tree
Showing 25 changed files with 865 additions and 930 deletions.
74 changes: 54 additions & 20 deletions DataFormats/L1TGlobal/interface/GlobalObjectMap.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef L1GlobalTrigger_L1TGtObjectMap_h
#define L1GlobalTrigger_L1TGtObjectMap_h
#ifndef DataFormats_L1TGlobal_GlobalObjectMap_h
#define DataFormats_L1TGlobal_GlobalObjectMap_h

/**
* \class GlobalObjectMap
Expand All @@ -15,28 +15,17 @@
*
*/

// system include files
#include <string>
#include <vector>

#include <iosfwd>

// user include files
#include "DataFormats/L1TGlobal/interface/GlobalObjectMapFwd.h"

#include "DataFormats/L1TGlobal/interface/GlobalLogicParser.h"

// forward declarations

// class declaration
class GlobalObjectMap {
public:
/// constructor(s)
GlobalObjectMap() {}

/// destructor
//~GlobalObjectMap(){}

public:
/// get / set name for algorithm in the object map
inline const std::string& algoName() const { return m_algoName; }
Expand All @@ -56,13 +45,47 @@ class GlobalObjectMap {

/// get / set the vector of combinations for the algorithm
/// return a constant reference to the vector of combinations for the algorithm
inline const std::vector<CombinationsBxInCond>& combinationBxVector() const { return m_combinationBxVector; }
inline const std::vector<CombinationsInCond>& combinationVector() const { return m_combinationVector; }

void setCombinationVector(const std::vector<CombinationsInCond>& combinationVectorValue) {
m_combinationVector = combinationVectorValue;
void clearCombinationVectors() {
m_combinationBxVector.clear();
m_combinationVector.clear();
}
void swapCombinationVector(std::vector<CombinationsInCond>& combinationVectorValue) {
m_combinationVector.swap(combinationVectorValue);

void reserveCombinationVectors(size_t const size) {
m_combinationBxVector.reserve(size);
m_combinationVector.reserve(size);
}

void appendToCombinationVectors(CombinationsWithBxInCond const& c0) {
CombinationsBxInCond a1;
a1.reserve(c0.size());
CombinationsInCond b1;
b1.reserve(c0.size());
for (auto const& c1 : c0) {
SingleCombBxInCond a2;
a2.reserve(c1.size());
SingleCombInCond b2;
b2.reserve(c1.size());
for (auto const& c2 : c1) {
a2.emplace_back(c2.first);
b2.emplace_back(c2.second);
}
a1.emplace_back(a2);
b1.emplace_back(b2);
}

m_combinationBxVector.emplace_back(a1);
m_combinationVector.emplace_back(b1);
}

void setCombinationVectors(std::vector<CombinationsWithBxInCond> const& combinationWithBxInCondVector) {
clearCombinationVectors();
reserveCombinationVectors(combinationWithBxInCondVector.size());
for (auto const& foo : combinationWithBxInCondVector) {
appendToCombinationVectors(foo);
}
}

/// get / set the vector of operand tokens
Expand All @@ -79,6 +102,7 @@ class GlobalObjectMap {
/// get / set the vector of object types
/// return a constant reference to the vector of operand tokens
inline const std::vector<L1TObjectTypeInCond>& objectTypeVector() const { return m_objectTypeVector; }

void setObjectTypeVector(const std::vector<L1TObjectTypeInCond>& objectTypeVectorValue) {
m_objectTypeVector = objectTypeVectorValue;
}
Expand All @@ -87,15 +111,24 @@ class GlobalObjectMap {
}

public:
/// return all the combinations passing the requirements imposed in condition condNameVal
/// return the bx values of all the combinations passing the requirements imposed in condition condNameVal
const CombinationsBxInCond* getCombinationsBxInCond(const std::string& condNameVal) const;

/// return the bx values of all the combinations passing the requirements imposed in condition condNumberVal
const CombinationsBxInCond* getCombinationsBxInCond(const int condNumberVal) const;

/// return the indices of all the combinations passing the requirements imposed in condition condNameVal
const CombinationsInCond* getCombinationsInCond(const std::string& condNameVal) const;

/// return all the combinations passing the requirements imposed in condition condNumberVal
/// return the indices of all the combinations passing the requirements imposed in condition condNumberVal
const CombinationsInCond* getCombinationsInCond(const int condNumberVal) const;

/// return the result for the condition condNameVal
const bool getConditionResult(const std::string& condNameVal) const;

/// check whether or not m_combinationBxVector is empty
bool hasBxInfo() const { return (not m_combinationBxVector.empty()); }

public:
/// reset the object map
void reset();
Expand All @@ -118,10 +151,11 @@ class GlobalObjectMap {
std::vector<GlobalLogicParser::OperandToken> m_operandTokenVector;

// vector of combinations for all conditions in an algorithm
std::vector<CombinationsBxInCond> m_combinationBxVector;
std::vector<CombinationsInCond> m_combinationVector;

// vector of object type vectors for all conditions in an algorithm
std::vector<L1TObjectTypeInCond> m_objectTypeVector;
};

#endif /* L1GlobalTrigger_L1TGtObjectMap_h */
#endif
28 changes: 21 additions & 7 deletions DataFormats/L1TGlobal/interface/GlobalObjectMapFwd.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef L1GlobalTrigger_L1TGtObjectMapFwd_h
#define L1GlobalTrigger_L1TGtObjectMapFwd_h
#ifndef DataFormats_L1TGlobal_L1TGtObjectMapFwd_h
#define DataFormats_L1TGlobal_L1TGtObjectMapFwd_h

/**
* \class GlobalObjectMap
* \class GlobalObjectMapFwd
*
*
* Description: group typedefs used by GlobalObjectMap.
Expand All @@ -16,6 +16,7 @@
*/

// system include files
#include <utility>
#include <vector>

// user include files
Expand All @@ -24,14 +25,27 @@
// forward declarations

/// typedefs
typedef int16_t L1TObjBxIndexType;
typedef int L1TObjIndexType;

/// list of object BX values corresponding to a condition evaluated to true
typedef std::vector<L1TObjBxIndexType> SingleCombBxInCond;

/// list of object indices corresponding to a condition evaluated to true
typedef std::vector<int> SingleCombInCond;
typedef std::vector<L1TObjIndexType> SingleCombInCond;

/// list of object indices:bx pairs corresponding to a condition evaluated to true
typedef std::vector<std::pair<L1TObjBxIndexType, L1TObjIndexType>> SingleCombWithBxInCond;

/// all the object combinations evaluated to true in the condition
/// all the object combinations evaluated to true in the condition (object BX indices)
typedef std::vector<SingleCombBxInCond> CombinationsBxInCond;

/// all the object combinations evaluated to true in the condition (object indices)
typedef std::vector<SingleCombInCond> CombinationsInCond;

/// all the object combinations evaluated to true in the condition (object indices + BX indices)
typedef std::vector<SingleCombWithBxInCond> CombinationsWithBxInCond;

typedef std::vector<l1t::GlobalObject> L1TObjectTypeInCond;
//typedef std::vector<int> ObjectTypeInCond;

#endif /* L1GlobalTrigger_L1TGtObjectMapFwd_h */
#endif
85 changes: 52 additions & 33 deletions DataFormats/L1TGlobal/src/GlobalObjectMap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,47 @@
*
*/

// this class header
#include "DataFormats/L1TGlobal/interface/GlobalObjectMap.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"

// system include files
#include <iostream>
#include <iomanip>
#include <iterator>

#include <algorithm>

// user include files
#include "FWCore/MessageLogger/interface/MessageLogger.h"
/// return the bx values of all the combinations passing the requirements imposed in condition condNameVal
const CombinationsBxInCond* GlobalObjectMap::getCombinationsBxInCond(const std::string& condNameVal) const {
for (size_t i = 0; i < m_operandTokenVector.size(); ++i) {
if ((m_operandTokenVector[i]).tokenName == condNameVal) {
return &(m_combinationBxVector.at((m_operandTokenVector[i]).tokenNumber));
}
}

// forward declarations
// return a null address - should not arrive here
edm::LogError("GlobalObjectMap") << "\n\n ERROR: The requested condition with tokenName = " << condNameVal
<< "\n does not exists in the operand token vector."
<< "\n Returning zero pointer for getCombinationsBxInCond\n\n";

// methods
return nullptr;
}

// return all the combinations passing the requirements imposed in condition condNameVal
/// return the bx values of all the combinations passing the requirements imposed in condition condNumberVal
const CombinationsBxInCond* GlobalObjectMap::getCombinationsBxInCond(const int condNumberVal) const {
for (size_t i = 0; i < m_operandTokenVector.size(); ++i) {
if ((m_operandTokenVector[i]).tokenNumber == condNumberVal) {
return &(m_combinationBxVector.at((m_operandTokenVector[i]).tokenNumber));
}
}

// return a null address - should not arrive here
edm::LogError("GlobalObjectMap") << "\n\n ERROR: The requested condition with tokenNumber = " << condNumberVal
<< "\n does not exists in the operand token vector."
<< "\n Returning zero pointer for getCombinationsBxInCond\n\n";

return nullptr;
}

/// return the indices of all the combinations passing the requirements imposed in condition condNameVal
const CombinationsInCond* GlobalObjectMap::getCombinationsInCond(const std::string& condNameVal) const {
for (size_t i = 0; i < m_operandTokenVector.size(); ++i) {
if ((m_operandTokenVector[i]).tokenName == condNameVal) {
Expand All @@ -40,13 +63,12 @@ const CombinationsInCond* GlobalObjectMap::getCombinationsInCond(const std::stri
// return a null address - should not arrive here
edm::LogError("GlobalObjectMap") << "\n\n ERROR: The requested condition with tokenName = " << condNameVal
<< "\n does not exists in the operand token vector."
<< "\n Returning zero pointer for getCombinationsInCond\n\n"
<< std::endl;
<< "\n Returning zero pointer for getCombinationsInCond\n\n";

return nullptr;
}

/// return all the combinations passing the requirements imposed in condition condNumberVal
/// return the indices of all the combinations passing the requirements imposed in condition condNumberVal
const CombinationsInCond* GlobalObjectMap::getCombinationsInCond(const int condNumberVal) const {
for (size_t i = 0; i < m_operandTokenVector.size(); ++i) {
if ((m_operandTokenVector[i]).tokenNumber == condNumberVal) {
Expand All @@ -57,12 +79,12 @@ const CombinationsInCond* GlobalObjectMap::getCombinationsInCond(const int condN
// return a null address - should not arrive here
edm::LogError("GlobalObjectMap") << "\n\n ERROR: The requested condition with tokenNumber = " << condNumberVal
<< "\n does not exists in the operand token vector."
<< "\n Returning zero pointer for getCombinationsInCond\n\n"
<< std::endl;
<< "\n Returning zero pointer for getCombinationsInCond\n\n";

return nullptr;
}
// return the result for the condition condNameVal

/// return the result for the condition condNameVal
const bool GlobalObjectMap::getConditionResult(const std::string& condNameVal) const {
for (size_t i = 0; i < m_operandTokenVector.size(); ++i) {
if ((m_operandTokenVector[i]).tokenName == condNameVal) {
Expand All @@ -73,8 +95,8 @@ const bool GlobalObjectMap::getConditionResult(const std::string& condNameVal) c
// return false - should not arrive here
edm::LogError("GlobalObjectMap") << "\n\n ERROR: The requested condition with name = " << condNameVal
<< "\n does not exists in the operand token vector."
<< "\n Returning false for getConditionResult\n\n"
<< std::endl;
<< "\n Returning false for getConditionResult\n\n";

return false;
}

Expand All @@ -91,8 +113,8 @@ void GlobalObjectMap::reset() {
// vector of operand tokens for an algorithm
m_operandTokenVector.clear();

// vector of combinations for all conditions in an algorithm
m_combinationVector.clear();
// vectors of bx/index combinations for all conditions in an algorithm
clearCombinationVectors();
}

void GlobalObjectMap::print(std::ostream& myCout) const {
Expand All @@ -117,35 +139,32 @@ void GlobalObjectMap::print(std::ostream& myCout) const {
}
}

myCout << " CombinationBxVector size: " << m_combinationBxVector.size() << std::endl;
myCout << " CombinationVector size: " << m_combinationVector.size() << std::endl;

myCout << " conditions: " << std::endl;

std::vector<CombinationsInCond>::const_iterator itVVV;
int iCond = 0;
for (itVVV = m_combinationVector.begin(); itVVV != m_combinationVector.end(); itVVV++) {
std::string condName = (m_operandTokenVector[iCond]).tokenName;
bool condResult = (m_operandTokenVector[iCond]).tokenResult;

for (size_t i1 = 0; i1 < m_combinationVector.size(); ++i1) {
auto const condName = (m_operandTokenVector[i1]).tokenName;
auto const condResult = (m_operandTokenVector[i1]).tokenResult;
myCout << " Condition " << condName << " evaluated to " << condResult << std::endl;

myCout << " List of combinations passing all requirements for this condition:" << std::endl;

myCout << " ";

if ((*itVVV).empty()) {
if (m_combinationVector[i1].empty()) {
myCout << "(none)";
} else {
CombinationsInCond::const_iterator itVV;
for (itVV = (*itVVV).begin(); itVV != (*itVVV).end(); itVV++) {
for (size_t i2 = 0; i2 < m_combinationVector[i1].size(); ++i2) {
myCout << "( ";

std::copy((*itVV).begin(), (*itVV).end(), std::ostream_iterator<int>(myCout, " "));

for (size_t i3 = 0; i3 < m_combinationVector[i1][i2].size(); ++i3) {
if (hasBxInfo()) {
myCout << m_combinationBxVector[i1][i2][i3] << ":";
}
myCout << m_combinationVector[i1][i2][i3] << " ";
}
myCout << "); ";
}
}
iCond++;
myCout << "\n\n";
}
}
3 changes: 2 additions & 1 deletion DataFormats/L1TGlobal/src/classes_def.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
</class>
<class name="edm::Wrapper<GlobalObjectMapRecord>"/>

<class name="GlobalObjectMap" ClassVersion="10">
<class name="GlobalObjectMap" ClassVersion="11">
<version ClassVersion="11" checksum="1430016230"/>
<version ClassVersion="10" checksum="1899280385"/>
</class>
<class name="edm::Wrapper<GlobalObjectMap>"/>
Expand Down
16 changes: 10 additions & 6 deletions DataFormats/L1TGlobal/test/TestGlobalObjectMapRecordFormat.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ function die { echo $1: status $2 ; exit $2; }

LOCAL_TEST_DIR=${SCRAM_TEST_PATH}

cmsRun ${LOCAL_TEST_DIR}/create_GlobalObjectMapRecord_test_file_cfg.py || die 'Failure using create_GlobalObjectMapRecord_test_file_cfg.py' $?

file=testGlobalObjectMapRecord.root

cmsRun ${LOCAL_TEST_DIR}/test_readGlobalObjectMapRecord_cfg.py "$file" || die "Failure using test_readGlobalObjectMapRecord_cfg.py $file" $?
tmpfile=testGlobalObjectMapRecord.root
cmsRun ${LOCAL_TEST_DIR}/create_GlobalObjectMapRecord_test_file_cfg.py --outputFileName "${tmpfile}" || die 'Failure using create_GlobalObjectMapRecord_test_file_cfg.py' $?
cmsRun ${LOCAL_TEST_DIR}/test_readGlobalObjectMapRecord_cfg.py --inputFileName "${tmpfile}" --globalObjectMapClassVersion 11 || die "Failure using test_readGlobalObjectMapRecord_cfg.py ${tmpfile}" $?

# The old files read below were generated as follows.
#
Expand All @@ -28,7 +26,13 @@ oldFiles="testGlobalObjectMapRecord_CMSSW_13_0_0_split_99.root testGlobalObjectM
oldFiles+=" testGlobalObjectMapRecord_CMSSW_13_1_0_pre3_split_99.root testGlobalObjectMapRecord_CMSSW_13_1_0_pre3_split_0.root"
for file in $oldFiles; do
inputfile=$(edmFileInPath DataFormats/L1TGlobal/data/$file) || die "Failure edmFileInPath DataFormats/L1TGlobal/data/$file" $?
cmsRun ${LOCAL_TEST_DIR}/test_readGlobalObjectMapRecord_cfg.py "$inputfile" || die "Failed to read old file $file" $?
cmsRun ${LOCAL_TEST_DIR}/test_readGlobalObjectMapRecord_cfg.py --inputFileName "$inputfile" --globalObjectMapClassVersion 10 || die "Failed to read old file $file" $?
done

#oldFiles="testGlobalObjectMapRecord_CMSSW_15_0_0_pre2_split_99.root testGlobalObjectMapRecord_CMSSW_15_0_0_pre2_split_0.root"
#for file in $oldFiles; do
# inputfile=$(edmFileInPath DataFormats/L1TGlobal/data/$file) || die "Failure edmFileInPath DataFormats/L1TGlobal/data/$file" $?
# cmsRun ${LOCAL_TEST_DIR}/test_readGlobalObjectMapRecord_cfg.py --inputFileName "$inputfile" --globalObjectMapClassVersion 11 || die "Failed to read old file $file" $?
#done

exit 0
Loading

0 comments on commit 052da05

Please sign in to comment.