CMS 3D CMS Logo

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  fedIds_( pset.getParameter<edm::FileInPath>("FedIdsFile") ),
21  pset_(pset)
22 {
23  findingRecord<SiStripFedCablingRcd>();
24  edm::LogVerbatim("FedCabling")
25  << "[SiStripFedCablingFakeESSource::" << __func__ << "]"
26  << " Constructing object...";
27 }
28 
29 // -----------------------------------------------------------------------------
30 //
32  edm::LogVerbatim("FedCabling")
33  << "[SiStripFedCablingFakeESSource::" << __func__ << "]"
34  << " Destructing object...";
35 }
36 
37 // -----------------------------------------------------------------------------
38 //
40  edm::LogVerbatim("FedCabling")
41  << "[SiStripFedCablingFakeESSource::" << __func__ << "]"
42  << " Building \"fake\" FED cabling map"
43  << " from real DetIds and FedIds (read from ascii file)";
44 
45  // Create FEC cabling object
46  SiStripFecCabling* fec_cabling = new SiStripFecCabling();
47 
48  // Read DetId list from file
50  typedef std::vector<uint32_t> Dets;
51 
52  Dets dets = Detreader->getAllDetIds();
53 
54  // Read FedId list from file
55  typedef std::vector<uint16_t> Feds;
56  Feds feds = SiStripFedIdListReader( fedIds_.fullPath() ).fedIds();
57 
58  bool populateAllFeds=pset_.getParameter<bool>("PopulateAllFeds");
59 
60  // Iterator through DetInfo objects and populate FEC cabling object
61  uint32_t imodule = 0;
62  Dets::const_iterator idet = dets.begin();
63  Dets::const_iterator jdet = dets.end();
64  for ( ; idet != jdet; ++idet ) {
65  uint16_t npairs = Detreader->getNumberOfApvsAndStripLength(*idet).first / 2;
66  for ( uint16_t ipair = 0; ipair < npairs; ++ipair ) {
67  uint16_t addr = 0;
68  if ( npairs == 2 && ipair == 0 ) { addr = 32; }
69  else if ( npairs == 2 && ipair == 1 ) { addr = 36; }
70  else if ( npairs == 3 && ipair == 0 ) { addr = 32; }
71  else if ( npairs == 3 && ipair == 1 ) { addr = 34; }
72  else if ( npairs == 3 && ipair == 2 ) { addr = 36; }
73  else {
74  edm::LogWarning("FedCabling")
75  << "[SiStripFedCablingFakeESSource::" << __func__ << "]"
76  << " Inconsistent values for nPairs (" << npairs
77  << ") and ipair (" << ipair << ")!";
78  }
79  uint32_t module_key = SiStripFecKey(fecCrate( imodule ),
80  fecSlot( imodule ),
81  fecRing( imodule ),
82  ccuAddr( imodule ),
83  ccuChan( imodule )).key();
84  FedChannelConnection conn( fecCrate( imodule ),
85  fecSlot( imodule ),
86  fecRing( imodule ),
87  ccuAddr( imodule ),
88  ccuChan( imodule ),
89  addr, addr+1, // apv i2c addresses
90  module_key, // dcu id
91  *idet, // det id
92  npairs ); // apv pairs
93  fec_cabling->addDevices( conn );
94  }
95  imodule++;
96  }
97 
98  // Assign "dummy" FED ids/chans
99  bool insufficient = false;
100  Feds::const_iterator ifed = feds.begin();
101  uint16_t fed_ch = 0;
102  for ( std::vector<SiStripFecCrate>::const_iterator icrate = fec_cabling->crates().begin(); icrate != fec_cabling->crates().end(); icrate++ ) {
103  for ( std::vector<SiStripFec>::const_iterator ifec = icrate->fecs().begin(); ifec != icrate->fecs().end(); ifec++ ) {
104  for ( std::vector<SiStripRing>::const_iterator iring = ifec->rings().begin(); iring != ifec->rings().end(); iring++ ) {
105  for ( std::vector<SiStripCcu>::const_iterator iccu = iring->ccus().begin(); iccu != iring->ccus().end(); iccu++ ) {
106  for ( std::vector<SiStripModule>::const_iterator imod = iccu->modules().begin(); imod != iccu->modules().end(); imod++ ) {
107  if(populateAllFeds){
108  for ( uint16_t ipair = 0; ipair < imod->nApvPairs(); ipair++ ) {
109 
110  if ( ifed == feds.end() ) { fed_ch++; ifed = feds.begin(); }
111  if ( fed_ch == 96 ) {
112  insufficient = true;
113  break;
114  }
115 
116  std::pair<uint16_t,uint16_t> addr = imod->activeApvPair( imod->lldChannel(ipair) );
117  SiStripModule::FedChannel fed_channel( (*ifed)/16+1, // 16 FEDs per crate, numbering starts from 1
118  (*ifed)%16+2, // FED slot starts from 2
119  *ifed,
120  fed_ch );
121  const_cast<SiStripModule&>(*imod).fedCh( addr.first, fed_channel );
122  ifed++;
123 
124  }
125  }else{
126  // Patch introduced by D.Giordano 2/12/08
127  //to reproduce the fake cabling used in 2x
128  //that was designed to fill each fed iteratively
129  //filling all channels of a fed before going to the next one
130  if ( 96-fed_ch < imod->nApvPairs() ) { ifed++; fed_ch = 0; } // move to next FED
131  for ( uint16_t ipair = 0; ipair < imod->nApvPairs(); ipair++ ) {
132  std::pair<uint16_t,uint16_t> addr = imod->activeApvPair( (*imod).lldChannel(ipair) );
133  SiStripModule::FedChannel fed_channel( (*ifed)/16+1, // 16 FEDs per crate, numbering starts from 1
134  (*ifed)%16+2, // FED slot starts from 2
135  (*ifed),
136  fed_ch );
137  const_cast<SiStripModule&>(*imod).fedCh( addr.first, fed_channel );
138  fed_ch++;
139  }
140 
141  }
142  }
143  }
144  }
145  }
146  }
147 
148  if ( insufficient ) {
150  << "[SiStripFedCablingFakeESSource::" << __func__ << "]"
151  << " Insufficient FED channels to cable entire system!";
152  }
153 
154  // Some debug
155  std::stringstream ss;
156  ss << "[SiStripFedCablingFakeESSource::" << __func__ << "]"
157  <<" First count devices of FEC cabling " << std::endl;
158  fec_cabling->countDevices().print(ss);
159  LogTrace(mlCabling_) << ss.str();
160 
161  // Build FED cabling using FedChannelConnections
162  std::vector<FedChannelConnection> conns;
163  fec_cabling->connections( conns );
164  SiStripFedCabling* cabling = new SiStripFedCabling( conns );
165 
166  return cabling;
167 
168 }
169 
170 // -----------------------------------------------------------------------------
171 //
173  const edm::IOVSyncValue& iov_sync,
174  edm::ValidityInterval& iov_validity ) {
175  edm::ValidityInterval infinity( iov_sync.beginOfTime(), iov_sync.endOfTime() );
176  iov_validity = infinity;
177 }
178 
179 
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)
const std::pair< unsigned short, double > getNumberOfApvsAndStripLength(uint32_t detId) const
void addDevices(const FedChannelConnection &conn)
static const IOVSyncValue & endOfTime()
Definition: IOVSyncValue.cc:82
const std::vector< SiStripFecCrate > & crates() const
static uint16_t fecSlot(const uint16_t &nth_module)
static uint16_t fecRing(const uint16_t &nth_module)
sistrip classes
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()
Definition: IOVSyncValue.cc:88
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...
SiStripFedCabling * make(const SiStripFedCablingRcd &) override
HLT enums.
FedChannel fedCh(const uint16_t &apv_pair_num) const
std::string fullPath() const
Definition: FileInPath.cc:163
void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &) override
NumberOfDevices countDevices() const