CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/src/OnlineDB/SiStripConfigDb/src/SiStripPartition.cc

Go to the documentation of this file.
00001 // Last commit: $Id: SiStripPartition.cc,v 1.20 2010/04/20 09:28:35 dstrom Exp $
00002 
00003 #include "OnlineDB/SiStripConfigDb/interface/SiStripPartition.h"
00004 #include "DataFormats/SiStripCommon/interface/SiStripEnumsAndStrings.h"
00005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00006 #include "OnlineDB/SiStripConfigDb/interface/SiStripConfigDb.h"
00007 #include <iostream>
00008 #include <cmath>
00009 
00010 using namespace sistrip;
00011 
00012 // -----------------------------------------------------------------------------
00013 //
00014 std::string SiStripPartition::defaultPartitionName_ = "DefaultPartition";
00015 
00016 // -----------------------------------------------------------------------------
00017 // 
00018 SiStripPartition::SiStripPartition() :
00019   partitionName_(defaultPartitionName_), 
00020   runNumber_(0),
00021   runType_(sistrip::UNDEFINED_RUN_TYPE),
00022   forceVersions_(false),
00023   forceCurrentState_(false),
00024   cabVersion_(0,0),
00025   fedVersion_(0,0),
00026   fecVersion_(0,0),
00027   dcuVersion_(0,0),
00028   psuVersion_(0,0),
00029   //#ifdef USING_DATABASE_MASKING
00030   maskVersion_(0,0),
00031                                   //#endif
00032   globalAnalysisV_(0),
00033   runTableVersion_(0,0),
00034   fastCablingV_(0,0),
00035   apvTimingV_(0,0),
00036   optoScanV_(0,0),
00037   vpspScanV_(0,0),
00038   apvCalibV_(0,0),
00039   pedestalsV_(0,0),
00040   apvLatencyV_(0,0),
00041   fineDelayV_(0,0),
00042   inputModuleXml_(""),
00043   inputDcuInfoXml_(""),
00044   inputFecXml_(),
00045   inputFedXml_()
00046 {;}
00047 
00048 // -----------------------------------------------------------------------------
00049 // 
00050 SiStripPartition::SiStripPartition( std::string partition ) :
00051   partitionName_(partition), 
00052   runNumber_(0),
00053   runType_(sistrip::UNDEFINED_RUN_TYPE),
00054   forceVersions_(false),
00055   forceCurrentState_(false),
00056   cabVersion_(0,0),
00057   fedVersion_(0,0),
00058   fecVersion_(0,0),
00059   dcuVersion_(0,0),
00060   psuVersion_(0,0),
00061   //#ifdef USING_DATABASE_MASKING
00062   maskVersion_(0,0),
00063                                   //#endif
00064   globalAnalysisV_(0),
00065   runTableVersion_(0,0),
00066   fastCablingV_(0,0),
00067   apvTimingV_(0,0),
00068   optoScanV_(0,0),
00069   vpspScanV_(0,0),
00070   apvCalibV_(0,0),
00071   pedestalsV_(0,0),
00072   apvLatencyV_(0,0),
00073   fineDelayV_(0,0),
00074   inputModuleXml_(""),
00075   inputDcuInfoXml_(""),
00076   inputFecXml_(),
00077   inputFedXml_()
00078 {
00079   if ( partitionName_.empty() ) { partitionName_ = defaultPartitionName_; }
00080 }
00081 
00082 // -----------------------------------------------------------------------------
00083 // 
00084 SiStripPartition::SiStripPartition( const SiStripPartition& input ) :
00085   partitionName_( input.partitionName() ), 
00086   runNumber_( input.runNumber() ),
00087   runType_( input.runType() ),
00088   forceVersions_( input.forceVersions() ),
00089   forceCurrentState_( input.forceCurrentState() ),
00090   cabVersion_( input.cabVersion() ),
00091   fedVersion_( input.fedVersion() ),
00092   fecVersion_( input.fecVersion() ),
00093   dcuVersion_( input.dcuVersion() ),
00094   psuVersion_( input.psuVersion() ),
00095   //#ifdef USING_DATABASE_MASKING
00096   maskVersion_( input.maskVersion() ),
00097                                   //#endif
00098   globalAnalysisV_( input.globalAnalysisVersion() ),
00099   runTableVersion_( input.runTableVersion() ),
00100   fastCablingV_( input.fastCablingVersion() ),
00101   apvTimingV_( input.apvTimingVersion() ),
00102   optoScanV_( input.optoScanVersion() ),
00103   vpspScanV_( input.vpspScanVersion() ),
00104   apvCalibV_( input.apvCalibVersion() ),
00105   pedestalsV_( input.pedestalsVersion() ),
00106   apvLatencyV_( input.apvLatencyVersion() ),
00107   fineDelayV_( input.fineDelayVersion() ),
00108   inputModuleXml_( input.inputModuleXml() ),
00109   inputDcuInfoXml_( input.inputDcuInfoXml() ),
00110   inputFecXml_( input.inputFecXml() ),
00111   inputFedXml_( input.inputFedXml() )
00112 {;}
00113 
00114 // -----------------------------------------------------------------------------
00115 // 
00116 SiStripPartition& SiStripPartition::operator= ( const SiStripPartition& input ){
00117   if ( this == &input ) { return *this; } // self-assignment
00118   partitionName_ = input.partitionName(); 
00119   runNumber_ = input.runNumber();
00120   runType_ = input.runType();
00121   forceVersions_ = input.forceVersions();
00122   forceCurrentState_ = input.forceCurrentState();
00123   cabVersion_ = input.cabVersion();
00124   fedVersion_ = input.fedVersion();
00125   fecVersion_ = input.fecVersion();
00126   dcuVersion_ = input.dcuVersion();
00127   psuVersion_ = input.psuVersion();
00128   //#ifdef USING_DATABASE_MASKING
00129   maskVersion_ = input.maskVersion();
00130   //#endif
00131   globalAnalysisV_ = input.globalAnalysisVersion();
00132   runTableVersion_ = input.runTableVersion();
00133   fastCablingV_ = input.fastCablingVersion();
00134   apvTimingV_ = input.apvTimingVersion();
00135   optoScanV_ = input.optoScanVersion();
00136   vpspScanV_ = input.vpspScanVersion();
00137   apvCalibV_ = input.apvCalibVersion();
00138   pedestalsV_ = input.pedestalsVersion();
00139   apvLatencyV_ = input.apvLatencyVersion();
00140   fineDelayV_ = input.fineDelayVersion();
00141   inputModuleXml_ = input.inputModuleXml();
00142   inputDcuInfoXml_ = input.inputDcuInfoXml();
00143   inputFecXml_ = input.inputFecXml();
00144   inputFedXml_ = input.inputFedXml();
00145   return *this;
00146 }
00147 
00148 // -----------------------------------------------------------------------------
00149 // 
00150 bool SiStripPartition::operator== ( const SiStripPartition& input ) const {
00151   return ( partitionName_ == input.partitionName() && 
00152            runNumber_ == input.runNumber() &&
00153            runType_ == input.runType() &&
00154            forceVersions_ == input.forceVersions() &&
00155            forceCurrentState_ == input.forceCurrentState() &&
00156            cabVersion_ == input.cabVersion() &&
00157            fedVersion_ == input.fedVersion() &&
00158            fecVersion_ == input.fecVersion() &&
00159            dcuVersion_ == input.dcuVersion() &&
00160            psuVersion_ == input.psuVersion() &&
00161            //#ifdef USING_DATABASE_MASKING
00162            maskVersion_ == input.maskVersion() &&
00163            //#endif
00164            globalAnalysisV_ == input.globalAnalysisVersion() &&
00165            runTableVersion_ == input.runTableVersion() &&
00166            fastCablingV_ == input.fastCablingVersion() &&
00167            apvTimingV_ == input.apvTimingVersion() &&
00168            optoScanV_ == input.optoScanVersion() &&
00169            vpspScanV_ == input.vpspScanVersion() &&
00170            apvCalibV_ == input.apvCalibVersion() &&
00171            pedestalsV_ == input.pedestalsVersion() &&
00172            apvLatencyV_ == input.apvLatencyVersion() &&
00173            fineDelayV_ == input.fineDelayVersion() &&
00174            inputModuleXml_ == input.inputModuleXml() &&
00175            inputDcuInfoXml_ == input.inputDcuInfoXml() &&
00176            inputFecXml_ == input.inputFecXml() &&
00177            inputFedXml_ == input.inputFedXml() );
00178 }
00179 
00180 // -----------------------------------------------------------------------------
00181 // 
00182 bool SiStripPartition::operator!= ( const SiStripPartition& input ) const {
00183   return !( *this == input );
00184 }
00185 
00186 // -----------------------------------------------------------------------------
00187 // 
00188 SiStripPartition::~SiStripPartition() {
00189   inputFecXml_.clear();
00190   inputFedXml_.clear();
00191 }
00192 
00193 // -----------------------------------------------------------------------------
00194 // 
00195 void SiStripPartition::reset() {
00196   partitionName_     = "";
00197   runNumber_         = 0;
00198   runType_           = sistrip::UNDEFINED_RUN_TYPE;
00199   forceVersions_     = false;
00200   forceCurrentState_ = false;
00201 
00202   cabVersion_ = std::make_pair(0,0);
00203   fedVersion_ = std::make_pair(0,0);
00204   fecVersion_ = std::make_pair(0,0);
00205   dcuVersion_ = std::make_pair(0,0);
00206   psuVersion_ = std::make_pair(0,0);
00207   //#ifdef USING_DATABASE_MASKING
00208   maskVersion_ = std::make_pair(0,0);
00209   //#endif
00210   
00211   globalAnalysisV_ = 0;
00212   runTableVersion_ = std::make_pair(0,0);
00213   fastCablingV_ = std::make_pair(0,0);
00214   apvTimingV_   = std::make_pair(0,0);
00215   optoScanV_    = std::make_pair(0,0);
00216   vpspScanV_    = std::make_pair(0,0);
00217   apvCalibV_    = std::make_pair(0,0);
00218   pedestalsV_   = std::make_pair(0,0);
00219   apvLatencyV_  = std::make_pair(0,0);
00220   fineDelayV_   = std::make_pair(0,0);
00221   
00222   inputModuleXml_   = "";
00223   inputDcuInfoXml_  = "";
00224   inputFecXml_.clear(); inputFecXml_.push_back("");
00225   inputFedXml_.clear(); inputFedXml_.push_back("");
00226 }
00227 
00228 // -----------------------------------------------------------------------------
00229 // 
00230 void SiStripPartition::pset( const edm::ParameterSet& pset ) {
00231 
00232   partitionName_     = pset.getUntrackedParameter<std::string>( "PartitionName", "" );
00233   runNumber_         = pset.getUntrackedParameter<unsigned int>( "RunNumber", 0 );
00234   forceVersions_     = pset.getUntrackedParameter<bool>( "ForceVersions", false );
00235   forceCurrentState_ = pset.getUntrackedParameter<bool>( "ForceCurrentState", false );
00236 
00237   std::vector<uint32_t> tmp1(2,0);
00238   cabVersion_ = versions( pset.getUntrackedParameter< std::vector<uint32_t> >( "CablingVersion", tmp1 ) );
00239   fedVersion_ = versions( pset.getUntrackedParameter< std::vector<uint32_t> >( "FedVersion", tmp1 ) );
00240   fecVersion_ = versions( pset.getUntrackedParameter< std::vector<uint32_t> >( "FecVersion", tmp1 ) );
00241   dcuVersion_ = versions( pset.getUntrackedParameter< std::vector<uint32_t> >( "DcuDetIdsVersion", tmp1 ) );
00242   psuVersion_ = versions( pset.getUntrackedParameter< std::vector<uint32_t> >( "DcuPsuMapVersion", tmp1 ) );
00243   //#ifdef USING_DATABASE_MASKING
00244   maskVersion_ = versions( pset.getUntrackedParameter< std::vector<uint32_t> >( "MaskVersion", tmp1 ) );
00245   //#endif
00246 
00247   std::vector<uint32_t> tmp2(2,0);
00248   globalAnalysisV_ = pset.getUntrackedParameter<uint32_t>( "GlobalAnalysisVersion", 0 );
00249   fastCablingV_    = versions( pset.getUntrackedParameter< std::vector<uint32_t> >( "FastCablingVersion", tmp2 ) );
00250   apvTimingV_      = versions( pset.getUntrackedParameter< std::vector<uint32_t> >( "ApvTimingVersion", tmp2 ) );
00251   optoScanV_       = versions( pset.getUntrackedParameter< std::vector<uint32_t> >( "OptoScanVersion", tmp2 ) );
00252   vpspScanV_       = versions( pset.getUntrackedParameter< std::vector<uint32_t> >( "VpspScanVersion", tmp2 ) );
00253   apvCalibV_       = versions( pset.getUntrackedParameter< std::vector<uint32_t> >( "ApvCalibVersion", tmp2 ) );
00254   pedestalsV_      = versions( pset.getUntrackedParameter< std::vector<uint32_t> >( "PedestalsVersion", tmp2 ) );
00255   apvLatencyV_     = versions( pset.getUntrackedParameter< std::vector<uint32_t> >( "ApvLatencyVersion", tmp2 ) );
00256   fineDelayV_      = versions( pset.getUntrackedParameter< std::vector<uint32_t> >( "FineDelayVersion", tmp2 ) );
00257   
00258   std::vector<std::string> tmp3(1,"");
00259   inputModuleXml_   = pset.getUntrackedParameter<std::string>( "InputModuleXml", "" );
00260   inputDcuInfoXml_  = pset.getUntrackedParameter<std::string>( "InputDcuInfoXml", "" ); 
00261   inputFecXml_      = pset.getUntrackedParameter< std::vector<std::string> >( "InputFecXml", tmp3 ); 
00262   inputFedXml_      = pset.getUntrackedParameter< std::vector<std::string> >( "InputFedXml", tmp3 );
00263   
00264 }
00265 
00266 // -----------------------------------------------------------------------------
00267 // 
00268 void SiStripPartition::update( const SiStripConfigDb* const db ) {
00269   
00270   // Check
00271   if ( !db ) {
00272     edm::LogError(mlConfigDb_)
00273       << "[SiStripPartition::" << __func__ << "]"
00274       << " NULL pointer to SiStripConfigDb object!"
00275       << " Aborting update...";
00276     return;
00277   }
00278   
00279   // Check
00280   DeviceFactory* const df = db->deviceFactory(__func__);
00281   if ( !df ) {
00282     edm::LogError(mlConfigDb_)
00283       << "[SiStripPartition::" << __func__ << "]"
00284       << " NULL pointer to DeviceFactory object!"
00285       << " Aborting update...";
00286     return;
00287   }
00288 
00289   // Check partition name
00290   if ( partitionName_ == defaultPartitionName_ ) { return; }
00291 
00292   // Debug
00293   std::stringstream ss;
00294   ss << "[SiStripPartition::" << __func__ << "]"
00295      << " Updating description versions for partition \""
00296      << partitionName_
00297      << "\"...";
00298   LogTrace(mlConfigDb_) << ss.str();
00299 
00300   try {
00301 
00302     // Reset container indicating state versions for commissioning runs 
00303     runTableVersion_ = Versions(0,0);
00304 
00305     // Update versions if using versions from "current state"
00306     if ( forceCurrentState_ || forceVersions_ ) { 
00307     
00308       // Find state for given partition
00309       tkStateVector states;
00310       states = df->getCurrentStates(); 
00311       tkStateVector::const_iterator istate = states.begin();
00312       tkStateVector::const_iterator jstate = states.end();
00313       while ( istate != jstate ) {
00314         if ( *istate && partitionName_ == (*istate)->getPartitionName() ) { break; }
00315         istate++;
00316       }
00317       
00318       // Set versions if state was found
00319       if ( istate != states.end() ) {
00320         
00321         if ( !cabVersion_.first &&
00322              !cabVersion_.second ) { 
00323           cabVersion_.first = (*istate)->getConnectionVersionMajorId(); 
00324           cabVersion_.second = (*istate)->getConnectionVersionMinorId(); 
00325         }
00326         if ( !fecVersion_.first &&
00327              !fecVersion_.second ) { 
00328           fecVersion_.first = (*istate)->getFecVersionMajorId(); 
00329           fecVersion_.second = (*istate)->getFecVersionMinorId(); 
00330         }
00331         if ( !fedVersion_.first &&
00332              !fedVersion_.second ) { 
00333           fedVersion_.first = (*istate)->getFedVersionMajorId(); 
00334           fedVersion_.second = (*istate)->getFedVersionMinorId(); 
00335         }
00336         if ( !dcuVersion_.first &&
00337              !dcuVersion_.second ) { 
00338           dcuVersion_.first = (*istate)->getDcuInfoVersionMajorId(); 
00339           dcuVersion_.second = (*istate)->getDcuInfoVersionMinorId(); 
00340         }
00341         if ( !psuVersion_.first &&
00342              !psuVersion_.second ) { 
00343           psuVersion_.first = (*istate)->getDcuPsuMapVersionMajorId();
00344           psuVersion_.second = (*istate)->getDcuPsuMapVersionMinorId(); 
00345         }
00346         //#ifdef USING_DATABASE_MASKING
00347         if ( !forceVersions_ &&
00348              !maskVersion_.first &&
00349              !maskVersion_.second ) { 
00350           maskVersion_.first = (*istate)->getMaskVersionMajorId();
00351           maskVersion_.second = (*istate)->getMaskVersionMinorId(); 
00352         }
00353         //#endif
00354         
00355         // Retrieve global and local versions 
00356         if ( forceCurrentState_ || globalAnalysisV_ ) { // use global version (or current state)
00357 
00358           // Set global version
00359           if ( forceCurrentState_ ) { globalAnalysisV_ = (*istate)->getAnalysisVersionMapPointerId(); }
00360           
00361           // Retrieve local versions
00362           HashMapAnalysisVersions local_versions = df->getLocalAnalysisVersions( globalAnalysisV_ );
00363           
00364           // Iterate through map< AnalysisType, pair<Major,Minor> >
00365           HashMapAnalysisVersions::const_iterator ivers = local_versions.begin();
00366           HashMapAnalysisVersions::const_iterator jvers = local_versions.end();
00367           for ( ; ivers != jvers; ++ivers ) {
00368             if ( ivers->first == CommissioningAnalysisDescription::T_ANALYSIS_FASTFEDCABLING ) { 
00369               fastCablingV_.first = ivers->second.first;
00370               fastCablingV_.second = ivers->second.second;
00371             } else if ( ivers->first == CommissioningAnalysisDescription::T_ANALYSIS_TIMING ) {
00372               apvTimingV_.first = ivers->second.first;
00373               apvTimingV_.second = ivers->second.second;
00374             } else if ( ivers->first == CommissioningAnalysisDescription::T_ANALYSIS_OPTOSCAN ) {
00375               optoScanV_.first = ivers->second.first;
00376               optoScanV_.second = ivers->second.second;
00377             } else if ( ivers->first == CommissioningAnalysisDescription::T_ANALYSIS_VPSPSCAN ) {
00378               vpspScanV_.first = ivers->second.first;
00379               vpspScanV_.second = ivers->second.second;
00380             } else if ( ivers->first == CommissioningAnalysisDescription::T_ANALYSIS_CALIBRATION ) {
00381               apvCalibV_.first = ivers->second.first;
00382               apvCalibV_.second = ivers->second.second;
00383             } else if ( ivers->first == CommissioningAnalysisDescription::T_ANALYSIS_PEDESTALS ) {
00384               pedestalsV_.first = ivers->second.first;
00385               pedestalsV_.second = ivers->second.second;
00386             } else if ( ivers->first == CommissioningAnalysisDescription::T_ANALYSIS_APVLATENCY ) {
00387               apvLatencyV_.first = ivers->second.first;
00388               apvLatencyV_.second = ivers->second.second;
00389             } else if ( ivers->first == CommissioningAnalysisDescription::T_ANALYSIS_FINEDELAY ) {
00390               fineDelayV_.first = ivers->second.first;
00391               fineDelayV_.second = ivers->second.second;
00392             } else if ( ivers->first == CommissioningAnalysisDescription::T_UNKNOWN ) {
00393               std::stringstream ss;
00394               edm::LogError(mlConfigDb_)
00395                 << "[SiStripPartition::" << __func__ << "]"
00396                 << " Found UNKNOWN AnalysisType!";
00397               edm::LogWarning(mlConfigDb_) << ss.str();
00398             } else {
00399               std::stringstream ss;
00400               edm::LogError(mlConfigDb_)
00401                 << "[SiStripPartition::" << __func__ << "]"
00402                 << " Unable to match content to any AnalysisType!";
00403               edm::LogWarning(mlConfigDb_) << ss.str();
00404             }
00405           }
00406       
00407         } else if ( !globalAnalysisV_ ) { // use local versions
00408         
00409           // Retrieve local versions and set if necessary
00410           globalAnalysisV_ = (*istate)->getAnalysisVersionMapPointerId(); 
00411           HashMapAnalysisVersions local_versions = df->getLocalAnalysisVersions( globalAnalysisV_ );
00412           
00413           // Iterate through map< AnalysisType, pair<Major,Minor> >
00414           HashMapAnalysisVersions::const_iterator ivers = local_versions.begin();
00415           HashMapAnalysisVersions::const_iterator jvers = local_versions.end();
00416           for ( ; ivers != jvers; ++ivers ) {
00417             if ( ivers->first == CommissioningAnalysisDescription::T_ANALYSIS_FASTFEDCABLING ) { 
00418               if ( !fastCablingV_.first && !fastCablingV_.second ) {
00419                 fastCablingV_.first = ivers->second.first;
00420                 fastCablingV_.second = ivers->second.second;
00421               }
00422             } else if ( ivers->first == CommissioningAnalysisDescription::T_ANALYSIS_TIMING ) {
00423               if ( !apvTimingV_.first && !apvTimingV_.second ) {
00424                 apvTimingV_.first = ivers->second.first;
00425                 apvTimingV_.second = ivers->second.second;
00426               }
00427             } else if ( ivers->first == CommissioningAnalysisDescription::T_ANALYSIS_OPTOSCAN ) {
00428               if ( !optoScanV_.first && !optoScanV_.second ) {
00429                 optoScanV_.first = ivers->second.first;
00430                 optoScanV_.second = ivers->second.second;
00431               }
00432             } else if ( ivers->first == CommissioningAnalysisDescription::T_ANALYSIS_VPSPSCAN ) {
00433               if ( !vpspScanV_.first && !vpspScanV_.second ) {
00434                 vpspScanV_.first = ivers->second.first;
00435                 vpspScanV_.second = ivers->second.second;
00436               }
00437             } else if ( ivers->first == CommissioningAnalysisDescription::T_ANALYSIS_CALIBRATION ) {
00438               if ( !apvCalibV_.first && !apvCalibV_.second ) {
00439                 apvCalibV_.first = ivers->second.first;
00440                 apvCalibV_.second = ivers->second.second;
00441               }
00442             } else if ( ivers->first == CommissioningAnalysisDescription::T_ANALYSIS_PEDESTALS ) {
00443               if ( !pedestalsV_.first && !pedestalsV_.second ) {
00444                 pedestalsV_.first = ivers->second.first;
00445                 pedestalsV_.second = ivers->second.second;
00446               }
00447             } else if ( ivers->first == CommissioningAnalysisDescription::T_ANALYSIS_APVLATENCY ) {
00448               if ( !apvLatencyV_.first && !apvLatencyV_.second ) {
00449                 apvLatencyV_.first = ivers->second.first;
00450                 apvLatencyV_.second = ivers->second.second;
00451               }
00452             } else if ( ivers->first == CommissioningAnalysisDescription::T_ANALYSIS_FINEDELAY ) {
00453               if ( !fineDelayV_.first && !fineDelayV_.second ) {
00454                 fineDelayV_.first = ivers->second.first;
00455                 fineDelayV_.second = ivers->second.second;
00456               }
00457             } else if ( ivers->first == CommissioningAnalysisDescription::T_UNKNOWN ) {
00458               std::stringstream ss;
00459               edm::LogError(mlConfigDb_)
00460                 << "[SiStripPartition::" << __func__ << "]"
00461                 << " Found UNKNOWN AnalysisType!";
00462               edm::LogWarning(mlConfigDb_) << ss.str();
00463             } else {
00464               std::stringstream ss;
00465               edm::LogError(mlConfigDb_)
00466                 << "[SiStripPartition::" << __func__ << "]"
00467                 << " Unable to match content to any AnalysisType!";
00468               edm::LogWarning(mlConfigDb_) << ss.str();
00469             }
00470           }
00471       
00472         }
00473 
00474       } else {
00475         std::stringstream ss;
00476         edm::LogError(mlConfigDb_)
00477           << "[SiStripPartition::" << __func__ << "]"
00478           << " Unable to find \"current state\" for partition \""
00479           << partitionName_ << "\"";
00480       }
00481     
00482     } else { // ---------- USE RUN NUMBER ----------
00483     
00484       // Retrieve TkRun object for given run (0 means "latest run")
00485       TkRun* run = 0;
00486       if ( !runNumber_ ) { run = df->getLastRun( partitionName_ ); }
00487       else { run = df->getRun( partitionName_, runNumber_ ); }
00488   
00489       // Retrieve versioning for given TkRun object 
00490       if ( run ) {
00491         
00492         if ( run->getRunNumber() ) {
00493           
00494           if ( !runNumber_ ) { runNumber_ = run->getRunNumber(); }
00495           
00496           if ( runNumber_ == run->getRunNumber() ) {
00497             
00498             cabVersion_.first = run->getConnectionVersionMajorId(); 
00499             cabVersion_.second = run->getConnectionVersionMinorId(); 
00500             
00501             fecVersion_.first = run->getFecVersionMajorId(); 
00502             fecVersion_.second = run->getFecVersionMinorId(); 
00503             
00504             fedVersion_.first = run->getFedVersionMajorId(); 
00505             fedVersion_.second = run->getFedVersionMinorId(); 
00506             
00507             dcuVersion_.first = run->getDcuInfoVersionMajorId(); 
00508             dcuVersion_.second = run->getDcuInfoVersionMinorId(); 
00509             
00510             psuVersion_.first = run->getDcuPsuMapVersionMajorId();
00511             psuVersion_.second = run->getDcuPsuMapVersionMinorId(); 
00512             
00513             //#ifdef USING_DATABASE_MASKING
00514             maskVersion_.first = run->getMaskVersionMajorId();
00515             maskVersion_.second = run->getMaskVersionMinorId(); 
00516             //#endif
00517             
00518             // Check run type
00519             uint16_t type = run->getModeId( run->getMode() );
00520             if      ( type ==  1 ) { runType_ = sistrip::PHYSICS; }
00521             else if ( type ==  2 ) { runType_ = sistrip::PEDESTALS; }
00522             else if ( type ==  3 ) { runType_ = sistrip::CALIBRATION; }
00523             else if ( type == 33 ) { runType_ = sistrip::CALIBRATION_DECO; }
00524             else if ( type ==  4 ) { runType_ = sistrip::OPTO_SCAN; }
00525             else if ( type ==  5 ) { runType_ = sistrip::APV_TIMING; }
00526             else if ( type ==  6 ) { runType_ = sistrip::APV_LATENCY; }
00527             else if ( type ==  7 ) { runType_ = sistrip::FINE_DELAY_PLL; }
00528             else if ( type ==  8 ) { runType_ = sistrip::FINE_DELAY_TTC; }
00529             else if ( type == 10 ) { runType_ = sistrip::MULTI_MODE; }
00530             else if ( type == 12 ) { runType_ = sistrip::FED_TIMING; }
00531             else if ( type == 13 ) { runType_ = sistrip::FED_CABLING; }
00532             else if ( type == 14 ) { runType_ = sistrip::VPSP_SCAN; }
00533             else if ( type == 15 ) { runType_ = sistrip::DAQ_SCOPE_MODE; }
00534             else if ( type == 16 ) { runType_ = sistrip::QUITE_FAST_CABLING; }
00535             else if ( type == 21 ) { runType_ = sistrip::FAST_CABLING; }
00536             else if ( type ==  0 ) { 
00537               runType_ = sistrip::UNDEFINED_RUN_TYPE;
00538               edm::LogWarning(mlConfigDb_)
00539                 << "[SiStripPartition::" << __func__ << "]"
00540                 << " NULL run type returned!"
00541                 << " for partition \"" << partitionName_ << "\"";
00542             } else { 
00543               runType_ = sistrip::UNKNOWN_RUN_TYPE; 
00544               edm::LogWarning(mlConfigDb_)
00545                 << "[SiStripPartition::" << __func__ << "]"
00546                 << " UNKNOWN run type (" << type<< ") returned!"
00547                 << " for partition \"" << partitionName_ << "\"";
00548             }
00549 
00550             // Retrieve global and local versions from state associated with given run
00551             globalAnalysisV_ = run->getAnalysisVersionMapPointerId(); 
00552             HashMapAnalysisVersions local_versions = df->getLocalAnalysisVersions( globalAnalysisV_ );
00553             HashMapAnalysisVersions::const_iterator ivers = local_versions.begin();
00554             HashMapAnalysisVersions::const_iterator jvers = local_versions.end();
00555             for ( ; ivers != jvers; ++ivers ) {
00556               if ( ivers->first == CommissioningAnalysisDescription::T_ANALYSIS_FASTFEDCABLING ) { 
00557                 fastCablingV_.first = ivers->second.first;
00558                 fastCablingV_.second = ivers->second.second;
00559               } else if ( ivers->first == CommissioningAnalysisDescription::T_ANALYSIS_TIMING ) {
00560                 apvTimingV_.first = ivers->second.first;
00561                 apvTimingV_.second = ivers->second.second;
00562               } else if ( ivers->first == CommissioningAnalysisDescription::T_ANALYSIS_OPTOSCAN ) {
00563                 optoScanV_.first = ivers->second.first;
00564                 optoScanV_.second = ivers->second.second;
00565               } else if ( ivers->first == CommissioningAnalysisDescription::T_ANALYSIS_VPSPSCAN ) {
00566                 vpspScanV_.first = ivers->second.first;
00567                 vpspScanV_.second = ivers->second.second;
00568               } else if ( ivers->first == CommissioningAnalysisDescription::T_ANALYSIS_CALIBRATION ) {
00569                 apvCalibV_.first = ivers->second.first;
00570                 apvCalibV_.second = ivers->second.second;
00571               } else if ( ivers->first == CommissioningAnalysisDescription::T_ANALYSIS_PEDESTALS ) {
00572                 pedestalsV_.first = ivers->second.first;
00573                 pedestalsV_.second = ivers->second.second;
00574               } else if ( ivers->first == CommissioningAnalysisDescription::T_ANALYSIS_APVLATENCY ) {
00575                 apvLatencyV_.first = ivers->second.first;
00576                 apvLatencyV_.second = ivers->second.second;
00577               } else if ( ivers->first == CommissioningAnalysisDescription::T_ANALYSIS_FINEDELAY ) {
00578                 fineDelayV_.first = ivers->second.first;
00579                 fineDelayV_.second = ivers->second.second;
00580               } else if ( ivers->first == CommissioningAnalysisDescription::T_UNKNOWN ) {
00581                 std::stringstream ss;
00582                 edm::LogError(mlConfigDb_)
00583                   << "[SiStripPartition::" << __func__ << "]"
00584                   << " Found UNKNOWN AnalysisType!";
00585                 edm::LogWarning(mlConfigDb_) << ss.str();
00586               } else {
00587                 std::stringstream ss;
00588                 edm::LogError(mlConfigDb_)
00589                   << "[SiStripPartition::" << __func__ << "]"
00590                   << " Unable to match content to any AnalysisType!";
00591                 edm::LogWarning(mlConfigDb_) << ss.str();
00592               }
00593             }
00594 
00595             // If commissioning run, override version of analysis type with version PRODUCED by run (from history)
00596             if ( runType_ != sistrip::PHYSICS &&
00597                  runType_ != sistrip::UNDEFINED_RUN_TYPE &&
00598                  runType_ != sistrip::UNKNOWN_RUN_TYPE ) { 
00599               
00600               // Determine analysis type from run type
00601               CommissioningAnalysisDescription::commissioningType type = CommissioningAnalysisDescription::T_UNKNOWN;
00602               if      ( runType_ == sistrip::FAST_CABLING )   { type = CommissioningAnalysisDescription::T_ANALYSIS_FASTFEDCABLING; }
00603               else if ( runType_ == sistrip::APV_TIMING )     { type = CommissioningAnalysisDescription::T_ANALYSIS_TIMING; }
00604               else if ( runType_ == sistrip::OPTO_SCAN )      { type = CommissioningAnalysisDescription::T_ANALYSIS_OPTOSCAN; }
00605               else if ( runType_ == sistrip::VPSP_SCAN )      { type = CommissioningAnalysisDescription::T_ANALYSIS_VPSPSCAN; }
00606               else if ( runType_ == sistrip::CALIBRATION )    { type = CommissioningAnalysisDescription::T_ANALYSIS_CALIBRATION; }
00607               else if ( runType_ == sistrip::PEDESTALS )      { type = CommissioningAnalysisDescription::T_ANALYSIS_PEDESTALS; }
00608               else if ( runType_ == sistrip::APV_LATENCY )    { type = CommissioningAnalysisDescription::T_ANALYSIS_APVLATENCY; }
00609               else if ( runType_ == sistrip::FINE_DELAY_TTC ) { type = CommissioningAnalysisDescription::T_ANALYSIS_FINEDELAY; }
00610 
00611               // Retrieve local versions for COMMISSIONING runs from history
00612               HashMapRunVersion local_versions = df->getAnalysisHistory( partitionName_, type );
00613 
00614               // Iterate through map< RunNumber, vector< pair<Major,Minor> > > to find appropriate run
00615               HashMapRunVersion::const_iterator ivers = local_versions.end();
00616               if ( runNumber_ == 0 ) { ivers = --(local_versions.end()); }
00617               else { ivers = local_versions.find( runNumber_ ); } 
00618               
00619               // Set appropriate versions
00620               if ( ivers != local_versions.end() ) {
00621                 if ( type == CommissioningAnalysisDescription::T_ANALYSIS_FASTFEDCABLING ) { 
00622                   runTableVersion_ = fastCablingV_;
00623                   fastCablingV_.first = ivers->second.back().first;
00624                   fastCablingV_.second = ivers->second.back().second;
00625 
00626                   //@@
00627 
00628                 } else if ( type == CommissioningAnalysisDescription::T_ANALYSIS_TIMING ) {
00629                   runTableVersion_ = apvTimingV_;
00630                   apvTimingV_.first = ivers->second.back().first;
00631                   apvTimingV_.second = ivers->second.back().second;
00632                 } else if ( type == CommissioningAnalysisDescription::T_ANALYSIS_OPTOSCAN ) {
00633                   runTableVersion_ = optoScanV_;
00634                   optoScanV_.first = ivers->second.back().first;
00635                   optoScanV_.second = ivers->second.back().second;
00636                 } else if ( type == CommissioningAnalysisDescription::T_ANALYSIS_VPSPSCAN ) {
00637                   runTableVersion_ = vpspScanV_;
00638                   vpspScanV_.first = ivers->second.back().first;
00639                   vpspScanV_.second = ivers->second.back().second;
00640                 } else if ( type == CommissioningAnalysisDescription::T_ANALYSIS_CALIBRATION ) {
00641                   runTableVersion_ = apvCalibV_;
00642                   apvCalibV_.first = ivers->second.back().first;
00643                   apvCalibV_.second = ivers->second.back().second;
00644                 } else if ( type == CommissioningAnalysisDescription::T_ANALYSIS_PEDESTALS ) {
00645                   runTableVersion_ = pedestalsV_;
00646                   pedestalsV_.first = ivers->second.back().first;
00647                   pedestalsV_.second = ivers->second.back().second;
00648                 } else if ( type == CommissioningAnalysisDescription::T_ANALYSIS_APVLATENCY ) {
00649                   runTableVersion_ = apvLatencyV_;
00650                   apvLatencyV_.first = ivers->second.back().first;
00651                   apvLatencyV_.second = ivers->second.back().second;
00652                 } else if ( type == CommissioningAnalysisDescription::T_ANALYSIS_FINEDELAY ) {
00653                   runTableVersion_ = fineDelayV_;
00654                   fineDelayV_.first = ivers->second.back().first;
00655                   fineDelayV_.second = ivers->second.back().second;
00656                 } else if ( type == CommissioningAnalysisDescription::T_UNKNOWN ) {
00657                   std::stringstream ss;
00658                   edm::LogError(mlConfigDb_)
00659                     << "[SiStripPartition::" << __func__ << "]"
00660                     << " Found UNKNOWN AnalysisType!";
00661                   edm::LogWarning(mlConfigDb_) << ss.str();
00662                 } else {
00663                   std::stringstream ss;
00664                   edm::LogError(mlConfigDb_)
00665                     << "[SiStripPartition::" << __func__ << "]"
00666                     << " Unable to match content to any AnalysisType!";
00667                   edm::LogWarning(mlConfigDb_) << ss.str();
00668                 }
00669               } else {
00670                 std::stringstream ss;
00671                 edm::LogError(mlConfigDb_)
00672                   << "[SiStripPartition::" << __func__ << "]"
00673                   << " Unable to find run number " << runNumber_
00674                   << " in \"history\" hash map ";
00675                 edm::LogWarning(mlConfigDb_) << ss.str();
00676               }
00677 
00678             }
00679         
00680           } else {
00681             edm::LogError(mlConfigDb_)
00682               << "[SiStripPartition::" << __func__ << "]"
00683               << " Mismatch of run number requested (" 
00684               << runNumber_
00685               << ") and received (" 
00686               << run->getRunNumber() << ")"
00687               << " to/from database for partition \"" 
00688               << partitionName_ << "\"";
00689           }
00690 
00691         } else {
00692           edm::LogError(mlConfigDb_)
00693             << "[SiStripPartition::" << __func__ << "]"
00694             << " NULL run number returned!"
00695             << " for partition \"" << partitionName_ << "\"";
00696         }
00697       
00698       } else {
00699         edm::LogError(mlConfigDb_)
00700           << "[SiStripPartition::" << __func__ << "]"
00701           << " NULL pointer to TkRun object!"
00702           << " Unable to retrieve versions for run number "
00703           << runNumber_
00704           << ". Run number may not be consistent with partition \"" 
00705           << partitionName_ << "\"!"; //@@ only using first here!!!
00706       }
00707 
00708     }
00709 
00710   } catch (...) { db->handleException( __func__, "" ); }
00711   
00712 }
00713 
00714 // -----------------------------------------------------------------------------
00715 // 
00716 void SiStripPartition::print( std::stringstream& ss, bool using_db ) const {
00717 
00718   ss << "  Partition                  : \"" << partitionName_ << "\"" << std::endl;
00719   
00720   if ( using_db ) {
00721     
00722     ss << "  Run number                 : ";
00723     if ( forceCurrentState_ )  { ss << "Forced \"current state\"! (equivalent to versions below)"; }
00724     else if ( forceVersions_ ) { ss << "Forced versions specified below!"; }
00725     else /* use run number */  { ss << runNumber_; }
00726     
00727     ss << std::endl;
00728     if ( !forceVersions_ ) { 
00729       ss << "  Run type                   : " << SiStripEnumsAndStrings::runType( runType_ ) << std::endl;
00730     }
00731     
00732     ss << "  Cabling major/minor vers   : " << cabVersion_.first << "." << cabVersion_.second << std::endl
00733        << "  FEC major/minor vers       : " << fecVersion_.first << "." << fecVersion_.second << std::endl
00734        << "  FED major/minor vers       : " << fedVersion_.first << "." << fedVersion_.second << std::endl
00735        << "  DCU-DetId map maj/min vers : " << dcuVersion_.first << "." << dcuVersion_.second << std::endl
00736       //#ifdef USING_DATABASE_MASKING
00737        << "  DCU-PSU map maj/min vers   : " << psuVersion_.first << "." << psuVersion_.second << std::endl
00738        << "  Mask maj/min vers          : " << maskVersion_.first << "." << maskVersion_.second << std::endl;
00739     //#else
00740     //       << "  DCU-PSU map maj/min vers   : " << psuVersion_.first << "." << psuVersion_.second << std::endl;
00741     //#endif
00742 
00743     ss << "  Global analysis version    : " << globalAnalysisV_ << std::endl;
00744 
00745 
00746     if ( runType_ == sistrip::PHYSICS ||
00747          runType_ == sistrip::UNDEFINED_RUN_TYPE ||
00748          runType_ == sistrip::UNKNOWN_RUN_TYPE ) { 
00749       
00750       ss << "  FED cabling maj/min vers   : " << fastCablingV_.first << "." << fastCablingV_.second << std::endl;
00751       ss << "  APV timing maj/min vers    : " << apvTimingV_.first << "." << apvTimingV_.second << std::endl;
00752       ss << "  Opto scan maj/min vers     : " << optoScanV_.first << "." << optoScanV_.second << std::endl;
00753       ss << "  VPSP scan maj/min vers     : " << vpspScanV_.first << "." << vpspScanV_.second << std::endl;
00754       ss << "  APV calib maj/min vers     : " << apvCalibV_.first << "." << apvCalibV_.second << std::endl;
00755       ss << "  Pedestals maj/min vers     : " << pedestalsV_.first << "." << pedestalsV_.second << std::endl;
00756       ss << "  APV latency maj/min vers   : " << apvLatencyV_.first << "." << apvLatencyV_.second << std::endl;
00757       ss << "  Fine delay maj/min vers    : " << fineDelayV_.first << "." << fineDelayV_.second << std::endl;
00758       
00759     } else {
00760       
00761       if ( runType_ != sistrip::FAST_CABLING ) { 
00762         ss << "  FED cabling maj/min vers   : " << fastCablingV_.first << "." << fastCablingV_.second << std::endl;
00763       } else {
00764         ss << "  FED cabling maj/min vers   : " << runTableVersion_.first << "." << runTableVersion_.second
00765            << " <= This \"state\" version overriden by \"history\" version " 
00766            << fastCablingV_.first << "." << fastCablingV_.second 
00767            << " for this FED cabling run!" << std::endl;
00768       }
00769 
00770       if ( runType_ != sistrip::APV_TIMING ) { 
00771         ss << "  APV timing maj/min vers    : " << apvTimingV_.first << "." << apvTimingV_.second << std::endl;
00772       } else {
00773         ss << "  APV timing maj/min vers    : " << runTableVersion_.first << "." << runTableVersion_.second
00774            << " <= This \"state\" version overriden by \"history\" version " 
00775            << apvTimingV_.first << "." << apvTimingV_.second 
00776            << " for this APV timing run!" << std::endl;
00777       }
00778 
00779       if ( runType_ != sistrip::OPTO_SCAN ) { 
00780         ss << "  Opto scan maj/min vers     : " << optoScanV_.first << "." << optoScanV_.second << std::endl;
00781       } else {
00782         ss << "  Opto scan maj/min vers     : " << runTableVersion_.first << "." << runTableVersion_.second
00783            << " <= This \"state\" version overriden by \"history\" version " 
00784            << optoScanV_.first << "." << optoScanV_.second 
00785            << " for this opto scan run!" << std::endl;
00786       }
00787 
00788       if ( runType_ != sistrip::VPSP_SCAN ) { 
00789         ss << "  VPSP scan maj/min vers     : " << vpspScanV_.first << "." << vpspScanV_.second << std::endl;
00790       } else {
00791         ss << "  VPSP scan maj/min vers     : " << runTableVersion_.first << "." << runTableVersion_.second
00792            << " <= This \"state\" version overriden by \"history\" version " 
00793            << vpspScanV_.first << "." << vpspScanV_.second 
00794            << " for this VPSP scan run!" << std::endl;
00795       }
00796 
00797       if ( runType_ != sistrip::CALIBRATION ) { 
00798         ss << "  APV calib maj/min vers     : " << apvCalibV_.first << "." << apvCalibV_.second << std::endl;
00799       } else {
00800         ss << "  APV calib maj/min vers     : " << runTableVersion_.first << "." << runTableVersion_.second
00801            << " <= This \"state\" version overriden by \"history\" version " 
00802            << apvCalibV_.first << "." << apvCalibV_.second 
00803            << " for this APV calib run!" << std::endl;
00804       }
00805 
00806       if ( runType_ != sistrip::PEDESTALS ) { 
00807         ss << "  Pedestals maj/min vers     : " << pedestalsV_.first << "." << pedestalsV_.second << std::endl;
00808       } else {
00809         ss << "  Pedestals maj/min vers     : " << runTableVersion_.first << "." << runTableVersion_.second
00810            << " <= This \"state\" version overriden by \"history\" version " 
00811            << pedestalsV_.first << "." << pedestalsV_.second 
00812            << " for this pedestals run!" << std::endl;
00813       }
00814 
00815       if ( runType_ != sistrip::APV_LATENCY ) { 
00816         ss << "  APV latency maj/min vers   : " << apvLatencyV_.first << "." << apvLatencyV_.second << std::endl;
00817       } else {
00818         ss << "  APV latency maj/min vers   : " << runTableVersion_.first << "." << runTableVersion_.second
00819            << " <= This \"state\" version overriden by \"history\" version " 
00820            << apvLatencyV_.first << "." << apvLatencyV_.second 
00821            << " for this APV latency run!" << std::endl;
00822       }
00823 
00824       if ( runType_ != sistrip::FINE_DELAY_TTC ) { 
00825         ss << "  Fine delay maj/min vers    : " << fineDelayV_.first << "." << fineDelayV_.second << std::endl;
00826       } else {
00827         ss << "  Fine delay maj/min vers    : " << runTableVersion_.first << "." << runTableVersion_.second
00828            << " <= This \"state\" version overriden by \"history\" version " 
00829            << fineDelayV_.first << "." << fineDelayV_.second 
00830            << " for this fine delay run!" << std::endl;
00831       }
00832 
00833     }
00834 
00835   } else {
00836     
00837     ss << "  Input \"module.xml\" file    : " << inputModuleXml_ << std::endl
00838        << "  Input \"dcuinfo.xml\" file   : " << inputDcuInfoXml_ << std::endl
00839        << "  Input \"fec.xml\" file(s)    : ";
00840     std::vector<std::string>::const_iterator ifec = inputFecXml_.begin();
00841     for ( ; ifec != inputFecXml_.end(); ifec++ ) { ss << *ifec << ", "; }
00842     ss << std::endl;
00843     ss << "  Input \"fed.xml\" file(s)    : ";
00844     std::vector<std::string>::const_iterator ifed = inputFedXml_.begin();
00845     for ( ; ifed != inputFedXml_.end(); ifed++ ) { ss << *ifed << ", "; }
00846     ss << std::endl;
00847     
00848   }
00849   
00850 }
00851 
00852 // -----------------------------------------------------------------------------
00853 // 
00854 std::ostream& operator<< ( std::ostream& os, const SiStripPartition& params ) {
00855   std::stringstream ss;
00856   params.print(ss);
00857   os << ss.str();
00858   return os;
00859 }
00860 
00861 // -----------------------------------------------------------------------------
00862 // 
00863 SiStripPartition::Versions SiStripPartition::versions( std::vector<uint32_t> input ) {
00864   if ( input.size() != 2 ) { 
00865     edm::LogWarning(mlConfigDb_)
00866       << "[SiStripPartition::" << __func__ << "]"
00867       << " Unexpected size (" << input.size()
00868       << ") for  vector containing version numbers (major,minor)!"
00869       << " Resizing to 2 elements (default values will be 0,0)...";
00870     input.resize(2,0);
00871   }
00872   return std::make_pair( input[0], input[1] );
00873 }