CMS 3D CMS Logo

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

Go to the documentation of this file.
00001 // Last commit: $Id: SiStripCondObjBuilderFromDb.cc,v 1.25 2011/10/24 12:38:52 eulisse Exp $
00002 // Latest tag:  $Name: V05-01-03 $
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 // -----------------------------------------------------------------------------
00071 
00073 void SiStripCondObjBuilderFromDb::checkUpdate() {
00074   if (!(dbParams_==dbParams())){
00075     dbParams_=dbParams();
00076     buildCondObj();
00077   }  
00078 }
00079 
00080 
00081 // -----------------------------------------------------------------------------
00083 bool SiStripCondObjBuilderFromDb::checkForCompatibility(std::stringstream& input,std::stringstream& output,std::string& label){
00084 
00085 
00086   //get current config DB parameter
00087       
00088   SiStripDbParams::const_iterator_range partitionsRange = dbParams().partitions(); 
00089 
00090   SiStripDbParams::SiStripPartitions::const_iterator ipart = partitionsRange.begin();
00091   SiStripDbParams::SiStripPartitions::const_iterator ipartEnd = partitionsRange.end();
00092   for ( ; ipart != ipartEnd; ++ipart ) { 
00093     SiStripPartition partition=ipart->second;
00094     output  << "@ "
00095             << " Partition " << partition.partitionName() ;
00096     if (label!="Cabling" && label !="ApvLatency")
00097         output << " FedVer "    << partition.fedVersion().first << "." << partition.fedVersion().second;       
00098     if(label=="Cabling")
00099       output << " CabVer "    << partition.cabVersion().first << "." << partition.cabVersion().second
00100              << " MaskVer "   << partition.maskVersion().first << "." << partition.maskVersion().second;
00101     if(label=="ApvTiming")
00102       output<< " ApvTimingVer " << partition.apvTimingVersion().first << "." << partition.apvTimingVersion().second;
00103     if(label=="ApvLatency")
00104       output<< " FecVersion " << partition.fecVersion().first << "." << partition.fecVersion().second;
00105   }
00106   
00107   if (!strcmp(output.str().c_str(),input.str().c_str()))
00108     return false;
00109 
00110   return true;
00111 }
00112 
00113 // -----------------------------------------------------------------------------
00115 void SiStripCondObjBuilderFromDb::buildCondObj() {
00116   LogTrace(mlESSources_) 
00117     << "[SiStripCondObjBuilderFromDb::" << __func__ << "]";
00118 
00119   // Check if DB connection is made 
00120   if ( db_ ) { 
00121     
00122     // Check if DB connection is made 
00123     if ( db_->deviceFactory() || 
00124          db_->databaseCache() ) { 
00125       
00126       // Build FEC cabling object
00127       SiStripFecCabling fec_cabling;
00128       
00129       SiStripFedCablingBuilderFromDb::buildFecCabling( &*db_, 
00130                                                        fec_cabling, 
00131                                                        sistrip::CABLING_FROM_CONNS );
00132       fed_cabling_=new SiStripFedCabling;
00133 
00134       SiStripFedCablingBuilderFromDb::getFedCabling( fec_cabling, *fed_cabling_ );
00135       SiStripDetCabling det_cabling( *fed_cabling_ );
00136       buildStripRelatedObjects( &*db_, det_cabling );
00137      
00138      
00139       if(m_useanalysis)buildAnalysisRelatedObjects(&*db_, v_trackercon);
00140       if(m_usefed) buildFEDRelatedObjects(&*db_, v_trackercon);
00141       if(m_usefec) buildFECRelatedObjects(&*db_, v_trackercon);
00142          
00143    
00144       
00145     } else {
00146       edm::LogWarning(mlESSources_)
00147         << "[SiStripCondObjBuilderFromDb::" << __func__ << "]"
00148         << " NULL pointer to DeviceFactory returned by SiStripConfigDb!"
00149         << " Cannot build Pedestals object!";
00150     }
00151   } else {
00152     edm::LogWarning(mlESSources_)
00153       << "[SiStripCondObjBuilderFromDb::" << __func__ << "]"
00154       << " NULL pointer to SiStripConfigDb returned by DB \"service\"!"
00155       << " Cannot build Pedestals object!";
00156   }
00157 }
00158 
00159 // -----------------------------------------------------------------------------
00161 //Retrieve FedDescriptions from configuration database
00162 bool SiStripCondObjBuilderFromDb::retrieveFedDescriptions(SiStripConfigDb* const db){
00163   SiStripConfigDb::FedDescriptionsRange descriptions = db->getFedDescriptions();
00164   if ( descriptions.empty() ) {
00165     edm::LogWarning(mlESSources_)
00166       << "SiStripCondObjBuilderFromDb::" << __func__ << "]"
00167       << " No FED descriptions found!";
00168     
00169     return false;
00170   }
00171   return true;
00172 }
00173 
00174 // -----------------------------------------------------------------------------
00176   // Retrieve gain from configuration database
00177 bool SiStripCondObjBuilderFromDb::retrieveTimingAnalysisDescriptions( SiStripConfigDb* const db){
00178   SiStripConfigDb::AnalysisDescriptionsRange anal_descriptions = 
00179     db->getAnalysisDescriptions( CommissioningAnalysisDescription::T_ANALYSIS_TIMING );
00180   if ( anal_descriptions.empty() ) {
00181     edm::LogWarning(mlESSources_)
00182       << "SiStripCondObjBuilderFromDb::" << __func__ << "]"
00183       << " Unable to build SiStripApvGain object!"
00184       << " No timing-scan analysis descriptions found!";
00185     return false;
00186   }
00187   return true;
00188 }
00189 
00190 // -----------------------------------------------------------------------------
00192   // Retrieve list of active DetIds
00193 vector<uint32_t> SiStripCondObjBuilderFromDb::retrieveActiveDetIds(const SiStripDetCabling& det_cabling){
00194   vector<uint32_t> det_ids;
00195   det_cabling.addActiveDetectorsRawIds(det_ids);
00196   if ( det_ids.empty() ) {
00197     edm::LogWarning(mlESSources_)
00198       << "SiStripCondObjBuilderFromDb::" << __func__ << "]"
00199       << " Unable to build Pedestals object!"
00200       << " No DetIds found!";
00201     return det_ids;
00202   }  
00203   LogTrace(mlESSources_)
00204     << "\n\nSiStripCondObjBuilderFromDb::" << __func__ << "]"
00205     << " Found " << det_ids.size() << " active DetIds";
00206   return det_ids;
00207 }
00208 
00209 // -----------------------------------------------------------------------------
00211  //build connections per DetId
00212 vector<const FedChannelConnection *> SiStripCondObjBuilderFromDb::buildConnections(const SiStripDetCabling& det_cabling, uint32_t det_id ){
00213   vector<const FedChannelConnection *> conns = det_cabling.getConnections(det_id);
00214   if (conns.size()==0){
00215     edm::LogWarning(mlESSources_)
00216         << "SiStripCondObjBuilderFromDb::" << __func__ << "]"
00217         << " Unable to build condition object!"
00218         << " No FED channel connections found for detid "<< det_id;
00219   }
00220   return conns;
00221 }
00222 
00223 // -----------------------------------------------------------------------------
00225 //retrieve number of APV pairs per detid
00226 uint16_t SiStripCondObjBuilderFromDb::retrieveNumberAPVPairs(uint32_t det_id){
00227   uint16_t nApvPairs;
00228   SiStripDetInfoFileReader * fr=edm::Service<SiStripDetInfoFileReader>().operator->();
00229   nApvPairs=fr->getNumberOfApvsAndStripLength(det_id).first/2;
00230   return nApvPairs;
00231 }
00232 
00233 // -----------------------------------------------------------------------------
00235 //set default values for Cabling Objects Peds, Noise, thresh, Quality
00236 void SiStripCondObjBuilderFromDb::setDefaultValuesCabling(uint16_t apvPair){
00237   uint16_t istrip = apvPair*sistrip::STRIPS_PER_FEDCH;  
00238   std::cout << "Found disabled FedConnection!  APVPair: " << apvPair << " Strips: " << sistrip::STRIPS_PER_FEDCH << std::endl;
00239   inputQuality.push_back(quality_->encode(istrip,sistrip::STRIPS_PER_FEDCH));
00240   for ( ;istrip < (apvPair+1)*sistrip::STRIPS_PER_FEDCH; ++istrip ){
00241     pedestals_->setData(m_defaultpedestalvalue,inputPedestals );
00242     noises_->setData(m_defaultnoisevalue ,inputNoises );
00243     threshold_->setData( istrip, m_defaultthresholdlowvalue, m_defaultthresholdhighvalue, inputThreshold );
00244    }
00245 }
00246 
00247 // -----------------------------------------------------------------------------
00249 void SiStripCondObjBuilderFromDb::setDefaultValuesApvTiming(){
00250   inputApvGain.push_back(m_defaulttickheightvalue/m_gaincalibrationfactor); // APV0
00251   inputApvGain.push_back(m_defaulttickheightvalue/m_gaincalibrationfactor); // APV1
00252 }
00253 
00254 // -----------------------------------------------------------------------------
00256 void SiStripCondObjBuilderFromDb::setDefaultValuesApvLatency(SiStripLatency & latency_, FedChannelConnection ipair, uint32_t detid, uint16_t apvnr){
00257   std::cout << "[SiStripCondObjBuilderFromDb::"<<__func__<<"]: Set Default Latency for Detid: " << detid << " ApvNr: " << apvnr << std::endl;
00258   if(!latency_.put( detid, apvnr, m_defaultapvmodevalue, m_defaultapvlatencyvalue))
00259     {
00260       std::cout << "[SiStripCondObjBuilderFromDb::"<<__func__<<"]: Unable to fill Latency for Detid: " << detid << " ApvNr: " << apvnr << std::endl;
00261     }
00262      if(!latency_.put( detid, ++apvnr, m_defaultapvmodevalue, m_defaultapvlatencyvalue))
00263        {
00264          std::cout << "[SiStripCondObjBuilderFromDb::"<<__func__<<"]: Unable to fill Latency for Detid: " << detid << " ApvNr: " << apvnr << std::endl;
00265        }
00266 
00267 }
00268 
00269 
00270 
00271 // -----------------------------------------------------------------------------
00273 bool SiStripCondObjBuilderFromDb::setValuesApvTiming(SiStripConfigDb* const db, FedChannelConnection &ipair){
00274   SiStripConfigDb::AnalysisDescriptionsRange anal_descriptions = db->getAnalysisDescriptions( CommissioningAnalysisDescription::T_ANALYSIS_TIMING );
00275    SiStripConfigDb::AnalysisDescriptionsV::const_iterator iii = anal_descriptions.begin();
00276   SiStripConfigDb::AnalysisDescriptionsV::const_iterator jjj = anal_descriptions.end();
00277  
00278   while ( iii != jjj ) {
00279     CommissioningAnalysisDescription* tmp = *iii;
00280     uint16_t fed_id = tmp->getFedId();
00281     uint16_t fed_ch = SiStripFedKey::fedCh( tmp->getFeUnit(), tmp->getFeChan() );
00282     if ( fed_id == ipair.fedId() && fed_ch == ipair.fedCh() ) { break; }
00283     iii++;
00284   }
00285   
00286   TimingAnalysisDescription *anal=0;
00287   if ( iii != jjj ) { anal = dynamic_cast<TimingAnalysisDescription*>(*iii); }
00288   if ( anal ) {
00289     float tick_height = (anal->getHeight() / m_gaincalibrationfactor);
00290     inputApvGain.push_back( tick_height ); // APV0
00291     inputApvGain.push_back( tick_height); // APV1
00292   } else {
00293     inputApvGain.push_back(m_defaulttickheightvalue/m_gaincalibrationfactor); // APV0
00294     inputApvGain.push_back(m_defaulttickheightvalue/m_gaincalibrationfactor); // APV1
00295     return false;
00296   }
00297 
00298   return true;
00299 }
00300 
00301 // -----------------------------------------------------------------------------
00303 bool SiStripCondObjBuilderFromDb::setValuesApvLatency(SiStripLatency & latency_, SiStripConfigDb* const db, FedChannelConnection &ipair, uint32_t detid, uint16_t apvnr, SiStripConfigDb::DeviceDescriptionsRange apvs  ){
00304 SiStripDetInfoFileReader * fr=edm::Service<SiStripDetInfoFileReader>().operator->();
00305  fr->getNumberOfApvsAndStripLength(detid).first/2;
00306  
00307  SiStripConfigDb::DeviceDescriptionsV::const_iterator iapv = apvs.begin();
00308  SiStripConfigDb::DeviceDescriptionsV::const_iterator japv = apvs.end();
00309  if(iapv==japv) return false;
00310  for ( ; iapv != japv; ++iapv ) {
00311    apvDescription* apv = dynamic_cast<apvDescription*>( *iapv );
00312    if ( !apv ) { continue; }
00313    if((apv->getCrateId()) != (ipair.fecCrate())) continue;
00314    if((apv->getFecSlot()) != (ipair.fecSlot())) continue;
00315    if((apv->getRingSlot()) != (ipair.fecRing())) continue;
00316    if((apv->getCcuAddress()) != (ipair.ccuAddr())) continue;
00317    if((apv->getChannel()) != (ipair.ccuChan())) continue;
00318      // Insert latency values into latency object
00319    if((apv->getAddress()) == (ipair.i2cAddr(0))) {
00320      if(!latency_.put( detid, apvnr, static_cast<uint16_t>(apv->getLatency()), static_cast<uint16_t>(apv->getApvMode()))){
00321        std::cout << "UNABLE APVLatency Put: Detid "<< dec<<detid 
00322                  << " APVNr.: " << apvnr 
00323                  << " Latency Value: " << dec <<static_cast<uint16_t>(apv->getLatency()) 
00324                  << " APV Mode: " << dec<< static_cast<uint16_t>(apv->getApvMode())
00325                  << std::endl;
00326        return false;
00327      }else{++apvnr;}
00328    }
00329    if((apv->getAddress()) == (ipair.i2cAddr(1))) {
00330      if(!latency_.put( detid, apvnr, static_cast<uint16_t>(apv->getLatency()), static_cast<uint16_t>(apv->getApvMode()))){
00331        std::cout << "UNABLE APVLatency Put: Detid "<<dec<< detid
00332                  << " APVNr.: " << apvnr
00333                  << " Latency Value: " << dec <<static_cast<uint16_t>(apv->getLatency())
00334                  << " APV Mode: " << dec <<static_cast<uint16_t>(apv->getApvMode())
00335                  << std::endl;
00336        continue;
00337        return false;
00338      }else{++apvnr;}
00339    }
00340   }
00341  return true;
00342 }
00343 
00344 // -----------------------------------------------------------------------------
00346 //bool SiStripCondObjBuilderFromDb::setValuesCabling(SiStripConfigDb* const db, FedChannelConnection &ipair, uint32_t detid){ 
00347 bool SiStripCondObjBuilderFromDb::setValuesCabling(SiStripConfigDb::FedDescriptionsRange &descriptions, FedChannelConnection &ipair, uint32_t detid){
00348   //SiStripConfigDb::FedDescriptionsRange descriptions = db->getFedDescriptions();
00349   SiStripConfigDb::FedDescriptionsV::const_iterator description = descriptions.begin();
00350   while ( description != descriptions.end() ) {
00351     if ( (*description)->getFedId() ==ipair.fedId() ) { break; }
00352     description++;
00353   }
00354   if ( description == descriptions.end() ) {return false;}
00355   // Retrieve Fed9UStrips object from FED description
00356   const Fed9U::Fed9UStrips& strips = (*description)->getFedStrips();
00357       
00358       
00359   // Retrieve StripDescriptions for each APV
00360   uint16_t jstrip = ipair.apvPairNumber()*sistrip::STRIPS_PER_FEDCH;
00361   for ( uint16_t iapv = 2*ipair.fedCh(); iapv < 2*ipair.fedCh()+2; iapv++ ) {
00362         
00363     // Get StripDescriptions for the given APV
00364     Fed9U::Fed9UAddress addr;
00365     addr.setFedApv(iapv);
00366     vector<Fed9U::Fed9UStripDescription> strip = strips.getApvStrips(addr);
00367         
00368     vector<Fed9U::Fed9UStripDescription>::const_iterator istrip = strip.begin();
00369 
00370     for ( ; istrip != strip.end(); istrip++ ) {
00371       pedestals_->setData( istrip->getPedestal() , inputPedestals);
00372       noises_   ->setData( istrip->getNoise()    , inputNoises );
00373       threshold_->setData( jstrip, istrip->getLowThresholdFactor(),
00374                            istrip->getHighThresholdFactor(), inputThreshold );
00375       if(istrip->getDisable()){
00376         std::cout << "Found disabled strip! Detid: " << detid << " APVNr: " << iapv << " Strips: " << jstrip << std::endl;
00377 
00378         inputQuality.push_back(quality_->encode(jstrip,1));
00379       }
00380       jstrip++;
00381     }
00382   }
00383   return true;
00384 }
00385 
00386 
00387 // -----------------------------------------------------------------------------
00389 //store objects
00390 void SiStripCondObjBuilderFromDb::storePedestals(uint32_t det_id){
00391   if ( !pedestals_->put(det_id, inputPedestals ) ) {
00392     std::cout
00393       << "[SiStripCondObjBuilderFromDb::" << __func__ << "]"
00394       << " Unable to insert values into SiStripPedestals object!"
00395       << " DetId already exists!" << std::endl;
00396   }
00397   inputPedestals.clear();
00398 
00399   }
00400 
00401 
00402 
00403 // -----------------------------------------------------------------------------
00405 void SiStripCondObjBuilderFromDb::storeNoise(uint32_t det_id){
00406   // Insert noise values into Noises object
00407 
00408     if ( !noises_->put(det_id, inputNoises ) ) {
00409       std::cout
00410         << "[SiStripCondObjBuilderFromDb::" << __func__ << "]"
00411         << " Unable to insert values into SiStripNoises object!"
00412         << " DetId already exists!" << std::endl;
00413     }
00414     inputNoises.clear();
00415 
00416  }
00417 
00418 // -----------------------------------------------------------------------------
00420 void SiStripCondObjBuilderFromDb::storeThreshold(uint32_t det_id){
00421   // Insert threshold values into Threshold object
00422     if ( !threshold_->put(det_id, inputThreshold ) ) {
00423       std::cout
00424         << "[SiStripCondObjBuilderFromDb::" << __func__ << "]"
00425         << " Unable to insert values into SiStripThreshold object!"
00426         << " DetId already exists!" << std::endl;
00427     }
00428     inputThreshold.clear();
00429 }
00430 
00431 // -----------------------------------------------------------------------------
00433 void SiStripCondObjBuilderFromDb::storeQuality(uint32_t det_id){
00434   // Insert quality values into Quality object
00435     if (inputQuality.size()){
00436       quality_->compact(det_id,inputQuality);
00437       if ( !quality_->put(det_id, inputQuality ) ) {
00438         std::cout
00439           << "[SiStripCondObjBuilderFromDb::" << __func__ << "]"
00440           << " Unable to insert values into SiStripQuality object!"
00441           << " DetId already exists!" << std::endl;
00442       }
00443     }
00444     inputQuality.clear();
00445 }
00446 
00447 // -----------------------------------------------------------------------------
00449 void SiStripCondObjBuilderFromDb::storeTiming(uint32_t det_id){
00450   // Insert tick height values into Gain object
00451       SiStripApvGain::Range range( inputApvGain.begin(), inputApvGain.end() );
00452       if ( !gain_->put( det_id, range ) ) {
00453         edm::LogWarning(mlESSources_)
00454           << "[SiStripCondObjBuilderFromDb::" << __func__ << "]"
00455           << " Unable to insert values into SiStripApvGain object!"
00456           << " DetId already exists!";
00457       }
00458       inputApvGain.clear();
00459 }
00460 
00461 // -----------------------------------------------------------------------------
00463 void SiStripCondObjBuilderFromDb::buildStripRelatedObjects( SiStripConfigDb* const db,
00464                                                             const SiStripDetCabling& det_cabling){
00465   //variables needed in this function
00466   uint16_t nApvPairs;
00467   vector<uint32_t>::const_iterator det_id;
00468   vector<uint32_t> det_ids;
00469  
00470   edm::LogInfo(mlESSources_)
00471     << "\n[SiStripCondObjBuilderFromDb::" << __func__ << "] first call to this method";
00472 
00473   //Check if FedDescriptions exist, if not return
00474   if (!retrieveFedDescriptions(db)) {std::cout<< "Found no FedDescription!" << std::endl;return;}
00475   // Retrieve list of active DetIds
00476   det_cabling.addActiveDetectorsRawIds(det_ids);
00477   if ( det_ids.empty() ) {
00478     std::cout
00479       << "SiStripCondObjBuilderFromDb::" << __func__ << "]"
00480       << " Unable to build Pedestals object!"
00481       << " No DetIds found!" << std::endl;
00482     return;
00483   }  
00484   std::cout << "\n\nSiStripCondObjBuilderFromDb::" << __func__ << "]"
00485             << " Found " << det_ids.size() << " active DetIds";
00486 
00487   // Loop Active DetIds
00488   det_id = det_ids.begin();
00489   for ( ; det_id != det_ids.end(); det_id++ ) {
00490     std::stringstream ssMessage;
00491               
00492     // Ignore NULL DetIds
00493     if ( !(*det_id) ) { continue; }
00494     if ( *det_id == sistrip::invalid32_ ) { continue; }
00495        
00496        
00497     //build connections per DetId
00498     const vector<const FedChannelConnection *>& conns=buildConnections(det_cabling, *det_id);
00499        
00500     vector<const FedChannelConnection *>::const_iterator ipair = conns.begin();
00501     if(conns.size() ==0 ) continue;
00502        
00503     //retrieve number of APV pairs per detid
00504     nApvPairs=retrieveNumberAPVPairs(*det_id);
00505        
00506 
00507     //loop connections and check if APVPair is connected
00508     vector< vector<const FedChannelConnection *>::const_iterator > listConns(nApvPairs,conns.end());
00509               
00510     for ( ; ipair != conns.end(); ++ipair ){
00511       // Check if the ApvPair is connected
00512       if ((*ipair)->fedId()!=sistrip::invalid_ && (*ipair)->apvPairNumber()<3){
00513         // (*ipair)->print(ssMessage);
00514         // ssMessage<< std::endl;
00515         listConns[ipair-conns.begin()]=ipair;
00516       } else {
00517         std::cout
00518           << "\n impossible to assign connection position in listConns " << std::endl;
00519         // (*ipair)->print(ssMessage);
00520         // ssMessage << std::endl;
00521       }
00522     }
00523     
00524     // get data
00525     // vector< vector<const FedChannelConnection *>::const_iterator >::const_iterator ilistConns=listConns.begin();
00526     for (uint16_t apvPair=0;apvPair<listConns.size();++apvPair){
00527       ipair=listConns[apvPair];
00528           if ( ipair == conns.end() ) {
00529         // Fill object with default values
00530         std::cout
00531           << "\n "
00532           << " Unable to find FED connection for detid : " << std::dec << *det_id << " APV pair number " << apvPair
00533           << " Writing default values" << std::endl;
00534         (*ipair)->print(ssMessage);
00535         //If no connection was found, add 100 to apvpair
00536         apvPair+=100;
00537         std::cout << " Put apvPair+100:" << apvPair << " into vector!" << std::endl;
00538         p_apvpcon=std::make_pair(apvPair,**ipair);
00539         v_apvpcon.push_back(p_apvpcon);
00540         apvPair=apvPair-100;
00541         continue;
00542       }
00543       p_apvpcon=std::make_pair(apvPair,**ipair);
00544       v_apvpcon.push_back(p_apvpcon);
00545     } //conns loop 
00546     p_detcon=std::make_pair(*det_id,v_apvpcon);
00547     v_trackercon.push_back(p_detcon);
00548     v_apvpcon.clear();
00549   } // det id loop
00550 }
00551 
00552 // -----------------------------------------------------------------------------
00554 void SiStripCondObjBuilderFromDb::buildAnalysisRelatedObjects( SiStripConfigDb* const db, trackercon tc){
00555   std::cout << "Entering [SiStripCondObjBuilderFromDb::"<<__func__ <<"]"<<std::endl;
00556   //data container
00557   gain_= new SiStripApvGain();
00558 
00559   //check if Timing analysis description is found, otherwise quit
00560   if(!retrieveTimingAnalysisDescriptions(&*db_)){
00561     edm::LogWarning(mlESSources_)
00562       << "[SiStripCondObjBuilderFromDb::" << __func__ << "]"
00563       << " NULL pointer to AnalysisDescriptions returned by SiStripConfigDb!"
00564       << " Cannot build Analysis object! QUIT";
00565     // some values have to be set, otherwise PopCon will crash
00566     setDefaultValuesApvTiming();
00567     storeTiming(4711);
00568     return;
00569   }
00570 
00571   i_trackercon detids_end=tc.end();
00572 
00573   //loop detids
00574   for(i_trackercon detids=tc.begin();detids!=detids_end;detids++){
00575     uint32_t detid = (*detids).first;
00576     i_apvpairconn connections_end=((*detids).second).end();
00577     
00578     //loop connections
00579     for(i_apvpairconn connections=((*detids).second).begin();connections!=connections_end;connections++){
00580       uint32_t apvPair =(*connections).first;
00581       FedChannelConnection ipair =(*connections).second;
00582 
00583           
00584       //no connection for apvPair found
00585       if(apvPair>=100){
00586         setDefaultValuesApvTiming();  
00587         continue;
00588       }
00589       
00590       //fill data
00591       if(!setValuesApvTiming(db, ipair)){
00592         std::cout
00593           << "\n "
00594           << " Unable to find Timing Analysis Description"
00595           << " Writing default values for DetId: " << detid
00596           << " Value: " << m_defaulttickheightvalue/m_gaincalibrationfactor << std::endl;
00597         setDefaultValuesApvTiming();
00598       }
00599     }//connections
00600     storeTiming(detid);
00601   }//detids
00602 
00603 }
00604  
00605 // -----------------------------------------------------------------------------
00607 void SiStripCondObjBuilderFromDb::buildFECRelatedObjects( SiStripConfigDb* const db, trackercon tc){
00608   std::cout << "Entering [SiStripCondObjBuilderFromDb::"<<__func__ <<"]"<<std::endl;
00609   //data container
00610   latency_ = new SiStripLatency();
00611 
00612   i_trackercon detids_end=tc.end();
00613  
00614   // get APV DeviceDescriptions
00615   SiStripConfigDb::DeviceDescriptionsRange apvs= db->getDeviceDescriptions( APV25 );;
00616 
00617 
00618   //loop detids
00619   for(i_trackercon detids=tc.begin();detids!=detids_end;detids++){
00620     uint32_t detid = (*detids).first;
00621     uint16_t apvnr=1;
00622     i_apvpairconn connections_end=((*detids).second).end();
00623     
00624 
00625     //loop connections
00626     for(i_apvpairconn connections=((*detids).second).begin();connections!=connections_end;connections++){
00627       uint32_t apvPair =(*connections).first;
00628       FedChannelConnection ipair =(*connections).second;
00629       
00630       //no connection for apvPair found
00631       if(apvPair>=100){
00632         //setDefaultValuesApvLatency((*latency_),ipair, detid, apvnr);  
00633         std::cout << "[SiStripCondObjBuilderFromDb::" << __func__ << "] No FEDConnection for DetId " << detid << " ApvPair " << apvPair-100 << " found, skipping Latency Insertion!" << std::endl;
00634         continue;
00635       }
00636       
00637       //fill data
00638            if(!setValuesApvLatency((*latency_),db, ipair, detid, apvnr, apvs)){
00639         std::cout
00640           << "\n "
00641           << " Unable to find FEC Description"
00642           << " Skipping Insertion for DetId: " << detid << std::endl;
00643           //setDefaultValuesApvLatency((*latency_),ipair, detid, apvnr);
00644        }
00645        apvnr+=2;
00646     }//connections
00647      // compact Latency Object
00648   
00649   }//detids
00650   latency_->compress();
00651   std::stringstream ss;
00652   // latency debug output
00653   latency_->printSummary(ss);
00654   latency_->printDebug(ss);
00655   std::cout << ss.str() << std::endl;
00656 }
00657 
00658 // -----------------------------------------------------------------------------
00660 void SiStripCondObjBuilderFromDb::buildFEDRelatedObjects( SiStripConfigDb* const db, trackercon tc){
00661   std::cout << "Entering [SiStripCondObjBuilderFromDb::"<<__func__ <<"]"<<std::endl;
00662 
00663   //data containers
00664   pedestals_= new SiStripPedestals();  
00665   noises_ = new SiStripNoises();  
00666   threshold_= new SiStripThreshold();  
00667   quality_ = new SiStripQuality();  
00668  
00669   i_trackercon detids_end=tc.end();
00670 
00671   //Build FED Descriptions out of db object
00672   SiStripConfigDb::FedDescriptionsRange descriptions = db->getFedDescriptions();
00673 
00674   //loop detids
00675   for(i_trackercon detids=tc.begin();detids!=detids_end;detids++){
00676     uint32_t detid = (*detids).first;
00677     i_apvpairconn connections_end=((*detids).second).end();
00678   
00679     //loop connections
00680     for(i_apvpairconn connections=((*detids).second).begin();connections!=connections_end;connections++){
00681       uint32_t apvPair =(*connections).first;
00682       FedChannelConnection ipair =(*connections).second;
00683             
00684       //no connection for apvPair found
00685       if(apvPair>=100){
00686         std::cout
00687           << "[SiStripCondObjBuilderFromDb::" << __func__ << "]"
00688           << " Unable to find FED description for FED id: " << ipair.fedId()
00689           << " detid : " << detid << " APV pair number " << apvPair
00690           << " Writing default values"<< std::endl; 
00691         setDefaultValuesCabling((apvPair-100)); 
00692         continue;
00693       }
00694       //  if(!setValuesCabling(db, ipair, detid)){
00695       if(!setValuesCabling(descriptions, ipair, detid)){
00696         std::cout
00697           << "[SiStripCondObjBuilderFromDb::" << __func__ << "]"
00698           << " Unable to find FED description for FED id: " << ipair.fedId()
00699           << " detid : " << detid << " APV pair number " << apvPair
00700           << " Writing default values"<< std::endl; 
00701         setDefaultValuesCabling(apvPair); 
00702       }
00703     }//connections
00704     storePedestals(detid);
00705     storeNoise(detid);
00706     storeThreshold(detid);
00707     storeQuality(detid);
00708   }//detids
00709 }
00710 
00711