28 edm::FileInPath f1(
"L1Trigger/L1TGlobal/data/Luminosity/startup/prescale_L1TGlobal.csv");
62 m_preScaleFileName =
f1.fullPath();
69 retrieveL1Setup(evSetup, isRun);
71 retrieveL1Event(
iEvent, evSetup);
79 retrieveL1Setup(evSetup, isRun);
81 retrieveL1Event(
iEvent, evSetup, gtAlgToken);
86 retrieveL1Setup(evSetup, isRun);
95 if (m_l1GtMenuCacheID != l1GtMenuCacheID) {
97 m_l1GtMenu = &menuRcd.get(m_L1TUtmTriggerMenuRunToken);
99 m_l1GtMenu = &menuRcd.get(m_L1TUtmTriggerMenuEventToken);
103 m_algorithmMap = &(m_l1GtMenu->getAlgorithmMap());
106 resetDecisionVectors();
108 m_l1GtMenuCacheID = l1GtMenuCacheID;
111 if (!m_readPrescalesFromFile) {
115 if (m_l1GtPfAlgoCacheID != l1GtPfAlgoCacheID) {
119 resetPrescaleVectors();
121 m_PreScaleColumn = 0;
122 m_numberOfPreScaleColumns = 0;
123 m_numberPhysTriggers = 0;
127 es = &vetosRcd.get(m_L1TGlobalPrescalesVetosFractRunToken);
129 es = &vetosRcd.get(m_L1TGlobalPrescalesVetosFractEventToken);
133 m_prescaleFactorsAlgoTrig = &(m_l1GtPrescalesVetoes->prescaleTable());
134 m_numberOfPreScaleColumns = m_prescaleFactorsAlgoTrig->size();
135 m_numberPhysTriggers =
136 (*m_prescaleFactorsAlgoTrig)[0].size();
138 m_triggerMaskAlgoTrig = &(m_l1GtPrescalesVetoes->triggerAlgoBxMask());
140 m_l1GtPfAlgoCacheID = l1GtPfAlgoCacheID;
145 if (!m_filledPrescales) {
146 resetPrescaleVectors();
149 loadPrescalesAndMasks();
152 m_prescaleFactorsAlgoTrig = &m_initialPrescaleFactorsAlgoTrig;
153 m_triggerMaskAlgoTrig = &m_initialTriggerMaskAlgoTrig;
154 m_filledPrescales =
true;
159 if (m_PreScaleColumn > m_prescaleFactorsAlgoTrig->size()) {
160 LogTrace(
"l1t|Global") <<
"\nNo Prescale Set: " << m_PreScaleColumn
161 <<
"\nMax Prescale Set value : " << m_prescaleFactorsAlgoTrig->size()
162 <<
"\nSetting prescale column to 0" << std::endl;
163 m_PreScaleColumn = 0;
166 const std::vector<double>& prescaleSet = (*m_prescaleFactorsAlgoTrig)[m_PreScaleColumn];
168 for (std::map<std::string, L1TUtmAlgorithm>::const_iterator itAlgo = m_algorithmMap->begin();
169 itAlgo != m_algorithmMap->end();
173 int algBit = (itAlgo->second).getIndex();
175 (m_prescales[algBit]).
first = algName;
176 if (
size_t(algBit) < prescaleSet.size()) {
177 (m_prescales[algBit]).
second = prescaleSet[algBit];
179 LogDebug(
"l1t|Global") <<
"Number of bunch crossings stored: " << (*m_triggerMaskAlgoTrig).size() << endl;
181 const std::map<int, std::vector<int> >* triggerAlgoMaskAlgoTrig = m_triggerMaskAlgoTrig;
182 std::map<int, std::vector<int> >::const_iterator it = triggerAlgoMaskAlgoTrig->begin();
184 std::vector<int> maskedBxs;
185 (m_masks[algBit]).
first = algName;
186 (m_masks[algBit]).
second = maskedBxs;
187 while (it != triggerAlgoMaskAlgoTrig->end()) {
188 std::vector<int> masks = it->second;
191 for (
unsigned int imask = 0; imask < masks.size(); imask++) {
192 if (masks.at(imask) == algBit)
193 maskedBxs.push_back(it->first);
200 if (!maskedBxs.empty()) {
201 LogDebug(
"l1t|Global") <<
"i Algo: " << algBit <<
"\t" << algName <<
" masked\n";
202 for (
unsigned int ibx = 0; ibx < maskedBxs.size(); ibx++) {
204 (m_masks[algBit]).
second = maskedBxs;
211 retrieveL1Event(
iEvent, evSetup, m_l1tGlobalUtilHelper->l1tAlgBlkToken());
218 iEvent.getByToken(gtAlgToken, m_uGtAlgBlk);
222 if (m_uGtAlgBlk.isValid()) {
224 std::vector<GlobalAlgBlk>::const_iterator algBlk = m_uGtAlgBlk->begin(0);
225 if (algBlk != m_uGtAlgBlk->end(0)) {
226 if (!m_readPrescalesFromFile) {
227 m_PreScaleColumn =
static_cast<unsigned int>(algBlk->getPreScColumn());
231 if (m_prescaleFactorsAlgoTrig->size() == 1 && m_PreScaleColumn == 1)
232 m_PreScaleColumn = 0;
236 if (m_PreScaleColumn >= m_prescaleFactorsAlgoTrig->size()) {
237 LogDebug(
"l1t|Global") <<
"Prescale column extracted from GlobalAlgBlk too large: " << m_PreScaleColumn
238 <<
"\tMaximum value allowed: " << m_prescaleFactorsAlgoTrig->size() - 1
239 <<
"\tResetting prescale column to 0" << std::endl;
240 m_PreScaleColumn = 0;
243 const std::vector<double>& prescaleSet = (*m_prescaleFactorsAlgoTrig)[m_PreScaleColumn];
246 m_finalOR = algBlk->getFinalOR();
250 for (std::map<std::string, L1TUtmAlgorithm>::const_iterator itAlgo = m_algorithmMap->begin();
251 itAlgo != m_algorithmMap->end();
255 int algBit = (itAlgo->second).getIndex();
257 bool decisionInitial = algBlk->getAlgoDecisionInitial(algBit);
258 (m_decisionsInitial[algBit]).
first = algName;
259 (m_decisionsInitial[algBit]).
second = decisionInitial;
261 bool decisionInterm = algBlk->getAlgoDecisionInterm(algBit);
262 (m_decisionsInterm[algBit]).
first = algName;
263 (m_decisionsInterm[algBit]).
second = decisionInterm;
265 bool decisionFinal = algBlk->getAlgoDecisionFinal(algBit);
266 (m_decisionsFinal[algBit]).
first = algName;
267 (m_decisionsFinal[algBit]).
second = decisionFinal;
269 (m_prescales[algBit]).
first = algName;
270 if (
size_t(algBit) < prescaleSet.size()) {
271 (m_prescales[algBit]).
second = prescaleSet[algBit];
283 std::ifstream inputPrescaleFile;
285 inputPrescaleFile.open(m_preScaleFileName);
287 std::vector<std::vector<int> > vec;
288 std::vector<std::vector<double> > prescale_vec;
290 if (inputPrescaleFile) {
298 while (getline(inputPrescaleFile,
line)) {
299 if (!
line.compare(0, prefix1.size(), prefix1))
311 vec.push_back(std::vector<int>());
326 int NumPrescaleSets = 0;
327 for (
int iCol = 0; iCol <
int(vec.size()); iCol++) {
328 if (!vec[iCol].
empty()) {
329 int firstRow = vec[iCol][0];
339 if (NumPrescaleSets > 0) {
341 for (
int iSet = 0; iSet < NumPrescaleSets; iSet++) {
342 prescale_vec.push_back(std::vector<double>());
343 for (
unsigned int iBit = 0; iBit < m_numberPhysTriggers; ++iBit) {
344 int inputDefaultPrescale = 1;
345 prescale_vec[iSet].push_back(inputDefaultPrescale);
350 for (
int iBit = 1; iBit <
int(vec[0].
size()); iBit++) {
351 unsigned int algoBit = vec[0][iBit];
353 if (algoBit < m_numberPhysTriggers) {
354 for (
int iSet = 0; iSet <
int(vec.size()); iSet++) {
356 if (!vec[iSet].
empty()) {
357 useSet = vec[iSet][0];
365 prescale_vec[useSet][algoBit] =
prescale;
368 LogTrace(
"l1t|Global") <<
"\nPrescale file has algo bit: " << algoBit
369 <<
"\nThis is larger than the number of triggers: " << m_numberPhysTriggers
370 <<
"\nSomething is wrong. Ignoring." << std::endl;
376 LogTrace(
"l1t|Global") <<
"\nCould not find file: " << m_preScaleFileName
377 <<
"\nFilling the prescale vectors with prescale 1" 378 <<
"\nSetting prescale set to 0" << std::endl;
380 m_PreScaleColumn = 0;
383 prescale_vec.push_back(std::vector<double>());
384 for (
unsigned int iBit = 0; iBit < m_numberPhysTriggers; ++iBit) {
385 int inputDefaultPrescale = 0;
386 prescale_vec[
col].push_back(inputDefaultPrescale);
391 inputPrescaleFile.close();
393 m_initialPrescaleFactorsAlgoTrig = prescale_vec;
395 std::map<int, std::vector<int> > m_initialTriggerMaskAlgoTrig;
401 if (!m_readPrescalesFromFile) {
402 m_L1TGlobalPrescalesVetosFractRunToken =
408 if (!m_readPrescalesFromFile) {
409 m_L1TGlobalPrescalesVetosFractEventToken =
417 m_decisionsInitial.clear();
418 m_decisionsInitial.resize(m_maxNumberPhysTriggers);
419 m_decisionsInterm.clear();
420 m_decisionsInterm.resize(m_maxNumberPhysTriggers);
421 m_decisionsFinal.clear();
422 m_decisionsFinal.resize(m_maxNumberPhysTriggers);
424 for (
unsigned int algBit = 0; algBit < m_maxNumberPhysTriggers; algBit++) {
425 (m_decisionsInitial[algBit]).
first =
"NULL";
426 (m_decisionsInitial[algBit]).
second =
false;
428 (m_decisionsInterm[algBit]).
first =
"NULL";
429 (m_decisionsInterm[algBit]).
second =
false;
431 (m_decisionsFinal[algBit]).
first =
"NULL";
432 (m_decisionsFinal[algBit]).
second =
false;
439 m_prescales.resize(m_maxNumberPhysTriggers);
441 for (
unsigned int algBit = 0; algBit < m_maxNumberPhysTriggers; algBit++) {
442 (m_prescales[algBit]).
first =
"NULL";
443 (m_prescales[algBit]).
second = 1;
450 m_masks.resize(m_maxNumberPhysTriggers);
452 for (
unsigned int algBit = 0; algBit < m_maxNumberPhysTriggers; algBit++) {
453 (m_masks[algBit]).
first =
"NULL";
459 std::map<std::string, L1TUtmAlgorithm>::const_iterator itAlgo = m_algorithmMap->find(algName);
460 if (itAlgo != m_algorithmMap->end()) {
461 bit = (itAlgo->second).getIndex();
470 if ((m_decisionsInitial[bit]).
first !=
"NULL") {
471 algName = (m_decisionsInitial[bit]).
first;
484 if ((m_decisionsInitial[bit]).
first !=
"NULL") {
485 decision = (m_decisionsInitial[bit]).
second;
493 if ((m_decisionsInterm[bit]).
first !=
"NULL") {
494 decision = (m_decisionsInterm[bit]).
second;
502 if ((m_decisionsFinal[bit]).
first !=
"NULL") {
503 decision = (m_decisionsFinal[bit]).
second;
511 if ((m_prescales[bit]).
first !=
"NULL") {
520 if ((m_masks[bit]).
first !=
"NULL") {
521 mask = (m_masks[bit]).
second;
530 if (getAlgBitFromName(algName, bit)) {
531 decision = (m_decisionsInitial[bit]).
second;
540 if (getAlgBitFromName(algName, bit)) {
541 decision = (m_decisionsInterm[bit]).
second;
550 if (getAlgBitFromName(algName, bit)) {
551 decision = (m_decisionsFinal[bit]).
second;
559 if (getAlgBitFromName(algName, bit)) {
568 if (getAlgBitFromName(algName, bit)) {
569 mask = (m_masks[bit]).
second;
std::string m_preScaleFileName
const bool getInitialDecisionByBit(int &bit, bool &decision) const
const bool getMaskByName(const std::string &algName, std::vector< int > &mask) const
void retrieveL1Event(const edm::Event &iEvent, const edm::EventSetup &evSetup)
const bool getAlgBitFromName(const std::string &AlgName, int &bit) const
unsigned long long m_l1GtPfAlgoCacheID
void OverridePrescalesAndMasks(std::string filename, unsigned int psColumn=1.)
static const PrescalesVetosFractHelper * readFromEventSetup(const L1TGlobalPrescalesVetosFract *es)
unsigned int m_PreScaleColumn
std::unique_ptr< L1TGlobalUtilHelper > m_l1tGlobalUtilHelper
void resetDecisionVectors()
clear decision vectors on a menu change
unsigned long long cacheIdentifier() const
const bool getIntermDecisionByBit(int &bit, bool &decision) const
U second(std::pair< T, U > const &p)
const std::map< int, std::vector< int > > * m_triggerMaskAlgoTrig
void eventSetupConsumes(edm::ConsumesCollector &iC, UseEventSetupIn useEventSetupIn)
const bool getFinalDecisionByBit(int &bit, bool &decision) const
const bool getInitialDecisionByName(const std::string &algName, bool &decision) const
bool m_readPrescalesFromFile
const std::vector< std::vector< double > > * m_prescaleFactorsAlgoTrig
def split(sequence, size)
const bool getPrescaleByName(const std::string &algName, double &prescale) const
unsigned long long m_l1GtMenuCacheID
bool valid() const
check that the L1TGlobalUtil has been properly initialised
const bool getIntermDecisionByName(const std::string &algName, bool &decision) const
void resetPrescaleVectors()
const bool getPrescaleByBit(int &bit, double &prescale) const
const bool getAlgNameFromBit(int &bit, std::string &AlgName) const
L1TGlobalPrescalesVetosFract
const bool getFinalDecisionByName(const std::string &algName, bool &decision) const
const bool getMaskByBit(int &bit, std::vector< int > &mask) const
virtual ~L1TGlobalUtil()
destructor
void retrieveL1Setup(const edm::EventSetup &evSetup)
void loadPrescalesAndMasks()
unsigned int m_numberPhysTriggers
void retrieveL1(const edm::Event &iEvent, const edm::EventSetup &evSetup)
initialize the class (mainly reserve)