CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/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().payloadName<< "\n"
00077              << this->logDBEntry().payloadToken<< "\n"
00078              << this->logDBEntry().payloadContainer<< "\n"
00079              << this->logDBEntry().exectime<< "\n"
00080              << this->logDBEntry().execmessage<< "\n"
00081              << "\n\n-- user text " << this->logDBEntry().usertext.substr(this->logDBEntry().usertext.find_last_of("@")) ;
00082         } else {
00083           ss << " First object for this tag ";
00084         }
00085         edm::LogInfo   ("SiStripPopPopConConfigDbObjHandler") << ss.str();
00086       }
00087       if (isTransferNeeded())
00088         setForTransfer();
00089   
00090       edm::LogInfo   ("SiStripPopPopConConfigDbObjHandler") << "[getNewObjects] for PopCon application " << m_name << " Done\n--------------\n";
00091     }
00092 
00093 
00094     //---------------------------------------
00095     //
00096     std::string id() const { return m_name;}
00097 
00098     private:
00099     //methods
00100     
00101     DataType getDataType(){
00102       
00103       if(typeid(T)==typeid(SiStripFedCabling)){
00104         edm::LogInfo   ("SiStripPopPopConConfigDbObjHandler") << "[getDataType] for PopCon application " << m_name << " " << typeid(T).name();
00105         return _Cabling;
00106       }
00107       return UNDEFINED;
00108     }
00109     
00110 
00111     
00112     //---------------------------------------
00113     //
00114     bool isTransferNeeded(){
00115 
00116 
00117       edm::LogInfo   ("SiStripPopPopConConfigDbObjHandler") << "[isTransferNeeded] checking for transfer"  << std::endl;
00118       std::stringstream ss_logdb, ss;
00119       std::stringstream ss1; 
00120 
00121       //get log information from previous upload
00122       if (this->tagInfo().size)
00123         ss_logdb << this->logDBEntry().usertext.substr(this->logDBEntry().usertext.find_last_of("@"));
00124       else
00125         ss_logdb << "";
00126 
00127       ss  << "@ " << clock() ;     
00128   
00129       if (!strcmp(ss.str().c_str(),ss_logdb.str().c_str())){
00130         //string are equal, no need to do transfer
00131         edm::LogInfo   ("SiStripPopPopConConfigDbObjHandler") 
00132           << "[isTransferNeeded] the selected conditions are already uploaded in the last iov ("  
00133           << this->tagInfo().lastInterval.first << ") open for the object " 
00134           << this->logDBEntry().payloadName << " in the db " 
00135           << this->logDBEntry().destinationDB << " parameters: "  << ss.str() << "\n NO TRANSFER NEEDED";
00136         return false;
00137       }
00138       this->m_userTextLog = ss.str();
00139       edm::LogInfo   ("SiStripPopPopConConfigDbObjHandler") 
00140         << "[isTransferNeeded] the selected conditions will be uploaded: " << ss.str() 
00141         << "\n A- "<< ss.str()  << "\n B- " << ss_logdb.str() << "\n Fine";
00142 
00143       return true;
00144     }
00145 
00146 
00147     //---------------------------------------
00148     //
00149     void setForTransfer(){
00150       edm::LogInfo   ("SiStripPopPopConConfigDbObjHandler") << "[setForTransfer] " << m_name << " getting data to be transferred "  << std::endl;
00151       
00152       T *obj=0; 
00153 
00154       fillObject(obj);
00155 
00156       if(!this->tagInfo().size)
00157         m_since=1;
00158       else
00159         if (m_debugMode)
00160           m_since=this->tagInfo().lastInterval.first+1; 
00161 
00162       if (obj!=0){
00163 
00164         edm::LogInfo   ("SiStripPopPopConConfigDbObjHandler") <<"setting since = "<< m_since <<std::endl;
00165         this->m_to_transfer.push_back(std::make_pair(obj,m_since));
00166       }else{
00167         edm::LogError   ("SiStripPopPopConConfigDbObjHandler") <<"[setForTransfer] " << m_name << "  : NULL pointer of obj " << typeid(T).name() << " reported by SiStripCondObjBuilderFromDb\n Transfer aborted"<<std::endl;
00168       }
00169     }
00170 
00171     private: 
00172     // data members
00173     std::string m_name;
00174     unsigned long long m_since;
00175     bool m_debugMode;
00176     edm::Service<SiStripCondObjBuilderFromDb> condObjBuilder;
00177 
00178 
00179     void fillObject(T*& obj){
00180 
00181      
00182       if(typeid(T)==typeid(SiStripNoises)){
00183 
00184 
00185         obj = new SiStripNoises();
00186 
00187         edm::FileInPath fp_("CalibTracker/SiStripCommon/data/SiStripDetInfo.dat");
00188         SiStripDetInfoFileReader reader(fp_.fullPath());
00189         
00190         const std::map<uint32_t, SiStripDetInfoFileReader::DetInfo > DetInfos  = reader.getAllData();
00191         
00192         int count=-1;
00193         for(std::map<uint32_t, SiStripDetInfoFileReader::DetInfo >::const_iterator it = DetInfos.begin(); it != DetInfos.end(); it++){    
00194           count++;
00195           //Generate Noise for det detid
00196           SiStripNoises::InputVector theSiStripVector;
00197           for(int strip=0; strip<128*it->second.nApvs; ++strip){
00198             
00199             float MeanNoise = 5;
00200             float RmsNoise  = 1;
00201 
00202             float noise =  CLHEP::RandGauss::shoot(MeanNoise,RmsNoise);
00203                   
00204             //double badStripProb = .5;
00205             //bool disable = (CLHEP::RandFlat::shoot(1.) < badStripProb ? true:false);
00206           
00207             obj->setData(noise,theSiStripVector);
00208             if (count<6)
00209               edm::LogInfo("SiStripNoisesBuilder") << "detid " << it->first << " \t"
00210                                                    << " strip " << strip << " \t"
00211                                                    << noise     << " \t" 
00212                                                    << theSiStripVector.back()/10 << " \t" 
00213                                                    << std::endl;            
00214           }    
00215       
00216           if ( ! obj->put(it->first,theSiStripVector) )
00217             edm::LogError("SiStripNoisesBuilder")<<"[SiStripNoisesBuilder::analyze] detid already exists"<<std::endl;
00218         }
00219       }
00220     }
00221   };
00222 
00223 }
00224 
00225 
00226 
00227 
00228 #endif //SISTRIPPOPCON_UNITTEST_HANDLER_H