ATLAS Offline Software
Loading...
Searching...
No Matches
ItemMap.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3*/
4
5// local includes
6#include "./ItemMap.h"
7
8// TrigT1 configuration includes
11
12
13// random number generator
14#include "CLHEP/Random/RandomEngine.h"
15#include "CLHEP/Random/RandFlat.h"
16
17#include "boost/algorithm/string.hpp"
18#include <boost/tokenizer.hpp>
19#include <charconv>
20#include <string_view>
21
23{
24 for( const TrigConf::L1Item & item : *l1menu ) {
25 const std::string & itemName( item.name() );
26
27 // get postion from ctp id
28 unsigned int ctpId = item.ctpId();
29
30 CTPTriggerItem * ctpItem = new CTPTriggerItem();
31 ctpItem->setPrescale( 1 );
32 ctpItem->setCtpId( ctpId );
33 ctpItem->setName(itemName);
34 ctpItem->setLogic(item.definition());
35 ctpItem->setTriggerType(item.triggerTypeAsUChar());
36 ctpItem->setBunchGroups(item.bunchgroups());
37
38 m_map[ itemName ] = ctpItem;
39 m_itemNames.insert( itemName );
40
41 }
42}
43
44
46 for( auto & entry : m_map ) {
47 delete entry.second;
48 }
49}
50
51
53 const TrigConf::PrescaleSet& prescales )
54{
55 for( const TrigConf::TriggerItem * item : item_vector ) {
56
57 std::string definition = getDefinition(item);
58
59 const std::string & itemName( item->name() );
60
61 // get postion from ctp id
62 unsigned int ctpId = item->ctpId();
63
64 CTPTriggerItem * ctpItem = new CTPTriggerItem();
65 ctpItem->setPrescale( prescales.prescales_float()[ ctpId ] );
66 ctpItem->setCtpId( ctpId );
67 ctpItem->setName(itemName);
68 ctpItem->setLogic(definition);
69 ctpItem->setTriggerType(item->triggerType());
70
71 m_map[ itemName ] = ctpItem;
72 m_itemNames.insert( itemName );
73 }
74}
75
76
77/*
78 e.g for the item L1_EM15VHI_2TAU12IM_J25_3J12
79 the definition that is stored in COOL is (1&2&3&4&5&6)
80 and the list of thresholds is 1,EM15VHI_x1,EM15VHI 2,HA12IM_x2,HA12IM 1,J25_x1,J25 3,J12_x3,J12 BGRP0 BGRP1
81
82 In this function this information is used to create a definition string
83 "(EM15VHI[x1]&HA12IM[x2]&J25[x1]&J12[x3]&BGRP0&BGRP1)"
84*/
85std::string
87
88
89 std::vector<std::string> thresholdlist;
90 std::string logic, conditions;
91 item->buildLogic(logic, thresholdlist); // get's the list of thresholds, e.g. 1,EM15VHI_x1,EM15VHI 2,HA12IM_x2,HA12IM 1,J25_x1,J25 3,J12_x3,J12 BGRP0 BGRP1
92
93 std::map<unsigned int, std::string> thrNames;
94 size_t idx = 1;
95 for(const std::string & thrmult : thresholdlist) {
96 std::vector<std::string> res;
97 boost::split(res, thrmult, boost::is_any_of(",")); // split 1,EM15VHI_x1,EM15VHI into multiplicity,name_mult, and name
98
99 std::string name_mult("");
100 if(res.size() == 1) {
101 name_mult=res[0]; // for thresholds without multiplicity requirement like RNDM0 or BGRP0,...
102 } else {
103 name_mult = res[2]+"[x"+res[0]+"]"; // build "EM15VHI[x1]"
104 }
105 thrNames[idx++] = std::move(name_mult);
106 }
107
108 // now take the logic (1&2&3&4&5&6) apart and replace the numbers with names "thr[xmult]"
109 std::string def = item->definition();
110 std::vector<std::string> tokens;
111 // build tokens with separators ()&|! and <space>. Keeps all separators except <space> in the list of tokens
112 for ( auto & tok : boost::tokenizer<boost::char_separator<char> > (item->definition(), boost::char_separator<char>(" ", "()&|!")) ) {
113 int n;
114 auto [ptr, ec] = std::from_chars(tok.data(), tok.data() + tok.size(), n);
115 if (ec == std::errc()) {
116 tokens.emplace_back(thrNames[n]);//AV: Note that this might be out of bounds
117 } else {
118 tokens.emplace_back(tok);
119 }
120 }
121
122 // and reassemble the logic definition string
123 std::string definition("");
124 for( auto & tok : tokens ) {
125 definition += tok;
126 }
127
128 return definition;
129}
std::pair< std::vector< unsigned int >, bool > res
Class storing information helping to make the CTP decision.
void setPrescale(int prescale)
void setBunchGroups(const std::vector< std::string > &bunchGroups)
void setCtpId(unsigned int ctpid)
void setName(const std::string &name)
void setLogic(const std::string &logicExpr)
void setTriggerType(unsigned char triggerType)
std::set< std::string > m_itemNames
Definition ItemMap.h:65
~ItemMap()
default destructor
Definition ItemMap.cxx:45
ItemMap(const TrigConf::L1Menu *l1menu)
Definition ItemMap.cxx:22
std::string getDefinition(const TrigConf::TriggerItem *item) const
Definition ItemMap.cxx:86
std::map< std::string, const CTPTriggerItem * > m_map
map from item name to CTPTriggerItem
Definition ItemMap.h:63
L1 threshold configuration.
Definition L1Item.h:18
L1 menu configuration.
Definition L1Menu.h:28
boost::multi_index::multi_index_container< TriggerItem *, boost::multi_index::indexed_by< boost::multi_index::random_access<>, boost::multi_index::ordered_unique< boost::multi_index::identity< TriggerItem > >, boost::multi_index::ordered_unique< boost::multi_index::tag< tag_ctpid >, boost::multi_index::const_mem_fun< TriggerItem, int, &TriggerItem::ctpId > >, boost::multi_index::hashed_unique< boost::multi_index::tag< tag_name_hash >, boost::multi_index::const_mem_fun< TrigConfData, const std::string &, &TrigConfData::name > > > > ItemContainer
Definition Menu.h:39