20 #include "CoralBase/TimeStamp.h"
33 #include "TMultiGraph.h"
44 #include <boost/ref.hpp>
45 #include <boost/bind.hpp>
46 #include <boost/function.hpp>
47 #include <boost/shared_ptr.hpp>
48 #include <boost/iterator/transform_iterator.hpp>
52 #include <boost/algorithm/string.hpp>
63 std::vector<RPCObVmon::V_Item>
const & vmon = pl.
ObVmon_rpc;
64 for(
unsigned int i = 0;
i < vmon.size(); ++
i ){
66 result.push_back(vmon[
i].dpid);
69 if(vmon[
i].dpid == which[0])
70 result.push_back(vmon[
i].dpid);
76 std::vector<RPCObVmon::V_Item>
const & vmon = pl.
ObVmon_rpc;
77 for(
unsigned int i = 0;
i < vmon.size(); ++
i ){
79 result.push_back(vmon[
i].
day);
82 if(vmon[
i].dpid == which[0])
83 result.push_back(vmon[
i].
day);
89 std::vector<RPCObVmon::V_Item>
const & vmon = pl.
ObVmon_rpc;
90 for(
unsigned int i = 0;
i < vmon.size(); ++
i ){
92 result.push_back(vmon[
i].
time);
95 if(vmon[
i].dpid == which[0])
96 result.push_back(vmon[
i].
time);
102 std::vector<RPCObVmon::V_Item>
const & vmon = pl.
ObVmon_rpc;
103 for(
unsigned int i = 0;
i < vmon.size(); ++
i ){
105 result.push_back(vmon[
i].
value);
108 if(vmon[
i].dpid == which[0])
109 result.push_back(vmon[
i].
value);
126 std::vector<int>
const &
which()
const {
return m_which;}
128 float const &
endTime()
const {
return m_endtime;}
165 std::vector<float> res;
166 extractor(m_what.how())(it,m_what.which(),res,m_what.startTime(),m_what.endTime());
184 std::vector<int>
const & vInts,
185 std::vector<float>
const & vFloats,
186 std::vector<std::string>
const & vStrings)
const {
188 std::stringstream
ss;
189 std::vector<std::string>::const_iterator iStr;
190 ss <<
"Strings got: " << std::endl;
191 for (iStr = vStrings.begin(); iStr != vStrings.end(); ++ iStr){
192 ss << *iStr << std::endl;
204 std::string conString=
"oracle://cms_orcoff_prod/CMS_COND_31X_RPC";
207 std::string token=
"[DB=00000000-0000-0000-0000-000000000000][CNT=RPCObPVSSmap][CLID=53B2D2D9-1F4E-9CA9-4D71-FFCCA123A454][TECH=00000B01][OID=0000000C-00000000]";
220 dbSes.
open(conString,
true);
226 boost::shared_ptr<RPCObPVSSmap> pvssPtr;
230 std::vector<RPCObPVSSmap::Item> pvssCont=pvssPtr->
ObIDMap_rpc;
232 std::stringstream
ss;
234 std::vector<RPCObVmon::V_Item>
const & vmon =
object().ObVmon_rpc;
236 ss <<
"DetID\t\t"<<
"V(V)\t"<<
"Time\t"<<
"Day\n";
237 for(
unsigned int i = 0;
i < vmon.size(); ++
i ){
238 for(
unsigned int p = 0;
p < pvssCont.size(); ++
p){
239 if(vmon[
i].dpid!=pvssCont[
p].dpid || pvssCont[
p].suptype!=0 || pvssCont[
p].
region!=0)
continue;
243 ss <<chName <<
"\t"<<vmon[
i].value<<
"\t"<<vmon[
i].time<<
"\t"<<vmon[
i].day<<
"\n";
252 Double_t
linearF(Double_t *
x, Double_t *par){
260 int yea_ = (int)date/100;
261 int yea = 2000 + (date - yea_*100);
262 int mon_ = (int)yea_/100;
263 int mon = yea_ - mon_*100;
264 int day = (int)yea_/100;
265 int sec_ = (int)time/100;
266 int sec = time - sec_*100;
267 int min_ = (int)sec_/100;
268 int min = sec_ - min_*100;
269 int hou = (int)sec_/100;
272 TS = coral::TimeStamp(yea, mon, day, hou, min, sec, nan);
274 long long UT = (TS.year()-1970)*31536000+static_cast<int>(
trunc((TS.year()-1972)/4))*86400+
275 (((TS.month()-1)*31)*86400)+((TS.day()-1)*86400)+TS.hour()*3600+TS.minute()*60+TS.second();
277 if (TS.month() == 3) UT = UT - 3*86400;
278 if (TS.month() == 4) UT = UT - 3*86400;
279 if (TS.month() == 5) UT = UT - 4*86400;
280 if (TS.month() == 6) UT = UT - 4*86400;
281 if (TS.month() == 7) UT = UT - 5*86400;
282 if (TS.month() == 8) UT = UT - 5*86400;
283 if (TS.month() == 9) UT = UT - 5*86400;
284 if (TS.month() == 10) UT = UT - 6*86400;
285 if (TS.month() == 11) UT = UT - 6*86400;
286 if (TS.month() == 12) UT = UT - 7*86400;
295 std::vector<int>
const&,
296 std::vector<float>
const& )
const {
303 gStyle->SetPalette(1);
305 TH1D *vDistr=
new TH1D(
"vDistr",
"IOV-averaged HV Distribution;Average HV (V);Entries/0.2 #muA",100,5000.,10000.);
306 TH1D *rmsDistr=
new TH1D(
"rmsDistr",
"RMS over IOV-HV Distribution;HV RMS (V);Entries/0.2 #muA",1000,0.,1000.);
311 std::string conString=
"oracle://cms_orcoff_prod/CMS_COND_31X_RPC";
314 std::string token=
"[DB=00000000-0000-0000-0000-000000000000][CNT=RPCObPVSSmap][CLID=53B2D2D9-1F4E-9CA9-4D71-FFCCA123A454][TECH=00000B01][OID=0000000C-00000000]";
327 dbSes.
open(conString,
true);
333 boost::shared_ptr<RPCObPVSSmap> pvssPtr;
337 std::vector<RPCObPVSSmap::Item> pvssCont=pvssPtr->
ObIDMap_rpc;
340 std::vector<RPCObVmon::V_Item>
const & vmon =
object().ObVmon_rpc;
342 std::map<int,std::pair<std::vector<double>,std::vector<double> > > dpidMap;
343 for(
unsigned int i = 0;
i < vmon.size(); ++
i){
344 for(
unsigned int p = 0;
p < pvssCont.size(); ++
p){
345 if(vmon[
i].dpid!=pvssCont[
p].dpid || pvssCont[
p].suptype!=0 || pvssCont[
p].
region!=0)
continue;
346 if(dpidMap.find(vmon[
i].dpid)==dpidMap.end()){
347 std::vector<double> dumVec1;dumVec1.push_back(vmon[i].
value);
348 std::vector<double> dumVec2;dumVec2.push_back((
double)
toUNIX(vmon[i].day,vmon[i].time));
349 dpidMap[vmon[
i].dpid]=make_pair(dumVec1,dumVec2);
352 dpidMap[vmon[
i].dpid].first.push_back(vmon[i].
value);
353 dpidMap[vmon[
i].dpid].second.push_back((
double)
toUNIX(vmon[i].day,vmon[i].time));
358 double maxMean(-1.),maxRms(-1.);
359 double minMean(9999.),minRms(9999.);
360 std::map<int,std::pair<std::vector<double>,std::vector<double> > >::const_iterator minIt,maxIt;
361 std::vector<float> means,rmss;
362 for(
std::map<
int,std::pair<std::vector<double>,std::vector<double> > >::const_iterator mIt=dpidMap.begin();
363 mIt!=dpidMap.end();mIt++){
364 std::pair<double, std::vector<double> > meanAndVals =
365 make_pair(accumulate(mIt->second.first.begin(),mIt->second.first.end(),0.)/(double)mIt->second.first.size(),mIt->second.first);
367 vDistr->Fill(meanAndVals.first);
368 if(meanAndVals.first>maxMean)maxMean=meanAndVals.first;
369 if(meanAndVals.first<minMean)minMean=meanAndVals.first;
371 for(std::vector<double>::iterator rmsIt=meanAndVals.second.begin();
372 rmsIt!=meanAndVals.second.end();++rmsIt){
373 rms+=
pow((*rmsIt-meanAndVals.first)/(
double)meanAndVals.second.size(),2);
376 if(
sqrt(rms)>maxRms){
380 if(
sqrt(rms)<minRms){
382 if(mIt->second.first.size()>5)
385 means.push_back(meanAndVals.first);
386 rmss.push_back(
sqrt(rms));
390 vDistr->GetXaxis()->SetRangeUser(minMean-0.00001,maxMean+1.);
392 rmsDistr->GetXaxis()->SetRangeUser(minRms-0.00001,maxRms+1.);
394 TCanvas
c(
"Vmon",
"Vmon",1200,700);
400 vDistr->SetFillColor(4);
401 vDistr->SetLineColor(4);
407 rmsDistr->SetFillColor(3);
408 rmsDistr->SetLineColor(3);
412 TGraph *vRmsDistr=
new TGraph(means.size(),
static_cast<const float *
>(&rmss[0]),static_cast<const float *>(&means[0]));
413 vRmsDistr->SetMarkerStyle(7);
414 vRmsDistr->SetMarkerColor(2);
417 vRmsDistr->GetXaxis()->SetTitle(
"HV RMS (V)");
418 vRmsDistr->GetYaxis()->SetTitle(
"HV Means (V)");
419 vRmsDistr->Draw(
"AP");
422 TMultiGraph *mProf=
new TMultiGraph();
423 TLegend *
leg=
new TLegend(0.65,0.91,0.99,0.99);
424 TGraph *minProf=
new TGraph(minIt->second.first.size(),&minIt->second.second[0],&minIt->second.first[0]);
425 TGraph *maxProf=
new TGraph(maxIt->second.first.size(),&maxIt->second.second[0],&maxIt->second.first[0]);
426 minProf->SetMarkerStyle(20);
427 maxProf->SetMarkerStyle(20);
428 minProf->SetMarkerColor(2);
429 maxProf->SetMarkerColor(4);
431 leg->AddEntry(minProf,
"V vs IOV for Min RMS case",
"lpf");
433 leg->AddEntry(maxProf,
"V vs IOV for Max RMS case",
"lpf");
436 mProf->GetXaxis()->SetTitle(
"IOV");
437 mProf->GetYaxis()->SetTitle(
"I (V)");
439 c.SaveAs(filename.c_str());
441 return filename.c_str();
449 std::vector<int>
const& nts,
450 std::vector<float>
const& floats,
451 std::vector<std::string>
const& strings)
const {
453 std::stringstream
ss(
"");
456 return (
"Error!Not enough data for initializing connection for making plots!(from template<> std::string PayLoadInspector<BeamSpotObjects>::trend_plot)");
458 std::vector<std::string>::const_iterator strIt=strings.begin();
476 dbSes.
open(conString,
true);
481 std::string pvssToken=
"[DB=00000000-0000-0000-0000-000000000000][CNT=RPCObPVSSmap][CLID=53B2D2D9-1F4E-9CA9-4D71-FFCCA123A454][TECH=00000B01][OID=0000000C-00000000]";
483 boost::shared_ptr<RPCObVmon> vmonPtr;
484 boost::shared_ptr<RPCObPVSSmap> pvssPtr;
488 std::vector<RPCObPVSSmap::Item> pvssCont=pvssPtr->
ObIDMap_rpc,pvssZero;
490 for(
unsigned int p=0;
p<pvssCont.size();
p++){
491 if(pvssCont[
p].suptype!=0)
492 pvssZero.push_back(pvssCont[
p]);
496 std::vector<float> vecI;vecI.assign(floats.size(),0.);
499 for(;strIt!=strings.end();++strIt){
503 std::vector<RPCObVmon::V_Item>
const & vmon = vmonPtr->
ObVmon_rpc;
506 for(
unsigned int i=0;
i<vmon.size();
i++){
507 for(
unsigned int p=0;
p<pvssZero.size();
p++){
508 if(vmon[
i].dpid!=pvssZero[
p].dpid || pvssZero[
p].
region!=0)
continue;
522 TGraph trend(vecI.size(),
static_cast<const float *
>(&floats[0]),static_cast<const float *>(&vecI[0]));
523 trend.SetLineColor(2);
524 trend.SetLineWidth(2);
525 trend.GetYaxis()->SetTitle(
"<V> (V)");
527 float min(*(floats.begin())),
max(*(floats.end()-1));
528 float scaleToggle((max-min)/max);
529 TCanvas
c(
"Itrend",
"Itrend",1200,700);
536 TLegend
leg(0.65,0.91,0.99,0.99);
537 leg.AddEntry(&trend,
"Vmon trend",
"lpf");
543 c.SaveAs((ss.str()).c_str());
552 namespace condPython {
555 using namespace boost::python;
556 enum_<cond::rpcobvmon::How>(
"How")
564 class_<What>(
"What",init<>())
565 .def(
"set_how",&What::set_how)
566 .def(
"set_which",&What::set_which)
567 .def(
"how",&What::how, return_value_policy<copy_const_reference>())
568 .def(
"which",&What::which, return_value_policy<copy_const_reference>())
569 .def(
"set_starttime",&What::set_starttime)
570 .def(
"set_endtime",&What::set_endtime)
571 .def(
"startTime",&
What::startTime, return_value_policy<copy_const_reference>())
572 .def(
"endTime",&What::endTime, return_value_policy<copy_const_reference>())
std::string trend_plot(std::string const &, std::string const &, std::vector< int > const &, std::vector< float > const &, std::vector< std::string > const &) const
std::vector< Item > ObIDMap_rpc
std::string plot(std::string const &, std::string const &, std::vector< int > const &, std::vector< float > const &) const
DbTransaction & transaction()
void open(const std::string &connectionString, bool readOnly=false)
DbConnectionConfiguration & configuration()
#define PYTHON_WRAPPER(_class, _name)
boost::function< void(RPCObVmon const &pl, std::vector< int > const &which, std::vector< float > &result, const float &starttime, const float &endtime)> RPCObVmonExtractor
Double_t linearF(Double_t *x, Double_t *par)
std::string summary() const
int start(bool readOnly=false)
start transaction
void extractDay(RPCObVmon const &pl, std::vector< int > const &which, std::vector< float > &result, const float &starttime, const float &endtime)
virtual std::string name()
std::vector< V_Item > ObVmon_rpc
void extractDetId(RPCObVmon const &pl, std::vector< int > const &which, std::vector< float > &result, const float &starttime, const float &endtime)
void extractTime(RPCObVmon const &pl, std::vector< int > const &which, std::vector< float > &result, const float &starttime, const float &endtime)
std::string summary_adv(std::string const &, std::vector< int > const &, std::vector< float > const &, std::vector< std::string > const &) const
unsigned long long toUNIX(int date, int time)
DbSession createSession() const
void defineWhat< RPCObVmon >()
void setAuthenticationPath(const std::string &p)
void extractCurrent(RPCObVmon const &pl, std::vector< int > const &which, std::vector< float > &result, const float &starttime, const float &endtime)
boost::shared_ptr< T > getTypedObject(const std::string &objectId)
Power< A, B >::type pow(const A &a, const B &b)