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
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
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
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
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
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 std::cout << __LINE__ << std::endl;
00181
00182 if(typeid(T)==typeid(SiStripApvGain)){
00183 std::cout << __LINE__ << std::endl;
00184
00185 obj = new SiStripApvGain();
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
00195 count++;
00196
00197 SiStripApvGain::InputVector inputApvGain;
00198 for(int apv=0; apv<it->second.nApvs; ++apv){
00199
00200 float MeanTick = 555.;
00201 float RmsTick = 55.;
00202
00203
00204 float tick = CLHEP::RandGauss::shoot(MeanTick,RmsTick);
00205
00206
00207
00208 if (count<6)
00209 edm::LogInfo("SiStripGainBuilder") << "detid " << it->first << " \t"
00210 << " APV " << apv << " \t"
00211 << tick << " \t"
00212 << std::endl;
00213 inputApvGain.push_back(tick);
00214 inputApvGain.push_back(tick);
00215 apv++;
00216 }
00217
00218
00219 SiStripApvGain::Range gain_range( inputApvGain.begin(), inputApvGain.end() );
00220 if ( ! obj->put(it->first,gain_range) )
00221 edm::LogError("SiStripGainBuilder")<<"[SiStripGainBuilder::analyze] detid already exists"<<std::endl;
00222 }
00223
00224
00225 }
00226
00227
00228 }
00229 };
00230
00231 }
00232
00233
00234
00235
00236 #endif //SISTRIPPOPCON_UNITTEST_HANDLER_H