CMS 3D CMS Logo

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