26 using namespace edm::es;
28 edm::LogInfo(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd" ) <<
"Producing L1TGlobalPrescalesVetos with RS key =" << objectKey ;
30 if( objectKey.empty() ){
31 edm::LogInfo(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd" ) <<
"Key is empty";
32 throw std::runtime_error(
"Empty objecKey");
38 std::vector< std::string > queryStrings ;
39 queryStrings.push_back(
"MP7" ) ;
40 queryStrings.push_back(
"AMC502_EXTCOND" ) ;
41 queryStrings.push_back(
"AMC502_FINOR" ) ;
42 queryStrings.push_back(
"ALGOBX_MASK" ) ;
43 queryStrings.push_back(
"ALGO_FINOR_MASK" ) ;
44 queryStrings.push_back(
"ALGO_FINOR_VETO" ) ;
45 queryStrings.push_back(
"ALGO_PRESCALE" ) ;
47 std::string prescale_key, bxmask_key, mask_key, vetomask_key;
58 if( queryResult.queryFailed() || queryResult.numberRows() != 1 ){
59 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;
60 throw std::runtime_error(
"Broken key");
64 if( !queryResult.fillVariable(
"ALGO_PRESCALE", prescale_key) ) prescale_key =
"";
65 if( !queryResult.fillVariable(
"ALGOBX_MASK", bxmask_key) ) bxmask_key =
"";
66 if( !queryResult.fillVariable(
"ALGO_FINOR_MASK", mask_key) ) mask_key =
"";
67 if( !queryResult.fillVariable(
"ALGO_FINOR_VETO", vetomask_key) ) vetomask_key =
"";
70 queryStrings.push_back(
"CONF" ) ;
73 std::string xmlPayload_prescale, xmlPayload_mask_algobx, xmlPayload_mask_finor, xmlPayload_mask_veto;
83 if( queryResult.queryFailed() || queryResult.numberRows() != 1 ){
84 edm::LogError(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd" ) <<
"Cannot get UGT_RS.CONF for prescale_key = "<<prescale_key ;
85 throw std::runtime_error(
"Broken key");
89 if( !queryResult.fillVariable(
"CONF", xmlPayload_prescale ) ) xmlPayload_prescale =
"";
100 if( queryResult.queryFailed() || queryResult.numberRows() != 1 ){
101 edm::LogError(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd" ) <<
"Cannot get UGT_RS.CONF for mask_key = "<<mask_key ;
102 throw std::runtime_error(
"Broken key");
106 if( !queryResult.fillVariable(
"CONF", xmlPayload_mask_finor ) ) xmlPayload_mask_finor =
"";
117 if( queryResult.queryFailed() || queryResult.numberRows() != 1 ){
118 edm::LogError(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd" ) <<
"Cannot get UGT_RS.CONF for bxmask_key = "<<bxmask_key ;
119 throw std::runtime_error(
"Broken key");
123 if( !queryResult.fillVariable(
"CONF", xmlPayload_mask_algobx ) ) xmlPayload_mask_algobx =
"";
134 if( queryResult.queryFailed() || queryResult.numberRows() != 1 ){
135 edm::LogError(
"L1-O2O: L1TGlobalPrescalesVetosOnlineProd" ) <<
"Cannot get UGT_RS.CONF for vetomask_key = "<<vetomask_key ;
136 throw std::runtime_error(
"Broken key");
140 if( !queryResult.fillVariable(
"CONF", xmlPayload_mask_veto ) ) xmlPayload_mask_veto =
"";
143 std::ofstream output1(
std::string(
"/tmp/").
append(prescale_key.substr(0,prescale_key.find(
"/"))).append(
".xml"));
144 output1<<xmlPayload_prescale;
146 std::ofstream output2(
std::string(
"/tmp/").
append(mask_key.substr(0,mask_key.find(
"/"))).append(
".xml"));
147 output2<<xmlPayload_mask_finor;
149 std::ofstream output3(
std::string(
"/tmp/").
append(bxmask_key.substr(0,bxmask_key.find(
"/"))).append(
".xml"));
150 output3<<xmlPayload_mask_algobx;
152 std::ofstream output4(
std::string(
"/tmp/").
append(vetomask_key.substr(0,vetomask_key.find(
"/"))).append(
".xml"));
153 output4<<xmlPayload_mask_veto;
158 unsigned int m_numberPhysTriggers = 512;
159 unsigned int m_bx_mask_default = 1;
162 std::vector<std::vector<int> >
prescales;
163 std::vector<unsigned int> triggerMasks;
164 std::vector<int> triggerVetoMasks;
165 std::map<int, std::vector<int> > triggerAlgoBxMaskAlgoTrig;
170 ts_prescale.
addProcRole(
"uGtProcessor",
"uGtProcessor");
173 xmlReader_prescale.readDOMFromString( xmlPayload_prescale );
174 xmlReader_prescale.readRootElement( ts_prescale,
"uGT" );
175 ts_prescale.setConfigured();
177 std::map<std::string, l1t::Setting> settings_prescale = ts_prescale.getSettings(
"uGtProcessor");
178 std::vector<l1t::TableRow> tRow_prescale = settings_prescale[
"prescales"].getTableRows();
180 unsigned int numColumns_prescale = 0;
181 if( tRow_prescale.size()>0 ){
182 std::vector<std::string> firstRow_prescale = tRow_prescale[0].getRow();
183 numColumns_prescale = firstRow_prescale.size();
186 int NumPrescaleSets = numColumns_prescale - 1;
189 unsigned int NumAlgos_prescale = 0;
190 for(
auto it=tRow_prescale.begin(); it!=tRow_prescale.end(); it++ ){
191 unsigned int algoBit = it->getRowValue<
unsigned int>(
"algo/prescale-index");
192 if( NumAlgos_prescale < algoBit+1 ) NumAlgos_prescale = algoBit+1;
195 if( NumPrescaleSets > 0 ){
197 for(
int iSet=0; iSet<NumPrescaleSets; iSet++ ){
199 for(
unsigned int iBit = 0; iBit < NumAlgos_prescale; ++iBit ){
200 int inputDefaultPrescale = 0;
201 prescales[iSet].push_back(inputDefaultPrescale);
205 for(
auto it=tRow_prescale.begin(); it!=tRow_prescale.end(); it++ ){
206 unsigned int algoBit = it->getRowValue<
unsigned int>(
"algo/prescale-index");
207 for(
int iSet=0; iSet<NumPrescaleSets; iSet++ ){
210 prescale = it->getRowValue<
unsigned int>(std::to_string(iSet));
211 }
catch (std::runtime_error &
e){
213 <<
"\nWarning: missing value for algoBit " << algoBit <<
" (row)"
214 <<
" in prescale set " << iSet <<
" (column) of " << prescale_key
215 <<
" also stored in /tmp/" << prescale_key.substr(0,prescale_key.find(
"/")).
append(
".xml")
216 <<
"\nWarning: no information on algoBit, setting to 0 "
229 for(
unsigned int iAlg=0; iAlg < m_numberPhysTriggers; iAlg++ )
230 triggerMasks.push_back(1);
234 ts_mask_finor.
addProcRole(
"uGtProcessor",
"uGtProcessor");
237 xmlReader_mask_finor.readDOMFromString( xmlPayload_mask_finor );
238 xmlReader_mask_finor.readRootElement( ts_mask_finor,
"uGT" );
239 ts_mask_finor.setConfigured();
241 std::map<std::string, l1t::Setting> settings_mask_finor = ts_mask_finor.getSettings(
"uGtProcessor");
242 std::vector<l1t::TableRow> tRow_mask_finor = settings_mask_finor[
"finorMask"].getTableRows();
244 for(
auto it=tRow_mask_finor.begin(); it!=tRow_mask_finor.end(); it++ ){
245 unsigned int algoBit = it->getRowValue<
unsigned int>(
"algo");
246 unsigned int mask = it->getRowValue<
unsigned int>(
"mask");
247 if( algoBit < m_numberPhysTriggers ) triggerMasks[algoBit] = mask;
254 for(
unsigned int iAlg=0; iAlg < m_numberPhysTriggers; iAlg++ )
255 triggerVetoMasks.push_back(0);
259 ts_mask_veto.
addProcRole(
"uGtProcessor",
"uGtProcessor");
262 xmlReader_mask_veto.readDOMFromString( xmlPayload_mask_veto );
263 xmlReader_mask_veto.readRootElement( ts_mask_veto,
"uGT" );
264 ts_mask_veto.setConfigured();
266 std::map<std::string, l1t::Setting> settings_mask_veto = ts_mask_veto.getSettings(
"uGtProcessor");
267 std::vector<l1t::TableRow> tRow_mask_veto = settings_mask_veto[
"vetoMask"].getTableRows();
269 for(
auto it=tRow_mask_veto.begin(); it!=tRow_mask_veto.end(); it++ ){
270 unsigned int algoBit = it->getRowValue<
unsigned int>(
"algo");
271 unsigned int veto = it->getRowValue<
unsigned int>(
"veto");
272 if( algoBit < m_numberPhysTriggers ) triggerVetoMasks[algoBit] = int(veto);
280 ts_mask_algobx.
addProcRole(
"uGtProcessor",
"uGtProcessor");
283 xmlReader_mask_algobx.readDOMFromString( xmlPayload_mask_algobx );
284 xmlReader_mask_algobx.readRootElement( ts_mask_algobx,
"uGT" );
285 ts_mask_algobx.setConfigured();
287 std::map<std::string, l1t::Setting> settings_mask_algobx = ts_mask_algobx.getSettings(
"uGtProcessor");
288 std::vector<l1t::TableRow> tRow_mask_algobx = settings_mask_algobx[
"algorithmBxMask"].getTableRows();
290 unsigned int numCol_mask_algobx = 0;
291 if( tRow_mask_algobx.size()>0 ){
292 std::vector<std::string> firstRow_mask_algobx = tRow_mask_algobx[0].getRow();
293 numCol_mask_algobx = firstRow_mask_algobx.size();
296 int NumAlgoBitsInMask = numCol_mask_algobx - 1;
297 if( NumAlgoBitsInMask > 0 ){
298 for(
auto it=tRow_mask_algobx.begin(); it!=tRow_mask_algobx.end(); it++ ){
299 int bx = it->getRowValue<
unsigned int>(
"bx/algo");
300 std::vector<int> maskedBits;
301 for(
int iBit=0; iBit<NumAlgoBitsInMask; iBit++ ){
302 unsigned int maskBit = it->getRowValue<
unsigned int>(std::to_string(iBit));
303 if( maskBit!=m_bx_mask_default ) maskedBits.push_back(iBit);
305 if( maskedBits.size()>0 ) triggerAlgoBxMaskAlgoTrig[bx] = maskedBits;
311 for(
unsigned int iSet=0; iSet <
prescales.size(); iSet++ ){
312 for(
unsigned int iBit=0; iBit <
prescales[iSet].size(); iBit++ ){
314 if( iBit >= triggerMasks.size() ){
316 <<
"\nWarning: algoBit in prescale table >= triggerMasks.size() "
317 <<
"\nWarning: no information on masking bit or not, setting as unmasked "
321 prescales[iSet][iBit] *= triggerMasks[iBit];
335 using namespace edm::es;
336 boost::shared_ptr<L1TGlobalPrescalesVetos> pMenu = boost::shared_ptr< L1TGlobalPrescalesVetos >(data_.
getWriteInstance());
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 ...
l1t::OMDSReader m_omdsReader
void addProcRole(const std::string &processor, const std::string &role)
virtual boost::shared_ptr< L1TGlobalPrescalesVetos > newObject(const std::string &objectKey, const L1TGlobalPrescalesVetosO2ORcd &record) override
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()