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
00038 SiStripFecCabling* fec_cabling = new SiStripFecCabling();
00039
00040
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
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
00070
00071
00072
00073
00074
00075
00076
00077
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
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
00106
00107
00108
00109
00110
00111
00112
00113
00114 cntr++;
00115 }
00116 }
00117 }
00118 }
00119 }
00120
00121
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; }
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,
00133 fed_id%16+2,
00134 fed_id,
00135 fed_ch );
00136 const_cast<SiStripModule&>(*imod).fedCh( addr.first, fed_channel );
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148 fed_ch++;
00149 }
00150 }
00151 }
00152 }
00153 }
00154 }
00155
00156
00157 std::stringstream ss;
00158 fec_cabling->countDevices().print(ss);
00159 LogDebug("FecCabling") << "["<<method<<"]" << ss.str();
00160
00161
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
00167
00168
00169 }
00170 SiStripFedCabling* cabling = new SiStripFedCabling( conns );
00171 LogDebug("FedCabling") << "["<<method<<"]"
00172 << " Finished building FED cabling map!";
00173 return cabling;
00174
00175 }
00176