CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SiStripFedCablingFakeESSource.cc
Go to the documentation of this file.
10 #include <sstream>
11 #include <vector>
12 #include <map>
13 
14 using namespace sistrip;
15 
16 // -----------------------------------------------------------------------------
17 //
20  detIds_( pset.getParameter<edm::FileInPath>("DetIdsFile") ),
21  fedIds_( pset.getParameter<edm::FileInPath>("FedIdsFile") ),
22  pset_(pset)
23 {
24  findingRecord<SiStripFedCablingRcd>();
25  edm::LogVerbatim("FedCabling")
26  << "[SiStripFedCablingFakeESSource::" << __func__ << "]"
27  << " Constructing object...";
28 }
29 
30 // -----------------------------------------------------------------------------
31 //
33  edm::LogVerbatim("FedCabling")
34  << "[SiStripFedCablingFakeESSource::" << __func__ << "]"
35  << " Destructing object...";
36 }
37 
38 // -----------------------------------------------------------------------------
39 //
41  edm::LogVerbatim("FedCabling")
42  << "[SiStripFedCablingFakeESSource::" << __func__ << "]"
43  << " Building \"fake\" FED cabling map"
44  << " from real DetIds and FedIds (read from ascii file)";
45 
46  // Create FEC cabling object
47  SiStripFecCabling* fec_cabling = new SiStripFecCabling();
48 
49  // Read DetId list from file
51  typedef std::vector<uint32_t> Dets;
52 
53  Dets dets = Detreader.getAllDetIds();
54 
55  // Read FedId list from file
56  typedef std::vector<uint16_t> Feds;
57  Feds feds = SiStripFedIdListReader( fedIds_.fullPath() ).fedIds();
58 
59  bool populateAllFeds=pset_.getParameter<bool>("PopulateAllFeds");
60 
61  // Iterator through DetInfo objects and populate FEC cabling object
62  uint32_t imodule = 0;
63  Dets::const_iterator idet = dets.begin();
64  Dets::const_iterator jdet = dets.end();
65  for ( ; idet != jdet; ++idet ) {
66  uint16_t npairs = Detreader.getNumberOfApvsAndStripLength(*idet).first / 2;
67  for ( uint16_t ipair = 0; ipair < npairs; ++ipair ) {
68  uint16_t addr = 0;
69  if ( npairs == 2 && ipair == 0 ) { addr = 32; }
70  else if ( npairs == 2 && ipair == 1 ) { addr = 36; }
71  else if ( npairs == 3 && ipair == 0 ) { addr = 32; }
72  else if ( npairs == 3 && ipair == 1 ) { addr = 34; }
73  else if ( npairs == 3 && ipair == 2 ) { addr = 36; }
74  else {
75  edm::LogWarning("FedCabling")
76  << "[SiStripFedCablingFakeESSource::" << __func__ << "]"
77  << " Inconsistent values for nPairs (" << npairs
78  << ") and ipair (" << ipair << ")!";
79  }
80  uint32_t module_key = SiStripFecKey(fecCrate( imodule ),
81  fecSlot( imodule ),
82  fecRing( imodule ),
83  ccuAddr( imodule ),
84  ccuChan( imodule )).key();
86  fecSlot( imodule ),
87  fecRing( imodule ),
88  ccuAddr( imodule ),
89  ccuChan( imodule ),
90  addr, addr+1, // apv i2c addresses
91  module_key, // dcu id
92  *idet, // det id
93  npairs ); // apv pairs
94  fec_cabling->addDevices( conn );
95  }
96  imodule++;
97  }
98 
99  // Assign "dummy" FED ids/chans
100  bool insufficient = false;
101  Feds::const_iterator ifed = feds.begin();
102  uint16_t fed_ch = 0;
103  for ( std::vector<SiStripFecCrate>::const_iterator icrate = fec_cabling->crates().begin(); icrate != fec_cabling->crates().end(); icrate++ ) {
104  for ( std::vector<SiStripFec>::const_iterator ifec = icrate->fecs().begin(); ifec != icrate->fecs().end(); ifec++ ) {
105  for ( std::vector<SiStripRing>::const_iterator iring = ifec->rings().begin(); iring != ifec->rings().end(); iring++ ) {
106  for ( std::vector<SiStripCcu>::const_iterator iccu = iring->ccus().begin(); iccu != iring->ccus().end(); iccu++ ) {
107  for ( std::vector<SiStripModule>::const_iterator imod = iccu->modules().begin(); imod != iccu->modules().end(); imod++ ) {
108  if(populateAllFeds){
109  for ( uint16_t ipair = 0; ipair < imod->nApvPairs(); ipair++ ) {
110 
111  if ( ifed == feds.end() ) { fed_ch++; ifed = feds.begin(); }
112  if ( fed_ch == 96 ) {
113  insufficient = true;
114  break;
115  }
116 
117  std::pair<uint16_t,uint16_t> addr = imod->activeApvPair( imod->lldChannel(ipair) );
118  SiStripModule::FedChannel fed_channel( (*ifed)/16+1, // 16 FEDs per crate, numbering starts from 1
119  (*ifed)%16+2, // FED slot starts from 2
120  *ifed,
121  fed_ch );
122  const_cast<SiStripModule&>(*imod).fedCh( addr.first, fed_channel );
123  ifed++;
124 
125  }
126  }else{
127  // Patch introduced by D.Giordano 2/12/08
128  //to reproduce the fake cabling used in 2x
129  //that was designed to fill each fed iteratively
130  //filling all channels of a fed before going to the next one
131  if ( 96-fed_ch < imod->nApvPairs() ) { ifed++; fed_ch = 0; } // move to next FED
132  for ( uint16_t ipair = 0; ipair < imod->nApvPairs(); ipair++ ) {
133  std::pair<uint16_t,uint16_t> addr = imod->activeApvPair( (*imod).lldChannel(ipair) );
134  SiStripModule::FedChannel fed_channel( (*ifed)/16+1, // 16 FEDs per crate, numbering starts from 1
135  (*ifed)%16+2, // FED slot starts from 2
136  (*ifed),
137  fed_ch );
138  const_cast<SiStripModule&>(*imod).fedCh( addr.first, fed_channel );
139  fed_ch++;
140  }
141 
142  }
143  }
144  }
145  }
146  }
147  }
148 
149  if ( insufficient ) {
151  << "[SiStripFedCablingFakeESSource::" << __func__ << "]"
152  << " Insufficient FED channels to cable entire system!";
153  }
154 
155  // Some debug
156  std::stringstream ss;
157  ss << "[SiStripFedCablingFakeESSource::" << __func__ << "]"
158  <<" First count devices of FEC cabling " << std::endl;
159  fec_cabling->countDevices().print(ss);
160  LogTrace(mlCabling_) << ss.str();
161 
162  // Build FED cabling using FedChannelConnections
163  std::vector<FedChannelConnection> conns;
164  fec_cabling->connections( conns );
165  SiStripFedCabling* cabling = new SiStripFedCabling( conns );
166 
167  return cabling;
168 
169 }
170 
171 // -----------------------------------------------------------------------------
172 //
174  const edm::IOVSyncValue& iov_sync,
175  edm::ValidityInterval& iov_validity ) {
176  edm::ValidityInterval infinity( iov_sync.beginOfTime(), iov_sync.endOfTime() );
177  iov_validity = infinity;
178 }
179 
180 
Device and connection information at the level of a front-end module.
Definition: SiStripModule.h:24
T getParameter(std::string const &) const
static uint16_t ccuAddr(const uint16_t &nth_module)
void print(std::stringstream &) const
static uint16_t fecCrate(const uint16_t &nth_module)
virtual SiStripFedCabling * make(const SiStripFedCablingRcd &)
void addDevices(const FedChannelConnection &conn)
static const IOVSyncValue & endOfTime()
Definition: IOVSyncValue.cc:97
const std::vector< SiStripFecCrate > & crates() const
static uint16_t fecSlot(const uint16_t &nth_module)
static uint16_t fecRing(const uint16_t &nth_module)
const uint32_t & key() const
Definition: SiStripKey.h:125
Utility class that identifies a position within the strip tracker control structure, down to the level of an APV25.
Definition: SiStripFecKey.h:45
static const char mlCabling_[]
const std::vector< uint32_t > & getAllDetIds() const
static const IOVSyncValue & beginOfTime()
void connections(std::vector< FedChannelConnection > &) const
Class containning control, module, detector and connection information, at the level of a FED channel...
const double infinity
Abstract base class for producer of SiStripFedCabling record.
SiStripFedCablingFakeESSource(const edm::ParameterSet &)
#define LogTrace(id)
static uint16_t ccuChan(const uint16_t &nth_module)
Contains cabling info at the device level, including DetId, APV pair numbers, hardware addresses...
list key
Definition: combine.py:13
FedChannel fedCh(const uint16_t &apv_pair_num) const
virtual void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &)
std::string fullPath() const
Definition: FileInPath.cc:171
tuple conn
Definition: results_mgr.py:53
NumberOfDevices countDevices() const