CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DTTFMasksOnlineProd.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: DTTFMasksOnlineProd
4 // Class: DTTFMasksOnlineProd
5 //
13 //
14 // Original Author: J. Troconiz - UAM Madrid
15 // Created: Fri Apr 3 00:26:52 CEST 2009
16 // $Id: DTTFMasksOnlineProd.cc,v 1.3 2009/05/27 20:02:44 wsun Exp $
17 //
18 //
19 
20 
21 // system include files
22 #include <iostream>
23 
24 // user include files
26 
29 
30 //
31 // class declaration
32 //
33 
35  public L1ConfigOnlineProdBase< L1MuDTTFMasksRcd, L1MuDTTFMasks > {
36  public:
39 
40  virtual boost::shared_ptr< L1MuDTTFMasks > newObject(
41  const std::string& objectKey ) ;
42 
43  private:
44 
45  // ----------member data ---------------------------
46 };
47 
48 //
49 // constructors and destructor
50 //
52  const edm::ParameterSet& iConfig)
54 {
55  //the following line is needed to tell the framework what
56  // data is being produced
57 
58  //now do what ever other initialization is needed
59 }
60 
61 
63 {
64 
65  // do anything here that needs to be done at desctruction time
66  // (e.g. close files, deallocate resources etc.)
67 
68 }
69 
70 boost::shared_ptr< L1MuDTTFMasks >
71 DTTFMasksOnlineProd::newObject( const std::string& objectKey )
72 {
73  using namespace edm::es;
74 
75  boost::shared_ptr< L1MuDTTFMasks > pDTTFMasks(
76  new L1MuDTTFMasks() ) ;
77 
78  pDTTFMasks->reset() ;
79 
80  std::string dttfSchema = "CMS_DT_TF" ;
81 
82  // Order of strings is used below -- don't change!
83  std::vector< std::string > crateMaskColumns ;
84  crateMaskColumns.push_back( "WEDGE_CRATE_1" ) ;
85  crateMaskColumns.push_back( "WEDGE_CRATE_2" ) ;
86  crateMaskColumns.push_back( "WEDGE_CRATE_3" ) ;
87  crateMaskColumns.push_back( "WEDGE_CRATE_4" ) ;
88  crateMaskColumns.push_back( "WEDGE_CRATE_5" ) ;
89  crateMaskColumns.push_back( "WEDGE_CRATE_6" ) ;
90  crateMaskColumns.push_back( "WEDGE_CRATE_1_E" ) ;
91  crateMaskColumns.push_back( "WEDGE_CRATE_2_E" ) ;
92  crateMaskColumns.push_back( "WEDGE_CRATE_3_E" ) ;
93  crateMaskColumns.push_back( "WEDGE_CRATE_4_E" ) ;
94  crateMaskColumns.push_back( "WEDGE_CRATE_5_E" ) ;
95  crateMaskColumns.push_back( "WEDGE_CRATE_6_E" ) ;
96 
97  l1t::OMDSReader::QueryResults crateMaskResults =
98  m_omdsReader.basicQuery( crateMaskColumns,
99  dttfSchema,
100  "DTTF_RUN_SETTINGS",
101  "DTTF_RUN_SETTINGS.ID",
102  m_omdsReader.singleAttribute( objectKey ) ) ;
103 
104  if( crateMaskResults.queryFailed() ||
105  crateMaskResults.numberRows() != 1 ) // check query successful
106  {
107  edm::LogError( "L1-O2O" )
108  << "Problem with L1MuDTTFMasks key " << objectKey ;
109  return boost::shared_ptr< L1MuDTTFMasks >() ;
110  }
111 
112  // Cache crate masks
113  unsigned long crateMaskL[ 6 ] ;
114  unsigned long crateMaskR[ 6 ] ;
115  unsigned long krateMaskL[ 6 ] ;
116  unsigned long krateMaskR[ 6 ] ;
117  for( int icrate = 0 ; icrate < 6 ; ++icrate )
118  {
119  std::string crateMask ;
120  crateMaskResults.fillVariable( crateMaskColumns[ icrate ],
121  crateMask ) ;
122  char* pEnd;
123  crateMaskL[ icrate ] = std::strtol( crateMask.c_str(), &pEnd, 16 ) ;
124  crateMaskR[ icrate ] = std::strtol( pEnd, (char **)NULL, 16 ) ;
125 
126  crateMaskResults.fillVariable( crateMaskColumns[ icrate+6 ],
127  crateMask ) ;
128  krateMaskL[ icrate ] = std::strtol( crateMask.c_str(), &pEnd, 16 ) ;
129  krateMaskR[ icrate ] = std::strtol( pEnd, (char **)NULL, 16 ) ;
130 
131  std::cout << "Crate " << icrate << " masks"
132  << " L: " << std::hex << crateMaskL[ icrate ]
133  << " " << std::hex << krateMaskL[ icrate ]
134  << " R: " << std::hex << crateMaskR[ icrate ]
135  << " " << std::hex << krateMaskR[ icrate ] << std::endl ;
136  }
137 
138  // Map of sector (0-11) to name (L/R)
139  std::string sectorNames[ 12 ] = {
140  "R", "L", "R", "L", "L", "R", "L", "R", "R", "L", "R", "L" } ;
141 
142  // Map of sector (0-11) to crate (0-5)
143  int crateNumbers[ 12 ] = { 3, 3, 4, 4, 5, 5, 2, 2, 1, 1, 0, 0 } ;
144 
145  // Map of wheel array index to wheel number (+- 3, 2, 1).
146  int wheelNumbers[ 6 ] = { -3, -2, -1, 1, 2, 3 } ;
147 
148  // Map of wheel array index to name ({N,P}{0,1,2}).
149  std::string wheelNames[ 6 ] = { "N2", "N1", "N0", "P0", "P1", "P2" } ;
150 
151  // Map of sector+wheel name to bit number in crate mask
152  std::map< std::string, unsigned int > crateMaskBitmap ;
153  crateMaskBitmap.insert( std::make_pair( "N2", 24 ) ) ;
154  crateMaskBitmap.insert( std::make_pair( "N1", 20 ) ) ;
155  crateMaskBitmap.insert( std::make_pair( "N0", 16 ) ) ;
156  crateMaskBitmap.insert( std::make_pair( "P0", 8 ) ) ;
157  crateMaskBitmap.insert( std::make_pair( "P1", 4 ) ) ;
158  crateMaskBitmap.insert( std::make_pair( "P2", 0 ) ) ;
159 
160  std::map< std::string, unsigned int > krateMaskBitmap ;
161  krateMaskBitmap.insert( std::make_pair( "N2", 16 ) ) ;
162  krateMaskBitmap.insert( std::make_pair( "N1", 12 ) ) ;
163  krateMaskBitmap.insert( std::make_pair( "P0", 8 ) ) ;
164  krateMaskBitmap.insert( std::make_pair( "P1", 4 ) ) ;
165  krateMaskBitmap.insert( std::make_pair( "P2", 0 ) ) ;
166 
167  // Loop over sectors 0-11
168  for( int isc = 0 ; isc < 12 ; ++isc )
169  {
170  int crateNumber = crateNumbers[ isc ] ;
171  unsigned long crateMask = crateMaskL[ crateNumber ] ;
172  if ( sectorNames[ isc ] == "R" ) crateMask = crateMaskR[ crateNumber ] ;
173  unsigned long krateMask = krateMaskL[ crateNumber ] ;
174  if ( sectorNames[ isc ] == "R" ) krateMask = krateMaskR[ crateNumber ] ;
175  std::cout << "isc " << isc << " icr " << crateNumber << std::endl ;
176 
177  // Loop over wheels 0-5
178  for( int iwh = 0 ; iwh < 6 ; ++iwh )
179  {
180  std::string sectorWheelName =
181  sectorNames[ isc ] + wheelNames[ iwh ] ;
182 
183  unsigned int maskBit = 30 ;
184  std::map< std::string, unsigned int >::const_iterator itr =
185  crateMaskBitmap.find( wheelNames[ iwh ] ) ;
186  if( itr != crateMaskBitmap.end() ) maskBit = itr->second ;
187 
188  unsigned long phtfEnabled = ( crateMask >> maskBit ) & 0xF ;
189 
190  if ( wheelNames[ iwh ] == "P2" ) phtfEnabled += ( crateMask >> 24 ) & 0x10 ;
191  if ( wheelNames[ iwh ] == "N2" ) phtfEnabled += ( crateMask >> 25 ) & 0x10 ;
192 
193  std::cout << "Bits " << std::dec << maskBit << " (" << sectorWheelName
194  << ") of mask " << std::hex << crateMask << " is "
195  << std::hex << phtfEnabled << std::endl ;
196 
197  int nwh = wheelNumbers[ iwh ] ;
198 
199  unsigned long chmask = phtfEnabled & 0x1;
200  std::cout << " INREC_CHDIS_ST1 " << 1-chmask ;
201  pDTTFMasks->set_inrec_chdis_st1( nwh, isc, 1-chmask ) ;
202  chmask = ( phtfEnabled >> 1 ) & 0x1;
203  std::cout << " INREC_CHDIS_ST2 " << 1-chmask ;
204  pDTTFMasks->set_inrec_chdis_st2( nwh, isc, 1-chmask ) ;
205  chmask = ( phtfEnabled >> 2 ) & 0x1;
206  std::cout << " INREC_CHDIS_ST3 " << 1-chmask ;
207  pDTTFMasks->set_inrec_chdis_st3( nwh, isc, 1-chmask ) ;
208  chmask = ( phtfEnabled >> 3 ) & 0x1;
209  std::cout << " INREC_CHDIS_ST4 " << 1-chmask ;
210  pDTTFMasks->set_inrec_chdis_st4( nwh, isc, 1-chmask ) ;
211  chmask = ( phtfEnabled >> 4 ) & 0x1;
212  std::cout << " INREC_CHDIS_CSC " << 1-chmask << std::endl ;
213  pDTTFMasks->set_inrec_chdis_csc( nwh, isc, 1-chmask ) ;
214 
215  if ( wheelNames[ iwh ] == "N0" ) continue ;
216 
217  maskBit = 20 ;
218  itr = krateMaskBitmap.find( wheelNames[ iwh ] ) ;
219  if( itr != krateMaskBitmap.end() ) maskBit = itr->second ;
220 
221  unsigned long ettfEnabled = ( krateMask >> maskBit ) & 0x7 ;
222 
223  std::cout << "Bits " << std::dec << maskBit << " (" << sectorWheelName
224  << ") of mask " << std::hex << krateMask << " is "
225  << std::hex << ettfEnabled << std::endl ;
226 
227  chmask = ettfEnabled & 0x1;
228  std::cout << " ETSOC_CHDIS_ST1 " << 1-chmask ;
229  pDTTFMasks->set_etsoc_chdis_st1( nwh, isc, 1-chmask ) ;
230  chmask = ( ettfEnabled >> 1 ) & 0x1;
231  std::cout << " ETSOC_CHDIS_ST2 " << 1-chmask ;
232  pDTTFMasks->set_etsoc_chdis_st2( nwh, isc, 1-chmask ) ;
233  chmask = ( ettfEnabled >> 2 ) & 0x1;
234  std::cout << " ETSOC_CHDIS_ST3 " << 1-chmask << std::endl ;
235  pDTTFMasks->set_etsoc_chdis_st3( nwh, isc, 1-chmask ) ;
236  }
237  }
238 
239  return pDTTFMasks ;
240 }
241 
242 // ------------ method called to produce the data ------------
243 
244 
245 //define this as a plug-in
const QueryResults singleAttribute(const T &data) const
Definition: OMDSReader.h:295
virtual boost::shared_ptr< L1MuDTTFMasks > newObject(const std::string &objectKey)
#define NULL
Definition: scimark2.h:8
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="") const
Definition: OMDSReader.cc:87
DTTFMasksOnlineProd(const edm::ParameterSet &)
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:56
tuple cout
Definition: gather_cfg.py:121