CMS 3D CMS Logo

SiStripFedCablingTrivialBuilder.cc

Go to the documentation of this file.
00001 #include "CalibTracker/SiStripConnectivity/plugins/SiStripFedCablingTrivialBuilder.h"
00002 // 
00003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00004 #include "DataFormats/SiStripCommon/interface/SiStripFecKey.h"
00005 #include "CondFormats/SiStripObjects/interface/SiStripFedCabling.h"
00006 #include "CondFormats/SiStripObjects/interface/FedChannelConnection.h"
00007 #include "CalibFormats/SiStripObjects/interface/SiStripFecCabling.h"
00008 // 
00009 #include "CLHEP/Random/RandFlat.h"
00010 // 
00011 #include <iostream>
00012 #include <sstream>
00013 
00014 // -----------------------------------------------------------------------------
00015 //
00016 SiStripFedCablingTrivialBuilder::SiStripFedCablingTrivialBuilder( const edm::ParameterSet& pset ) 
00017   : SiStripFedCablingESSource( pset ),
00018     nFeds_( pset.getUntrackedParameter<unsigned int>("NumberOfFeds",1) )
00019 {
00020   LogDebug("FedCabling") << "[SiStripFedCablingTrivialBuilder::SiStripFedCablingTrivialBuilder]"
00021                          << " Constructing object...";
00022 }
00023 
00024 // -----------------------------------------------------------------------------
00025 //
00026 SiStripFedCablingTrivialBuilder::~SiStripFedCablingTrivialBuilder() {
00027   LogDebug("FedCabling") << "[SiStripFedCablingTrivialBuilder::~SiStripFedCablingTrivialBuilder]"
00028                          << " Destructing object...";
00029 }
00030 
00031 // -----------------------------------------------------------------------------
00032 //
00033 SiStripFedCabling* SiStripFedCablingTrivialBuilder::makeFedCabling() {
00034   static const std::string method = "SiStripFedCablingTrivialBuilder::makeFedCabling";
00035   LogDebug("FedCabling") << "["<<method<<"] Building FED cabling map!";
00036 
00037   // Create FEC cabling object 
00038   SiStripFecCabling* fec_cabling = new SiStripFecCabling();
00039 
00040   // Random number of APV pairs (2 or 3) per module 
00041   std::vector<uint16_t> pairs_per_module;
00042   for ( uint16_t ifed = 0; ifed < nFeds_; ifed++ ) {
00043     uint16_t remaining_pairs = 96;
00044     while ( remaining_pairs > 3 ) {
00045       uint16_t npairs = (RandFlat::shoot()>0.5) ? 3 : 2;
00046       pairs_per_module.push_back( npairs );
00047       remaining_pairs -= npairs;
00048     }
00049     if ( remaining_pairs == 2 || remaining_pairs == 3 ) { 
00050       pairs_per_module.push_back( remaining_pairs ); 
00051     }
00052   }
00053   
00054   // Register APV devices
00055   uint32_t idevice = 0;
00056   for ( uint32_t imod = 0; imod < pairs_per_module.size(); imod++ ) {
00057     for ( uint16_t ipair = 0; ipair < pairs_per_module[imod]; ipair++ ) {
00058       uint16_t addr = 0;
00059       if      ( pairs_per_module[imod] == 2 && ipair == 0 ) { addr = 32; }
00060       else if ( pairs_per_module[imod] == 2 && ipair == 1 ) { addr = 36; }
00061       else if ( pairs_per_module[imod] == 3 && ipair == 0 ) { addr = 32; }
00062       else if ( pairs_per_module[imod] == 3 && ipair == 1 ) { addr = 34; }
00063       else if ( pairs_per_module[imod] == 3 && ipair == 2 ) { addr = 36; }
00064       else {
00065         edm::LogWarning("FedCabling") << "["<<method<<"]"
00066                                     << " Unexpected values: nPairs/ipair = "
00067                                     << pairs_per_module[imod] << "/" << ipair;
00068       }
00069 //       LogDebug("FedCabling") << "["<<method<<"]"
00070 //                           << " Adding device number " << idevice
00071 //                           << " with crate/FEC/Ring/CCU/Module/APV0/APV1 " 
00072 //                           << fecCrate( imod ) << "/" 
00073 //                           << fecSlot( imod ) << "/" 
00074 //                           << fecRing( imod ) << "/" 
00075 //                           << ccuAddr( imod ) << "/" 
00076 //                           << ccuChan( imod ) << "/" 
00077 //                           << addr << "/" << addr+1;
00078       FedChannelConnection conn( fecCrate( imod ),
00079                                  fecSlot( imod ), 
00080                                  fecRing( imod ), 
00081                                  ccuAddr( imod ), 
00082                                  ccuChan( imod ), 
00083                                  addr, addr+1 );
00084       fec_cabling->addDevices( conn );
00085       idevice += 2;
00086     }
00087   }
00088   
00089   // Set DcuId, DetId and number of APV pairs 
00090   uint32_t cntr = 0;
00091   for ( std::vector<SiStripFecCrate>::const_iterator icrate = fec_cabling->crates().begin(); icrate != fec_cabling->crates().end(); icrate++ ) {
00092     for ( std::vector<SiStripFec>::const_iterator ifec = icrate->fecs().begin(); ifec != icrate->fecs().end(); ifec++ ) {
00093       for ( std::vector<SiStripRing>::const_iterator iring = ifec->rings().begin(); iring != ifec->rings().end(); iring++ ) {
00094         for ( std::vector<SiStripCcu>::const_iterator iccu = iring->ccus().begin(); iccu != iring->ccus().end(); iccu++ ) {
00095           for ( std::vector<SiStripModule>::const_iterator imod = iccu->modules().begin(); imod != iccu->modules().end(); imod++ ) {
00096             uint32_t module_key = SiStripFecKey( icrate->fecCrate(), 
00097                                                  ifec->fecSlot(), 
00098                                                  iring->fecRing(), 
00099                                                  iccu->ccuAddr(), 
00100                                                  imod->ccuChan() ).key();
00101             SiStripModule& module = const_cast<SiStripModule&>(*imod);
00102             module.dcuId( module_key );
00103             module.detId( cntr+1 );
00104             module.nApvPairs(0);
00105 //          LogDebug("FedCabling") << "["<<method<<"]"
00106 //                                 << " Setting DcuId/DetId/nApvPairs = " 
00107 //                                 << module_key << "/" << cntr+1 << "/" << module.nApvPairs()
00108 //                                 << " for Crate/FEC/Ring/CCU/Module " 
00109 //                                 << icrate->fecCrate() << "/" 
00110 //                                 << ifec->fecSlot() << "/" 
00111 //                                 << iring->fecRing() << "/" 
00112 //                                 << iccu->ccuAddr() << "/" 
00113 //                                 << imod->ccuChan();
00114             cntr++;
00115           }
00116         }
00117       }
00118     }
00119   }
00120 
00121   // Set "dummy" FED id / channel 
00122   uint16_t fed_id = 50;
00123   uint16_t fed_ch = 0;
00124   for ( std::vector<SiStripFecCrate>::const_iterator icrate = fec_cabling->crates().begin(); icrate != fec_cabling->crates().end(); icrate++ ) {
00125     for ( std::vector<SiStripFec>::const_iterator ifec = icrate->fecs().begin(); ifec != icrate->fecs().end(); ifec++ ) {
00126       for ( std::vector<SiStripRing>::const_iterator iring = ifec->rings().begin(); iring != ifec->rings().end(); iring++ ) {
00127         for ( std::vector<SiStripCcu>::const_iterator iccu = iring->ccus().begin(); iccu != iring->ccus().end(); iccu++ ) {
00128           for ( std::vector<SiStripModule>::const_iterator imod = iccu->modules().begin(); imod != iccu->modules().end(); imod++ ) {
00129             if ( 96-fed_ch < imod->nApvPairs() ) { fed_id++; fed_ch = 0; } // move to next FED
00130             for ( uint16_t ipair = 0; ipair < imod->nApvPairs(); ipair++ ) {
00131               std::pair<uint16_t,uint16_t> addr = imod->activeApvPair( (*imod).lldChannel(ipair) );
00132               SiStripModule::FedChannel fed_channel( fed_id/16+1, // 16 FEDs per crate, numbering starts from 1
00133                                                      fed_id%16+2, // FED slot starts from 2
00134                                                      fed_id,
00135                                                      fed_ch );
00136               const_cast<SiStripModule&>(*imod).fedCh( addr.first, fed_channel );
00137 //            LogDebug("FedCabling") << "["<<method<<"]"
00138 //                                   << " Setting FED id/channel = " 
00139 //                                   << fed_id << "/" << fed_ch
00140 //                                   <<" for Crate/FEC/Ring/CCU/Module/Pair/APVaddr " 
00141 //                                   << icrate->fecCrate() << "/" 
00142 //                                   << ifec->fecSlot() << "/" 
00143 //                                   << iring->fecRing() << "/" 
00144 //                                   << iccu->ccuAddr() << "/" 
00145 //                                   << imod->ccuChan() << "/"
00146 //                                   << ipair << "/"
00147 //                                   << addr.first; 
00148               fed_ch++;
00149             }
00150           }
00151         }
00152       }
00153     }
00154   }
00155 
00156   // Debug
00157   std::stringstream ss;
00158   fec_cabling->countDevices().print(ss);
00159   LogDebug("FecCabling") << "["<<method<<"]" << ss.str();
00160   
00161   // Build FED cabling using FedChannelConnections
00162   std::vector<FedChannelConnection> conns;
00163   fec_cabling->connections( conns );
00164   std::vector<FedChannelConnection>::iterator iconn;
00165   for ( iconn = conns.begin(); iconn != conns.end(); iconn++ ) { 
00166     // std::stringstream ss;
00167     // iconn->print(ss);
00168     // LogDebug("FedCabling") << "["<<method<<"]" << ss.str();
00169   }
00170   SiStripFedCabling* cabling = new SiStripFedCabling( conns );
00171   LogDebug("FedCabling") << "["<<method<<"]"
00172                          << " Finished building FED cabling map!";
00173   return cabling;
00174   
00175 }
00176 

Generated on Tue Jun 9 17:25:50 2009 for CMSSW by  doxygen 1.5.4