CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SiStripPopConHandlerUnitTestGain.h
Go to the documentation of this file.
1 #ifndef SISTRIPPOPCON_UNITTEST_HANDLER_GAIN_H
2 #define SISTRIPPOPCON_UNITTEST_HANDLER_GAIN_H
3 
9 
13 
17 
18 #include <sstream>
19 #include <vector>
20 #include <string>
21 #include <iostream>
22 #include <typeinfo>
23 #include <time.h>
24 
25 #include "CLHEP/Random/RandFlat.h"
26 #include "CLHEP/Random/RandGauss.h"
27 
31 
32 
33 namespace popcon{
34 
35  template <typename T>
37  public:
38 
40 
41  //---------------------------------------
42  //
44  m_name(pset.getUntrackedParameter<std::string>("name","SiStripPopPopConConfigDbObjHandler")),
45  m_since(pset.getUntrackedParameter<uint32_t>("since",5)),
46  m_debugMode(pset.getUntrackedParameter<bool>("debug",true)){};
47 
48  //---------------------------------------
49  //
51 
52  //---------------------------------------
53  //
54  void getNewObjects(){
55  edm::LogInfo ("SiStripPopPopConConfigDbObjHandler") << "[getNewObjects] for PopCon application " << m_name;
56 
57  if (m_debugMode){
58  std::stringstream ss;
59  ss << "\n\n------- " << m_name
60  << " - > getNewObjects\n";
61  if (this->tagInfo().size){
62  //check whats already inside of database
63  ss << "got offlineInfo"<<
64  this->tagInfo().name << ", size " << this->tagInfo().size << " " << this->tagInfo().token
65  << " , last object valid since "
66  << this->tagInfo().lastInterval.first << " token "
67  << this->tagInfo().lastPayloadToken << "\n\n UserText " << this->userTextLog()
68  << "\n LogDBEntry \n"
69  << this->logDBEntry().logId<< "\n"
70  << this->logDBEntry().destinationDB<< "\n"
71  << this->logDBEntry().provenance<< "\n"
72  << this->logDBEntry().usertext<< "\n"
73  << this->logDBEntry().iovtag<< "\n"
74  << this->logDBEntry().iovtimetype<< "\n"
75  << this->logDBEntry().payloadIdx<< "\n"
76  << this->logDBEntry().payloadClass<< "\n"
77  << this->logDBEntry().payloadToken<< "\n"
78  << this->logDBEntry().exectime<< "\n"
79  << this->logDBEntry().execmessage<< "\n"
80  << "\n\n-- user text " << this->logDBEntry().usertext.substr(this->logDBEntry().usertext.find_last_of("@")) ;
81  } else {
82  ss << " First object for this tag ";
83  }
84  edm::LogInfo ("SiStripPopPopConConfigDbObjHandler") << ss.str();
85  }
86  if (isTransferNeeded())
88 
89  edm::LogInfo ("SiStripPopPopConConfigDbObjHandler") << "[getNewObjects] for PopCon application " << m_name << " Done\n--------------\n";
90  }
91 
92 
93  //---------------------------------------
94  //
95  std::string id() const { return m_name;}
96 
97  private:
98  //methods
99 
101 
102  if(typeid(T)==typeid(SiStripFedCabling)){
103  edm::LogInfo ("SiStripPopPopConConfigDbObjHandler") << "[getDataType] for PopCon application " << m_name << " " << typeid(T).name();
104  return _Cabling;
105  }
106  return UNDEFINED;
107  }
108 
109 
110 
111  //---------------------------------------
112  //
114 
115 
116  edm::LogInfo ("SiStripPopPopConConfigDbObjHandler") << "[isTransferNeeded] checking for transfer" << std::endl;
117  std::stringstream ss_logdb, ss;
118  std::stringstream ss1;
119 
120  //get log information from previous upload
121  if (this->tagInfo().size)
122  ss_logdb << this->logDBEntry().usertext.substr(this->logDBEntry().usertext.find_last_of("@"));
123  else
124  ss_logdb << "";
125 
126  ss << "@ " << clock() ;
127 
128  if (!strcmp(ss.str().c_str(),ss_logdb.str().c_str())){
129  //string are equal, no need to do transfer
130  edm::LogInfo ("SiStripPopPopConConfigDbObjHandler")
131  << "[isTransferNeeded] the selected conditions are already uploaded in the last iov ("
132  << this->tagInfo().lastInterval.first << ") open for the object "
133  << this->logDBEntry().payloadClass << " in the db "
134  << this->logDBEntry().destinationDB << " parameters: " << ss.str() << "\n NO TRANSFER NEEDED";
135  return false;
136  }
137  this->m_userTextLog = ss.str();
138  edm::LogInfo ("SiStripPopPopConConfigDbObjHandler")
139  << "[isTransferNeeded] the selected conditions will be uploaded: " << ss.str()
140  << "\n A- "<< ss.str() << "\n B- " << ss_logdb.str() << "\n Fine";
141 
142  return true;
143  }
144 
145 
146  //---------------------------------------
147  //
149  edm::LogInfo ("SiStripPopPopConConfigDbObjHandler") << "[setForTransfer] " << m_name << " getting data to be transferred " << std::endl;
150 
151  T *obj=0;
152 
153  fillObject(obj);
154 
155  if(!this->tagInfo().size)
156  m_since=1;
157  else
158  if (m_debugMode)
159  m_since=this->tagInfo().lastInterval.first+1;
160 
161  if (obj!=0){
162 
163  edm::LogInfo ("SiStripPopPopConConfigDbObjHandler") <<"setting since = "<< m_since <<std::endl;
164  this->m_to_transfer.push_back(std::make_pair(obj,m_since));
165  }else{
166  edm::LogError ("SiStripPopPopConConfigDbObjHandler") <<"[setForTransfer] " << m_name << " : NULL pointer of obj " << typeid(T).name() << " reported by SiStripCondObjBuilderFromDb\n Transfer aborted"<<std::endl;
167  }
168  }
169 
170  private:
171  // data members
173  unsigned long long m_since;
176 
177 
178  void fillObject(T*& obj){
179  std::cout << __LINE__ << std::endl;
180 
181  if(typeid(T)==typeid(SiStripApvGain)){
182  std::cout << __LINE__ << std::endl;
183 
184  obj = new SiStripApvGain();
185 
186  edm::FileInPath fp_("CalibTracker/SiStripCommon/data/SiStripDetInfo.dat");
188 
189  const std::map<uint32_t, SiStripDetInfoFileReader::DetInfo > DetInfos = reader.getAllData();
190 
191  int count=-1;
192  for(std::map<uint32_t, SiStripDetInfoFileReader::DetInfo >::const_iterator it = DetInfos.begin(); it != DetInfos.end(); it++){
193 
194  count++;
195  //Generate Gains for det detid
196  SiStripApvGain::InputVector inputApvGain;
197  for(int apv=0; apv<it->second.nApvs; ++apv){
198 
199  float MeanTick = 555.;
200  float RmsTick = 55.;
201 
202 
203  float tick = CLHEP::RandGauss::shoot(MeanTick,RmsTick);
204 
205 
206 
207  if (count<6)
208  edm::LogInfo("SiStripGainBuilder") << "detid " << it->first << " \t"
209  << " APV " << apv << " \t"
210  << tick << " \t"
211  << std::endl;
212  inputApvGain.push_back(tick); //APV0
213  inputApvGain.push_back(tick); //APV1
214  apv++;
215  }
216 
217 
218  SiStripApvGain::Range gain_range( inputApvGain.begin(), inputApvGain.end() );
219  if ( ! obj->put(it->first,gain_range) )
220  edm::LogError("SiStripGainBuilder")<<"[SiStripGainBuilder::analyze] detid already exists"<<std::endl;
221  }
222 
223 
224  }
225 
226 
227  }
228  };
229 
230 }
231 
232 
233 
234 
235 #endif //SISTRIPPOPCON_UNITTEST_HANDLER_H
edm::Service< SiStripCondObjBuilderFromDb > condObjBuilder
std::string const & userTextLog() const
unsigned long long logId
Definition: Types.h:87
std::string provenance
Definition: Types.h:89
std::string payloadToken
Definition: Types.h:96
size_t size
Definition: Types.h:72
std::string execmessage
Definition: Types.h:98
std::string name
Definition: Types.h:68
cond::ValidityInterval lastInterval
Definition: Types.h:70
std::string payloadClass
Definition: Types.h:95
cond::LogDBEntry_t const & logDBEntry() const
std::pair< ContainerIterator, ContainerIterator > Range
SiStripPopConHandlerUnitTestGain(const edm::ParameterSet &pset)
std::string destinationDB
Definition: Types.h:88
std::string exectime
Definition: Types.h:97
std::string lastPayloadToken
Definition: Types.h:71
Contains cabling info at the device level, including DetId, APV pair numbers, hardware addresses...
std::vector< float > InputVector
unsigned int payloadIdx
Definition: Types.h:93
std::string usertext
Definition: Types.h:90
tuple cout
Definition: gather_cfg.py:121
std::string fullPath() const
Definition: FileInPath.cc:165
long double T
tuple size
Write out results.
std::string token
Definition: Types.h:69
cond::TagInfo_t const & tagInfo() const
std::string iovtimetype
Definition: Types.h:92
std::string iovtag
Definition: Types.h:91