CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/OnlineDB/SiStripO2O/plugins/SiStripPopConHandlerUnitTestGain.h

Go to the documentation of this file.
00001 #ifndef SISTRIPPOPCON_UNITTEST_HANDLER_GAIN_H
00002 #define SISTRIPPOPCON_UNITTEST_HANDLER_GAIN_H
00003 
00004 #include "FWCore/ParameterSet/interface/ParameterSetfwd.h"
00005 #include "FWCore/ServiceRegistry/interface/Service.h"
00006 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00007 #include "FWCore/ParameterSet/interface/ParameterSetfwd.h"
00008 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00009 
00010 #include "CondCore/PopCon/interface/PopConSourceHandler.h"
00011 #include "CondCore/DBCommon/interface/TagInfo.h"
00012 #include "CondCore/DBCommon/interface/LogDBEntry.h"
00013 
00014 #include "OnlineDB/SiStripESSources/interface/SiStripCondObjBuilderFromDb.h"
00015 #include "OnlineDB/SiStripConfigDb/interface/SiStripDbParams.h"
00016 #include "OnlineDB/SiStripConfigDb/interface/SiStripPartition.h"
00017 
00018 #include <sstream>
00019 #include <vector>
00020 #include <string>
00021 #include <iostream>
00022 #include <typeinfo>
00023 #include <time.h>
00024 
00025 #include "CLHEP/Random/RandFlat.h"
00026 #include "CLHEP/Random/RandGauss.h"
00027 
00028 #include "CondFormats/SiStripObjects/interface/SiStripNoises.h"
00029 #include "CondFormats/SiStripObjects/interface/SiStripApvGain.h"
00030 #include "CalibTracker/SiStripCommon/interface/SiStripDetInfoFileReader.h"
00031 
00032 
00033 namespace popcon{
00034   
00035   template <typename T>
00036     class SiStripPopConHandlerUnitTestGain : public popcon::PopConSourceHandler<T>{
00037     public:
00038 
00039     enum DataType { UNDEFINED=0, _Cabling=1, _Pedestal=2, _Noise=3, _Threshold=4, _BadStrip=5, _Gain=6};
00040 
00041     //---------------------------------------
00042     //
00043     SiStripPopConHandlerUnitTestGain(const edm::ParameterSet& pset):
00044       m_name(pset.getUntrackedParameter<std::string>("name","SiStripPopPopConConfigDbObjHandler")),
00045       m_since(pset.getUntrackedParameter<uint32_t>("since",5)),
00046       m_debugMode(pset.getUntrackedParameter<bool>("debug",true)){}; 
00047 
00048     //---------------------------------------
00049     //
00050     ~SiStripPopConHandlerUnitTestGain(){}; 
00051 
00052     //---------------------------------------
00053     //
00054     void getNewObjects(){
00055       edm::LogInfo   ("SiStripPopPopConConfigDbObjHandler") << "[getNewObjects] for PopCon application " << m_name;
00056      
00057       if (m_debugMode){
00058         std::stringstream ss;
00059         ss << "\n\n------- " << m_name 
00060            << " - > getNewObjects\n"; 
00061         if (this->tagInfo().size){
00062           //check whats already inside of database
00063           ss << "got offlineInfo"<<
00064             this->tagInfo().name << ", size " << this->tagInfo().size << " " << this->tagInfo().token 
00065              << " , last object valid since " 
00066              << this->tagInfo().lastInterval.first << " token "   
00067              << this->tagInfo().lastPayloadToken << "\n\n UserText " << this->userTextLog() 
00068              << "\n LogDBEntry \n" 
00069              << this->logDBEntry().logId<< "\n"
00070              << this->logDBEntry().destinationDB<< "\n"   
00071              << this->logDBEntry().provenance<< "\n"
00072              << this->logDBEntry().usertext<< "\n"
00073              << this->logDBEntry().iovtag<< "\n"
00074              << this->logDBEntry().iovtimetype<< "\n"
00075              << this->logDBEntry().payloadIdx<< "\n"
00076              << this->logDBEntry().payloadClass<< "\n"
00077              << this->logDBEntry().payloadToken<< "\n"
00078              << this->logDBEntry().exectime<< "\n"
00079              << this->logDBEntry().execmessage<< "\n"
00080              << "\n\n-- user text " << this->logDBEntry().usertext.substr(this->logDBEntry().usertext.find_last_of("@")) ;
00081         } else {
00082           ss << " First object for this tag ";
00083         }
00084         edm::LogInfo   ("SiStripPopPopConConfigDbObjHandler") << ss.str();
00085       }
00086       if (isTransferNeeded())
00087         setForTransfer();
00088   
00089       edm::LogInfo   ("SiStripPopPopConConfigDbObjHandler") << "[getNewObjects] for PopCon application " << m_name << " Done\n--------------\n";
00090     }
00091 
00092 
00093     //---------------------------------------
00094     //
00095     std::string id() const { return m_name;}
00096 
00097     private:
00098     //methods
00099     
00100     DataType getDataType(){
00101       
00102       if(typeid(T)==typeid(SiStripFedCabling)){
00103         edm::LogInfo   ("SiStripPopPopConConfigDbObjHandler") << "[getDataType] for PopCon application " << m_name << " " << typeid(T).name();
00104         return _Cabling;
00105       }
00106       return UNDEFINED;
00107     }
00108     
00109 
00110     
00111     //---------------------------------------
00112     //
00113     bool isTransferNeeded(){
00114 
00115 
00116       edm::LogInfo   ("SiStripPopPopConConfigDbObjHandler") << "[isTransferNeeded] checking for transfer"  << std::endl;
00117       std::stringstream ss_logdb, ss;
00118       std::stringstream ss1; 
00119 
00120       //get log information from previous upload
00121       if (this->tagInfo().size)
00122         ss_logdb << this->logDBEntry().usertext.substr(this->logDBEntry().usertext.find_last_of("@"));
00123       else
00124         ss_logdb << "";
00125 
00126       ss  << "@ " << clock() ;     
00127   
00128       if (!strcmp(ss.str().c_str(),ss_logdb.str().c_str())){
00129         //string are equal, no need to do transfer
00130         edm::LogInfo   ("SiStripPopPopConConfigDbObjHandler") 
00131           << "[isTransferNeeded] the selected conditions are already uploaded in the last iov ("  
00132           << this->tagInfo().lastInterval.first << ") open for the object " 
00133           << this->logDBEntry().payloadClass << " in the db " 
00134           << this->logDBEntry().destinationDB << " parameters: "  << ss.str() << "\n NO TRANSFER NEEDED";
00135         return false;
00136       }
00137       this->m_userTextLog = ss.str();
00138       edm::LogInfo   ("SiStripPopPopConConfigDbObjHandler") 
00139         << "[isTransferNeeded] the selected conditions will be uploaded: " << ss.str() 
00140         << "\n A- "<< ss.str()  << "\n B- " << ss_logdb.str() << "\n Fine";
00141 
00142       return true;
00143     }
00144 
00145 
00146     //---------------------------------------
00147     //
00148     void setForTransfer(){
00149       edm::LogInfo   ("SiStripPopPopConConfigDbObjHandler") << "[setForTransfer] " << m_name << " getting data to be transferred "  << std::endl;
00150       
00151       T *obj=0; 
00152 
00153       fillObject(obj);
00154 
00155       if(!this->tagInfo().size)
00156         m_since=1;
00157       else
00158         if (m_debugMode)
00159           m_since=this->tagInfo().lastInterval.first+1; 
00160 
00161       if (obj!=0){
00162 
00163         edm::LogInfo   ("SiStripPopPopConConfigDbObjHandler") <<"setting since = "<< m_since <<std::endl;
00164         this->m_to_transfer.push_back(std::make_pair(obj,m_since));
00165       }else{
00166         edm::LogError   ("SiStripPopPopConConfigDbObjHandler") <<"[setForTransfer] " << m_name << "  : NULL pointer of obj " << typeid(T).name() << " reported by SiStripCondObjBuilderFromDb\n Transfer aborted"<<std::endl;
00167       }
00168     }
00169 
00170     private: 
00171     // data members
00172     std::string m_name;
00173     unsigned long long m_since;
00174     bool m_debugMode;
00175     edm::Service<SiStripCondObjBuilderFromDb> condObjBuilder;
00176 
00177 
00178     void fillObject(T*& obj){
00179             std::cout << __LINE__ << std::endl;
00180 
00181         if(typeid(T)==typeid(SiStripApvGain)){
00182             std::cout << __LINE__ << std::endl;
00183 
00184           obj = new SiStripApvGain();
00185           
00186           edm::FileInPath fp_("CalibTracker/SiStripCommon/data/SiStripDetInfo.dat");
00187           SiStripDetInfoFileReader reader(fp_.fullPath());
00188           
00189           const std::map<uint32_t, SiStripDetInfoFileReader::DetInfo > DetInfos  = reader.getAllData();
00190           
00191           int count=-1;
00192           for(std::map<uint32_t, SiStripDetInfoFileReader::DetInfo >::const_iterator it = DetInfos.begin(); it != DetInfos.end(); it++){    
00193 
00194           count++;
00195           //Generate Gains for det detid
00196           SiStripApvGain::InputVector inputApvGain;
00197           for(int apv=0; apv<it->second.nApvs; ++apv){
00198             
00199             float MeanTick = 555.;
00200             float RmsTick  = 55.;
00201 
00202       
00203             float tick =  CLHEP::RandGauss::shoot(MeanTick,RmsTick);
00204 
00205           
00206             
00207             if (count<6)
00208               edm::LogInfo("SiStripGainBuilder") << "detid " << it->first << " \t"
00209                                                    << " APV " << apv << " \t"
00210                                                    << tick     << " \t" 
00211                                                    << std::endl;            
00212             inputApvGain.push_back(tick); //APV0
00213             inputApvGain.push_back(tick); //APV1
00214             apv++;
00215           }    
00216           
00217           
00218           SiStripApvGain::Range gain_range( inputApvGain.begin(), inputApvGain.end() );
00219           if ( ! obj->put(it->first,gain_range) )
00220             edm::LogError("SiStripGainBuilder")<<"[SiStripGainBuilder::analyze] detid already exists"<<std::endl;
00221         }
00222 
00223           
00224         }
00225 
00226      
00227     }
00228   };
00229 
00230 }
00231 
00232 
00233 
00234 
00235 #endif //SISTRIPPOPCON_UNITTEST_HANDLER_H