CMS 3D CMS Logo

DcuDetIds.cc

Go to the documentation of this file.
00001 // Last commit: $Id: DcuDetIds.cc,v 1.6 2008/06/06 14:48:53 bainbrid Exp $
00002 
00003 #include "OnlineDB/SiStripConfigDb/interface/SiStripConfigDb.h"
00004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00005 
00006 using namespace std;
00007 using namespace sistrip;
00008 
00009 // -----------------------------------------------------------------------------
00010 // 
00011 SiStripConfigDb::DcuDetIdsRange SiStripConfigDb::getDcuDetIds( std::string partition ) {
00012 
00013   // Check
00014   if ( ( !dbParams_.usingDbCache() && !deviceFactory(__func__) ) ||
00015        (  dbParams_.usingDbCache() && !databaseCache(__func__) ) ) { 
00016     return dcuDetIds_.emptyRange(); 
00017   }
00018   
00019   try {
00020 
00021     if ( !dbParams_.usingDbCache() ) { 
00022 
00023       SiStripDbParams::SiStripPartitions::const_iterator iter = dbParams_.partitions().begin();
00024       SiStripDbParams::SiStripPartitions::const_iterator jter = dbParams_.partitions().end();
00025       for ( ; iter != jter; ++iter ) {
00026         
00027         if ( partition == "" || partition == iter->second.partitionName() ) {
00028           
00029           if ( iter->second.partitionName() == SiStripPartition::defaultPartitionName_ ) { continue; }
00030 
00031           DcuDetIdsRange range = dcuDetIds_.find( iter->second.partitionName() );
00032           if ( range == dcuDetIds_.emptyRange() ) {
00033             
00034 #ifdef USING_NEW_DATABASE_MODEL
00035             deviceFactory(__func__)->addDetIdPartition( iter->second.partitionName(),
00036                                                         iter->second.dcuVersion().first, 
00037                                                         iter->second.dcuVersion().second );
00038 #else
00039             deviceFactory(__func__)->addDetIdPartition( iter->second.partitionName() );
00040 #endif
00041             
00042             // Retrieve DCU-DetId map
00043             DcuDetIdMap src = deviceFactory(__func__)->getInfos(); 
00044             
00045             // Make local copy 
00046             DcuDetIdsV dst;
00047             clone( src, dst );
00048             
00049             // Add to cache
00050             dcuDetIds_.loadNext( iter->second.partitionName(), dst );
00051             
00052           }
00053 
00054         }
00055 
00056       }
00057       
00058     } else { // Using database cache
00059       
00060 #ifdef USING_NEW_DATABASE_MODEL
00061       
00062       // Retrieve DCU-DetId map
00063       DcuDetIdMap* src = databaseCache(__func__)->getInfos(); 
00064 
00065       if ( src ) { 
00066         
00067         // Make local copy 
00068         DcuDetIdsV dst;
00069         clone( *src, dst ); 
00070         
00071         // Add to cache
00072         dcuDetIds_.loadNext( SiStripPartition::defaultPartitionName_, dst );
00073         
00074       } else {
00075         edm::LogWarning(mlConfigDb_)
00076           << "[SiStripConfigDb::" << __func__ << "]"
00077           << " NULL pointer to Dcu-DetId map!";
00078       }
00079 #endif
00080       
00081     }
00082     
00083   } catch (... ) { handleException( __func__ ); }
00084 
00085   // Create range object
00086   uint16_t np = 0;
00087   uint16_t nc = 0;
00088   DcuDetIdsRange range;
00089   if ( partition != "" ) { 
00090     range = dcuDetIds_.find( partition );
00091     np = 1;
00092     nc = range.size();
00093   } else { 
00094     if ( !dcuDetIds_.empty() ) {
00095       range = DcuDetIdsRange( dcuDetIds_.find( dbParams_.partitions().begin()->second.partitionName() ).begin(),
00096                               dcuDetIds_.find( (--(dbParams_.partitions().end()))->second.partitionName() ).end() );
00097     } else { range = dcuDetIds_.emptyRange(); }
00098     np = dcuDetIds_.size();
00099     nc = range.size();
00100   }
00101   
00102   stringstream ss; 
00103   ss << "[SiStripConfigDb::" << __func__ << "]"
00104      << " Found " << nc << " entries in DCU-DetId map";
00105   if ( !dbParams_.usingDb() ) { ss << " in " << dbParams_.inputDcuInfoXmlFiles().size() << " 'module.xml' file(s)"; }
00106   else { if ( !dbParams_.usingDbCache() )  { ss << " in " << np << " database partition(s)"; } 
00107   else { ss << " from shared memory name '" << dbParams_.sharedMemory() << "'"; } }
00108   if ( dcuDetIds_.empty() ) { edm::LogWarning(mlConfigDb_) << ss.str(); }
00109   else { LogTrace(mlConfigDb_) << ss.str(); }
00110 
00111   return range;
00112 }
00113 
00114 // -----------------------------------------------------------------------------
00115 // 
00116 void SiStripConfigDb::addDcuDetIds( std::string partition, DcuDetIdsV& dcus ) {
00117 
00118   stringstream ss; 
00119   ss << "[SiStripConfigDb::" << __func__ << "]" 
00120      << " Cannot add to local cache! This functionality not allowed!";
00121   edm::LogWarning(mlConfigDb_) << ss.str(); 
00122   
00123   //   if ( !deviceFactory(__func__) ) { return; }
00124   
00125   //   if ( partition.empty() ) { 
00126   //     stringstream ss; 
00127   //     ss << "[SiStripConfigDb::" << __func__ << "]" 
00128   //        << " Partition string is empty,"
00129   //        << " therefore cannot add DCU-DetId map to local cache!"; 
00130   //     edm::LogWarning(mlConfigDb_) << ss.str(); 
00131   //     return; 
00132   //   }
00133   
00134   //   if ( dcus.empty() ) { 
00135   //     stringstream ss; 
00136   //     ss << "[SiStripConfigDb::" << __func__ << "]" 
00137   //        << " Vector of DCU-DetId map is empty,"
00138   //        << " therefore cannot add DCU-DetId map to local cache!"; 
00139   //     edm::LogWarning(mlConfigDb_) << ss.str(); 
00140   //     return; 
00141   //   }
00142 
00143   //   SiStripDbParams::SiStripPartitions::const_iterator iter = dbParams_.partitions().begin();
00144   //   SiStripDbParams::SiStripPartitions::const_iterator jter = dbParams_.partitions().end();
00145   //   for ( ; iter != jter; ++iter ) { if ( partition == iter->second.partitionName() ) { break; } }
00146   //   if ( iter == dbParams_.partitions().end() ) { 
00147   //     stringstream ss; 
00148   //     ss << "[SiStripConfigDb::" << __func__ << "]" 
00149   //        << " Partition \"" << partition
00150   //        << "\" not found in partition list, "
00151   //        << " therefore cannot add DCU-DetId map!";
00152   //     edm::LogWarning(mlConfigDb_) << ss.str(); 
00153   //     return; 
00154   //   }
00155   
00156   //   DcuDetIdsRange range = dcuDetIds_.find( partition );
00157   //   if ( range == dcuDetIds_.emptyRange() ) {
00158     
00159   //     // Make local copy 
00160   //     DcuDetIdsV dst;
00161   // #ifdef USING_NEW_DATABASE_MODEL
00162   //     clone( dcus, dst );
00163   // #else
00164   //     dst = dcus;
00165   // #endif
00166     
00167   //     // Add to local cache
00168   //     dcuDetIds_.loadNext( partition, dst );
00169     
00170   //     // Some debug
00171   //     std::stringstream ss;
00172   //     ss << "[SiStripConfigDb::" << __func__ << "]"
00173   //        << " Added " << dst.size() 
00174   //        << " DCU-DetId map to local cache for partition \""
00175   //        << partition << "\"" << std::endl;
00176   //     ss << "[SiStripConfigDb::" << __func__ << "]"
00177   //        << " Cache holds DCU-DetId map for " 
00178   //        << dcuDetIds_.size() << " partitions.";
00179   //     LogTrace(mlConfigDb_) << ss.str();
00180     
00181   //   } else {
00182   //     stringstream ss; 
00183   //     ss << "[SiStripConfigDb::" << __func__ << "]" 
00184   //        << " Partition \"" << partition
00185   //        << "\" already found in local cache, "
00186   //        << " therefore cannot add new DCU-DetId map!";
00187   //     edm::LogWarning(mlConfigDb_) << ss.str(); 
00188   //     return; 
00189   //   }
00190   
00191 }
00192 
00193 // -----------------------------------------------------------------------------
00194 // 
00195 void SiStripConfigDb::uploadDcuDetIds( std::string partition ) {
00196 
00197   stringstream ss; 
00198   ss << "[SiStripConfigDb::" << __func__ << "]" 
00199      << " Cannot upload to database! This functionality not allowed!";
00200   edm::LogWarning(mlConfigDb_) << ss.str(); 
00201   
00202   /*
00203     addAllDetId => all detids
00204     addAllDetId => to download (up to you)
00205     change in the detids
00206     setTkDcuInfo
00207     getCurrentStates
00208     setCurrentState
00209     addDetIpartiton
00210     AddAllDetId
00211   */
00212   
00213   //   if ( dbParams_.usingDbCache() ) {
00214   //     edm::LogWarning(mlConfigDb_)
00215   //       << "[SiStripConfigDb::" << __func__ << "]" 
00216   //       << " Using database cache! No uploads allowed!"; 
00217   //     return;
00218   //   }
00219 
00220   //   if ( !deviceFactory(__func__) ) { return; }
00221   
00222   //   if ( dcuDetIds_.empty() ) { 
00223   //     stringstream ss; 
00224   //     ss << "[SiStripConfigDb::" << __func__ << "]" 
00225   //        << " Found no cached DCU-DetId map, therefore no upload!"; 
00226   //     edm::LogWarning(mlConfigDb_) << ss.str(); 
00227   //     return; 
00228   //   }
00229 
00230   //   try {
00231     
00232   //     SiStripDbParams::SiStripPartitions::const_iterator iter = dbParams_.partitions().begin();
00233   //     SiStripDbParams::SiStripPartitions::const_iterator jter = dbParams_.partitions().end();
00234   //     for ( ; iter != jter; ++iter ) {
00235       
00236   //       if ( partition == "" || partition == iter->second.partitionName() ) {
00237         
00238   //    DcuDetIdsRange range = dcuDetIds_.find( iter->second.partitionName() );
00239   //    if ( range != dcuDetIds_.emptyRange() ) {
00240           
00241   //      // Extract 
00242   //      DcuDetIdMap dst;
00243   //      clone( DcuDetIdsV( range.begin(), range.end() ), dst );
00244   //      deviceFactory(__func__)->setTkDcuInfo( dst );
00245   //      getcurrentstate
00246   //      deviceFactory(__func__)->addAllDetId();
00247           
00248   //      // Some debug
00249   //      std::stringstream ss;
00250   //      ss << "[SiStripConfigDb::" << __func__ << "]"
00251   //         << " Uploaded " << dst.size() 
00252   //         << " DCU-DetId map to DB/xml for partition \""
00253   //         << iter->second.partitionName() << "\".";
00254   //      LogTrace(mlConfigDb_) << ss.str();
00255           
00256   //    } else {
00257   //      stringstream ss; 
00258   //      ss << "[SiStripConfigDb::" << __func__ << "]" 
00259   //         << " Vector of DCU-DetId map is empty for partition \"" 
00260   //         << iter->second.partitionName()
00261   //         << "\", therefore aborting upload for this partition!";
00262   //      edm::LogWarning(mlConfigDb_) << ss.str(); 
00263   //      continue; 
00264   //    }
00265         
00266   //       } else {
00267   //    //        stringstream ss; 
00268   //    //        ss << "[SiStripConfigDb::" << __func__ << "]" 
00269   //    //           << " Cannot find partition \"" << partition
00270   //    //           << "\" in cached partitions list: \""
00271   //    //           << dbParams_.partitionNames( dbParams_.partitionNames() ) 
00272   //    //           << "\", therefore aborting upload for this partition!";
00273   //    //        edm::LogWarning(mlConfigDb_) << ss.str(); 
00274   //       }
00275       
00276   //     }
00277     
00278   //   } catch (... ) { handleException( __func__, "Problems updating objects in TkDcuInfoFactory!" ); }
00279   
00280 }
00281 
00282 // -----------------------------------------------------------------------------
00283 // 
00284 void SiStripConfigDb::clearDcuDetIds( std::string partition ) {
00285   LogTrace(mlConfigDb_) << "[SiStripConfigDb::" << __func__ << "]";
00286   
00287   if ( dcuDetIds_.empty() ) { 
00288     stringstream ss; 
00289     ss << "[SiStripConfigDb::" << __func__ << "]" 
00290        << " Found no cached DCU-DetId map!"; 
00291     //edm::LogWarning(mlConfigDb_) << ss.str(); 
00292     return; 
00293   }
00294   
00295   // Reproduce temporary cache for "all partitions except specified one" (or clear all if none specified)
00296   DcuDetIds temporary_cache;
00297   if ( partition == ""  ) { temporary_cache = DcuDetIds(); }
00298   else {
00299     SiStripDbParams::SiStripPartitions::const_iterator iter = dbParams_.partitions().begin();
00300     SiStripDbParams::SiStripPartitions::const_iterator jter = dbParams_.partitions().end();
00301     for ( ; iter != jter; ++iter ) {
00302       if ( partition != iter->second.partitionName() ) {
00303         DcuDetIdsRange range = dcuDetIds_.find( iter->second.partitionName() );
00304         if ( range != dcuDetIds_.emptyRange() ) {
00305           temporary_cache.loadNext( partition, DcuDetIdsV( range.begin(), range.end() ) );
00306         } else {
00307           //      stringstream ss; 
00308           //      ss << "[SiStripConfigDb::" << __func__ << "]" 
00309           //         << " Cannot find partition \"" << iter->second.partitionName()
00310           //         << "\" in local cache!";
00311           //      edm::LogWarning(mlConfigDb_) << ss.str(); 
00312         }
00313       }
00314     }
00315   }
00316   
00317   // Delete objects in local cache for specified partition (or all if not specified) 
00318   DcuDetIdsRange dcus;
00319   if ( partition == "" ) { 
00320     if ( !dcuDetIds_.empty() ) {
00321       dcus = DcuDetIdsRange( dcuDetIds_.find( dbParams_.partitions().begin()->second.partitionName() ).begin(),
00322                              dcuDetIds_.find( (--(dbParams_.partitions().end()))->second.partitionName() ).end() );
00323     } else { dcus = dcuDetIds_.emptyRange(); }
00324   } else {
00325     SiStripDbParams::SiStripPartitions::const_iterator iter = dbParams_.partitions().begin();
00326     SiStripDbParams::SiStripPartitions::const_iterator jter = dbParams_.partitions().end();
00327     for ( ; iter != jter; ++iter ) { if ( partition == iter->second.partitionName() ) { break; } }
00328     dcus = dcuDetIds_.find( iter->second.partitionName() );
00329   }
00330   
00331   if ( dcus != dcuDetIds_.emptyRange() ) {
00332     
00333 #ifdef USING_NEW_DATABASE_MODEL 
00334     DcuDetIdsV::const_iterator ifed = dcus.begin();
00335     DcuDetIdsV::const_iterator jfed = dcus.end();
00336     for ( ; ifed != jfed; ++ifed ) { if ( ifed->second ) { delete ifed->second; } }
00337 #endif
00338     
00339   } else {
00340     stringstream ss; 
00341     ss << "[SiStripConfigDb::" << __func__ << "]";
00342     if ( partition == "" ) { ss << " Found no DCU-DetId map in local cache!"; }
00343     else { ss << " Found no DCU-DetId map in local cache for partition \"" << partition << "\"!"; }
00344     edm::LogWarning(mlConfigDb_) << ss.str(); 
00345   }
00346   
00347   // Overwrite local cache with temporary cache
00348   dcuDetIds_ = temporary_cache; 
00349 
00350 }
00351 
00352 // -----------------------------------------------------------------------------
00353 // 
00354 void SiStripConfigDb::printDcuDetIds( std::string partition ) {
00355 
00356   std::stringstream ss;
00357   ss << "[SiStripConfigDb::" << __func__ << "]"
00358      << " Contents of DcuDetIds container:" << std::endl;
00359   ss << " Number of partitions: " << dcuDetIds_.size() << std::endl;
00360 
00361   // Loop through partitions
00362   uint16_t cntr = 0;
00363   DcuDetIds::const_iterator idcu = dcuDetIds_.begin();
00364   DcuDetIds::const_iterator jdcu = dcuDetIds_.end();
00365   for ( ; idcu != jdcu; ++idcu ) {
00366 
00367     cntr++;
00368     if ( partition == "" || partition == idcu->first ) {
00369       
00370       ss << "  Partition number      : " << cntr << " (out of " << dcuDetIds_.size() << ")" << std::endl;
00371       ss << "  Partition name        : \"" << idcu->first << "\"" << std::endl;
00372       ss << "  Size of DCU-DetId map : " << idcu->second.size() << std::endl;
00373       
00374     }
00375     
00376   }
00377   
00378   LogTrace(mlConfigDb_) << ss.str();
00379   
00380 }
00381 
00382 // -----------------------------------------------------------------------------
00383 // 
00384 void SiStripConfigDb::clone( const DcuDetIdMap& input, DcuDetIdsV& output ) const {
00385   output.clear();
00386   DcuDetIdMap::const_iterator ii = input.begin();
00387   DcuDetIdMap::const_iterator jj = input.end();
00388   for ( ; ii != jj; ++ii ) { if ( ii->second ) { output.push_back( std::make_pair( ii->first, new TkDcuInfo( *(ii->second) ) ) ); } }
00389 }
00390 
00391 // -----------------------------------------------------------------------------
00392 // 
00393 void SiStripConfigDb::clone( const DcuDetIdsV& input, DcuDetIdMap& output ) const {
00394   output.clear();
00395   DcuDetIdsV::const_iterator ii = input.begin();
00396   DcuDetIdsV::const_iterator jj = input.end();
00397   for ( ; ii != jj; ++ii ) { if ( ii->second ) { output[ii->first] = new TkDcuInfo( *(ii->second) ); } }
00398 }
00399 
00400 // -----------------------------------------------------------------------------
00401 // 
00402 void SiStripConfigDb::clone( const DcuDetIdsV& input, DcuDetIdsV& output ) const {
00403   output.clear();
00404   DcuDetIdsV::const_iterator ii = input.begin();
00405   DcuDetIdsV::const_iterator jj = input.end();
00406   for ( ; ii != jj; ++ii ) { if ( ii->second ) { output.push_back( std::make_pair( ii->first, new TkDcuInfo( *(ii->second) ) ) ); } }
00407 }
00408 
00409 // -----------------------------------------------------------------------------
00410 // 
00411 SiStripConfigDb::DcuDetIdsV::const_iterator SiStripConfigDb::findDcuDetId( DcuDetIdsV::const_iterator begin, 
00412                                                                            DcuDetIdsV::const_iterator end, 
00413                                                                            uint32_t dcu_id  ) {
00414   DcuDetIdsV::const_iterator iter = begin;
00415   DcuDetIdsV::const_iterator jter = end;
00416   for ( ; iter != jter; ++iter  ) {
00417     if ( iter->second && iter->second->getDcuHardId() == dcu_id ) { return iter; }
00418   }
00419   return end;
00420 }
00421 
00422 // -----------------------------------------------------------------------------
00423 // 
00424 SiStripConfigDb::DcuDetIdsV::iterator SiStripConfigDb::findDcuDetId( DcuDetIdsV::iterator begin, 
00425                                                                      DcuDetIdsV::iterator end, 
00426                                                                      uint32_t dcu_id  ) {
00427   DcuDetIdsV::iterator iter = begin;
00428   DcuDetIdsV::iterator jter = end;
00429   for ( ; iter != jter; ++iter  ) {
00430     if ( iter->second && iter->second->getDcuHardId() == dcu_id ) { return iter; }
00431   }
00432   return end;
00433 }

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