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>
41 using boost::lexical_cast;
52 payload[
"ItemName"].setValue<cool::String255>(
item.name());
53 payload[
"ItemVersion"].setValue<cool::UInt32>(
item.version());
61 vector<string> thresholdlist;
62 string logic, conditions;
63 item.buildLogic(logic, thresholdlist);
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);
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 += lexical_cast<std::string,int>(*wIt);
83 payload[
"Threshold"].setValue<cool::String255>(
"JetWeights");
84 payload[
"ThresholdValue"].setValue<cool::String4k>(thrValDef);
85 payload[
"Cable"].setValue<cool::String255>(
"");
94 thrValDef += lexical_cast<std::string,int>(metSigParams.
xsSigmaScale()) +
",";
95 thrValDef += lexical_cast<std::string,int>(metSigParams.
xsSigmaOffset()) +
",";
96 thrValDef += lexical_cast<std::string,int>(metSigParams.
xeMin()) +
",";
97 thrValDef += lexical_cast<std::string,int>(metSigParams.
xeMax()) +
",";
98 thrValDef += lexical_cast<std::string,int>(metSigParams.
teSqrtMin()) +
",";
99 thrValDef += lexical_cast<std::string,int>(metSigParams.
teSqrtMax());
100 payload[
"Threshold"].setValue<cool::String255>(
"METSigParams");
101 payload[
"ThresholdValue"].setValue<cool::String4k>(thrValDef);
102 payload[
"Cable"].setValue<cool::String255>(
"");
112 thrDef += thr.
name(); thrDef +=
",";
113 thrDef += lexical_cast<std::string,int>(thr.
version()); thrDef +=
",";
114 thrDef += thr.
type(); thrDef +=
",";
115 thrDef += lexical_cast<std::string,int>(thr.
mapping()); thrDef +=
",";
116 thrDef += lexical_cast<std::string,bool>(thr.
active());
120 string thrValDef(
"");
123 for(;thrValIt!=thrValEnd;++thrValIt) {
126 string valName = thrVal->
name();
127 string valType = thrVal->
type();
128 string valThresholdval = lexical_cast<string,float> (thrVal->
ptcut());
129 string valEtamin = lexical_cast<string,int> (thrVal->
etamin());
130 string valEtamax = lexical_cast<string,int> (thrVal->
etamax());
131 string valPhimin = lexical_cast<string,int> (thrVal->
phimin());
132 string valPhimax = lexical_cast<string,int> (thrVal->
phimax());
133 string valWindow = lexical_cast<string,int> (thrVal->
window());
134 string valEm_isolation =
"63";
135 string valHad_isolation =
"63";
136 string valHad_veto =
"63";
137 string valPriority = lexical_cast<string,float>(thrVal->
priority());
139 if ( thr.
type()==L1DataDef::emType() ||
140 thr.
type()==L1DataDef::tauType() ) {
143 valEm_isolation = lexical_cast<string,float>(cluThrVal->
emIsolation());
144 valHad_isolation = lexical_cast<string,float>(cluThrVal->
hadIsolation());
145 valHad_veto = lexical_cast<string,float>(cluThrVal->
hadVeto());
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 +=
",";
170 cableDef += lexical_cast<std::string,int>(thr.
cableStart()); cableDef +=
",";
171 cableDef += lexical_cast<std::string,int>(thr.
cableEnd());
174 payload[
"Threshold"].setValue<cool::String255>(thrDef);
175 payload[
"ThresholdValue"].setValue<cool::String4k>(thrValDef);
176 payload[
"Cable"].setValue<cool::String255>(cableDef);
184 payload[
"Lvl1PrescaleConfigurationKey"].setValue<cool::UInt32>(lvl1PrescaleKey);
192 if(
payload[
"Lvl1Prescale"].storageType()==cool::StorageType::Int32)
193 payload[
"Lvl1Prescale"].setValue<cool::Int32>(prescale);
195 payload[
"Lvl1Prescale"].setValue<cool::Int64>(prescale);
203 if(
payload[
"Lvl1Prescale"].storageType()==cool::StorageType::Int32)
204 payload[
"Lvl1Prescale"].setValue<cool::Int32>(prescale);
206 payload[
"Lvl1Prescale"].setValue<cool::Int64>(prescale);
214 payload[
"Lvl1BunchGroupConfigurationKey"].setValue<cool::UInt32>(lvl1BunchgroupKey);
225 vector<unsigned char>
codes(2 * TrigConfCoolFolderSpec::mBGContentBlobSize, 0 );
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) );
242 unsigned int bgOffset = bgC < 8 ? 0 : TrigConfCoolFolderSpec::mBGContentBlobSize;
244 for(
int b :
bg->bunches()) {
245 if(b<0 || b >= TrigConfCoolFolderSpec::mBGContentBlobSize) {
248 "Bunch group " +
to_string(bgC) +
" contains bunch number "
249 +
to_string(
b) +
" which is outside the range [0,3563]";
252 codes[
static_cast<unsigned int>(
b) + bgOffset] |=
mask;
256 std::cout <<
"LVL1 bunchgroups [list 16 bunches per line]:" << std::endl;
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;
292 unsigned int internalNumber = bunchgroup.internalNumber();
294 const string bgname = bunchgroup.name();
296 std::string payloadKey =
"BunchGroup" + boost::lexical_cast<std::string,int>(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> >())
334 unsigned char*
p =
static_cast<unsigned char*
>(
blob.startingAddress());
335 for (
size_t i=0;
i <
codes.size(); ++
i,++
p) {
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()));
369 const std::string&
type,
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)
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);
400 item->setName ( al[
"ItemName"]. data<cool::String255>() );
401 item->setVersion( al[
"ItemVersion"].data<cool::UInt32>() );
408 const vector<TriggerThreshold*>& thrs) {
409 string logic = al[
"Logic"].data<cool::String255>();
410 vector<string> condList =
split(al[
"ConditionsList"].data<cool::String4k>(),
";");
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(lexical_cast<int, string>(thrDefV[1]));
436 thr->setType(thrDefV[2]);
437 thr->setMapping(lexical_cast<int, string>(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 = boost::lexical_cast<int,string>(thr->name().substr(
pos));
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 = lexical_cast<float, string>(thrValDefV[2]);
460 int valEtamin = lexical_cast<int, string>(thrValDefV[3]);
461 int valEtamax = lexical_cast<int, string>(thrValDefV[4]);
462 int valPhimin = lexical_cast<int, string>(thrValDefV[5]);
463 int valPhimax = lexical_cast<int, string>(thrValDefV[6]);
464 float valEm_isolation = lexical_cast<float, string>(thrValDefV[7]);
465 float valHad_isolation = lexical_cast<float, string>(thrValDefV[8]);
466 float valHad_veto = lexical_cast<float, string>(thrValDefV[9]);
467 int valWindow = lexical_cast<int, string>(thrValDefV[10]);
468 float valPriority = lexical_cast<float, string>(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 = lexical_cast<int,std::string>(cableDefV[3]);
499 int cableEnd = lexical_cast<int,std::string>(cableDefV[4]);
500 thr->setCableName ( cableName );
501 thr->setCableCtpin ( cableCtpin);
502 string ctpin(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 );
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);
554 pair< vector<string>, map<unsigned int,unsigned char> >
556 vector<string>
names;
557 names.push_back(al[
"BunchGroup0"].data<cool::String255>());
558 names.push_back(al[
"BunchGroup1"].data<cool::String255>());
559 names.push_back(al[
"BunchGroup2"].data<cool::String255>());
560 names.push_back(al[
"BunchGroup3"].data<cool::String255>());
561 names.push_back(al[
"BunchGroup4"].data<cool::String255>());
562 names.push_back(al[
"BunchGroup5"].data<cool::String255>());
563 names.push_back(al[
"BunchGroup6"].data<cool::String255>());
564 names.push_back(al[
"BunchGroup7"].data<cool::String255>());
566 names.push_back(al[
"BunchGroup8"].data<cool::String255>());
567 names.push_back(al[
"BunchGroup9"].data<cool::String255>());
568 names.push_back(al[
"BunchGroup10"].data<cool::String255>());
569 names.push_back(al[
"BunchGroup11"].data<cool::String255>());
570 names.push_back(al[
"BunchGroup12"].data<cool::String255>());
571 names.push_back(al[
"BunchGroup13"].data<cool::String255>());
572 names.push_back(al[
"BunchGroup14"].data<cool::String255>());
573 names.push_back(al[
"BunchGroup15"].data<cool::String255>());
575 catch(
const coral::AttributeListException &) {}
577 std::map<unsigned int,unsigned char>
codes;
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);
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>();
649 tip->
setSlot(
static_cast<uint16_t>(al[
"CtpinSlot"].data<cool::UChar>()) );
659 std::vector<TrigConf::ThresholdMonitor*>
662 vector<ThresholdMonitor*>
vec;
663 vector<string>
names =
split(
payload[
"ThresholdName"].data<cool::String255>(),
":");
664 vector<string> slots =
split(
payload[
"CtpinSlot"].data<cool::String255>(),
":");
665 vector<string> cons =
split(
payload[
"CtpinConnector"].data<cool::String255>(),
":");
666 vector<string> mults =
split(
payload[
"Multiplicity"].data<cool::String255>(),
":");
667 vector<string> starts =
split(
payload[
"ThresholdBitStart"].data<cool::String255>(),
":");
668 vector<string> ends =
split(
payload[
"ThresholdBitEnd"].data<cool::String255>(),
":");
669 vector<string> actives =
split(
payload[
"ThresholdActive"].data<cool::String255>(),
":");
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) );
695 mon->setCtpinSlot( lexical_cast<uint16_t,std::string>(slots[
i]) );
696 mon->setCtpinConnector( lexical_cast<uint16_t,std::string>(cons[
i]) );
697 mon->setThresholdStartBit( lexical_cast<int,std::string>(starts[
i]) );
698 mon->setThresholdEndBit( lexical_cast<int,std::string>(ends[
i]) );
699 mon->setMultiplicity( lexical_cast<int,std::string>(mults[
i]) );
700 bool active = (actives[
i]==
"ENABLED");