36 using namespace Gaudi;
37 typedef const string&
CSTR;
39 #define S_OK StatusCode::SUCCESS
40 #define S_FAIL StatusCode::FAILURE
44 static map<string, TClass*> s_classesNames;
45 static map<CLID, TClass*> s_classesClids;
47 #define MBYTE 1024*1024
52 m_ioMgr(0), m_incidentSvc(0), m_current(0), m_setup(0)
98 return error(
"Failed to initialize ConversionSvc base class.");
108 return error(
"Unable to localize interface from service:IODataManager");
110 return error(
"Unable to localize interface from service:IncidentSvc");
115 m_classDO = TClass::GetClass(cname.c_str());
117 return error(
"Unable to load class description for DataObject");
121 return error(
"Unable to load class description for ObjectRefs");
130 for(IIODataManager::Connections::iterator
i=cons.begin();
i != cons.end(); ++
i) {
138 if ( num_clients == 0 ) {
140 log() <<
"Disconnected data IO:" << pc->
fid()
158 if ( wanted == CLID_StatisticsFile )
160 else if ( wanted == CLID_StatisticsDirectory )
162 else if ( wanted == CLID_RowWiseTuple )
164 else if ( wanted == CLID_ColumnWiseTuple )
176 TClass* cl = s_classesNames[cname];
178 cl = TClass::GetClass(cname.c_str());
180 s_classesNames[cname] = cl;
181 s_classesClids[pObject->
clID()] = cl;
189 map<CLID, TClass*>::iterator
i=s_classesClids.find(pObject->
clID());
190 if ( i != s_classesClids.end() )
return (*i).second;
192 i=s_classesClids.find(pObject->
clID());
193 if ( i != s_classesClids.end() )
return (*i).second;
196 throw runtime_error(
"Unknown ROOT class for object:"+cname);
205 if ( ::strncasecmp(openMode.c_str(),
"RECREATE",3)==0 )
207 else if ( ::strncasecmp(openMode.c_str(),
"NEW",1)==0 )
209 else if ( ::strncasecmp(openMode.c_str(),
"CREATE",1)==0 )
211 else if ( ::strncasecmp(openMode.c_str(),
"UPDATE",1)==0 )
217 log() <<
MSG::ERROR <<
"The dataset " << dsn <<
" cannot be opened in mode "
218 << openMode <<
". [Invalid mode]" <<
endmsg;
227 bool fire_incident =
false;
246 connection.release();
264 if ( fire_incident ) {
266 string fid = pc->
fid();
271 unsigned long ipar[2] = { (
unsigned long)(*con), (
unsigned long)b->GetEntries()-1 };
272 for(
int i=0;
i<b->GetEntries(); ++
i) {
279 <<
" [" << pc->
fid() <<
"][" <<
i <<
"]" <<
endmsg;
295 for(IIODataManager::Connections::iterator
i=cons.begin();
i != cons.end(); ++
i) {
300 if ( num_client == 0 ) {
315 catch (exception& e) {
317 return error(
string(
"connectDatabase> Caught exception:")+e.what());
321 return error(
"connectDatabase> Unknown Fatal Exception for "+dataset);
334 string section =
m_currSection.substr(1,len==string::npos ? string::npos : len-1);
337 Long64_t
evt = b->GetEntries();
338 TTree* t = b->GetTree();
339 TObjArray* a = t->GetListOfBranches();
340 Int_t nb = a->GetEntriesFast();
342 for(Int_t
i=0;
i<nb; ++
i) {
343 TBranch* br_ptr = (TBranch*)a->UncheckedAt(
i);
344 Long64_t br_evt = br_ptr->GetEntries();
345 if ( br_evt < evt ) {
346 Long64_t num = evt-br_evt;
347 br_ptr->SetAddress(0);
353 <<
"commit: Added " << long(evt-br_evt)
354 <<
" Section: " << evt <<
" Branch: " << br_ptr->GetEntries()
355 <<
" RefNo: " << br_ptr->GetEntries()-1
356 <<
" NULL entries to:" << br_ptr->GetName() <<
endmsg;
360 b->GetTree()->SetEntries(evt);
365 if ( evt == m_autoFlush ) {
366 b->GetTree()->SetAutoFlush(m_autoFlush);
370 b->GetTree()->FlushBaskets();
375 <<
" to " << long(evt) <<
" entries." <<
endmsg;
378 return error(
"commitOutput> Failed to update entry numbers on "+dsn);
394 const unsigned long* ip,
397 refpAddress =
new RootAddress(typ,clid,par[0],par[1],ip[0],ip[1]);
403 size_t len = path.find(
'/',1);
404 string section = path.substr(1,len==string::npos ? string::npos : len-1);
412 size_t len = path.find(
'/',1);
413 string section = path.substr(1,len==string::npos ? string::npos : len-1);
414 pair<int,unsigned long> ret =
418 << ret.first <<
" " << hex << ret.second << dec <<
" [NULL]" <<
endmsg;
430 size_t len = p[1].find(
'/',1);
431 string sect = p[1].substr(1,len==string::npos ? string::npos : len-1);
432 pair<int,unsigned long> ret =
434 if ( ret.first > 1 || (clid == CLID_DataObject && ret.first==1) ) {
435 unsigned long ip[2] = {0,ret.second};
439 return error(
"Failed to write object data for:"+p[1]);
441 return error(
"createRep> Current Database is invalid!");
447 typedef vector<IRegistry*> Leaves;
453 StatusCode status = dataMgr->objectLeaves(pObj, leaves);
457 size_t len =
id.find(
'/',1);
458 string sect =
id.substr(1,len==string::npos ? string::npos : len-1);
460 for(Leaves::iterator
i=leaves.begin(), iend=leaves.end();
i != iend; ++
i) {
461 if ( (*i)->address() ) {
463 ref.
entry = (*i)->address()->ipar()[1];
464 refs.
refs.push_back(ref);
467 for(
int i = 0,
n=pLinks->
size();
i <
n; ++
i) {
470 refs.
links.push_back(link_id);
472 pair<int,unsigned long> ret =
474 if ( ret.first > 1 ) {
477 << ret.first <<
" " << hex << ret.second << dec <<
endmsg;
491 const string*
par = pA->
par();
492 unsigned long* ipar =
const_cast<unsigned long*
>(pA->
ipar());
495 ipar[0] = (
unsigned long)con;
497 size_t len = par[1].find(
'/',1);
498 string section = par[1].substr(1,len==string::npos ? string::npos : len-1);
500 int nb = con->
loadObj(section,par[1],ipar[1],pObj);
501 if ( nb > 1 || (nb == 1 && pObj->
clID() == CLID_DataObject) ) {
507 string tag = par[0]+
":"+par[1];
510 return error(
"createObj> Cannot access the object:"+tag);
520 const unsigned long* ipar = pA->
ipar();
524 const string*
par = pA->
par();
525 size_t len = par[1].find(
'/',1);
526 string section = par[1].substr(1,len==string::npos ? string::npos : len-1);
527 int nb = con->
loadRefs(section,par[1],ipar[1],refs);
530 unsigned long nipar[2];
536 for(vector<int>::const_iterator
i=refs.
links.begin();
i!=refs.
links.end();++
i) {
539 for(
size_t j=0,
n=refs.
refs.size(); j<
n; ++j) {
550 <<
"#" << npar[2] <<
"[" << r.
entry <<
"]" <<
endmsg;
551 sc = dataMgr->registerAddress(pA->
registry(),npar[2],nPA);
562 string tag = par[0]+
":"+par[1];
565 return error(
"createObj> Cannot access the object:"+tag+
" [Corrupted file]");
571 return error(
"read> Cannot read object -- no valid object address present ");
void addClient(const IInterface *client)
Add new client to this data source.
bool lookupClient(const IInterface *client) const
Lookup client for this data source.
const std::string & path() const
Access to path of object.
virtual const std::string * par() const =0
Retrieve String parameters.
Definition of the MsgStream class used to transmit messages.
virtual StatusCode update()
Provide empty placeholder for internal object reconfiguration callback.
MsgStream & log() const
Helper: Use message streamer.
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
The data converters are responsible to translate data from one representation into another...
const std::string & fid() const
Access file id.
std::string m_currSection
Property: ROOT section name.
virtual IConverter * createConverter(long typ, const CLID &wanted, const ICnvFactory *fac)
ConversionSvc overload: Create new Converter using factory.
virtual void loadConverter(DataObject *pObj)
ConversionSvc overload: Load the class (dictionary) for the converter.
virtual StatusCode createNullRef(const std::string &path)
Insert null marker for not existent transient object.
IoType
I/O Connection types.
Gaudi::IIODataManager * m_ioMgr
Reference to the I/O data manager.
std::pair< int, unsigned long > saveObj(const std::string §ion, const std::string &cnt, TClass *cl, DataObject *pObj, int buff_siz, int split_lvl, bool fill_missing=false)
Save object of a given class to section and container.
TFile * file() const
Direct access to TFile structure.
void saveStatistics(const std::string &statisticsFile)
Save TTree access statistics if required.
MSG::Level level()
Retrieve output level.
virtual StatusCode createAddress(long svc_type, const CLID &clid, const std::string *par, const unsigned long *ip, IOpaqueAddress *&refpAddress)
IAddressCreator implementation: Address creation.
const std::string & getDb(int which) const
Access database/file name from saved index.
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
int m_basketSize
Property: Basket optimization parameter for ROOT TTree (total basket size)
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
bool isSuccess() const
Test for a status code of SUCCESS.
int loadObj(const std::string §ion, const std::string &cnt, unsigned long entry, DataObject *&pObj)
Load object.
std::vector< Connection * > Connections
RootConnectionSetup * m_setup
Setup structure (ref-counted) and passed to data connections.
void release()
Decrease reference count.
IIncidentSvc * m_incidentSvc
Reference to incident service.
size_t removeClient(const IInterface *client)
Remove client from this data source.
virtual Connection * connection(const std::string &dsn) const =0
Retrieve known connection.
bool patchStreamers(MsgStream &log)
const std::string & getLink(int which) const
Access link name from saved index.
StatusCode connectDatabase(const std::string &dataset, int mode, RootDataConnection **con)
Connect the output file to the service with open mode.
std::vector< RootRef > refs
The references corresponding to the next layer of items in the data store.
void setMessageSvc(MsgStream *m)
Set message service reference.
const std::string FailInputFile
could not open or read from this file
int cacheSize
RootCnvSvc Property: Root data cache size.
const std::string & pfn() const
Access physical file name.
IRegistry * registry() const
Get pointer to Registry.
int loadRefs(const std::string §ion, const std::string &cnt, unsigned long entry, RootObjectRefs &refs)
Load references object.
Persistent reference object containing all leafs and links corresponding to a Gaudi DataObject...
LinkManager * linkMgr() const
Retrieve Link manager.
virtual StatusCode disconnect(IDataConnection *con)=0
Release data stream.
std::string loadSection
RootCnvSvc Property: Root data cache size.
int dbase
Data members to define object location in the persistent world.
Persistent reference object.
int m_splitLevel
Property: Split level optimization parameter for ROOT TTree.
virtual bool isConnected() const
Check if connected to data source.
virtual void fireIncident(const Incident &incident)=0
Fire an Incident.
virtual long repSvcType() const
Retrieve the class type of the data store the converter uses.
virtual const CLID & clID() const
Retrieve reference to class definition structure.
virtual ~RootCnvSvc()
Standard destructor.
virtual StatusCode finalize()
stop the service.
virtual IRegistry * registry() const =0
Update branch name.
int learnEntries
RootCnvSvc Property: ROOT cache learn entries.
This class is used for returning status codes from appropriate routines.
virtual Connections connections(const IInterface *owner) const =0
Get connection by owner instance (0=ALL)
TBranch * getBranch(const std::string §ion, const std::string &branch_name)
Access data branch by name: Get existing branch in read only mode.
void makeRef(IRegistry *pA, RootRef &ref)
Create reference object from registry entry.
Link * link(long id)
Retrieve symbolic link identified by ID.
Statistics file converter class definition.
virtual StatusCode connectRead(bool keep_open, IDataConnection *con)=0
Open data stream in read mode.
TClass * m_classDO
TClass pointer to DataObject class.
StringVec cacheBranches
Vector of strings with branches to be cached for input files.
The IRegistry represents the entry door to the environment any data object residing in a transient da...
const long ROOT_StorageType
virtual StatusCode i__createObj(IOpaqueAddress *pAddr, DataObject *&refpObj)
Create transient object from persistent data.
virtual StatusCode commitOutput(const std::string &outputFile, bool do_commit)
Commit pending output.
const std::string & getCont(int which) const
Access container name from saved index.
unsigned int CLID
Class ID definition.
virtual StatusCode finalize()
ConversionSvc overload: Finalize Db service.
NTuple converter class definition for NTuples writted/read using ROOT.
virtual const std::string & name() const
Retrieve name of the service.
StringVec vetoBranches
Vector of strings with branches to NOT be cached for input files.
virtual StatusCode disconnect(const std::string &dbName)
Disconnect from an existing data stream.
GAUDI_API std::string path(const AIDA::IBaseHistogram *aida)
get the path in THS for AIDA histogram
bool m_incidentEnabled
Property: Flag to enable incidents on FILE_OPEN.
std::vector< int > links
The links of the link manager.
std::pair< int, unsigned long > save(const std::string §ion, const std::string &cnt, TClass *cl, void *pObj, int buff_siz, int split_lvl, bool fill_missing=false)
Save object of a given class to section and container.
const StringVec & mergeFIDs() const
Access merged FIDs.
std::set< std::string > m_badFiles
Set with bad files/tables.
std::string m_shareFiles
Property: Share files ? If set to YES, files will not be closed on finalize.
Description: NTuple directory converter class definition Definition of the converter to manage the di...
virtual StatusCode createNullRep(const std::string &path)
Insert null marker for not existent transient object.
MsgStream * m_log
Message streamer.
virtual StatusCode connectOutput(const std::string &outputFile, const std::string &openMode)
Connect the output file to the service with open mode.
const IInterface * owner() const
Owner instance.
ABC describing basic data connection.
int makeLink(const std::string &p)
Convert path string to path index.
virtual StatusCode connectRead()
Open data stream in read mode.
void resetAge()
Reset age.
Base class for all Incidents (computing events).
std::string m_compression
Property: Compression-algorithm:compression-level.
virtual StatusCode i__fillRepRefs(IOpaqueAddress *pAddr, DataObject *pObj)
Resolve the references of the converted object.
static long setCompression(const std::string &compression)
Set the global compression level.
std::string m_recordName
Property: Records name to fire incident for file records.
virtual StatusCode i__fillObjRefs(IOpaqueAddress *pAddr, DataObject *pObj)
Resolve the references of the created transient object.
virtual IDataProviderSvc * dataSvc() const =0
Retrieve pointer to Transient Store.
virtual SmartIF< IAddressCreator > & addressCreator() const
Retrieve address creator facility.
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 StatusCode initialize()
Initialize the service.
virtual const id_type & identifier() const =0
Full identifier (or key)
virtual StatusCode initialize()
ConversionSvc overload: initialize Db service.
const std::string FailOutputFile
could not create or write to this file
Embedded class defining a symbolic link Note: No copy constructor; bitwise copy (done by the compiler...
Opaque address interface definition.
Base class for all conversion services.
Property * declareProperty(const std::string &name, T &property, const std::string &doc="none") const
Declare the named property.
This is a number of static methods for bootstrapping the Gaudi framework.
std::string m_ioPerfStats
Property: Enable TTree IOperfStats if not empty; otherwise perf stat file name.
void setIncidentSvc(IIncidentSvc *m)
Set incident service reference.
void enableStatistics(const std::string §ion)
Enable TTreePerStats.
A DataObject is the base class of any identifiable object on any data store.
Concrete implementation of the IDataConnection interface to access ROOT files.
virtual StatusCode connectWrite(IDataConnection *con, IoType mode=Connection::CREATE, const std::string &doctype="UNKNOWN")=0
Open data stream in write mode.
virtual const unsigned long * ipar() const =0
Access to generic link parameters.
A LinkManager is the object aggregated into a DataObject, which is responsible for the handling of no...
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
virtual StatusCode i__createRep(DataObject *pObj, IOpaqueAddress *&refpAddr)
Convert the transient object to the requested persistent representation.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Description: Definition of the ROOT data converter.
int m_bufferSize
Property: Buffer size optimization parameter for ROOT TTree.
long size() const
Retrieve number of link present.
SmartIF< ISvcLocator > & serviceLocator() const
Retrieve pointer to service locator.
Gaudi::RootDataConnection * m_current
On writing: reference to active output stream.
int m_autoFlush
Property: AutoFlush parameter for ROOT TTree (Number of events between auto flushes) ...
TClass * getClass(DataObject *pObject)
Helper: Get TClass for a given DataObject pointer.
TClass * m_classRefs
TClass pointer to reference class.