21 #include "CoralBase/TimeStamp.h"
30 #include "TVirtualPad.h"
34 #include "TMultiGraph.h"
49 #include <boost/ref.hpp>
50 #include <boost/bind.hpp>
51 #include <boost/function.hpp>
52 #include <boost/shared_ptr.hpp>
53 #include <boost/iterator/transform_iterator.hpp>
64 std::vector<RPCObImon::I_Item>
const & imon = pl.
ObImon_rpc;
65 for(
unsigned int i = 0;
i < imon.size(); ++
i ){
67 result.push_back(imon[
i].dpid);
70 if(imon[
i].dpid == which[0])
71 result.push_back(imon[
i].dpid);
77 std::vector<RPCObImon::I_Item>
const & imon = pl.
ObImon_rpc;
78 for(
unsigned int i = 0;
i < imon.size(); ++
i ){
80 result.push_back(imon[
i].
day);
83 if(imon[
i].dpid == which[0])
84 result.push_back(imon[
i].
day);
90 std::vector<RPCObImon::I_Item>
const & imon = pl.
ObImon_rpc;
91 for(
unsigned int i = 0;
i < imon.size(); ++
i ){
93 result.push_back(imon[
i].
time);
96 if(imon[
i].dpid == which[0])
97 result.push_back(imon[
i].
time);
103 std::vector<RPCObImon::I_Item>
const & imon = pl.
ObImon_rpc;
104 for(
unsigned int i = 0;
i < imon.size(); ++
i ){
106 result.push_back(imon[
i].
value);
109 if(imon[
i].dpid == which[0])
110 result.push_back(imon[
i].
value);
127 std::vector<int>
const &
which()
const {
return m_which;}
129 float const &
endTime()
const {
return m_endtime;}
166 std::vector<float> res;
167 extractor(m_what.how())(it,m_what.which(),res,m_what.startTime(),m_what.endTime());
179 std::stringstream ss;
184 std::string conString=
"oracle://cms_orcoff_prod/CMS_COND_31X_RPC";
187 std::string token=
"[DB=00000000-0000-0000-0000-000000000000][CNT=RPCObPVSSmap][CLID=53B2D2D9-1F4E-9CA9-4D71-FFCCA123A454][TECH=00000B01][OID=0000000C-00000000]";
200 dbSes.
open(conString,
true);
207 boost::shared_ptr<RPCObPVSSmap> pvssPtr;
211 std::vector<RPCObPVSSmap::Item> pvssCont=pvssPtr->
ObIDMap_rpc;
214 std::vector<RPCObImon::I_Item>
const & imon =
object().ObImon_rpc;
216 ss<<
"DetID\t\t\tI(uA)\tTime\tDay\n";
217 for(
unsigned int i = 0;
i < imon.size(); ++
i ){
218 for(
unsigned int p = 0;
p < pvssCont.size(); ++
p){
219 if(imon[
i].dpid!=pvssCont[
p].dpid || pvssCont[
p].suptype!=0 || pvssCont[
p].region!=0)
continue;
220 RPCDetId rpcId(pvssCont[
p].region,pvssCont[
p].
ring,pvssCont[
p].
station,pvssCont[
p].sector,pvssCont[
p].layer,pvssCont[
p].subsector,1);
223 ss <<chName <<
"\t"<<imon[
i].value<<
"\t"<<imon[
i].time<<
"\t"<<imon[
i].day<<
"\n";
234 Double_t
linearF(Double_t *
x, Double_t *par){
242 int yea_ = (int)date/100;
243 int yea = 2000 + (date - yea_*100);
244 int mon_ = (int)yea_/100;
245 int mon = yea_ - mon_*100;
246 int day = (int)yea_/100;
247 int sec_ = (int)time/100;
248 int sec = time - sec_*100;
249 int min_ = (int)sec_/100;
250 int min = sec_ - min_*100;
251 int hou = (int)sec_/100;
254 TS = coral::TimeStamp(yea, mon, day, hou, min, sec, nan);
256 long long UT = (TS.year()-1970)*31536000+static_cast<int>(
trunc((TS.year()-1972)/4))*86400+
257 (((TS.month()-1)*31)*86400)+((TS.day()-1)*86400)+TS.hour()*3600+TS.minute()*60+TS.second();
259 if (TS.month() == 3) UT = UT - 3*86400;
260 if (TS.month() == 4) UT = UT - 3*86400;
261 if (TS.month() == 5) UT = UT - 4*86400;
262 if (TS.month() == 6) UT = UT - 4*86400;
263 if (TS.month() == 7) UT = UT - 5*86400;
264 if (TS.month() == 8) UT = UT - 5*86400;
265 if (TS.month() == 9) UT = UT - 5*86400;
266 if (TS.month() == 10) UT = UT - 6*86400;
267 if (TS.month() == 11) UT = UT - 6*86400;
268 if (TS.month() == 12) UT = UT - 7*86400;
277 std::vector<int>
const & vInt,
278 std::vector<float>
const& vFlt)
const {
280 gStyle->SetPalette(1);
282 TH1D *iDistr=
new TH1D(
"iDistr",
"IOV-averaged Current Distribution;Average Current (#muA);Entries/0.2 #muA",500,0.,100.);
283 TH1D *rmsDistr=
new TH1D(
"rmsDistr",
"RMS over IOV-Current Distribution;Current RMS (#muA);Entries/0.2 #muA",5000,0.,1000.);
288 std::string conString=
"oracle://cms_orcoff_prod/CMS_COND_31X_RPC";
291 std::string token=
"[DB=00000000-0000-0000-0000-000000000000][CNT=RPCObPVSSmap][CLID=53B2D2D9-1F4E-9CA9-4D71-FFCCA123A454][TECH=00000B01][OID=0000000C-00000000]";
304 dbSes.
open(conString,
true);
310 boost::shared_ptr<RPCObPVSSmap> pvssPtr;
314 std::vector<RPCObPVSSmap::Item> pvssCont=pvssPtr->
ObIDMap_rpc;
317 std::vector<RPCObImon::I_Item>
const & imon =
object().ObImon_rpc;
321 std::map<int,std::pair<std::vector<double>,std::vector<double> > > dpidMap;
322 for(
unsigned int i = 0;
i < imon.size(); ++
i){
323 for(
unsigned int p = 0;
p < pvssCont.size(); ++
p){
324 if(imon[
i].dpid!=pvssCont[
p].dpid || pvssCont[
p].suptype!=0 || pvssCont[
p].region!=0)
continue;
325 if(dpidMap.find(imon[
i].dpid)==dpidMap.end()){
326 std::vector<double> dumVec1;dumVec1.push_back(imon[i].
value);
327 std::vector<double> dumVec2;dumVec2.push_back((
double)
toUNIX(imon[i].
day,imon[i].
time));
328 dpidMap[imon[
i].dpid]=make_pair(dumVec1,dumVec2);
331 dpidMap[imon[
i].dpid].first.push_back(imon[i].
value);
332 dpidMap[imon[
i].dpid].second.push_back((
double)
toUNIX(imon[i].
day,imon[i].
time));
339 double maxMean(-1.),maxRms(-1.);
340 double minMean(9999.),minRms(9999.);
341 std::map<int,std::pair<std::vector<double>,std::vector<double> > >::const_iterator minIt,maxIt;
342 std::vector<float> means,rmss;
343 for(
std::map<
int,std::pair<std::vector<double>,std::vector<double> > >::const_iterator mIt=dpidMap.begin();
344 mIt!=dpidMap.end();mIt++){
345 std::pair<double, std::vector<double> > meanAndVals =
346 make_pair(accumulate(mIt->second.first.begin(),mIt->second.first.end(),0.)/(double)mIt->second.first.size(),mIt->second.first);
348 iDistr->Fill(meanAndVals.first);
349 if(meanAndVals.first>maxMean)maxMean=meanAndVals.first;
350 if(meanAndVals.first<minMean)minMean=meanAndVals.first;
352 for(std::vector<double>::iterator rmsIt=meanAndVals.second.begin();
353 rmsIt!=meanAndVals.second.end();++rmsIt){
354 rms+=
pow((*rmsIt-meanAndVals.first)/(
double)meanAndVals.second.size(),2);
356 rmsDistr->Fill(
sqrt(rms));
357 if(
sqrt(rms)>maxRms){
361 if(
sqrt(rms)<minRms){
363 if(mIt->second.first.size()>10)
366 means.push_back(meanAndVals.first);
367 rmss.push_back(
sqrt(rms));
371 iDistr->GetXaxis()->SetRangeUser(minMean-0.00001,maxMean+1.);
373 rmsDistr->GetXaxis()->SetRangeUser(minRms-0.00001,maxRms+1.);
375 TCanvas
c(
"Imon",
"Imon",1200,700);
378 TVirtualPad *
p1=c.cd(1);
380 iDistr->SetFillColor(4);
381 iDistr->SetLineColor(4);
385 TVirtualPad *
p2=c.cd(2);
387 rmsDistr->SetFillColor(3);
388 rmsDistr->SetLineColor(3);
392 TGraph *iRmsDistr=
new TGraph(means.size(),
static_cast<const float *
>(&rmss[0]),static_cast<const float *>(&means[0]));
393 iRmsDistr->SetMarkerStyle(7);
394 iRmsDistr->SetMarkerColor(2);
395 TF1 *
func=
new TF1(
"linearF",
linearF,minRms,maxRms,1);
396 iRmsDistr->Fit(func,
"r");
397 iRmsDistr->GetXaxis()->SetTitle(
"Current RMS (#muA)");
398 iRmsDistr->GetYaxis()->SetTitle(
"Current Means (#muA)");
399 iRmsDistr->Draw(
"AP");
402 TVirtualPad *
p4=c.cd(4);
404 TMultiGraph *mProf=
new TMultiGraph();
405 TLegend *
leg=
new TLegend(0.65,0.91,0.99,0.99);
406 TGraph *minProf=
new TGraph(minIt->second.first.size(),&minIt->second.second[0],&minIt->second.first[0]);
407 TGraph *maxProf=
new TGraph(maxIt->second.first.size(),&maxIt->second.second[0],&maxIt->second.first[0]);
408 minProf->SetMarkerStyle(20);
409 maxProf->SetMarkerStyle(20);
410 minProf->SetMarkerColor(2);
411 maxProf->SetMarkerColor(4);
413 leg->AddEntry(minProf,
"I vs IOV for Min RMS case",
"lpf");
415 leg->AddEntry(maxProf,
"I vs IOV for Max RMS case",
"lpf");
418 mProf->GetXaxis()->SetTitle(
"IOV");
419 mProf->GetYaxis()->SetTitle(
"I (#muA)");
421 c.SaveAs(filename.c_str());
423 return filename.c_str();
430 std::vector<int>
const& nts,
431 std::vector<float>
const& floats,
432 std::vector<std::string>
const& strings)
const {
434 std::stringstream ss(
"");
437 return (
"Error!Not enough data for initializing connection for making plots!(from template<> std::string PayLoadInspector<BeamSpotObjects>::trend_plot)");
439 std::vector<std::string>::const_iterator strIt=strings.begin();
457 dbSes.
open(conString,
true);
462 std::string pvssToken=
"[DB=00000000-0000-0000-0000-000000000000][CNT=RPCObPVSSmap][CLID=53B2D2D9-1F4E-9CA9-4D71-FFCCA123A454][TECH=00000B01][OID=0000000C-00000000]";
464 boost::shared_ptr<RPCObImon> imonPtr;
465 boost::shared_ptr<RPCObPVSSmap> pvssPtr;
469 std::vector<RPCObPVSSmap::Item> pvssCont=pvssPtr->
ObIDMap_rpc,pvssZero;
471 for(
unsigned int p=0;
p<pvssCont.size();
p++){
472 if(pvssCont[
p].suptype!=0)
473 pvssZero.push_back(pvssCont[
p]);
477 std::vector<float> vecI;vecI.assign(floats.size(),0.);
480 for(;strIt!=strings.end();++strIt){
484 std::vector<RPCObImon::I_Item>
const & imon = imonPtr->
ObImon_rpc;
487 for(
unsigned int i=0;
i<imon.size();
i++){
488 for(
unsigned int p=0;
p<pvssZero.size();
p++){
489 if(imon[
i].dpid!=pvssZero[
p].dpid || pvssZero[
p].region!=0)
continue;
503 std::vector<unsigned long long> lngs ;
504 for(std::vector<float>::const_iterator fIt=floats.begin();fIt!=floats.end();fIt++){
505 lngs.push_back((
unsigned long long)*fIt);
508 std::vector<unsigned long long>
const longs=lngs;
511 std::cout<<(int)longs[longs.size()-1]-longs[0]<<std::endl;
512 TH1F trend(
"trend",
"trend",(
int)longs[longs.size()-1]-longs[0],longs[0],longs[longs.size()-1]);
514 trend.GetXaxis()->SetTimeDisplay(1);
515 trend.GetXaxis()->SetTimeFormat(
"%d/%m/%y %H:%M");
516 trend.SetLineColor(2);
517 trend.SetLineWidth(2);
518 trend.GetYaxis()->SetTitle(
"<I> (#muA)");
520 std::cout<<
"Bins "<<trend.GetNbinsX()<<std::endl;
522 trend.SetBinContent(longs[
fill]-longs[0],vecI[
fill]);
526 float min(*(floats.begin())),
max(*(floats.end()-1));
527 float scaleToggle((max-
min)/max);
528 TCanvas
c(
"Itrend",
"Itrend",1200,700);
535 TLegend
leg(0.65,0.91,0.99,0.99);
536 leg.AddEntry(&trend,
"Imon trend",
"lpf");
542 c.SaveAs((ss.str()).c_str());
551 namespace condPython {
554 using namespace boost::python;
555 enum_<cond::rpcobimon::How>(
"How")
563 class_<What>(
"What",init<>())
564 .def(
"set_how",&What::set_how)
565 .def(
"set_which",&What::set_which)
566 .def(
"how",&What::how, return_value_policy<copy_const_reference>())
567 .def(
"which",&What::which, return_value_policy<copy_const_reference>())
568 .def(
"set_starttime",&What::set_starttime)
569 .def(
"set_endtime",&What::set_endtime)
570 .def(
"startTime",&What::startTime, return_value_policy<copy_const_reference>())
571 .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)
void defineWhat< RPCObImon >()
Double_t linearF(Double_t *x, Double_t *par)
std::string summary() const
int start(bool readOnly=false)
start transaction
virtual std::string name()
const T & max(const T &a, const T &b)
void extractDay(RPCObImon const &pl, std::vector< int > const &which, std::vector< float > &result, const float &starttime, const float &endtime)
void extractTime(RPCObImon const &pl, std::vector< int > const &which, std::vector< float > &result, const float &starttime, const float &endtime)
unsigned long long toUNIX(int date, int time)
DbSession createSession() const
boost::function< void(RPCObImon const &pl, std::vector< int > const &which, std::vector< float > &result, const float &starttime, const float &endtime)> RPCObImonExtractor
std::vector< I_Item > ObImon_rpc
void setAuthenticationPath(const std::string &p)
void extractCurrent(RPCObImon 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)
void extractDetId(RPCObImon const &pl, std::vector< int > const &which, std::vector< float > &result, const float &starttime, const float &endtime)