CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/OnlineDB/SiStripO2O/plugins/SiStripPopConHandlerUnitTestNoise.h

Go to the documentation of this file.
00001 #ifndef SISTRIPPOPCON_UNITTEST_HANDLER_NOISE_H
00002 #define SISTRIPPOPCON_UNITTEST_HANDLER_NOISE_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 SiStripPopConHandlerUnitTestNoise : 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     SiStripPopConHandlerUnitTestNoise(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",false)){}; 
00047 
00048     //---------------------------------------
00049     //
00050     ~SiStripPopConHandlerUnitTestNoise(){}; 
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 
00180      
00181       if(typeid(T)==typeid(SiStripNoises)){
00182 
00183 
00184         obj = new SiStripNoises();
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           count++;
00194           //Generate Noise for det detid
00195           SiStripNoises::InputVector theSiStripVector;
00196           for(int strip=0; strip<128*it->second.nApvs; ++strip){
00197             
00198             float MeanNoise = 5;
00199             float RmsNoise  = 1;
00200 
00201             float noise =  CLHEP::RandGauss::shoot(MeanNoise,RmsNoise);
00202                   
00203             //double badStripProb = .5;
00204             //bool disable = (CLHEP::RandFlat::shoot(1.) < badStripProb ? true:false);
00205           
00206             obj->setData(noise,theSiStripVector);
00207             if (count<6)
00208               edm::LogInfo("SiStripNoisesBuilder") << "detid " << it->first << " \t"
00209                                                    << " strip " << strip << " \t"
00210                                                    << noise     << " \t" 
00211                                                    << theSiStripVector.back()/10 << " \t" 
00212                                                    << std::endl;            
00213           }    
00214       
00215           if ( ! obj->put(it->first,theSiStripVector) )
00216             edm::LogError("SiStripNoisesBuilder")<<"[SiStripNoisesBuilder::analyze] detid already exists"<<std::endl;
00217         }
00218       }
00219     }
00220   };
00221 
00222 }
00223 
00224 
00225 
00226 
00227 #endif //SISTRIPPOPCON_UNITTEST_HANDLER_H