20 #include <TDirectory.h>
23 #include <TSeqCollection.h>
26 #include <TCollection.h>
54 while ((obj = next()))
57 if (obj->InheritsFrom(
"TPad"))
59 static_cast<TPad*
>(obj)->Modified();
60 static_cast<TPad*
>(obj)->Update();
91 if (obj->InheritsFrom(
"TH1"))
93 if (find(_allkeys.begin(),_allkeys.end(),obj->GetName()) == _allkeys.end())
95 if (
string(obj->GetName()) ==
string(obj->GetTitle()))
97 cout<<
"deleteObsoleteHistogram(): delete '"<< obj->GetName()<<
"' it is not on the casshistogram list"<<endl;
122 while ((obj = next()))
125 if (obj->InheritsFrom(
"TPad"))
128 else if(obj->InheritsFrom(
"TH1"))
130 updateList.push_back(obj->GetName());
149 list<string> updateList;
150 for (list<string>::const_iterator it(allkeys.begin()); it!=allkeys.end(); ++ it)
151 if (!gDirectory->FindObjectAny((*it).c_str()))
152 updateList.push_back((*it));
192 :_file(TFile::Open(filename.c_str(),
"RECREATE"))
213 if (obj->InheritsFrom(
"TH1"))
215 cout<<
"writeObject(): writing '"<< obj->GetName()<<
"' to '"<<_file->GetName()<<
"'"<<endl;
217 obj->Write(0,TObject::kOverwrite);
235 return (static_cast<int>(ca.
nBins) == ra.GetNbins() &&
236 fabs(ca.
low - ra.GetXmin()) < sqrt(numeric_limits<double>::epsilon()) &&
237 fabs(ca.
up - ra.GetXmax()) < sqrt(numeric_limits<double>::epsilon()) &&
238 ca.
title == ra.GetTitle());
292 void operator() (
const string& key)
const
294 using namespace cass;
300 TH1 * roothist(dynamic_cast<TH1*>(gDirectory->FindObjectAny(key.c_str())));
301 switch (result->
dim())
309 cout <<
"updateHist(): '"<<key<<
"' create roothist with X("<<xaxis.title<<
") '"<<xaxis.nBins<<
" "<<xaxis.low<<
" "<<xaxis.up<<
"' "
310 "Y("<<yaxis.title<<
") '"<<yaxis.nBins<<
" "<<yaxis.low<<
" "<<yaxis.up<<
"'"<<endl;
311 roothist =
new TH2F(key.c_str(),key.c_str(),
312 xaxis.nBins, xaxis.low, xaxis.up,
313 yaxis.nBins, yaxis.low, yaxis.up);
314 roothist->SetOption(
"colz");
316 const TAxis &rxaxis(*roothist->GetXaxis());
317 const TAxis &ryaxis(*roothist->GetYaxis());
318 if(xaxis != rxaxis || yaxis != ryaxis)
320 cout <<
"updateHist(): '"<<key<<
"' resize because axis differs: roothist: "<<xaxis.nBins<<
"<->"<<rxaxis.GetNbins()<<
" "<<xaxis.low<<
"<->"<<rxaxis.GetXmin()<<
" "<<xaxis.up<<
"<->"<<rxaxis.GetXmax()<<
" "
321 <<yaxis.nBins<<
"<->"<<ryaxis.GetNbins()<<
" "<<yaxis.low<<
"<->"<<ryaxis.GetXmin()<<
" "<<yaxis.up<<
"<->"<<ryaxis.GetXmax()<<endl;
322 roothist->SetBins(xaxis.nBins, xaxis.low, xaxis.up,
323 yaxis.nBins, yaxis.low, yaxis.up);
324 roothist->SetXTitle(xaxis.title.c_str());
325 roothist->GetXaxis()->CenterTitle(
true);
326 roothist->SetYTitle(yaxis.title.c_str());
327 roothist->GetYaxis()->CenterTitle(
true);
328 roothist->GetYaxis()->SetTitleOffset(1.5);
331 for (
size_t iY(0); iY<yaxis.nBins;++iY)
332 for (
size_t iX(0); iX<xaxis.nBins;++iX)
334 const double histvalue((*result)[iX + iY*xaxis.nBins]);
335 const float value = (std::tr1::isnan(histvalue)) ?
336 0. : (*result)[iX + iY*xaxis.nBins];
337 roothist->SetBinContent(roothist->GetBin(iX+1,iY+1),
value);
340 size_t OverUnderFlowStart (xaxis.nBins*yaxis.nBins);
343 roothist->SetBinContent(roothist->GetBin(xaxis.nBins+1,yaxis.nBins+1),(*result)[OverUnderFlowStart+
Result<float>::UpperRight]);
347 roothist->SetBinContent(roothist->GetBin(xaxis.nBins+1,1),(*result)[OverUnderFlowStart+
Result<float>::Right]);
348 roothist->SetBinContent(roothist->GetBin(0,1),(*result)[OverUnderFlowStart+
Result<float>::Left]);
358 cout <<
"updateHist(): '"<<key<<
"' create roothist with X("<<xaxis.title<<
"):'"<<xaxis.nBins<<
" "<<xaxis.low<<
" "<<xaxis.up<<
"'"<<endl;
359 roothist =
new TH1F(key.c_str(),key.c_str(),
360 xaxis.nBins, xaxis.low, xaxis.up);
361 roothist->GetXaxis()->CenterTitle(
true);
363 const TAxis &rxaxis(*roothist->GetXaxis());
366 cout <<
"updateHist(): '"<<key<<
"' resize because axis differs: roothist: "<<xaxis.nBins<<
"<->"<<rxaxis.GetNbins()<<
" "<<xaxis.low<<
"<->"<<rxaxis.GetXmin()<<
" "<<xaxis.up<<
"<->"<<rxaxis.GetXmax()<<endl;
367 roothist->SetBins(xaxis.nBins, xaxis.low, xaxis.up);
368 roothist->SetXTitle(xaxis.title.c_str());
371 for (
size_t iX(0); iX<xaxis.nBins;++iX)
373 const double histvalue((*result)[iX]);
374 const float value = (std::tr1::isnan(histvalue)) ? 0. : (*result)[iX];
375 roothist->SetBinContent(roothist->GetBin(iX+1),
value);
378 size_t OverUnderFlowStart (xaxis.nBins);
380 roothist->SetBinContent(roothist->GetBin(xaxis.nBins+1),(*result)[OverUnderFlowStart+
Result<float>::Overflow]);
389 cout <<
"updateHist(): '"<<key<<
"' create roothist with for 0D histogram"<<endl;
390 roothist =
new TH1F(key.c_str(),key.c_str(),1,0,1);
392 const double histvalue(result->
getValue());
393 const float value = (std::tr1::isnan(histvalue)) ? 0. : histvalue;
394 roothist->SetBinContent(1,value);
403 catch (
const runtime_error& error)
405 cout <<
"updateHist(): "<< error.what()<<endl;
414 _timer(new TTimer()),
417 _timer->Connect(
"Timeout()",
"HistogramUpdater",
this,
"syncHistograms()");
422 if(freq < sqrt(numeric_limits<double>::epsilon()))
426 _timer->Start(static_cast<int>(1.e3/freq));
434 stringstream serveradress;
437 list<string> allkeylist(client());
438 list<string> updatableHistsList(
checkList(allkeylist));
439 for_each(updatableHistsList.begin(),updatableHistsList.end(),
updateHist(client));
442 TIter next(gDirectory->GetList());
445 while ((obj = next()))
446 removeUnusedHist(obj);
450 catch (
const runtime_error &error)
452 cout <<
"HistogramUpdater::updateHistograms(): "<<error.what()<<endl;
460 stringstream serveradress;
466 catch (
const runtime_error &error)
468 cout <<
"HistogramUpdater::updateHistogram(): "<<error.what()<<endl;
476 stringstream serveradress;
479 list<string> allkeylist(client());
480 for_each(allkeylist.begin(),allkeylist.end(),
updateHist(client));
483 TIter next(gDirectory->GetList());
486 while ((obj = next()))
490 catch (
const runtime_error &error)
492 cout <<
"HistogramUpdater::writeRootFile(): "<<error.what()<<endl;
500 stringstream serveradress;
505 catch (
const runtime_error &error)
507 cout <<
"HistogramUpdater::reloadIni(): "<<error.what()<<endl;
515 stringstream serveradress;
520 catch (
const runtime_error &error)
522 cout <<
"HistogramUpdater::controlDarkcal(): "<<error.what()<<endl;
void updateCanvases(TSeqCollection *list)
update the contents of the canvases
bool operator==(const cass::Result< float >::axe_t &ca, const TAxis &ra)
comapre axis for equalitiy
size_t dim() const
what is the dimension of the result
void operator()(TObject *obj) const
the operator
value_t getValue() const
return the value
create the list of updateable histograms from all available keys
an axis of a more than 0 dimensional container
std::string title
the title of the axis
writeObject(const std::string &filename)
constructor
size_t nBins
the number of bins in this axis
void reloadIni() const
reload .ini file
void writeRootFile(const std::string &name)
write all histograms to a root file
std::auto_ptr< TTimer > _timer
the timer for auto update
const axis_t & axis() const
read access to the axis
delete all root histograms that are not on the list
HistogramUpdater(const std::string &server, int port)
constructor
void autoSync(double freq)
automaticly update
deleteObsoleteHistogram(const list< string > &allkeys)
constructor
bool _updateCanv
flag whether after updating the histogram the canvas should also update
void controlCalibration(const std::string &command="startDarkcal")
control the dark calibration
void operator()(TObject *obj)
the operator
void controlCalibration(const std::string &command) const
reload .ini file
void syncHistograms()
update the shown histograms
list< string > checkList(const list< string > &allkeys)
create the list of updateable histograms from all available keys
bool operator!=(const cass::Result< float >::axe_t &ca, const TAxis &ra)
comapre axis for inequality
HistogramUpdater * gCASSClient(0)
void iterateListAndAddDisplayedHistograms(TSeqCollection *list, std::list< string > &updateList)
iteratively go through canvas list and find histgrams
value_t low
lower end of the axis
void syncHistogram(const std::string &name)
copy a single result into a histogram
value_t up
upper end of the axis
TFile * _file
the file to write the object to
const list< string > & _allkeys
the list with all cass histogram keys
void reloadIni()
tell the server reload the .ini parameters
the tcp client that connects to the cass server
file contains the classes connect to cass
updateHist(const TCPClient &client)
constructor
file contains the classes that update histograms
check if there is some light in the chamber based upon the GMD value
std::string _server
the server
const TCPClient & _client
the client for the server