4 #pragma warning(disable:2259)
10 #pragma warning(disable:4996)
23 #include "GaudiKernel/Property.h"
24 #include "GaudiKernel/AttribStringParser.h"
25 #include "GaudiKernel/MsgStream.h"
26 #include "GaudiKernel/DataObject.h"
27 #include "GaudiKernel/IConversionSvc.h"
28 #include "GaudiKernel/GenericAddress.h"
42 inline std::string histoAddr
43 (
const std::string&
name)
45 if ( 0 == name.find (
"/stat/" ) ){
return std::string( name , 6 ) ; }
49 inline std::string histoAddr
51 const std::string& rel )
53 if ( !obj ) {
return rel ; }
55 if ( !reg ) {
return rel ; }
58 if ( rel .empty() ) {
return histoAddr ( name ) ; }
59 if (
'/' == name[name.size()-1] ||
60 '/' == rel[0] ) {
return histoAddr ( name + rel ) ; }
61 return histoAddr ( name +
"/" + rel ) ;
67 std::pair<std::string,std::string> split=
i_splitPath(full);
76 if (!hObj->annotation().addItem(
"id", obj.substr(1)))
77 hObj->annotation().setValue(
"id", obj.substr(1));
81 if (!hObj->annotation().addItem(
"id", obj))
82 hObj->annotation().setValue(
"id", obj);
91 TH3D *h3d = Gaudi::getRepresentation<IHistogram3D,TH3D>(
h);
93 TH2D *h2d =
dynamic_cast<TH2D*
>(h3d->Project3D(dir.c_str()));
109 if (b)
return b->
print(s);
111 log <<
MSG::ERROR <<
"Unknown histogram type: Cannot cast to Gaudi::HistogramBase."
118 if (b)
return b->
write(s);
120 log <<
MSG::ERROR <<
"Unknown histogram type: Cannot cast to Gaudi::HistogramBase."
127 if (b)
return b->
write(file_name);
129 log <<
MSG::ERROR <<
"Unknown histogram type: Cannot cast to Gaudi::HistogramBase."
135 std::string tmp = full;
138 tmp.insert(tmp.begin(), m_rootName.begin(), m_rootName.end());
141 if (tmp.rfind(
SEPARATOR) == tmp.length()-1) {
145 return { tmp.substr(0,sep), tmp.substr(sep) };
149 std::string tmpPath = newPath;
151 tmpPath.insert(tmpPath.begin(),
SEPARATOR);
152 tmpPath.insert(tmpPath.begin(), m_rootName.begin(), m_rootName.end());
155 if (tmpPath.rfind(
SEPARATOR) == tmpPath.length()-1) {
156 tmpPath.erase(tmpPath.rfind(
SEPARATOR),1);
164 std::string rest(tmpPath, sep+1, tmpPath.length()-sep);
165 std::string subPath(tmpPath, 0, sep);
179 std::unique_ptr<DataObject> directory{
new DataObject() };
187 log <<
MSG::ERROR <<
"Unable to create the histogram directory: "
188 << parentDir <<
"/" << subDir <<
endmsg;
194 log <<
MSG::ERROR <<
"Unable to create the histogram directory: "
195 << parentDir <<
"/" << subDir <<
endmsg;
199 return directory.release();
203 setDataLoader(
nullptr ).ignore();
204 clearStore().ignore();
208 using Parser = Gaudi::Utils::AttribStringParser;
213 std::string::size_type loc = ident.find(
" ");
214 std::string
filename, auth, svc =
"", typ =
"";
215 std::string logname = ident.substr(0, loc);
216 for (
auto attrib: Parser(ident.substr(loc+1))) {
217 switch(::
toupper(attrib.tag[0])) {
220 filename = std::move(attrib.value);
223 typ = std::move(attrib.value);
229 if (typ.length() > 0) {
231 std::string entryname = m_rootName;
233 entryname += logname;
238 filename,entryname,0,
'O');
242 filename,entryname,0,
'O');
246 status = registerAddress(pO, logname, pA);
248 log <<
MSG::INFO <<
"Added stream file:" << filename
249 <<
" as " << logname <<
endmsg;
256 log <<
MSG::ERROR <<
"Cannot add " << ident <<
" invalid filename!" <<
endmsg;
265 std::unique_ptr<DataObject> rootObj{
new DataObject() };
266 status = setRoot(
"/stat", rootObj.get());
273 auto svc = service<IConversionSvc>(
"HistogramPersistencySvc",
true);
275 setDataLoader( svc.get() ).ignore();
292 <<
" Path='" << ih.first <<
"'"
293 <<
" Description " << ih.second <<
endmsg ;
304 (
CSTR name,
const IHistogram2D& h,
int idxY1,
int idxY2) {
305 std::pair<DataObject*,IHistogram1D*> o(
nullptr,
nullptr);
312 throw GaudiException(
"Cannot cast 2D histogram to H2D to create sliceX `"
319 throw GaudiException(
"Cannot create sliceX `" + name +
"' of 2D histogram!",
325 std::pair<DataObject*,IHistogram1D*> o(
nullptr,
nullptr);
340 throw GaudiException(
"Cannot create sliceY `"+name+
"' of 2D histogram!",
354 if ( m_defs1D.empty () )
356 std::string hn = histoAddr ( pPar , rel ) ;
357 auto ifound = m_defs1D.find( hn ) ;
358 if ( m_defs1D.end() == ifound )
363 <<
" Redefine the parameters for the histogram '" + hn +
"' to be "
367 m_mods1D.insert ( hn ) ;
368 return i_book ( pPar , rel , ifound ->
second.title () ,
370 ( ifound ->
second.title () ,
371 ifound ->
second.bins () ,
372 ifound ->
second.lowEdge () ,
373 ifound ->
second.lowEdge () ) ) ;
382 m_rootName =
"/stat";
383 m_rootCLID = CLID_DataObject;
384 declareProperty (
"Input",
m_input);
385 declareProperty (
"Predefined1DHistos" ,
m_defs1D ,
386 "Histograms with predefined parameters" ) ;
397 inline size_t removeLeading
400 for (
auto it = m.begin() ; m.end() != it ; ++it )
402 if ( 0 == it->first.find ( lead ) )
404 std::string addr = std::string( it->first , lead.size() ) ;
408 return 1 + removeLeading ( m , lead ) ;
418 removeLeading (
m_defs1D ,
"/stat/" ) ;
429 <<
" Substituted histograms #" <<
m_mods1D.size() <<
" : " <<
endmsg;
435 if (
m_defs1D.end() != im ) { log <<
" " << im->second ; }
std::pair< DataObject *, AIDA::IHistogram1D * > slice1DY(const std::string &name, const AIDA::IHistogram2D &h, int firstbin, int lastbin)
Create 1D slice from 2D histogram.
Definition of the MsgStream class used to transmit messages.
Define general base for Gaudi exception.
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
std::set< std::string > m_mods1D
std::ostream & write(Base *h, std::ostream &s=std::cout) const override
Write (ASCII) the 1D histogram table into the output stream.
H1D * book(CSTR par, CSTR rel, CSTR title, DBINS(x)) override
Book histogram and register it with the histogram data store.
virtual Property & declareUpdateHandler(std::function< void(Property &)> fun)
set new callback for update
std::pair< DataObject *, AIDA::IHistogram1D * > createH1D(const AIDA::IHistogram1D &hist)
Copy constructor.
bool isSuccess() const
Test for a status code of SUCCESS.
unsigned long release() override
release reference to object
StatusCode findObject(IRegistry *pReg, CSTR path, P1D *&obj) override
virtual std::ostream & print(std::ostream &s) const =0
Print histogram to output stream.
virtual std::ostream & write(std::ostream &s) const =0
Write (binary) histogram to output stream.
~HistogramSvc() override
Destructor.
StatusCode unregisterObject(Base *obj) override
Generic Transient Address.
StatusCode registerObject(const std::string &fullPath, DataObject *pObject) override
Register object with the data store.
H2D * i_project(CSTR nameAndTitle, const H3D &h, CSTR dir)
Helper for 2D projections.
DBaseEntries m_input
Input streams.
StatusCode initialize() override
Initialise the service.
StatusCode connectInput(CSTR ident)
Connect input histogram file to the service.
IRegistry * registry() const
Get pointer to Registry.
StatusCode finalize() override
finalize the service
std::pair< std::string, std::string > i_splitPath(CSTR full)
Split full path into its components.
DataObject * createPath(CSTR newPath) override
Create all directories in a given full path.
bool destroy(IBaseHistogram *hist) override
This class is used for returning status codes from appropriate routines.
void clear(STATE_TYPE _i=std::ios_base::failbit)
#define DECLARE_COMPONENT(type)
H1D * sliceY(CSTR name, const H2D &h, int indexX) override
Simple helper class for description of 1D-histogram The class is targeted to act as the primary "hist...
StatusCode findObject(const std::string &fullPath, DataObject *&pObject) override
Find object identified by its full path in the data store.
std::pair< DataObject *, AIDA::IHistogram2D * > createH2D(const AIDA::IHistogram2D &hist)
Copy constructor.
void update1Ddefs(Property &)
handler to be invoked for updating property m_defs1D
std::pair< DataObject *, AIDA::IHistogram1D * > slice1DX(const std::string &name, const AIDA::IHistogram2D &h, int firstbin, int lastbin)
Create 1D slice from 2D histogram.
static DataObject * __cast(T *p)
The IRegistry represents the entry door to the environment any data object residing in a transient da...
std::ostream & print(Base *h, std::ostream &s=std::cout) const override
Print (ASCII) the 1D histogram into the output stream.
StatusCode finalize() override
Service initialization.
StatusCode registerObject(CSTR parent, CSTR rel, Base *obj) override
StatusCode retrieveObject(IRegistry *pDirectory, const std::string &path, DataObject *&pObject) override
Retrieve object from data store.
GAUDI_API Property * getProperty(const IProperty *p, const std::string &name)
simple function which gets the property with given name from the component
const long HBOOK_StorageType
Property base class allowing Property* collections to be "homogeneous".
Common base class for all histograms Use is solely functional to minimize dynamic_casts inside Histog...
HistogramSvc(const std::string &name, ISvcLocator *svc)
Statndard Constructor.
Base class used to extend a class implementing other interfaces.
StatusCode initialize() override
Service initialization.
H1D * sliceX(CSTR name, const H2D &h, int indexY) override
static int toRootIndex(int index, int nbins)
virtual const id_type & identifier() const =0
Full identifier (or key)
DataObject * createDirectory(CSTR parentDir, CSTR subDir) override
Create a sub-directory in a directory.
StatusCode reinitialize() override
Initialise the service.
A DataObject is the base class of any identifiable object on any data store.
void toupper(std::string &s)
std::map< std::string, Gaudi::Histo1DDef > Histo1DMap
const long ROOT_StorageType
HistogramSvc class definition.