25 using namespace edm::es;
27 edm::LogInfo(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd" ) <<
"Producing L1TGlobalPrescalesVetos with RS key =" << objectKey ;
29 if( objectKey.empty() ){
30 edm::LogInfo(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd" ) <<
"Key is empty";
31 throw std::runtime_error(
"Empty objecKey");
37 std::vector< std::string > queryStrings ;
38 queryStrings.push_back(
"MP7" ) ;
39 queryStrings.push_back(
"AMC502_EXTCOND" ) ;
40 queryStrings.push_back(
"AMC502_FINOR" ) ;
41 queryStrings.push_back(
"ALGOBX_MASK" ) ;
42 queryStrings.push_back(
"ALGO_FINOR_MASK" ) ;
43 queryStrings.push_back(
"ALGO_FINOR_VETO" ) ;
44 queryStrings.push_back(
"ALGO_PRESCALE" ) ;
46 std::string prescale_key, bxmask_key, mask_key, vetomask_key;
57 if( queryResult.queryFailed() || queryResult.numberRows() != 1 ){
58 edm::LogError(
"L1-O2O" ) <<
"Cannot get UGT_RS_KEYS.{MP7,AMC502_EXTCOND,AMC502_FINOR,ALGOBX_MASK,ALGO_FINOR_MASK,ALGO_FINOR_VETO,ALGO_PRESCALE} for ID = " << objectKey;
59 throw std::runtime_error(
"Broken key");
63 if( !queryResult.fillVariable(
"ALGO_PRESCALE", prescale_key) ) prescale_key =
"";
64 if( !queryResult.fillVariable(
"ALGOBX_MASK", bxmask_key) ) bxmask_key =
"";
65 if( !queryResult.fillVariable(
"ALGO_FINOR_MASK", mask_key) ) mask_key =
"";
66 if( !queryResult.fillVariable(
"ALGO_FINOR_VETO", vetomask_key) ) vetomask_key =
"";
69 queryStrings.push_back(
"CONF" ) ;
72 std::string xmlPayload_prescale, xmlPayload_mask_algobx, xmlPayload_mask_finor, xmlPayload_mask_veto;
82 if( queryResult.queryFailed() || queryResult.numberRows() != 1 ){
83 edm::LogError(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd" ) <<
"Cannot get UGT_RS.CONF for prescale_key = "<<prescale_key ;
84 throw std::runtime_error(
"Broken key");
88 if( !queryResult.fillVariable(
"CONF", xmlPayload_prescale ) ) xmlPayload_prescale =
"";
99 if( queryResult.queryFailed() || queryResult.numberRows() != 1 ){
100 edm::LogError(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd" ) <<
"Cannot get UGT_RS.CONF for mask_key = "<<mask_key ;
101 throw std::runtime_error(
"Broken key");
105 if( !queryResult.fillVariable(
"CONF", xmlPayload_mask_finor ) ) xmlPayload_mask_finor =
"";
116 if( queryResult.queryFailed() || queryResult.numberRows() != 1 ){
117 edm::LogError(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd" ) <<
"Cannot get UGT_RS.CONF for bxmask_key = "<<bxmask_key ;
118 throw std::runtime_error(
"Broken key");
122 if( !queryResult.fillVariable(
"CONF", xmlPayload_mask_algobx ) ) xmlPayload_mask_algobx =
"";
133 if( queryResult.queryFailed() || queryResult.numberRows() != 1 ){
134 edm::LogError(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd" ) <<
"Cannot get UGT_RS.CONF for vetomask_key = "<<vetomask_key ;
135 throw std::runtime_error(
"Broken key");
139 if( !queryResult.fillVariable(
"CONF", xmlPayload_mask_veto ) ) xmlPayload_mask_veto =
"";
142 std::ofstream output1(
std::string(
"/tmp/").
append(prescale_key.substr(0,prescale_key.find(
"/"))).append(
".xml"));
143 output1<<xmlPayload_prescale;
145 std::ofstream output2(
std::string(
"/tmp/").
append(mask_key.substr(0,mask_key.find(
"/"))).append(
".xml"));
146 output2<<xmlPayload_mask_finor;
148 std::ofstream output3(
std::string(
"/tmp/").
append(bxmask_key.substr(0,bxmask_key.find(
"/"))).append(
".xml"));
149 output3<<xmlPayload_mask_algobx;
151 std::ofstream output4(
std::string(
"/tmp/").
append(vetomask_key.substr(0,vetomask_key.find(
"/"))).append(
".xml"));
152 output4<<xmlPayload_mask_veto;
157 unsigned int m_numberPhysTriggers = 512;
158 unsigned int m_bx_mask_default = 1;
161 std::vector<std::vector<int> >
prescales;
162 std::vector<unsigned int> triggerMasks;
163 std::vector<int> triggerVetoMasks;
164 std::map<int, std::vector<int> > triggerAlgoBxMaskAlgoTrig;
169 ts_prescale.
addProcRole(
"uGtProcessor",
"uGtProcessor");
172 xmlReader_prescale.readDOMFromString( xmlPayload_prescale );
173 xmlReader_prescale.readRootElement( ts_prescale,
"uGT" );
174 ts_prescale.setConfigured();
176 std::map<std::string, l1t::Setting> settings_prescale = ts_prescale.getSettings(
"uGtProcessor");
177 std::vector<l1t::TableRow> tRow_prescale = settings_prescale[
"prescales"].getTableRows();
179 unsigned int numColumns_prescale = 0;
180 if( tRow_prescale.size()>0 ){
181 std::vector<std::string> firstRow_prescale = tRow_prescale[0].getRow();
182 numColumns_prescale = firstRow_prescale.size();
185 int NumPrescaleSets = numColumns_prescale - 1;
188 unsigned int NumAlgos_prescale = 0;
189 for(
auto it=tRow_prescale.begin(); it!=tRow_prescale.end(); it++ ){
190 unsigned int algoBit = it->getRowValue<
unsigned int>(
"algo/prescale-index");
191 if( NumAlgos_prescale < algoBit+1 ) NumAlgos_prescale = algoBit+1;
194 if( NumPrescaleSets > 0 ){
196 for(
int iSet=0; iSet<NumPrescaleSets; iSet++ ){
198 for(
unsigned int iBit = 0; iBit < NumAlgos_prescale; ++iBit ){
199 int inputDefaultPrescale = 0;
200 prescales[iSet].push_back(inputDefaultPrescale);
204 for(
auto it=tRow_prescale.begin(); it!=tRow_prescale.end(); it++ ){
205 unsigned int algoBit = it->getRowValue<
unsigned int>(
"algo/prescale-index");
206 for(
int iSet=0; iSet<NumPrescaleSets; iSet++ ){
209 prescale = it->getRowValue<
unsigned int>(std::to_string(iSet));
210 }
catch (std::runtime_error &
e){
212 <<
"\nWarning: missing value for algoBit " << algoBit <<
" (row)"
213 <<
" in prescale set " << iSet <<
" (column) of " << prescale_key
214 <<
" also stored in /tmp/" << prescale_key.substr(0,prescale_key.find(
"/")).
append(
".xml")
215 <<
"\nWarning: no information on algoBit, setting to 0 "
228 for(
unsigned int iAlg=0; iAlg < m_numberPhysTriggers; iAlg++ )
229 triggerMasks.push_back(1);
233 ts_mask_finor.
addProcRole(
"uGtProcessor",
"uGtProcessor");
236 xmlReader_mask_finor.readDOMFromString( xmlPayload_mask_finor );
237 xmlReader_mask_finor.readRootElement( ts_mask_finor,
"uGT" );
238 ts_mask_finor.setConfigured();
240 std::map<std::string, l1t::Setting> settings_mask_finor = ts_mask_finor.getSettings(
"uGtProcessor");
241 std::vector<l1t::TableRow> tRow_mask_finor = settings_mask_finor[
"finorMask"].getTableRows();
243 for(
auto it=tRow_mask_finor.begin(); it!=tRow_mask_finor.end(); it++ ){
244 unsigned int algoBit = it->getRowValue<
unsigned int>(
"algo");
245 unsigned int mask = it->getRowValue<
unsigned int>(
"mask");
246 if( algoBit < m_numberPhysTriggers ) triggerMasks[algoBit] = mask;
253 for(
unsigned int iAlg=0; iAlg < m_numberPhysTriggers; iAlg++ )
254 triggerVetoMasks.push_back(0);
258 ts_mask_veto.
addProcRole(
"uGtProcessor",
"uGtProcessor");
261 xmlReader_mask_veto.readDOMFromString( xmlPayload_mask_veto );
262 xmlReader_mask_veto.readRootElement( ts_mask_veto,
"uGT" );
263 ts_mask_veto.setConfigured();
265 std::map<std::string, l1t::Setting> settings_mask_veto = ts_mask_veto.getSettings(
"uGtProcessor");
266 std::vector<l1t::TableRow> tRow_mask_veto = settings_mask_veto[
"vetoMask"].getTableRows();
268 for(
auto it=tRow_mask_veto.begin(); it!=tRow_mask_veto.end(); it++ ){
269 unsigned int algoBit = it->getRowValue<
unsigned int>(
"algo");
270 unsigned int veto = it->getRowValue<
unsigned int>(
"veto");
271 if( algoBit < m_numberPhysTriggers ) triggerVetoMasks[algoBit] = int(veto);
279 ts_mask_algobx.
addProcRole(
"uGtProcessor",
"uGtProcessor");
282 xmlReader_mask_algobx.readDOMFromString( xmlPayload_mask_algobx );
283 xmlReader_mask_algobx.readRootElement( ts_mask_algobx,
"uGT" );
284 ts_mask_algobx.setConfigured();
286 std::map<std::string, l1t::Setting> settings_mask_algobx = ts_mask_algobx.getSettings(
"uGtProcessor");
287 std::vector<l1t::TableRow> tRow_mask_algobx = settings_mask_algobx[
"algorithmBxMask"].getTableRows();
289 unsigned int numCol_mask_algobx = 0;
290 if( tRow_mask_algobx.size()>0 ){
291 std::vector<std::string> firstRow_mask_algobx = tRow_mask_algobx[0].getRow();
292 numCol_mask_algobx = firstRow_mask_algobx.size();
295 int NumAlgoBitsInMask = numCol_mask_algobx - 1;
296 if( NumAlgoBitsInMask > 0 ){
297 for(
auto it=tRow_mask_algobx.begin(); it!=tRow_mask_algobx.end(); it++ ){
298 int bx = it->getRowValue<
unsigned int>(
"bx/algo");
299 std::vector<int> maskedBits;
300 for(
int iBit=0; iBit<NumAlgoBitsInMask; iBit++ ){
301 unsigned int maskBit = it->getRowValue<
unsigned int>(std::to_string(iBit));
302 if( maskBit!=m_bx_mask_default ) maskedBits.push_back(iBit);
304 if( maskedBits.size()>0 ) triggerAlgoBxMaskAlgoTrig[bx] = maskedBits;
310 for(
unsigned int iSet=0; iSet <
prescales.size(); iSet++ ){
311 for(
unsigned int iBit=0; iBit <
prescales[iSet].size(); iBit++ ){
313 if( iBit >= triggerMasks.size() ){
315 <<
"\nWarning: algoBit in prescale table >= triggerMasks.size() "
316 <<
"\nWarning: no information on masking bit or not, setting as unmasked "
320 prescales[iSet][iBit] *= triggerMasks[iBit];
334 using namespace edm::es;
tuple L1TGlobalPrescalesVetos
L1TGlobalPrescalesVetosOnlineProd(const edm::ParameterSet &)
void setPrescaleFactorTable(std::vector< std::vector< int > > value)
const QueryResults singleAttribute(const T &data) const
boost::dynamic_bitset append(const boost::dynamic_bitset<> &bs1, const boost::dynamic_bitset<> &bs2)
this method takes two bitsets bs1 and bs2 and returns result of bs2 appended to the end of bs1 ...
virtual std::shared_ptr< L1TGlobalPrescalesVetos > newObject(const std::string &objectKey, const L1TGlobalPrescalesVetosO2ORcd &record) override
l1t::OMDSReader m_omdsReader
void addProcRole(const std::string &processor, const std::string &role)
const QueryResults basicQuery(const std::vector< std::string > &columnNames, const std::string &schemaName, const std::string &tableName, const std::string &conditionLHS="", const QueryResults conditionRHS=QueryResults(), const std::string &conditionRHSName="")
void setTriggerMaskVeto(std::vector< int > value)
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
void setBxMaskDefault(int value)
~L1TGlobalPrescalesVetosOnlineProd(void)
void setTriggerAlgoBxMask(std::map< int, std::vector< int > > value)
L1TGlobalPrescalesVetos * getWriteInstance()