CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch12/src/OnlineDB/SiStripESSources/src/SiStripCondObjBuilderFromDb.cc

Go to the documentation of this file.
00001 // Last commit: $Id: SiStripCondObjBuilderFromDb.cc,v 1.20 2010/01/28 14:15:56 alinn Exp $
00002 // Latest tag:  $Name: V05-00-02-05 $
00003 
00004 #include "OnlineDB/SiStripESSources/interface/SiStripCondObjBuilderFromDb.h"
00005 #include "OnlineDB/SiStripESSources/interface/SiStripFedCablingBuilderFromDb.h"
00006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00007 #include "DataFormats/SiStripCommon/interface/SiStripFecKey.h"
00008 #include "DataFormats/SiStripCommon/interface/SiStripFedKey.h"
00009 #include "CondFormats/SiStripObjects/interface/SiStripPedestals.h"
00010 #include "CondFormats/SiStripObjects/interface/SiStripNoises.h"
00011 #include "CondFormats/SiStripObjects/interface/SiStripThreshold.h"
00012 #include "CondFormats/SiStripObjects/interface/SiStripApvGain.h"
00013 #include "CondFormats/SiStripObjects/interface/SiStripLatency.h"
00014 #include "CondFormats/SiStripObjects/interface/SiStripFedCabling.h"
00015 #include "CondFormats/SiStripObjects/interface/FedChannelConnection.h"
00016 #include "CalibFormats/SiStripObjects/interface/SiStripFecCabling.h"
00017 #include "CalibFormats/SiStripObjects/interface/SiStripDetCabling.h"
00018 #include "CalibFormats/SiStripObjects/interface/SiStripQuality.h"
00019 #include "CalibTracker/SiStripCommon/interface/SiStripDetInfoFileReader.h"
00020 
00021 #include <cstdlib>
00022 #include <iostream>
00023 #include <sstream>
00024 #include <iomanip>
00025 #include "Fed9UUtils.hh"
00026 
00027 using namespace std;
00028 using namespace sistrip;
00029 
00030                                    
00031 // -----------------------------------------------------------------------------
00033 SiStripCondObjBuilderFromDb::SiStripCondObjBuilderFromDb(const edm::ParameterSet& pset,
00034                                                          const edm::ActivityRegistry&):
00035   m_gaincalibrationfactor(static_cast<float>(pset.getUntrackedParameter<double>("GainNormalizationFactor",690.))), 
00036   m_defaultpedestalvalue(static_cast<float>(pset.getUntrackedParameter<double>("DefaultPedestal",0.))), 
00037   m_defaultnoisevalue(static_cast<float>(pset.getUntrackedParameter<double>("DefaultNoise",0.))), 
00038   m_defaultthresholdhighvalue(static_cast<float>(pset.getUntrackedParameter<double>("DefaultThresholdHigh",0.))), 
00039   m_defaultthresholdlowvalue(static_cast<float>(pset.getUntrackedParameter<double>("DefaultThresholdLow",0.))), 
00040   m_defaultapvmodevalue(static_cast<uint16_t>(pset.getUntrackedParameter<uint32_t>("DefaultAPVMode",37))),
00041   m_defaultapvlatencyvalue(static_cast<uint16_t>(pset.getUntrackedParameter<uint32_t>("DefaultAPVLatency",142))),
00042   m_defaulttickheightvalue(static_cast<float>(pset.getUntrackedParameter<double>("DefaultTickHeight",690.))),
00043   m_useanalysis(static_cast<bool>(pset.getUntrackedParameter<bool>("UseAnalysis",false))),
00044   m_usefed(static_cast<bool>(pset.getUntrackedParameter<bool>("UseFED",false))),
00045   m_usefec(static_cast<bool>(pset.getUntrackedParameter<bool>("UseFEC",false))),
00046   m_debug(static_cast<bool>(pset.getUntrackedParameter<bool>("DebugMode",false)))
00047 {
00048   LogTrace(mlESSources_) 
00049     << "[SiStripCondObjBuilderFromDb::" << __func__ << "]"
00050     << " Constructing object...";
00051 }
00052 
00053 // -----------------------------------------------------------------------------
00055 SiStripCondObjBuilderFromDb::SiStripCondObjBuilderFromDb() 
00056 {
00057   LogTrace(mlESSources_) 
00058     << "[SiStripCondObjBuilderFromDb::" << __func__ << "]"
00059     << " Constructing object...";
00060 }
00061 
00062 // -----------------------------------------------------------------------------
00064 SiStripCondObjBuilderFromDb::~SiStripCondObjBuilderFromDb() {
00065   LogTrace(mlESSources_)
00066     << "[SiStripCondObjBuilderFromDb::" << __func__ << "]"
00067     << " Destructing object...";
00068 }
00069 
00070 // -----------------------------------------------------------------------------
00072 void SiStripCondObjBuilderFromDb::checkUpdate() {
00073   if (!(dbParams_==dbParams())){
00074     dbParams_=dbParams();
00075     buildCondObj();
00076   }  
00077 }
00078 
00079 
00080 // -----------------------------------------------------------------------------
00082 bool SiStripCondObjBuilderFromDb::checkForCompatibility(std::stringstream& input,std::stringstream& output,std::string& label){
00083 
00084 
00085   //get current config DB parameter
00086       
00087   SiStripDbParams::const_iterator_range partitionsRange = dbParams().partitions(); 
00088 
00089   SiStripDbParams::SiStripPartitions::const_iterator ipart = partitionsRange.begin();
00090   SiStripDbParams::SiStripPartitions::const_iterator ipartEnd = partitionsRange.end();
00091   for ( ; ipart != ipartEnd; ++ipart ) { 
00092     SiStripPartition partition=ipart->second;
00093     output  << "@ "
00094             << " Partition " << partition.partitionName() ;
00095     if (label!="Cabling" && label !="ApvLatency")
00096         output << " FedVer "    << partition.fedVersion().first << "." << partition.fedVersion().second;       
00097     if(label=="Cabling")
00098       output << " CabVer "    << partition.cabVersion().first << "." << partition.cabVersion().second
00099              << " MaskVer "   << partition.maskVersion().first << "." << partition.maskVersion().second;
00100     if(label=="ApvTiming")
00101       output<< " ApvTimingVer " << partition.apvTimingVersion().first << "." << partition.apvTimingVersion().second;
00102     if(label=="ApvLatency")
00103       output<< " FecVersion " << partition.fecVersion().first << "." << partition.fecVersion().second;
00104   }
00105   
00106   if (!strcmp(output.str().c_str(),input.str().c_str()))
00107     return false;
00108 
00109   return true;
00110 }
00111 
00112 // -----------------------------------------------------------------------------
00114 void SiStripCondObjBuilderFromDb::buildCondObj() {
00115   LogTrace(mlESSources_) 
00116     << "[SiStripCondObjBuilderFromDb::" << __func__ << "]";
00117 
00118   // Check if DB connection is made 
00119   if ( db_ ) { 
00120     
00121     // Check if DB connection is made 
00122     if ( db_->deviceFactory() || 
00123          db_->databaseCache() ) { 
00124       
00125       // Build FEC cabling object
00126       SiStripFecCabling fec_cabling;
00127       
00128       SiStripFedCablingBuilderFromDb::buildFecCabling( &*db_, 
00129                                                        fec_cabling, 
00130                                                        sistrip::CABLING_FROM_CONNS );
00131       fed_cabling_=new SiStripFedCabling;
00132 
00133       SiStripFedCablingBuilderFromDb::getFedCabling( fec_cabling, *fed_cabling_ );
00134       SiStripDetCabling det_cabling( *fed_cabling_ );
00135       buildStripRelatedObjects( &*db_, det_cabling );
00136      
00137      
00138       if(m_useanalysis)buildAnalysisRelatedObjects(&*db_, v_trackercon);
00139       if(m_usefed) buildFEDRelatedObjects(&*db_, v_trackercon);
00140       if(m_usefec) buildFECRelatedObjects(&*db_, v_trackercon);
00141          
00142    
00143       
00144     } else {
00145       edm::LogWarning(mlESSources_)
00146         << "[SiStripCondObjBuilderFromDb::" << __func__ << "]"
00147         << " NULL pointer to DeviceFactory returned by SiStripConfigDb!"
00148         << " Cannot build Pedestals object!";
00149     }
00150   } else {
00151     edm::LogWarning(mlESSources_)
00152       << "[SiStripCondObjBuilderFromDb::" << __func__ << "]"
00153       << " NULL pointer to SiStripConfigDb returned by DB \"service\"!"
00154       << " Cannot build Pedestals object!";
00155   }
00156 }
00157 
00158 // -----------------------------------------------------------------------------
00160 //Retrieve FedDescriptions from configuration database
00161 bool SiStripCondObjBuilderFromDb::retrieveFedDescriptions(SiStripConfigDb* const db){
00162   SiStripConfigDb::FedDescriptionsRange descriptions = db->getFedDescriptions();
00163   if ( descriptions.empty() ) {
00164     edm::LogWarning(mlESSources_)
00165       << "SiStripCondObjBuilderFromDb::" << __func__ << "]"
00166       << " No FED descriptions found!";
00167     
00168     return false;
00169   }
00170   return true;
00171 }
00172 
00173 // -----------------------------------------------------------------------------
00175   // Retrieve gain from configuration database
00176 bool SiStripCondObjBuilderFromDb::retrieveTimingAnalysisDescriptions( SiStripConfigDb* const db){
00177   SiStripConfigDb::AnalysisDescriptionsRange anal_descriptions = 
00178     db->getAnalysisDescriptions( CommissioningAnalysisDescription::T_ANALYSIS_TIMING );
00179   if ( anal_descriptions.empty() ) {
00180     edm::LogWarning(mlESSources_)
00181       << "SiStripCondObjBuilderFromDb::" << __func__ << "]"
00182       << " Unable to build SiStripApvGain object!"
00183       << " No timing-scan analysis descriptions found!";
00184     return false;
00185   }
00186   return true;
00187 }
00188 
00189 // -----------------------------------------------------------------------------
00191   // Retrieve list of active DetIds
00192 vector<uint32_t> SiStripCondObjBuilderFromDb::retrieveActiveDetIds(const SiStripDetCabling& det_cabling){
00193   vector<uint32_t> det_ids;
00194   det_cabling.addActiveDetectorsRawIds(det_ids);
00195   if ( det_ids.empty() ) {
00196     edm::LogWarning(mlESSources_)
00197       << "SiStripCondObjBuilderFromDb::" << __func__ << "]"
00198       << " Unable to build Pedestals object!"
00199       << " No DetIds found!";
00200     return det_ids;
00201   }  
00202   LogTrace(mlESSources_)
00203     << "\n\nSiStripCondObjBuilderFromDb::" << __func__ << "]"
00204     << " Found " << det_ids.size() << " active DetIds";
00205   return det_ids;
00206 }
00207 
00208 // -----------------------------------------------------------------------------
00210  //build connections per DetId
00211 vector<FedChannelConnection> SiStripCondObjBuilderFromDb::buildConnections(const SiStripDetCabling& det_cabling, uint32_t det_id ){
00212     vector<FedChannelConnection> conns = det_cabling.getConnections(det_id);
00213     if (conns.size()==0){
00214       edm::LogWarning(mlESSources_)
00215         << "SiStripCondObjBuilderFromDb::" << __func__ << "]"
00216         << " Unable to build condition object!"
00217         << " No FED channel connections found for detid "<< det_id;
00218     }
00219     return conns;
00220 }
00221 
00222 // -----------------------------------------------------------------------------
00224 //retrieve number of APV pairs per detid
00225 uint16_t SiStripCondObjBuilderFromDb::retrieveNumberAPVPairs(uint32_t det_id){
00226   uint16_t nApvPairs;
00227   SiStripDetInfoFileReader * fr=edm::Service<SiStripDetInfoFileReader>().operator->();
00228   nApvPairs=fr->getNumberOfApvsAndStripLength(det_id).first/2;
00229   return nApvPairs;
00230 }
00231 
00232 // -----------------------------------------------------------------------------
00234 //set default values for Cabling Objects Peds, Noise, thresh, Quality
00235 void SiStripCondObjBuilderFromDb::setDefaultValuesCabling(uint16_t apvPair){
00236   uint16_t istrip = apvPair*sistrip::STRIPS_PER_FEDCH;  
00237   inputQuality.push_back(quality_->encode(istrip,sistrip::STRIPS_PER_FEDCH));
00238   threshold_->setData( istrip, m_defaultthresholdlowvalue, m_defaultthresholdlowvalue, inputThreshold );
00239   for ( ;istrip < (apvPair+1)*sistrip::STRIPS_PER_FEDCH; ++istrip ){
00240     pedestals_->setData(m_defaultpedestalvalue,inputPedestals );
00241     noises_->setData(m_defaultnoisevalue ,inputNoises );
00242   }
00243 }
00244 
00245 // -----------------------------------------------------------------------------
00247 void SiStripCondObjBuilderFromDb::setDefaultValuesApvTiming(){
00248   inputApvGain.push_back(m_defaulttickheightvalue/m_gaincalibrationfactor); // APV0
00249   inputApvGain.push_back(m_defaulttickheightvalue/m_gaincalibrationfactor); // APV1
00250 }
00251 
00252 // -----------------------------------------------------------------------------
00254 void SiStripCondObjBuilderFromDb::setDefaultValuesApvLatency(SiStripLatency & latency_, FedChannelConnection ipair, uint16_t apvnr){
00255   latency_.put( ipair.detId(), apvnr, m_defaultapvmodevalue, m_defaultapvlatencyvalue);
00256   latency_.put( ipair.detId(), ++apvnr, m_defaultapvmodevalue, m_defaultapvlatencyvalue);
00257 }
00258 
00259 
00260 
00261 // -----------------------------------------------------------------------------
00263 bool SiStripCondObjBuilderFromDb::setValuesApvTiming(SiStripConfigDb* const db, FedChannelConnection &ipair){
00264   SiStripConfigDb::AnalysisDescriptionsRange anal_descriptions = db->getAnalysisDescriptions( CommissioningAnalysisDescription::T_ANALYSIS_TIMING );
00265    SiStripConfigDb::AnalysisDescriptionsV::const_iterator iii = anal_descriptions.begin();
00266   SiStripConfigDb::AnalysisDescriptionsV::const_iterator jjj = anal_descriptions.end();
00267  
00268   while ( iii != jjj ) {
00269     CommissioningAnalysisDescription* tmp = *iii;
00270     uint16_t fed_id = tmp->getFedId();
00271     uint16_t fed_ch = SiStripFedKey::fedCh( tmp->getFeUnit(), tmp->getFeChan() );
00272     if ( fed_id == ipair.fedId() && fed_ch == ipair.fedCh() ) { break; }
00273     iii++;
00274   }
00275   
00276   TimingAnalysisDescription *anal=0;
00277   if ( iii != jjj ) { anal = dynamic_cast<TimingAnalysisDescription*>(*iii); }
00278   if ( anal ) {
00279     float tick_height = (anal->getHeight() / m_gaincalibrationfactor);
00280     inputApvGain.push_back( tick_height ); // APV0
00281     inputApvGain.push_back( tick_height); // APV1
00282   } else {
00283     inputApvGain.push_back(m_defaulttickheightvalue/m_gaincalibrationfactor); // APV0
00284     inputApvGain.push_back(m_defaulttickheightvalue/m_gaincalibrationfactor); // APV1
00285     return false;
00286   }
00287 
00288   return true;
00289 }
00290 
00291 // -----------------------------------------------------------------------------
00293 bool SiStripCondObjBuilderFromDb::setValuesApvLatency(SiStripLatency & latency_, SiStripConfigDb* const db, FedChannelConnection &ipair, uint32_t detid, uint16_t apvnr){
00294 SiStripDetInfoFileReader * fr=edm::Service<SiStripDetInfoFileReader>().operator->();
00295  uint16_t nApvPairs;
00296  nApvPairs=fr->getNumberOfApvsAndStripLength(detid).first/2;
00297  SiStripConfigDb::DeviceDescriptionsRange apvs = db->getDeviceDescriptions( APV25 );
00298  
00299  SiStripConfigDb::DeviceDescriptionsV::const_iterator iapv = apvs.begin();
00300  SiStripConfigDb::DeviceDescriptionsV::const_iterator japv = apvs.end();
00301  if(iapv==japv) return false;
00302  for ( ; iapv != japv; ++iapv ) {
00303    apvDescription* apv = dynamic_cast<apvDescription*>( *iapv );
00304    if ( !apv ) { continue; }
00305    if((apv->getFecSlot()) != (ipair.fecSlot())) continue;
00306    if((apv->getRingSlot()) != (ipair.fecRing())) continue;
00307    if((apv->getCcuAddress()) != (ipair.ccuAddr())) continue;
00308    if((apv->getChannel()) != (ipair.ccuChan())) continue;
00309    // Insert latency values into latency object
00310    if((apv->getAddress()) == (ipair.i2cAddr(0))) {
00311      if(!latency_.put( ipair.detId(), apvnr, static_cast<uint16_t>(apv->getLatency()), static_cast<uint16_t>(apv->getApvMode()))){
00312        std::cout << "UNABLE APVLatency Put: Detid "<< ipair.detId() << " APVNr.: " << apvnr << " Latency Value: " << apv->getLatency() << " APV Mode: " << apv->getApvMode()<< std::endl;
00313        return false;
00314      }
00315      apvnr++;
00316    }
00317    if((apv->getAddress()) == (ipair.i2cAddr(1))) {
00318      if(!latency_.put( ipair.detId(), apvnr, static_cast<uint16_t>(apv->getLatency()), static_cast<uint16_t>(apv->getApvMode()))){
00319        std::cout << "UNABLE APVLatency Put: Detid "<< ipair.detId() << " APVNr.: " << apvnr << " Latency Value: " << dec <<apv->getLatency() << " APV Mode: " << dec <<apv->getApvMode()<< std::endl;
00320        return false;
00321      }
00322      apvnr++;
00323    }
00324  }
00325  return true;
00326 }
00327 
00328 // -----------------------------------------------------------------------------
00330 bool SiStripCondObjBuilderFromDb::setValuesCabling(SiStripConfigDb* const db, FedChannelConnection &ipair, uint32_t detid){  SiStripConfigDb::FedDescriptionsRange descriptions = db->getFedDescriptions();
00331   SiStripConfigDb::FedDescriptionsV::const_iterator description = descriptions.begin();
00332   while ( description != descriptions.end() ) {
00333     if ( (*description)->getFedId() ==ipair.fedId() ) { break; }
00334     description++;
00335   }
00336   if ( description == descriptions.end() ) {return false;}
00337   // Retrieve Fed9UStrips object from FED description
00338   const Fed9U::Fed9UStrips& strips = (*description)->getFedStrips();
00339       
00340       
00341   // Retrieve StripDescriptions for each APV
00342   uint16_t jstrip = ipair.apvPairNumber()*sistrip::STRIPS_PER_FEDCH;
00343   for ( uint16_t iapv = 2*ipair.fedCh(); iapv < 2*ipair.fedCh()+2; iapv++ ) {
00344         
00345     // Get StripDescriptions for the given APV
00346     Fed9U::Fed9UAddress addr;
00347     addr.setFedApv(iapv);
00348     vector<Fed9U::Fed9UStripDescription> strip = strips.getApvStrips(addr);
00349         
00350     vector<Fed9U::Fed9UStripDescription>::const_iterator istrip = strip.begin();
00351     uint16_t stripcount=0;
00352     for ( ; istrip != strip.end(); istrip++ ) {
00353       pedestals_->setData( istrip->getPedestal() , inputPedestals);
00354       noises_   ->setData( istrip->getNoise()    , inputNoises );
00355       threshold_->setData( jstrip, istrip->getLowThresholdFactor(),
00356                            istrip->getHighThresholdFactor(), inputThreshold );
00357       if(istrip->getDisable())
00358         inputQuality.push_back(quality_->encode(jstrip,1));
00359       stripcount++;
00360       jstrip++;
00361     }
00362   }
00363   return true;
00364 }
00365 
00366 
00367 // -----------------------------------------------------------------------------
00369 //store objects
00370 void SiStripCondObjBuilderFromDb::storePedestals(uint32_t det_id){
00371    if ( !pedestals_->put(det_id, inputPedestals ) ) {
00372     std::cout
00373       << "[SiStripCondObjBuilderFromDb::" << __func__ << "]"
00374       << " Unable to insert values into SiStripPedestals object!"
00375       << " DetId already exists!" << std::endl;
00376   }
00377   inputPedestals.clear();
00378 }
00379 
00380 // -----------------------------------------------------------------------------
00382 void SiStripCondObjBuilderFromDb::storeNoise(uint32_t det_id){
00383   // Insert noise values into Noises object
00384     if ( !noises_->put(det_id, inputNoises ) ) {
00385       std::cout
00386         << "[SiStripCondObjBuilderFromDb::" << __func__ << "]"
00387         << " Unable to insert values into SiStripNoises object!"
00388         << " DetId already exists!" << std::endl;
00389     }
00390     inputNoises.clear();
00391 }
00392 
00393 // -----------------------------------------------------------------------------
00395 void SiStripCondObjBuilderFromDb::storeThreshold(uint32_t det_id){
00396   // Insert threshold values into Threshold object
00397     if ( !threshold_->put(det_id, inputThreshold ) ) {
00398       std::cout
00399         << "[SiStripCondObjBuilderFromDb::" << __func__ << "]"
00400         << " Unable to insert values into SiStripThreshold object!"
00401         << " DetId already exists!" << std::endl;
00402     }
00403     inputThreshold.clear();
00404 }
00405 
00406 // -----------------------------------------------------------------------------
00408 void SiStripCondObjBuilderFromDb::storeQuality(uint32_t det_id){
00409   // Insert quality values into Quality object
00410     if (inputQuality.size()){
00411       quality_->compact(det_id,inputQuality);
00412       if ( !quality_->put(det_id, inputQuality ) ) {
00413         std::cout
00414           << "[SiStripCondObjBuilderFromDb::" << __func__ << "]"
00415           << " Unable to insert values into SiStripThreshold object!"
00416           << " DetId already exists!" << std::endl;
00417       }
00418     }
00419     inputQuality.clear();
00420 }
00421 
00422 // -----------------------------------------------------------------------------
00424 void SiStripCondObjBuilderFromDb::storeTiming(uint32_t det_id){
00425   // Insert tick height values into Gain object
00426       SiStripApvGain::Range range( inputApvGain.begin(), inputApvGain.end() );
00427       if ( !gain_->put( det_id, range ) ) {
00428         edm::LogWarning(mlESSources_)
00429           << "[SiStripCondObjBuilderFromDb::" << __func__ << "]"
00430           << " Unable to insert values into SiStripApvGain object!"
00431           << " DetId already exists!";
00432       }
00433       inputApvGain.clear();
00434 }
00435 
00436 
00437 // -----------------------------------------------------------------------------
00439 void SiStripCondObjBuilderFromDb::buildStripRelatedObjects( SiStripConfigDb* const db,
00440                                                             const SiStripDetCabling& det_cabling){
00441   //variables needed in this function
00442   uint16_t nApvPairs;
00443   vector<uint32_t>::const_iterator det_id;
00444   vector<uint32_t> det_ids;
00445  
00446   edm::LogInfo(mlESSources_)
00447     << "\n[SiStripCondObjBuilderFromDb::" << __func__ << "] first call to this method";
00448 
00449   //Check if FedDescriptions exist, if not return
00450   if (!retrieveFedDescriptions(db)) {std::cout<< "Found no FedDescription!" << std::endl;return;}
00451   // Retrieve list of active DetIds
00452   det_cabling.addActiveDetectorsRawIds(det_ids);
00453   if ( det_ids.empty() ) {
00454     std::cout
00455       << "SiStripCondObjBuilderFromDb::" << __func__ << "]"
00456       << " Unable to build Pedestals object!"
00457       << " No DetIds found!" << std::endl;
00458     return;
00459   }  
00460   std::cout << "\n\nSiStripCondObjBuilderFromDb::" << __func__ << "]"
00461             << " Found " << det_ids.size() << " active DetIds";
00462 
00463   // Loop Active DetIds
00464   det_id = det_ids.begin();
00465   for ( ; det_id != det_ids.end(); det_id++ ) {
00466     std::stringstream ssMessage;
00467               
00468     // Ignore NULL DetIds
00469     if ( !(*det_id) ) { continue; }
00470     if ( *det_id == sistrip::invalid32_ ) { continue; }
00471        
00472        
00473     //build connections per DetId
00474     const vector<FedChannelConnection>& conns=buildConnections(det_cabling, *det_id);
00475        
00476     vector<FedChannelConnection>::const_iterator ipair = conns.begin(); 
00477     if(conns.size() ==0 ) continue;
00478        
00479     //retrieve number of APV pairs per detid
00480     nApvPairs=retrieveNumberAPVPairs(*det_id);
00481        
00482     //loop connections and check if APVPair is connected
00483     vector< vector<FedChannelConnection>::const_iterator > listConns(nApvPairs,conns.end());
00484               
00485     for ( ; ipair != conns.end(); ipair++ ){ 
00486       // Check if the ApvPair is connected
00487       if (ipair->fedId()!=sistrip::invalid_ && ipair->apvPairNumber()<3){
00488         ipair->print(ssMessage);
00489         ssMessage<< std::endl;
00490         listConns[ipair-conns.begin()]=ipair;
00491       } else {
00492         std::cout
00493           << "\n impossible to assign connection position in listConns " << std::endl;
00494         ipair->print(ssMessage);
00495         ssMessage << std::endl;
00496       } 
00497     }
00498     
00499     // get data
00500     vector< vector<FedChannelConnection>::const_iterator >::const_iterator ilistConns=listConns.begin();
00501     for (uint16_t apvPair=0;apvPair<listConns.size();apvPair++){
00502       ipair=listConns[apvPair];
00503       if ( ipair == conns.end() ) {
00504         // Fill object with default values
00505         std::cout
00506           << "\n "
00507           << " Unable to find FED connection for detid : " << *det_id << " APV pair number " << apvPair
00508           << " Writing default values" << std::endl;
00509         //If no connection was found, add 100 to apvpair
00510         apvPair+=100;
00511         continue;
00512       }
00513       p_apvpcon=std::make_pair(apvPair,*ipair);
00514       v_apvpcon.push_back(p_apvpcon);
00515     } //conns loop 
00516     p_detcon=std::make_pair(*det_id,v_apvpcon);
00517     v_trackercon.push_back(p_detcon);
00518     v_apvpcon.clear();
00519     edm::LogInfo(mlESSources_) << ssMessage.str();
00520   } // det id loop
00521 }
00522 
00523 // -----------------------------------------------------------------------------
00525 void SiStripCondObjBuilderFromDb::buildAnalysisRelatedObjects( SiStripConfigDb* const db, trackercon tc){
00526   std::cout << "Entering [SiStripCondObjBuilderFromDb::"<<__func__ <<"]"<<std::endl;
00527   //data container
00528   gain_= new SiStripApvGain();
00529 
00530   //check if Timing analysis description is found, otherwise quit
00531   if(!retrieveTimingAnalysisDescriptions(&*db_)){
00532     edm::LogWarning(mlESSources_)
00533       << "[SiStripCondObjBuilderFromDb::" << __func__ << "]"
00534       << " NULL pointer to AnalysisDescriptions returned by SiStripConfigDb!"
00535       << " Cannot build Analysis object! QUIT";
00536     // some values have to be set, otherwise PopCon will crash
00537     setDefaultValuesApvTiming();
00538     storeTiming(4711);
00539     return;
00540   }
00541 
00542    i_trackercon detids_end=tc.end();
00543  
00544   //loop detids
00545   for(i_trackercon detids=tc.begin();detids!=detids_end;detids++){
00546     uint32_t detid = (*detids).first;
00547     i_apvpairconn connections_end=((*detids).second).end();
00548     
00549     //loop connections
00550     for(i_apvpairconn connections=((*detids).second).begin();connections!=connections_end;connections++){
00551       uint32_t apvPair =(*connections).first;
00552       FedChannelConnection ipair =(*connections).second;
00553       std::cout << "Detid: " << std::dec << detid << " ApvPair: " << apvPair << std::endl;
00554       
00555       //no connection for apvPair found
00556       if(apvPair>=100){
00557         setDefaultValuesApvTiming();  
00558       }
00559       
00560       //fill data
00561        if(!setValuesApvTiming(db, ipair)){
00562         std::cout
00563           << "\n "
00564           << " Unable to find Timing Analysis Description"
00565           << " Writing default values for DetId: " << detid
00566           << " Value: " << m_defaulttickheightvalue/m_gaincalibrationfactor << std::endl;
00567         setDefaultValuesApvTiming();
00568        }
00569     }//connections
00570     storeTiming(detid);
00571   }//detids
00572 }
00573  
00574 // -----------------------------------------------------------------------------
00576 void SiStripCondObjBuilderFromDb::buildFECRelatedObjects( SiStripConfigDb* const db, trackercon tc){
00577   std::cout << "Entering [SiStripCondObjBuilderFromDb::"<<__func__ <<"]"<<std::endl;
00578   //data container
00579   latency_ = new SiStripLatency();
00580 
00581   i_trackercon detids_end=tc.end();
00582  
00583   //loop detids
00584   for(i_trackercon detids=tc.begin();detids!=detids_end;detids++){
00585     uint32_t detid = (*detids).first;
00586     uint16_t apvnr=1;
00587     i_apvpairconn connections_end=((*detids).second).end();
00588     
00589     //loop connections
00590     for(i_apvpairconn connections=((*detids).second).begin();connections!=connections_end;connections++){
00591       uint32_t apvPair =(*connections).first;
00592       FedChannelConnection ipair =(*connections).second;
00593       
00594       //no connection for apvPair found
00595       if(apvPair>=100){
00596         setDefaultValuesApvLatency((*latency_),ipair, apvnr);  
00597       }
00598       
00599       //fill data
00600        if(!setValuesApvLatency((*latency_),db, ipair,detid, apvnr)){
00601         std::cout
00602           << "\n "
00603           << " Unable to find FEC Description"
00604           << " Writing default values for DetId: " << detid
00605           << " Value: Latency " << m_defaultapvlatencyvalue << " ApvMode " << m_defaultapvmodevalue << std::endl;
00606         setDefaultValuesApvLatency((*latency_),ipair, apvnr);
00607        }
00608        apvnr+=2;
00609     }//connections
00610      // compact Latency Object
00611     latency_->compress();
00612     std::stringstream ss;
00613     // latency debug output
00614     latency_->printSummary(ss);
00615   }//detids
00616 }
00617 
00618 // -----------------------------------------------------------------------------
00620 void SiStripCondObjBuilderFromDb::buildFEDRelatedObjects( SiStripConfigDb* const db, trackercon tc){
00621   std::cout << "Entering [SiStripCondObjBuilderFromDb::"<<__func__ <<"]"<<std::endl;
00622 
00623   //data containers
00624   pedestals_= new SiStripPedestals();  
00625   noises_ = new SiStripNoises();  
00626   threshold_= new SiStripThreshold();  
00627   quality_ = new SiStripQuality();  
00628  
00629   i_trackercon detids_end=tc.end();
00630  
00631   //loop detids
00632   for(i_trackercon detids=tc.begin();detids!=detids_end;detids++){
00633     uint32_t detid = (*detids).first;
00634     i_apvpairconn connections_end=((*detids).second).end();
00635   
00636     //loop connections
00637     for(i_apvpairconn connections=((*detids).second).begin();connections!=connections_end;connections++){
00638       uint32_t apvPair =(*connections).first;
00639       FedChannelConnection ipair =(*connections).second;
00640             
00641       //no connection for apvPair found
00642       if(apvPair>=100){
00643         setDefaultValuesCabling((apvPair-100)); 
00644       }
00645       if(!setValuesCabling(db, ipair, detid)){
00646         std::cout
00647           << "[SiStripCondObjBuilderFromDb::" << __func__ << "]"
00648           << " Unable to find FED description for FED id: " << ipair.fedId()
00649           << " detid : " << detid << " APV pair number " << apvPair
00650           << " Writing default values"<< std::endl; 
00651         setDefaultValuesCabling(apvPair); 
00652       }
00653     }//connections
00654     storePedestals(detid);
00655     storeNoise(detid);
00656     storeThreshold(detid);
00657     storeQuality(detid);
00658   }//detids
00659 }
00660 
00661