8#include "CoolKernel/Record.h"
9#include "CoolKernel/IFolder.h"
10#include "CoralBase/Attribute.h"
11#include "CoralBase/AttributeList.h"
12#include "CoralBase/AttributeListException.h"
14#include "CTPfragment/CTPdataformatVersion.h"
38#include "boost/lexical_cast.hpp"
39#include <boost/algorithm/string.hpp>
41using boost::lexical_cast;
51 Record payload(fld->payloadSpecification());
52 payload[
"ItemName"].setValue<cool::String255>(item.name());
53 payload[
"ItemVersion"].setValue<cool::UInt32>(item.version());
60 Record payload(fld->payloadSpecification());
61 vector<string> thresholdlist;
62 string logic, conditions;
63 item.buildLogic(logic, thresholdlist);
64 vector<string>::iterator thrIt = thresholdlist.begin();
65 for(;thrIt!=thresholdlist.end();++thrIt) {
66 if(thrIt!=thresholdlist.begin()) conditions +=
";";
69 payload[
"Logic"].setValue<cool::String255>(logic);
70 payload[
"ConditionsList"].setValue<cool::String4k>(conditions);
77 Record payload(fld->payloadSpecification());
78 std::string thrValDef(
"");
79 for(std::vector<int>::const_iterator wIt = jetweights.begin(); wIt!=jetweights.end(); ++wIt) {
80 if(wIt != jetweights.begin()) thrValDef +=
",";
81 thrValDef += std::to_string(*wIt);
83 payload[
"Threshold"].setValue<cool::String255>(
"JetWeights");
84 payload[
"ThresholdValue"].setValue<cool::String4k>(thrValDef);
85 payload[
"Cable"].setValue<cool::String255>(
"");
92 Record payload(fld->payloadSpecification());
94 thrValDef += std::to_string(metSigParams.
xsSigmaScale()) +
",";
95 thrValDef += std::to_string(metSigParams.
xsSigmaOffset()) +
",";
96 thrValDef += std::to_string(metSigParams.
xeMin()) +
",";
97 thrValDef += std::to_string(metSigParams.
xeMax()) +
",";
98 thrValDef += std::to_string(metSigParams.
teSqrtMin()) +
",";
99 thrValDef += std::to_string(metSigParams.
teSqrtMax());
100 payload[
"Threshold"].setValue<cool::String255>(
"METSigParams");
101 payload[
"ThresholdValue"].setValue<cool::String4k>(thrValDef);
102 payload[
"Cable"].setValue<cool::String255>(
"");
109 Record payload(fld->payloadSpecification());
112 thrDef += thr.name(); thrDef +=
",";
113 thrDef += std::to_string(thr.version()); thrDef +=
",";
114 thrDef += thr.type(); thrDef +=
",";
115 thrDef += std::to_string(thr.mapping()); thrDef +=
",";
116 thrDef += lexical_cast<std::string,bool>(thr.active());
120 string thrValDef(
"");
121 vector<TriggerThresholdValue*>::const_iterator thrValIt = thr.thresholdValueVector().begin();
122 vector<TriggerThresholdValue*>::const_iterator thrValEnd = thr.thresholdValueVector().end();
123 for(;thrValIt!=thrValEnd;++thrValIt) {
126 string valName = thrVal->
name();
127 string valType = thrVal->
type();
128 string valThresholdval = std::to_string(thrVal->
ptcut());
129 string valEtamin = std::to_string(thrVal->
etamin());
130 string valEtamax = std::to_string(thrVal->
etamax());
131 string valPhimin = std::to_string(thrVal->
phimin());
132 string valPhimax = std::to_string(thrVal->
phimax());
133 string valWindow = std::to_string(thrVal->
window());
134 string valEm_isolation =
"63";
135 string valHad_isolation =
"63";
136 string valHad_veto =
"63";
137 string valPriority = std::to_string(thrVal->
priority());
143 valEm_isolation = std::to_string(cluThrVal->
emIsolation());
144 valHad_isolation = std::to_string(cluThrVal->
hadIsolation());
145 valHad_veto = std::to_string(cluThrVal->
hadVeto());
149 if(thrValIt!=thr.thresholdValueVector().begin()) thrValDef +=
";";
150 thrValDef += valName; thrValDef +=
",";
151 thrValDef += valType; thrValDef +=
",";
152 thrValDef += valThresholdval; thrValDef +=
",";
153 thrValDef += valEtamin; thrValDef +=
",";
154 thrValDef += valEtamax; thrValDef +=
",";
155 thrValDef += valPhimin; thrValDef +=
",";
156 thrValDef += valPhimax; thrValDef +=
",";
157 thrValDef += valEm_isolation; thrValDef +=
",";
158 thrValDef += valHad_isolation; thrValDef +=
",";
159 thrValDef += valHad_veto; thrValDef +=
",";
160 thrValDef += valWindow; thrValDef +=
",";
161 thrValDef += valPriority;
166 std::string cableDef(
"");
167 cableDef += thr.cableName(); cableDef +=
",";
168 cableDef += thr.cableCtpin(); cableDef +=
",";
169 cableDef += thr.cableConnector(); cableDef +=
",";
170 cableDef += std::to_string(thr.cableStart()); cableDef +=
",";
171 cableDef += std::to_string(thr.cableEnd());
174 payload[
"Threshold"].setValue<cool::String255>(thrDef);
175 payload[
"ThresholdValue"].setValue<cool::String4k>(thrValDef);
176 payload[
"Cable"].setValue<cool::String255>(cableDef);
183 Record payload(fld->payloadSpecification());
184 payload[
"Lvl1PrescaleConfigurationKey"].setValue<cool::UInt32>(lvl1PrescaleKey);
191 Record payload(fld->payloadSpecification());
192 if(payload[
"Lvl1Prescale"].storageType()==cool::StorageType::Int32)
193 payload[
"Lvl1Prescale"].setValue<cool::Int32>(prescale);
195 payload[
"Lvl1Prescale"].setValue<cool::Int64>(prescale);
202 Record payload(fld->payloadSpecification());
203 if(payload[
"Lvl1Prescale"].storageType()==cool::StorageType::Int32)
204 payload[
"Lvl1Prescale"].setValue<cool::Int32>(prescale);
206 payload[
"Lvl1Prescale"].setValue<cool::Int64>(prescale);
213 Record payload(fld->payloadSpecification());
214 payload[
"Lvl1BunchGroupConfigurationKey"].setValue<cool::UInt32>(lvl1BunchgroupKey);
222 Record payload(fld->payloadSpecification());
227 std::vector<const BunchGroup*> bgOrdered(16,(
const BunchGroup*)0);
230 bgOrdered.at(bgp.internalNumber()) = &bgp;
235 for(
int bgC=0; bgC<16; ++bgC) {
241 unsigned char mask = (1 << (bgC % 8) );
244 for(
int b : bg->bunches()) {
247 std::string errorMsg =
248 "Bunch group " +
to_string(bgC) +
" contains bunch number "
249 +
to_string(b) +
" which is outside the range [0,3563]";
250 throw std::runtime_error(errorMsg);
252 codes[
static_cast<unsigned int>(b) + bgOffset] |= mask;
256 std::cout <<
"LVL1 bunchgroups [list 16 bunches per line]:" << std::endl;
259 blob.resize( codes.size() );
261 unsigned char* p =
static_cast<unsigned char*
>(blob.startingAddress());
263 for (
size_t i=0; i < codes.size() ; ++i,++p) {
266 cout << string(std::bitset<8>(codes[i]).to_string<char,std::char_traits<char>,std::allocator<char> >());
267 if((i+1)%16==0) cout << endl;
272 payload[
"BunchCode"].setValue<coral::Blob>( blob );
287 Record payload(fld->payloadSpecification());
292 unsigned int internalNumber = bunchgroup.internalNumber();
294 const string bgname = bunchgroup.name();
296 std::string payloadKey =
"BunchGroup" + std::to_string(internalNumber);
298 if(payload.specification().exists(payloadKey)) {
299 std::cout <<
"Write bunch group " << payloadKey <<
": '"<< bgname <<
"'" << std::endl;
300 payload[payloadKey].setValue<cool::String255>( bgname );
302 std::cout <<
"WARNING: COOL DB schema has not yet made fields for bunchgroup " << internalNumber <<
" (" << bgname <<
")" << endl;
306 cout <<
"Writing bunch group description with size " << ctpDataformat.getMaxTrigItems() << endl;
308 vector<unsigned char> codes( ctpDataformat.getMaxTrigItems() ,0);
311 unsigned int ctpid = item->ctpId();
312 if(ctpid >= codes.size())
313 throw runtime_error(
"Item ctpid exceeds blob size!");
316 throw runtime_error(
"Item " + item->name() +
" has no definition nodes attached");
321 for(
size_t i = 0; i<v1.size();++i) {
322 if(v1[i]) codes[ctpid] |= (1<<i);
325 cout <<
"Item " << setw(3) << setfill(
' ') << ctpid <<
" bunch-group code "
326 << string(bitset<8>(codes[ctpid]).
to_string<
char,char_traits<char>,allocator<char> >())
333 blob.resize( codes.size() );
334 unsigned char* p =
static_cast<unsigned char*
>(blob.startingAddress());
335 for (
size_t i=0; i < codes.size(); ++i,++p) {
339 payload[
"ItemToBunchGroupMap"].setValue<coral::Blob>( blob );
353 Record payload(fld->payloadSpecification());
354 payload[
"ThresholdName"].setValue<cool::String255>(tip.
thresholdName());
355 payload[
"CtpinSlot"].setValue<cool::UChar>(
static_cast<unsigned char>(tip.
slot()));
356 payload[
"CtpinConnector"].setValue<cool::UChar>(
static_cast<unsigned char>(tip.
connector()));
357 payload[
"ThresholdBit"].setValue<cool::UChar>(
static_cast<unsigned char>(tip.
thresholdBit()));
358 payload[
"CableBit"].setValue<cool::UChar>(
static_cast<unsigned char>(tip.
cableBit()));
359 payload[
"ThresholdMapping"].setValue<cool::UChar>(
static_cast<unsigned char>(tip.
thresholdMapping()));
360 payload[
"ThresholdActive"].setValue<cool::Bool>(tip.
thresholdActive());
369 const std::string&
type,
370 const uint16_t& bgId,
371 const std::string& threshName,
372 const std::string& slot,
373 const std::string& con,
374 const std::string& mult,
375 const std::string& start,
376 const std::string& end,
377 const std::string& active,
378 const std::string& monName,
379 const std::string& CounterLogic)
381 Record payload(fld->payloadSpecification());
382 payload[
"CounterType"].setValue<cool::String255>(
type);
383 payload[
"BunchGroupId"].setValue<cool::UChar>(
static_cast<unsigned char>(bgId));
384 payload[
"ThresholdName"].setValue<cool::String255>(threshName);
385 payload[
"CtpinSlot"].setValue<cool::String255>(slot);
386 payload[
"CtpinConnector"].setValue<cool::String255>(con);
387 payload[
"Multiplicity"].setValue<cool::String255>(mult);
388 payload[
"ThresholdBitStart"].setValue<cool::String255>(start);
389 payload[
"ThresholdBitEnd"].setValue<cool::String255>(end);
390 payload[
"ThresholdActive"].setValue<cool::String255>(active);
391 payload[
"CounterName"].setValue<cool::String255>(monName);
392 payload[
"CounterLogic"].setValue<cool::String255>(CounterLogic);
408 const vector<TriggerThreshold*>& thrs) {
409 string logic =
al[
"Logic"].data<cool::String255>();
412 item->setCondition(logic, condList, thrs);
418 string thrDef =
al[
"Threshold"].data<cool::String255>();
419 string thrValDef =
al[
"ThresholdValue"].data<cool::String4k>();
420 string cableDef =
al[
"Cable"].data<cool::String255>();
424 vector<string> thrDefV =
split(thrDef,
",");
425 thr->setName(thrDefV[0]);
430 if(thr->name()==
"JetWeights" || thr->name()==
"METSigParams") {
431 thr->setCableName(thrValDef);
435 thr->setVersion(std::stoi(thrDefV[1]));
436 thr->setType(thrDefV[2]);
437 thr->setMapping(std::stoi(thrDefV[3]));
438 thr->setActive(lexical_cast<bool, string>(thrDefV[4]));
445 if(thr->isInternal()) {
446 string::size_type pos = thr->name().find_first_of(
"0123456789");
447 int mapping = std::stoi(thr->name().substr(pos));
448 thr->setMapping( mapping );
452 vector<string> thrAllValDefV =
split(thrValDef,
";");
453 for(
const string& thrAllVal: thrAllValDefV) {
454 if(thrAllVal==
"")
continue;
455 vector<string> thrValDefV =
split(thrAllVal,
",");
457 string valName = thrValDefV[0];
458 string valType = thrValDefV[1];
459 float valThresholdval = std::stof(thrValDefV[2]);
460 int valEtamin = std::stoi(thrValDefV[3]);
461 int valEtamax = std::stoi(thrValDefV[4]);
462 int valPhimin = std::stoi(thrValDefV[5]);
463 int valPhimax = std::stoi(thrValDefV[6]);
464 float valEm_isolation = std::stof(thrValDefV[7]);
465 float valHad_isolation = std::stof(thrValDefV[8]);
466 float valHad_veto = std::stof(thrValDefV[9]);
467 int valWindow = std::stoi(thrValDefV[10]);
468 float valPriority = std::stof(thrValDefV[11]);
490 thr->addThresholdValue(thrv);
494 vector<string> cableDefV =
split(cableDef,
",");
495 string cableName = cableDefV[0];
496 string cableCtpin = cableDefV[1];
497 string cableConnector = cableDefV[2];
498 int cableStart = std::stoi(cableDefV[3]);
499 int cableEnd = std::stoi(cableDefV[4]);
500 thr->setCableName ( cableName );
501 thr->setCableCtpin ( cableCtpin);
502 string ctpin(std::move(cableCtpin));
503 boost::to_lower(ctpin);
504 if( ctpin ==
"ctpcore" ) {
505 thr->setInput(
"ctpcore" );
507 thr->setInput(
"ctpin" );
509 thr->setCableConnector( cableConnector);
510 thr->setCableStart ( cableStart );
511 thr->setCableEnd ( cableEnd );
519 const coral::Blob& blob =
al[
"BunchCode"].data<coral::Blob>();
522 if(blob.size() != 3564 && blob.size() != 2 * 3564)
523 throw runtime_error(
"Read BLOB for BunchCode of unexpected size!");
526 unsigned int numberBG = (blob.size() == 3564) ? 8 : 16;
528 vector<BunchGroup> bgV(numberBG);
529 unsigned int bgIdx(0);
531 bg.setInternalNumber(bgIdx++);
534 const unsigned char* p =
static_cast<const unsigned char*
>(blob.startingAddress());
536 for (
size_t bunch = 0; bunch < 3564; ++bunch, ++p) {
537 unsigned char mask = *p;
538 for(
int i=0; i<8;i++) {
539 if( (mask>>i) & 0x1) bgV[i].addBunch(bunch);
543 if(blob.size() == 2 * 3564) {
544 for (
size_t bunch = 0; bunch < 3564; ++bunch, ++p) {
545 unsigned char mask = *p;
546 for(
int i=0; i<8;i++)
547 if( (mask>>i) & 0x1) bgV[8+i].addBunch(bunch);
554pair< vector<string>, map<unsigned int,unsigned char> >
556 vector<string> names;
575 catch(
const coral::AttributeListException &) {}
577 std::map<unsigned int,unsigned char> codes;
578 const coral::Blob& blob =
al[
"ItemToBunchGroupMap"].data<coral::Blob>();
582 if(blob.size() != 256 && blob.size() != 512)
583 throw runtime_error(
"Read BLOB for ItemToBunchGroupMap of unexpected size!");
585 const unsigned char* p =
static_cast<const unsigned char*
>(blob.startingAddress());
586 for (
long i = 0; i < blob.size(); ++i,++p) {
587 unsigned char mask = (*p);
588 codes.insert( make_pair(i,mask) );
590 return make_pair(names,codes);
596 unsigned int & lvl1PrescaleKey )
598 lvl1PrescaleKey =
al[
"Lvl1PrescaleConfigurationKey"].data<cool::UInt32>();
605 if (
al[
"Lvl1Prescale"].specification().
type() ==
typeid(cool::Int32) )
606 prescaleValue =
al[
"Lvl1Prescale"].data<cool::Int32>();
608 prescaleValue =
al[
"Lvl1Prescale"].data<cool::Int64>();
615 if (
al[
"Lvl1Prescale"].specification().
type() ==
typeid(cool::Int32) )
616 prescaleValue =
al[
"Lvl1Prescale"].data<cool::Int32>();
618 prescaleValue =
al[
"Lvl1Prescale"].data<cool::Int64>();
625 return al[
"Lvl1BunchGroupConfigurationKey"].data<cool::UInt32>();
659std::vector<TrigConf::ThresholdMonitor*>
662 vector<ThresholdMonitor*>
vec;
671 string monname = payload[
"CounterName"].data<cool::String255>();
672 string type = payload[
"CounterType"].data<cool::String255>();
674 unsigned char bgId = payload[
"BunchGroupId"].data<cool::UChar>();
678 names.size() != slots.size() ||
679 names.size() != cons.size() ||
680 names.size() != mults.size() ||
681 names.size() != starts.size() ||
682 names.size() != ends.size() ||
683 names.size() != actives.size()
685 throw std::runtime_error(
"Inconsistent mon vector sizes!");
687 for(
size_t i = 0 ; i < names.size(); ++i) {
690 mon->setName(monname);
691 mon->setBunchGroupId(
static_cast<int>(bgId) );
692 mon->setCounterType(
type);
694 mon->setThresholdName(names[i]);
695 mon->setCtpinSlot(
static_cast<uint16_t
>(std::stoul(slots[i])) );
696 mon->setCtpinConnector(
static_cast<uint16_t
>(std::stoul(cons[i])) );
697 mon->setThresholdStartBit( std::stoi(starts[i]) );
698 mon->setThresholdEndBit( std::stoi(ends[i]) );
699 mon->setMultiplicity( std::stoi(mults[i]) );
700 bool active = (actives[i]==
"ENABLED");
701 mon->setThresholdActive( active );
std::vector< size_t > vec
char data[hepevt_bytes_allocation_ATLAS]
const std::vector< BunchGroup > & bunchGroups() const
void setHadIsolation(float v)
void setEmIsolation(float v)
float emIsolation() const
float hadIsolation() const
static std::string & typeAsString(TriggerType tt)
int xsSigmaOffset() const
void setCtpinConnector(const uint16_t &id)
void setThresholdActive(const bool &a)
void setCableBit(const uint16_t &num)
void setThresholdBit(const uint16_t &num)
void setThresholdName(const std::string &name)
void setCtpinSlot(const uint16_t &id)
void setThresholdMapping(const int16_t &m)
uint16_t connector() const
void setThresholdName(const std::string &name)
void setThresholdMapping(const int16_t &m)
void setConnector(const uint16_t &id)
const std::string & thresholdName() const
void setThresholdActive(const bool &a)
void setSlot(const uint16_t &id)
uint16_t thresholdBit() const
void setThresholdBit(const uint16_t &num)
uint16_t cableBit() const
void setCableBit(const uint16_t &num)
int16_t thresholdMapping() const
bool thresholdActive() const
unsigned int ctpVersion() const
static const long mBGContentBlobSize
void setName(const std::string &name)
const std::string & name() const
void getAllBunchGroups(std::vector< bool > &) const
void setEtaMax(int value)
void setWindow(int value)
void setPriority(float prio)
void setType(const std::string &type)
void setPhiMin(int value)
void setPhiMax(int value)
void setEtaMin(int value)
unsigned int window() const
const std::string & type() const
static TriggerThresholdValue * createThresholdValue(const std::string &type)
std::vector< TrigConf::ThresholdMonitor * > readLvl1MonMap(const cool::IRecord &payload)
Build a LVL1 mon counter object from COOL payload.
cool::Record createLvl1MonMapPayload(cool::IFolderPtr, const std::string &type, const uint16_t &bgId, const std::string &threshName, const std::string &slot, const std::string &con, const std::string &mult, const std::string &start, const std::string &end, const std::string &active, const std::string &monName=std::string(""), const std::string &CounterLogic=std::string(""))
build a COOL db record from a monitoring-mapping string value
cool::Record createLvl1METSigPayload(cool::IFolderPtr, const METSigParam &metSigParams)
build a COOL db record from a L1 MET significance global parameters
cool::Record createLvl1ConfigKeyPayload(cool::IFolderPtr, unsigned int lvl1PrescaleKey)
build a COOL db record from a LVL1 configuration key
std::pair< std::vector< std::string >, std::map< unsigned int, unsigned char > > readLvl1BGDesc(const coral::AttributeList &al)
build the LVL1 Bunchgroup descriptions from a coral::AttributeList
cool::Record createLvl1BGKeyPayload(cool::IFolderPtr, unsigned int lvl1BunchgroupKey)
build a COOL db record from a LVL1 bunch group key
cool::Record createLvl1MenuPayload(cool::IFolderPtr, const TrigConf::TriggerItem &item)
build a COOL db record from a LVL1 TriggerItem (the item name and version)
cool::Record createLvl1PrescalesPayload(cool::IFolderPtr, int prescale)
build a COOL db record from a LVL1 prescale value
TrigConf::PIT * readLvl1InputMap(const coral::AttributeList &al)
Build a LVL1 PIT object from COOL payload.
TrigConf::TIP * readLvl1TIPMap(const coral::AttributeList &al)
void readLvl1Prescale(const coral::AttributeList &al, int &ps)
build the LVL1 prescale value from a coral::AttributeList
cool::Record createLvl1BGDescPayload(cool::IFolderPtr fld, const TrigConf::BunchGroupSet &bgs, const TrigConf::Menu &lvl1Menu)
build a COOL db record from a bunch group description
cool::Record createLvl1BGContentPayload(cool::IFolderPtr fld, const TrigConf::BunchGroupSet &bgs)
build a COOL db record from a bunch group definition value
cool::Record createLvl1ItemDefPayload(cool::IFolderPtr, const TrigConf::TriggerItem &item)
build a COOL db record from a LVL1 TriggerItem (the conditions)
void readLvl1ConfigKey(const coral::AttributeList &al, unsigned int &lvl1PrescaleKey)
build the LVL1 configuration key from a coral::AttributeList
std::vector< TrigConf::BunchGroup > readLvl1BGContent(const coral::AttributeList &al)
build the LVL1 Bunchgroup code
TriggerItem * createLvl1TriggerItem(const coral::AttributeList &al)
build a LVL1 TriggerItem from a COOL db record
cool::Record createLvl1InputMapPayload(cool::IFolderPtr, const TrigConf::TIP &tip)
build a COOL db record from a PIT-mapping string value
cool::Record createLvl1ThresholdPayload(cool::IFolderPtr, const TrigConf::TriggerThreshold &thr)
build a COOL db record from a LVL1 TriggerItem
void addThresholdsToTriggerItem(const coral::AttributeList &al, TriggerItem *item, const std::vector< TrigConf::TriggerThreshold * > &thrs)
build a TriggerThreshold definition from a COOL db record and add to the corresponding item
TriggerThreshold * createLvl1Threshold(const coral::AttributeList &al)
build a LVL1 TriggerThreshold from a COOL db record
cool::Record createLvl1JetWeightPayload(cool::IFolderPtr, const std::vector< int > &jetweights)
build a COOL db record from a L1 Jet Weights vector
int readLvl1BGKey(const coral::AttributeList &al)
build the LVL1 Bunchgroup key value
Forward iterator to traverse the main components of the trigger configuration.
std::vector< std::string > split(const std::string &line, const std::string &del=" ")