5 #pragma warning(disable:2259)
11 #pragma warning(disable:4996)
24 #include "GaudiKernel/xtoa.h"
25 #include "GaudiKernel/Property.h"
26 #include "GaudiKernel/Tokenizer.h"
27 #include "GaudiKernel/MsgStream.h"
28 #include "GaudiKernel/DataObject.h"
29 #include "GaudiKernel/IConversionSvc.h"
30 #include "GaudiKernel/GenericAddress.h"
44 inline std::string histoAddr
45 (
const std::string& name)
47 if ( 0 == name.find (
"/stat/" ) ){
return std::string( name , 6 ) ; }
51 inline std::string histoAddr
53 const std::string& rel )
55 if ( 0 == obj ) {
return rel ; }
57 if ( 0 == reg ) {
return rel ; }
60 if ( rel .empty() ) {
return histoAddr ( name ) ; }
61 if (
'/' == name[name.size()-1] ||
62 '/' == rel[0] ) {
return histoAddr ( name + rel ) ; }
63 return histoAddr ( name +
"/" + rel ) ;
69 std::ostringstream txt; txt <<
i;
74 std::pair<std::string,std::string> split=
i_splitPath(full);
83 if (!hObj->annotation().addItem(
"id", obj.substr(1)))
84 hObj->annotation().setValue(
"id", obj.substr(1));
88 if (!hObj->annotation().addItem(
"id", obj))
89 hObj->annotation().setValue(
"id", obj);
98 TH3D *h3d = Gaudi::getRepresentation<IHistogram3D,TH3D>(h);
100 TH2D *h2d =
dynamic_cast<TH2D*
>(h3d->Project3D(dir.c_str()));
115 Gaudi::HistogramBase* b =
dynamic_cast<Gaudi::HistogramBase*
>(h);
116 if(0 != b)
return b->print(s);
118 log <<
MSG::ERROR <<
"Unknown histogram type: Cannot cast to Gaudi::HistogramBase."
124 Gaudi::HistogramBase* b =
dynamic_cast<Gaudi::HistogramBase*
>(h);
125 if(0 != b)
return b->write(s);
127 log <<
MSG::ERROR <<
"Unknown histogram type: Cannot cast to Gaudi::HistogramBase."
133 Gaudi::HistogramBase* b =
dynamic_cast<Gaudi::HistogramBase*
>(h);
134 if(0 != b)
return b->write(file_name);
136 log <<
MSG::ERROR <<
"Unknown histogram type: Cannot cast to Gaudi::HistogramBase."
142 std::string tmp = full;
148 if (tmp.rfind(
SEPARATOR) == tmp.length()-1) {
152 return std::pair<std::string,std::string>
153 (tmp.substr(0,sep),tmp.substr(sep,tmp.length()-sep));
157 std::string tmpPath = newPath;
159 tmpPath.insert(tmpPath.begin(),
SEPARATOR);
163 if (tmpPath.rfind(
SEPARATOR) == tmpPath.length()-1) {
164 tmpPath.erase(tmpPath.rfind(
SEPARATOR),1);
172 std::string rest(tmpPath, sep+1, tmpPath.length()-sep);
173 std::string subPath(tmpPath, 0, sep);
188 if (0 != directory) {
195 log <<
MSG::ERROR <<
"Unable to create the histogram directory: "
196 << parentDir <<
"/" << subDir <<
endmsg;
203 log <<
MSG::ERROR <<
"Unable to create the histogram directory: "
204 << parentDir <<
"/" << subDir <<
endmsg;
223 std::string::size_type loc = ident.find(
" ");
224 std::string filename, auth, svc =
"", typ =
"";
225 std::string logname = ident.substr(0,loc);
226 tok.
analyse(ident.substr(loc+1,ident.length()),
" ",
"",
"",
"=",
"'",
"'");
227 for (Tokenizer::Items::iterator
i = tok.
items().begin();
229 CSTR tag = (*i).tag();
233 filename = (*i).value();
242 if (typ.length() > 0) {
246 entryname += logname;
251 filename,entryname,0,
'O');
255 filename,entryname,0,
'O');
261 log <<
MSG::INFO <<
"Added stream file:" << filename
262 <<
" as " << logname <<
endmsg;
269 log <<
MSG::ERROR <<
"Cannot add " << ident <<
" invalid filename!" <<
endmsg;
279 status =
setRoot(
"/stat", rootObj);
286 status =
service(
"HistogramPersistencySvc",svc,
true);
296 for (DBaseEntries::iterator j =
m_input.begin(); j !=
m_input.end(); j++) {
306 for ( Histo1DMap::const_iterator ih =
m_defs1D.begin() ;
310 <<
" Path='" << ih->first <<
"'"
311 <<
" Description " << ih->second <<
endmsg ;
322 (
CSTR name,
const IHistogram2D& h,
int idxY1,
int idxY2) {
323 std::pair<DataObject*,IHistogram1D*> o(0,0);
325 int firstbin = Gaudi::Axis::toRootIndex(idxY1,h.yAxis().bins());
326 int lastbin = Gaudi::Axis::toRootIndex(idxY2,h.yAxis().bins());
330 throw GaudiException(
"Cannot cast 2D histogram to H2D to create sliceX `"
337 throw GaudiException(
"Cannot create sliceX `" + name +
"' of 2D histogram!",
343 std::pair<DataObject*,IHistogram1D*> o(0,0);
358 throw GaudiException(
"Cannot create sliceY `"+name+
"' of 2D histogram!",
365 if ( hist )
delete hist;
372 if ( m_defs1D.empty () )
374 std::string hn = histoAddr ( pPar , rel ) ;
375 Histo1DMap::const_iterator ifound = m_defs1D.find( hn ) ;
376 if ( m_defs1D.end() == ifound )
381 <<
" Redefine the parameters for the histogram '" + hn +
"' to be "
385 m_mods1D.insert ( hn ) ;
386 return i_book ( pPar , rel , ifound -> second.title () ,
388 ( ifound -> second.title () ,
389 ifound -> second.bins () ,
390 ifound -> second.lowEdge () ,
391 ifound -> second.lowEdge () ) ) ;
406 "Histograms with predefined parameters" ) ;
417 inline size_t removeLeading
420 for ( HistogramSvc::Histo1DMap::iterator it = m.begin() ;
421 m.end() != it ; ++it )
423 if ( 0 == it->first.find ( lead ) )
425 std::string addr = std::string( it->first , lead.size() ) ;
426 Gaudi::Histo1DDef hdef = it->second ;
429 return 1 + removeLeading ( m , lead ) ;
439 removeLeading (
m_defs1D ,
"/stat/" ) ;
450 <<
" Substituted histograms #" <<
m_mods1D.size() <<
" : " <<
endmsg;
451 for ( std::set<std::string>::const_iterator ih =
m_mods1D.begin() ;
455 log <<
MSG::DEBUG <<
" Path='" << (*ih) <<
"'" ;
456 Histo1DMap::const_iterator im =
m_defs1D.find( *ih ) ;
457 if (
m_defs1D.end() != im ) { log <<
" " << im->second ; }