5 #pragma warning(disable:2259)
11 #pragma warning(disable:4996)
24 #include "GaudiKernel/xtoa.h"
25 #include "GaudiKernel/Property.h"
26 #include "GaudiKernel/AttribStringParser.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()));
116 if(0 != b)
return b->
print(s);
118 log <<
MSG::ERROR <<
"Unknown histogram type: Cannot cast to Gaudi::HistogramBase."
125 if(0 != b)
return b->
write(s);
127 log <<
MSG::ERROR <<
"Unknown histogram type: Cannot cast to Gaudi::HistogramBase."
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;
218 using Parser = Gaudi::Utils::AttribStringParser;
223 std::string::size_type loc = ident.find(
" ");
224 std::string filename, auth, svc =
"", typ =
"";
225 std::string logname = ident.substr(0, loc);
226 for (
auto attrib: Parser(ident.substr(loc+1))) {
227 switch(::
toupper(attrib.tag[0])) {
230 filename = std::move(attrib.value);
233 typ = std::move(attrib.value);
239 if (typ.length() > 0) {
243 entryname += logname;
248 filename,entryname,0,
'O');
252 filename,entryname,0,
'O');
258 log <<
MSG::INFO <<
"Added stream file:" << filename
259 <<
" as " << logname <<
endmsg;
266 log <<
MSG::ERROR <<
"Cannot add " << ident <<
" invalid filename!" <<
endmsg;
276 status =
setRoot(
"/stat", rootObj);
283 status =
service(
"HistogramPersistencySvc",svc,
true);
293 for (DBaseEntries::iterator j =
m_input.begin(); j !=
m_input.end(); j++) {
303 for ( Histo1DMap::const_iterator ih =
m_defs1D.begin() ;
307 <<
" Path='" << ih->first <<
"'"
308 <<
" Description " << ih->second <<
endmsg ;
319 (
CSTR name,
const IHistogram2D& h,
int idxY1,
int idxY2) {
320 std::pair<DataObject*,IHistogram1D*> o(0,0);
327 throw GaudiException(
"Cannot cast 2D histogram to H2D to create sliceX `"
334 throw GaudiException(
"Cannot create sliceX `" + name +
"' of 2D histogram!",
340 std::pair<DataObject*,IHistogram1D*> o(0,0);
355 throw GaudiException(
"Cannot create sliceY `"+name+
"' of 2D histogram!",
362 if ( hist )
delete hist;
369 if ( m_defs1D.empty () )
371 std::string hn = histoAddr ( pPar , rel ) ;
372 Histo1DMap::const_iterator ifound = m_defs1D.find( hn ) ;
373 if ( m_defs1D.end() == ifound )
378 <<
" Redefine the parameters for the histogram '" + hn +
"' to be "
382 m_mods1D.insert ( hn ) ;
383 return i_book ( pPar , rel , ifound ->
second.title () ,
385 ( ifound ->
second.title () ,
386 ifound ->
second.bins () ,
387 ifound ->
second.lowEdge () ,
388 ifound ->
second.lowEdge () ) ) ;
403 "Histograms with predefined parameters" ) ;
414 inline size_t removeLeading
417 for ( HistogramSvc::Histo1DMap::iterator it = m.begin() ;
418 m.end() != it ; ++it )
420 if ( 0 == it->first.find ( lead ) )
422 std::string addr = std::string( it->first , lead.size() ) ;
426 return 1 + removeLeading ( m , lead ) ;
436 removeLeading (
m_defs1D ,
"/stat/" ) ;
447 <<
" Substituted histograms #" <<
m_mods1D.size() <<
" : " <<
endmsg;
448 for ( std::set<std::string>::const_iterator ih =
m_mods1D.begin() ;
452 log <<
MSG::DEBUG <<
" Path='" << (*ih) <<
"'" ;
453 Histo1DMap::const_iterator im =
m_defs1D.find( *ih ) ;
454 if (
m_defs1D.end() != im ) { log <<
" " << im->second ; }
virtual StatusCode setDataLoader(IConversionSvc *svc)
IDataManagerSvc: IDataManagerSvc: Pass a default data loader to the service.
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...
virtual StatusCode findObject(const std::string &fullPath, DataObject *&pObject)
Find object identified by its full path in the data store.
virtual StatusCode registerObject(const std::string &fullPath, DataObject *pObject)
Register object with the data store.
std::set< std::string > m_mods1D
bool destroy(IBaseHistogram *hist)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
std::pair< DataObject *, AIDA::IHistogram1D * > createH1D(const AIDA::IHistogram1D &hist)
Copy constructor.
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
bool isSuccess() const
Test for a status code of SUCCESS.
std::string m_rootName
Name of root event.
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.
const long ROOT_StorageType
virtual std::ostream & write(Base *h, std::ostream &s=std::cout) const
Write (ASCII) the 1D histogram table into the output stream.
virtual StatusCode initialize()
Initialise the service.
virtual H1D * book(CSTR par, CSTR rel, CSTR title, DBINS(x))
Book histogram and register it with the histogram data store.
virtual H1D * sliceY(CSTR name, const H2D &h, int indexX)
Generic Transient Address.
H2D * i_project(CSTR nameAndTitle, const H3D &h, CSTR dir)
Helper for 2D projections.
virtual StatusCode registerAddress(const std::string &fullPath, IOpaqueAddress *pAddress)
IDataManagerSvc: Register object address with the data store.
DBaseEntries m_input
Input streams.
StatusCode connectInput(CSTR ident)
Connect input histogram file to the service.
IRegistry * registry() const
Get pointer to Registry.
virtual ~HistogramSvc()
Destructor.
virtual StatusCode finalize()
finalize the service
virtual StatusCode setRoot(const std::string &root_name, DataObject *pRootObj)
Initialize data store for new event by giving new event path and root object.
virtual void declareUpdateHandler(PropertyCallbackFunctor *pf)
set new callback for update
virtual std::ostream & print(Base *h, std::ostream &s=std::cout) const
Print (ASCII) the 1D histogram into the output stream.
std::pair< std::string, std::string > i_splitPath(CSTR full)
Split full path into its components.
virtual unsigned long release()
release reference to object
HistogramSvc(CSTR name, ISvcLocator *svc)
Statndard Constructor.
#define DECLARE_COMPONENT(type)
This class is used for returning status codes from appropriate routines.
Simple helper class for description of 1D-histogram The class is targeted to act as the primary "hist...
virtual DataObject * createPath(CSTR newPath)
Create all directories in a given full path.
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...
virtual H1D * sliceX(CSTR name, const H2D &h, int indexY)
virtual StatusCode retrieveObject(IRegistry *pDirectory, const std::string &path, DataObject *&pObject)
Retrieve object from data store.
virtual StatusCode registerObject(CSTR parent, CSTR rel, Base *obj)
GAUDI_API Property * getProperty(const IProperty *p, const std::string &name)
simple function which gets the property with given name from the component
virtual const std::string & name() const
Retrieve name of the service.
virtual StatusCode initialize()
Service initialization.
virtual DataObject * createDirectory(CSTR parentDir, CSTR subDir)
Create a sub-directory in a directory.
virtual StatusCode findObject(IRegistry *pReg, CSTR path, P1D *&obj)
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...
virtual unsigned long release()=0
Release Interface instance.
virtual StatusCode clearStore()
IDataManagerSvc: Remove all data objects in the data store.
Templated class to add the standard messaging functionalities.
CLID m_rootCLID
Integer Property corresponding to CLID of root entry.
static int toRootIndex(int index, int nbins)
StatusCode service(const std::string &name, const T *&psvc, bool createIf=true) const
Access a service by name, creating it if it doesn't already exist.
virtual const id_type & identifier() const =0
Full identifier (or key)
Property * declareProperty(const std::string &name, T &property, const std::string &doc="none") const
Declare the named property.
virtual StatusCode unregisterObject(Base *obj)
A DataObject is the base class of any identifiable object on any data store.
void toupper(std::string &s)
virtual StatusCode finalize()
Service initialization.
virtual StatusCode reinitialize()
Initialise the service.
std::map< std::string, Gaudi::Histo1DDef > Histo1DMap
const long HBOOK_StorageType
MSG::Level msgLevel() const
get the output level from the embedded MsgStream
HistogramSvc class definition.