RootHistCnv::RCWNTupleCnv Class Reference

Converter of Column-wise NTuple into ROOT format. More...

#include <src/RCWNTupleCnv.h>

Inheritance diagram for RootHistCnv::RCWNTupleCnv:
Collaboration diagram for RootHistCnv::RCWNTupleCnv:

Public Member Functions

 RCWNTupleCnv (ISvcLocator *svc)
 Standard constructor. More...
 
virtual ~RCWNTupleCnv ()
 Standard destructor. More...
 
- Public Member Functions inherited from RootHistCnv::RNTupleCnv
virtual StatusCode initialize ()
 Initialize the converter. More...
 
virtual StatusCode finalize ()
 Finalize the converter. More...
 
virtual StatusCode createObj (IOpaqueAddress *pAddr, DataObject *&refpObj)
 Create the transient representation of an object. More...
 
virtual StatusCode updateObj (IOpaqueAddress *pAddr, DataObject *refpObj)
 Update the transient object from the other representation. More...
 
virtual StatusCode createRep (DataObject *pObj, IOpaqueAddress *&refpAddr)
 Convert the transient object to the requested representation. More...
 
virtual StatusCode updateRep (IOpaqueAddress *pAddr, DataObject *pObj)
 Update the converted representation of a transient object. More...
 
- Public Member Functions inherited from RootHistCnv::RConverter
long repSvcType () const
 Retrieve the class type of the data store the converter uses. More...
 
StatusCode error (const std::string &msg)
 
StatusCode regTFile (const std::string, const TFile *)
 
StatusCode findTFile (const std::string, TFile *&)
 
std::string diskDirectory (const std::string &loc)
 
std::string directory (const std::string &loc)
 
void setDirectory (const std::string &loc)
 
void setDiskDirectory (const std::string &loc)
 
StatusCode createDirectory (const std::string &loc)
 
StatusCode createDiskDirectory (const std::string &loc)
 
std::string getDirectory ()
 
std::string convertId (const std::string &) const
 
- Public Member Functions inherited from Converter
virtual StatusCode setDataProvider (IDataProviderSvc *svc)
 Set Data provider service. More...
 
virtual SmartIF< IDataProviderSvc > & dataProvider () const
 Get Data provider service. More...
 
virtual StatusCode setConversionSvc (IConversionSvc *svc)
 Set conversion service the converter is connected to. More...
 
virtual SmartIF< IConversionSvc > & conversionSvc () const
 Get conversion service the converter is connected to. More...
 
virtual StatusCode setAddressCreator (IAddressCreator *creator)
 Set address creator facility. More...
 
virtual SmartIF< IAddressCreator > & addressCreator () const
 Retrieve address creator facility. More...
 
virtual const CLIDobjType () const
 Retrieve the class type of objects the converter produces. More...
 
virtual long i_repSvcType () const
 Retrieve the class type of the data store the converter uses. More...
 
virtual StatusCode fillObjRefs (IOpaqueAddress *pAddress, DataObject *pObject)
 Resolve the references of the created transient object. More...
 
virtual StatusCode updateObjRefs (IOpaqueAddress *pAddress, DataObject *pObject)
 Update the references of an updated transient object. More...
 
virtual StatusCode fillRepRefs (IOpaqueAddress *pAddress, DataObject *pObject)
 Resolve the references of the converted object. More...
 
virtual StatusCode updateRepRefs (IOpaqueAddress *pAddress, DataObject *pObject)
 Update the references of an already converted object. More...
 
 Converter (long storage_type, const CLID &class_type, ISvcLocator *svc=0)
 Standard Constructor. More...
 
template<class T >
StatusCode service (const std::string &name, T *&psvc, bool createIf=false) const
 Access a service by name, creating it if it doesn't already exist. More...
 
template<class T >
StatusCode service (const std::string &type, const std::string &name, T *&psvc) const
 Access a service by name, type creating it if it doesn't already exist. More...
 
SmartIF< IServiceservice (const std::string &name, const bool createIf=true) const
 Return a pointer to the service identified by name (or "type/name") More...
 
virtual StatusCode setDataProvider (IDataProviderSvc *svc)
 Set Data provider service. More...
 
virtual SmartIF< IDataProviderSvc > & dataProvider () const
 Get Data provider service. More...
 
virtual StatusCode setConversionSvc (IConversionSvc *svc)
 Set conversion service the converter is connected to. More...
 
virtual SmartIF< IConversionSvc > & conversionSvc () const
 Get conversion service the converter is connected to. More...
 
virtual StatusCode setAddressCreator (IAddressCreator *creator)
 Set address creator facility. More...
 
virtual SmartIF< IAddressCreator > & addressCreator () const
 Retrieve address creator facility. More...
 
virtual const CLIDobjType () const
 Retrieve the class type of objects the converter produces. More...
 
virtual long i_repSvcType () const
 Retrieve the class type of the data store the converter uses. More...
 
virtual StatusCode fillObjRefs (IOpaqueAddress *pAddress, DataObject *pObject)
 Resolve the references of the created transient object. More...
 
virtual StatusCode updateObjRefs (IOpaqueAddress *pAddress, DataObject *pObject)
 Update the references of an updated transient object. More...
 
virtual StatusCode fillRepRefs (IOpaqueAddress *pAddress, DataObject *pObject)
 Resolve the references of the converted object. More...
 
virtual StatusCode updateRepRefs (IOpaqueAddress *pAddress, DataObject *pObject)
 Update the references of an already converted object. More...
 
 Converter (long storage_type, const CLID &class_type, ISvcLocator *svc=0)
 Standard Constructor. More...
 
template<class T >
StatusCode service (const std::string &name, T *&psvc, bool createIf=false) const
 Access a service by name, creating it if it doesn't already exist. More...
 
template<class T >
StatusCode service (const std::string &type, const std::string &name, T *&psvc) const
 Access a service by name, type creating it if it doesn't already exist. More...
 
SmartIF< IServiceservice (const std::string &name, const bool createIf=true) const
 Return a pointer to the service identified by name (or "type/name") More...
 
- Public Member Functions inherited from extend_interfaces1< IConverter >
virtual ~extend_interfaces1 ()
 Virtual destructor. More...
 
virtual ~extend_interfaces1 ()
 Virtual destructor. More...
 
- Public Member Functions inherited from IConverter
 DeclareInterfaceID (IConverter, 3, 0)
 InterfaceID. More...
 
virtual ~IConverter ()
 Virtual destructor. More...
 
 DeclareInterfaceID (IConverter, 3, 0)
 InterfaceID. More...
 
virtual ~IConverter ()
 Virtual destructor. More...
 
- Public Member Functions inherited from IInterface
virtual void * i_cast (const InterfaceID &) const =0
 main cast function More...
 
virtual std::vector< std::string > getInterfaceNames () const =0
 Returns a vector of strings containing the names of all the implemented interfaces. More...
 
virtual unsigned long addRef ()=0
 Increment the reference count of Interface instance. More...
 
virtual unsigned long release ()=0
 Release Interface instance. More...
 
virtual unsigned long refCount () const =0
 Current reference count. More...
 
virtual StatusCode queryInterface (const InterfaceID &ti, void **pp)=0
 Set the void** to the pointer to the requested interface of the instance. More...
 
virtual ~IInterface ()
 Virtual destructor. More...
 
virtual void * i_cast (const InterfaceID &) const =0
 main cast function More...
 
virtual std::vector< std::string > getInterfaceNames () const =0
 Returns a vector of strings containing the names of all the implemented interfaces. More...
 
virtual unsigned long addRef ()=0
 Increment the reference count of Interface instance. More...
 
virtual unsigned long release ()=0
 Release Interface instance. More...
 
virtual unsigned long refCount () const =0
 Current reference count. More...
 
virtual StatusCode queryInterface (const InterfaceID &ti, void **pp)=0
 Set the void** to the pointer to the requested interface of the instance. More...
 
virtual ~IInterface ()
 Virtual destructor. More...
 

Static Public Member Functions

static const CLIDclassID ()
 Inquire class type. More...
 
- Static Public Member Functions inherited from RootHistCnv::RConverter
static long storageType ()
 Inquire storage type. More...
 
- Static Public Member Functions inherited from IInterface
static const InterfaceIDinterfaceID ()
 Return an instance of InterfaceID identifying the interface. More...
 
static const InterfaceIDinterfaceID ()
 Return an instance of InterfaceID identifying the interface. More...
 

Protected Member Functions

virtual StatusCode load (TTree *tree, INTuple *&refpObject)
 Create the transient representation of an object. More...
 
virtual StatusCode book (const std::string &desc, INTuple *pObject, TTree *&tree)
 Book the N tuple. More...
 
virtual StatusCode writeData (TTree *rtree, INTuple *pObject)
 Write N tuple data. More...
 
virtual StatusCode readData (TTree *rtree, INTuple *pObject, long ievt)
 Read N tuple data. More...
 
template<class T >
size_t saveItem (char *target, const T *src, size_t len)
 
template<typename T >
size_t saveItem (char *target, T *src, size_t len)
 
template<class T >
size_t loadItem (char *src, T *tar, size_t len)
 
size_t loadItem (char *src, bool *tar, size_t len)
 
size_t loadItem (char *src, float *target, size_t len)
 
size_t loadItem (char *src, double *target, size_t len)
 
size_t loadItem (char *src, long *target, size_t len)
 
size_t loadItem (char *src, unsigned long *target, size_t len)
 
- Protected Member Functions inherited from RootHistCnv::RNTupleCnv
 RNTupleCnv (ISvcLocator *svc, const CLID &clid)
 Standard constructor. More...
 
virtual ~RNTupleCnv ()
 Standard destructor. More...
 
virtual std::string rootVarType (int)
 Return ROOT type info: More...
 
- Protected Member Functions inherited from RootHistCnv::RConverter
 RConverter (const CLID &clid, ISvcLocator *svc)
 Standard constructor. More...
 
virtual ~RConverter ()
 Standard destructor. More...
 
virtual StatusCode readObject (IOpaqueAddress *pAddr, DataObject *&refpObj)
 Create the transient representation of an object. More...
 
virtual TObject * createPersistent (DataObject *pObj)
 Create the persistent representation of an object. More...
 
StatusCode createAddress (DataObject *pObject, TDirectory *pDir, TObject *pTObject, IOpaqueAddress *&refpAddr)
 Create address of the transient object according to the requested representation. More...
 
StatusCode createAddress (const std::string &rzdir, const CLID &clid, long id, TObject *pTobj, IOpaqueAddress *&refpAddress)
 
StatusCode createAddress (const std::string &rzdir, const CLID &clid, const std::string &title, TObject *pTobj, IOpaqueAddress *&refpAddress)
 
TDirectory * changeDirectory (DataObject *pObject)
 Switch to object directory (=Parent directory) More...
 
- Protected Member Functions inherited from Converter
virtual ~Converter ()
 Standard Destructor. More...
 
SmartIF< ISvcLocator > & serviceLocator () const
 Retrieve pointer to service locator. More...
 
SmartIF< IMessageSvc > & msgSvc () const
 Retrieve pointer to message service. More...
 
SmartIF< IMessageSvc > & messageService () const
 
SmartIF< IDataManagerSvc > & dataManager () const
 Get Data Manager service. More...
 
virtual ~Converter ()
 Standard Destructor. More...
 
SmartIF< ISvcLocator > & serviceLocator () const
 Retrieve pointer to service locator. More...
 
SmartIF< IMessageSvc > & msgSvc () const
 Retrieve pointer to message service. More...
 
SmartIF< IMessageSvc > & messageService () const
 
SmartIF< IDataManagerSvc > & dataManager () const
 Get Data Manager service. More...
 

Additional Inherited Members

- Public Types inherited from Converter
typedef Gaudi::PluginService::Factory< IConverter *, ISvcLocator * > Factory
 
typedef Gaudi::PluginService::Factory< IConverter *, ISvcLocator * > Factory
 
- Public Types inherited from implements1< IConverter >
typedef implements1 base_class
 Typedef to this class. More...
 
typedef implements1 base_class
 Typedef to this class. More...
 
typedef extend_interfaces1< IConverterextend_interfaces_base
 Typedef to the base of this class. More...
 
typedef extend_interfaces1< IConverterextend_interfaces_base
 Typedef to the base of this class. More...
 
typedef extend_interfaces_base::ext_iids interfaces
 MPL set of all the implemented interfaces. More...
 
typedef extend_interfaces_base::ext_iids interfaces
 MPL set of all the implemented interfaces. More...
 
- Public Types inherited from extend_interfaces1< IConverter >
typedef IConverter::iid::iids::type ext_iids
 MPL set of interfaces extended by this one. More...
 
typedef IConverter::iid::iids::type ext_iids
 MPL set of interfaces extended by this one. More...
 
- Public Types inherited from IConverter
enum  Status {
  INVALID_ADDRESS = IInterface::LAST_ERROR+1, INVALID_OBJECT, NO_MEMORY, BAD_STORAGE_TYPE,
  NO_SOURCE_OBJECT, ICONVERSIONSVC_LAST_ERROR, INVALID_ADDRESS = IInterface::LAST_ERROR+1, INVALID_OBJECT,
  NO_MEMORY, BAD_STORAGE_TYPE, NO_SOURCE_OBJECT, ICONVERSIONSVC_LAST_ERROR
}
 Status code. More...
 
enum  Status {
  INVALID_ADDRESS = IInterface::LAST_ERROR+1, INVALID_OBJECT, NO_MEMORY, BAD_STORAGE_TYPE,
  NO_SOURCE_OBJECT, ICONVERSIONSVC_LAST_ERROR, INVALID_ADDRESS = IInterface::LAST_ERROR+1, INVALID_OBJECT,
  NO_MEMORY, BAD_STORAGE_TYPE, NO_SOURCE_OBJECT, ICONVERSIONSVC_LAST_ERROR
}
 Status code. More...
 
- Public Types inherited from IInterface
enum  Status {
  SUCCESS = 1, NO_INTERFACE, VERSMISMATCH, LAST_ERROR,
  SUCCESS = 1, NO_INTERFACE, VERSMISMATCH, LAST_ERROR
}
 Return status. More...
 
enum  Status {
  SUCCESS = 1, NO_INTERFACE, VERSMISMATCH, LAST_ERROR,
  SUCCESS = 1, NO_INTERFACE, VERSMISMATCH, LAST_ERROR
}
 Return status. More...
 
typedef Gaudi::InterfaceId< IInterface, 0, 0 > iid
 Interface ID. More...
 
typedef mpl::set1< iidext_iids
 Extra interfaces. More...
 
typedef Gaudi::InterfaceId< IInterface, 0, 0 > iid
 Interface ID. More...
 
typedef mpl::set1< iidext_iids
 Extra interfaces. More...
 
- Protected Attributes inherited from RootHistCnv::RNTupleCnv
SmartIF< INTupleSvcm_ntupleSvc
 Reference to N tuple service. More...
 

Detailed Description

Converter of Column-wise NTuple into ROOT format.

Author
Charles Leggett

Definition at line 23 of file RCWNTupleCnv.h.

Constructor & Destructor Documentation

RootHistCnv::RCWNTupleCnv::RCWNTupleCnv ( ISvcLocator svc)
inline

Standard constructor.

Definition at line 30 of file RCWNTupleCnv.h.

30  : RNTupleCnv(svc, classID()) {
31  }
RNTupleCnv(ISvcLocator *svc, const CLID &clid)
Standard constructor.
Definition: RNTupleCnv.cpp:35
static const CLID & classID()
Inquire class type.
Definition: RCWNTupleCnv.h:26
virtual RootHistCnv::RCWNTupleCnv::~RCWNTupleCnv ( )
inlinevirtual

Standard destructor.

Definition at line 33 of file RCWNTupleCnv.h.

33  {
34  }

Member Function Documentation

StatusCode RootHistCnv::RCWNTupleCnv::book ( const std::string &  desc,
INTuple pObject,
TTree *&  tree 
)
protectedvirtual

Book the N tuple.

Implements RootHistCnv::RNTupleCnv.

Definition at line 91 of file RCWNTupleCnv.cpp.

95 {
96  MsgStream log(msgSvc(), "RCWNTupleCnv");
97  rtree = new TTree(desc.c_str(), nt->title().c_str());
98  log << MSG::VERBOSE << "created tree id: " << rtree->GetName()
99  << " title: "<< nt->title() << " desc: " << desc << endmsg;
100 
101  // Loop over the items
102 
103  std::string block_name,var_name;
104  long lowerRange, upperRange;
105  long size = 0;
106  long cursize, oldsize = 0;
107  std::vector<std::string> item_fullname;
108  // std::vector<long> item_size,item_size2;
109  std::vector<long> item_buf_pos, item_buf_len, item_buf_end;
110  std::vector<long> item_range_lower, item_range_upper;
111  std::vector<std::pair<std::string,std::string> > item_name;
112 
113  const INTuple::ItemContainer& cols = nt->items();
114  for (INTuple::ItemContainer::const_iterator i = cols.begin();
115  i != cols.end(); ++i ) {
116  std::string item = "";
117 
118  switch( (*i)->type() ) {
119  case DataTypeInfo::INT: // int
120  analyzeItem(rootVarType( (*i)->type() ),
121  dynamic_cast<const NTuple::_Data<int>*>(*i),item,
122  block_name,var_name,lowerRange,upperRange,size);
123  break;
124  case DataTypeInfo::CHAR: // char
125  analyzeItem(rootVarType( (*i)->type() ),
126  dynamic_cast<const NTuple::_Data<char>*>(*i),
127  item, block_name,var_name,lowerRange,upperRange,size);
128  break;
129  case DataTypeInfo::SHORT: // short
130  analyzeItem(rootVarType( (*i)->type() ),
131  dynamic_cast<const NTuple::_Data<short>*>(*i),item,
132  block_name,var_name,lowerRange,upperRange,size);
133  break;
134  case DataTypeInfo::LONG: // long
135  analyzeItem(rootVarType( (*i)->type() ),
136  dynamic_cast<const NTuple::_Data<long>*>(*i),item,
137  block_name,var_name,lowerRange,upperRange,size);
138  break;
139  case DataTypeInfo::LONGLONG: // long long
140  analyzeItem(rootVarType( (*i)->type() ),
141  dynamic_cast<const NTuple::_Data<long long>*>(*i),item,
142  block_name,var_name,lowerRange,upperRange,size);
143  break;
144  case DataTypeInfo::UCHAR: // unsigned char
145  analyzeItem(rootVarType( (*i)->type() ),
146  dynamic_cast<const NTuple::_Data<unsigned char>*>(*i),
147  item, block_name,var_name,lowerRange,upperRange,size);
148  break;
149  case DataTypeInfo::USHORT: // unsigned short
150  analyzeItem(rootVarType( (*i)->type() ),
151  dynamic_cast<const NTuple::_Data<unsigned short>*>(*i),
152  item, block_name,var_name,lowerRange,upperRange,size);
153  break;
154  case DataTypeInfo::UINT: // unsigned int
155  analyzeItem(rootVarType( (*i)->type() ),
156  dynamic_cast<const NTuple::_Data<unsigned int>*>(*i),
157  item, block_name,var_name,lowerRange,upperRange,size);
158  break;
159  case DataTypeInfo::ULONG: // unsigned long
160  analyzeItem(rootVarType( (*i)->type() ),
161  dynamic_cast<const NTuple::_Data<unsigned long>*>(*i),
162  item, block_name,var_name,lowerRange,upperRange,size);
163  break;
164  case DataTypeInfo::ULONGLONG: // unsigned long long
165  analyzeItem(rootVarType( (*i)->type() ),
166  dynamic_cast<const NTuple::_Data<unsigned long long>*>(*i),
167  item, block_name,var_name,lowerRange,upperRange,size);
168  break;
169  case DataTypeInfo::DOUBLE: // double
170  analyzeItem(rootVarType( (*i)->type() ),
171  dynamic_cast<const NTuple::_Data<double>*>(*i),item,
172  block_name,var_name,lowerRange,upperRange,size);
173  break;
174  case DataTypeInfo::FLOAT: // float
175  analyzeItem(rootVarType( (*i)->type() ),
176  dynamic_cast<const NTuple::_Data<float>*>(*i),item,
177  block_name,var_name,lowerRange,upperRange,size);
178  break;
179  case DataTypeInfo::BOOL: // bool
180  analyzeItem(rootVarType( (*i)->type() ),
181  dynamic_cast<const NTuple::_Data<bool>*>(*i),item,
182  block_name,var_name,lowerRange,upperRange,size);
183  break;
184  default:
185  break;
186  }
187 
188  item_name.push_back(std::pair<std::string,std::string>(block_name,item));
189  cursize = size - oldsize;
190 
191  log << MSG::VERBOSE << "item: " << item << " type " << (*i)->type()
192  << " blk: " << block_name
193  << " var: " << var_name << " rng: " << lowerRange << " "
194  << upperRange << " sz: " << size << " " << cursize
195  << " buf_pos: " << size-cursize << endmsg;
196 
197  item_fullname.push_back(var_name);
198  item_buf_pos.push_back(size-cursize);
199  item_buf_len.push_back(cursize);
200  item_buf_end.push_back(size);
201  item_range_lower.push_back(lowerRange);
202  item_range_upper.push_back(upperRange);
203 
204  oldsize = size;
205  }
206 
207  char* buff = new char[size];
208  log << MSG::VERBOSE << "Created buffer size: " << size << " at "
209  << (void*)buff << endmsg;
210 
211  // Zero out the buffer to make ROOT happy
212  memset (buff,0,size);
213 
214  // Tell the ntuple where it is
215  nt->setBuffer(buff);
216 
217  char *buf_pos = buff;
218 
219  std::vector<std::pair<std::string,std::string> >::const_iterator itr,end;
220  end = item_name.end();
221 
222  // Loop over items, creating a new branch for each one;
223  unsigned int i_item = 0;
224  for (itr=item_name.begin(); itr!=end; ++itr, ++i_item) {
225 
226  buf_pos = buff + item_buf_pos[i_item];
227 
228 // log << MSG::WARNING << "adding TBranch " << i_item << " "
229 // << item_fullname[i_item]
230 // << " format: " << itr->second.c_str() << " at "
231 // << (void*) buf_pos << " (" << (void*) buff << "+"
232 // << (void*)item_buf_pos[i_item] << ")"
233 // << endmsg;
234 
235 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,15,0)
236  TBranch *br = new TBranch(rtree,
237 #else
238  TBranch *br = new TBranch(
239 #endif
240  item_fullname[i_item].c_str(),
241  buf_pos,
242  itr->second.c_str()
243  );
244 
245  if (itr->first != "AUTO_BLK") {
246  std::string tit = itr->first;
247  tit = itr->first + "::" + br->GetTitle();
248  br->SetTitle(tit.c_str());
249  }
250 
251  log << MSG::DEBUG << "adding TBranch " << br->GetTitle() << " at "
252  << (void*) buf_pos << endmsg;
253 
254 
255  // for index items with a limited range. Must be a TLeafI!
256  if ( item_range_lower[i_item] < item_range_upper[i_item] ) {
257 // log << MSG::VERBOSE << "\"" << item_fullname[i_item]
258 // << "\" is range limited " << item_range_lower[i_item] << " "
259 // << item_range_upper[i_item] << endmsg;
260  TLeafI *index = 0;
261  TObject *tobj = br->GetListOfLeaves()->FindObject( item_fullname[i_item].c_str() );
262  if (tobj->IsA()->InheritsFrom("TLeafI")) {
263  index = dynamic_cast<TLeafI*>(tobj);
264 
265  if (index != 0) {
266  index->SetMaximum( item_range_upper[i_item] );
267  // FIXME -- add for next version of ROOT
268  // index->SetMinimum( item_range_lower[i_item] );
269  } else {
270  log << MSG::ERROR << "Could dynamic cast to TLeafI: "
271  << item_fullname[i_item] << endmsg;
272  }
273  }
274  }
275 
276  rtree->GetListOfBranches()->Add(br);
277 
278  }
279 
280 
281  log << MSG::INFO << "Booked TTree with ID: " << desc
282  << " \"" << nt->title() << "\" in directory "
283  << getDirectory() << endmsg;
284 
285  return StatusCode::SUCCESS;
286 
287 }
std::string getDirectory()
Definition: RConverter.cpp:162
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
std::vector< INTupleItem * > ItemContainer
Definition: INTuple.h:86
SmartIF< IMessageSvc > & msgSvc() const
Retrieve pointer to message service.
Definition: Converter.cpp:131
Abstract class describing basic data in an Ntuple.
Definition: NTuple.h:38
tuple end
Definition: IOTest.py:101
tuple item
print s1,s2
Definition: ana.py:146
list i
Definition: ana.py:128
void analyzeItem(std::string typ, const NTuple::_Data< T > *it, std::string &desc, std::string &block_name, std::string &var_name, long &lowerRange, long &upperRange, long &size)
virtual std::string rootVarType(int)
Return ROOT type info:
Definition: RNTupleCnv.cpp:229
static const CLID& RootHistCnv::RCWNTupleCnv::classID ( )
inlinestatic

Inquire class type.

Definition at line 26 of file RCWNTupleCnv.h.

26  {
27  return CLID_ColumnWiseTuple;
28  }
StatusCode RootHistCnv::RCWNTupleCnv::load ( TTree *  tree,
INTuple *&  refpObject 
)
protectedvirtual

Create the transient representation of an object.

Implements RootHistCnv::RNTupleCnv.

Definition at line 428 of file RCWNTupleCnv.cpp.

430 {
431  MsgStream log(msgSvc(), "RCWNTupleCnv::load");
432 
433  StatusCode status;
434 
435  NTuple::Tuple *pObj = 0;
436 
437  std::string title = tree->GetTitle();
438  log << MSG::VERBOSE << "loading CWNT " << title << " at: "
439  << tree << endmsg;
440 
441  status = m_ntupleSvc->create(CLID_ColumnWiseTuple, title, pObj);
442  INTuple* ntup = dynamic_cast<INTuple*>(pObj);
443 
444  INTupleItem* item=0;
445 
446  std::string itemName, indexName, item_type, itemTitle, blockName;
447  // long numEnt, numVar;
448  long size, totsize=0;
449  std::list< std::pair<TLeaf*,int> > itemList;
450 
451  // numEnt = (int)tree->GetEntries();
452  // numVar = tree->GetNbranches();
453 
454  // loop over all branches (==leaves)
455  TObjArray* lbr = tree->GetListOfBranches();
456  TIter bitr ( lbr );
457  while ( TObject *tobjb = bitr() ) {
458 
459  TBranch* br = (TBranch*)tobjb;
460  itemTitle = br->GetTitle();
461 
462  int ipos = itemTitle.find("::");
463  if (ipos >= 0) {
464  blockName = itemTitle.substr(0,ipos);
465  } else {
466  blockName = "";
467  }
468 
469  TObjArray* lf = br->GetListOfLeaves();
470 
471  TIter litr ( lf );
472  while ( TObject *tobj = litr() ) {
473 
474  bool hasRange=false;
475  int indexRange = 0;
476  int itemSize;
477  item = 0;
478 
479  // TLeaf* tl = (TLeaf*)tobj;
480  TLeaf* tl = dynamic_cast<TLeaf*> (tobj);
481  itemName = tl->GetName();
482 
483  // char* buf_pos = (char*)tl->GetValuePointer();
484  // cout << " " << itemName << " " << blockName << " "
485  // << (void*)buf_pos;
486 
487 
488  if (blockName != "") {
489  log << MSG::DEBUG << "loading NTuple item " << blockName << "/"
490  << itemName;
491  } else {
492  log << MSG::DEBUG << "loading NTuple item " << itemName;
493  }
494 
495  int arraySize;
496  TLeaf* indexLeaf = tl->GetLeafCounter(arraySize);
497 
498  if (arraySize == 0) {
499  log << MSG::ERROR << "TLeaf counter size = 0. This should not happen!"
500  << endmsg;
501  }
502 
503  if (indexLeaf != 0) {
504  //index Arrays and Matrices
505 
506  indexName = indexLeaf->GetName();
507  // indexRange = tl->GetNdata();
508  indexRange = indexLeaf->GetMaximum();
509  itemSize = indexRange * tl->GetLenType() * arraySize;
510 
511  log << "[" << indexName;
512 
513  // Just for Matrices
514  if (arraySize != 1) {
515  log << "][" << arraySize;
516  }
517  log << "]";
518 
519  } else {
520  itemSize = tl->GetLenType() * arraySize;
521 
522  indexName = "";
523 
524  if (arraySize == 1) {
525  // Simple items
526  } else {
527  // Arrays of constant size
528  log << "[" << arraySize << "]";
529  }
530  }
531 
532  log << endmsg;
533 
534  // cout << " index: " << indexName << endl;
535 
536  // size = tl->GetNdata() * tl->GetLenType();
537  size = itemSize;
538  totsize += size;
539 
540  hasRange = tl->IsRange();
541 
542  itemList.push_back(std::pair<TLeaf*,int>(tl,itemSize));
543 
544 
545  // Integer
546  if (tobj->IsA()->InheritsFrom("TLeafI")) {
547 
548  TLeafI *tli = dynamic_cast<TLeafI*>(tobj);
549  if (tli->IsUnsigned()) {
550  unsigned long min=0, max=0;
551  if (hasRange) {
552  min = tli->GetMinimum();
553  max = tli->GetMaximum();
554  }
555 
556  item = createNTupleItem(itemName, blockName, indexName, indexRange,
557  arraySize,
558  min, max, ntup);
559  } else {
560  long min=0, max=0;
561  if (hasRange) {
562  min = tli->GetMinimum();
563  max = tli->GetMaximum();
564  }
565 
566  item = createNTupleItem(itemName, blockName, indexName, indexRange,
567  arraySize,
568  min, max, ntup);
569  }
570 
571  // Float
572  } else if (tobj->IsA()->InheritsFrom("TLeafF")) {
573  float min=0., max=0.;
574 
575  TLeafF *tlf = dynamic_cast<TLeafF*>(tobj);
576  if (hasRange) {
577  min = float(tlf->GetMinimum());
578  max = float(tlf->GetMaximum());
579  }
580 
581  item = createNTupleItem(itemName, blockName, indexName, indexRange,
582  arraySize,
583  min, max, ntup);
584 
585  // Double
586  } else if (tobj->IsA()->InheritsFrom("TLeafD")) {
587  double min=0., max=0.;
588 
589  TLeafD *tld = dynamic_cast<TLeafD*>(tobj);
590  if (hasRange) {
591  min = tld->GetMinimum();
592  max = tld->GetMaximum();
593  }
594 
595  item = createNTupleItem(itemName, blockName, indexName, indexRange,
596  arraySize,
597  min, max, ntup);
598 
599 
600  } else {
601  log << MSG::ERROR << "Uknown data type" << endmsg;
602  }
603 
604 
605  if (item) {
606  ntup->add(item);
607  } else {
608  log << MSG::ERROR
609  << "Unable to create ntuple item \""
610  << itemName << "\"" << endmsg;
611  }
612 
613  } // end litr
614  } // end bitr
615 
616  log << MSG::DEBUG << "Total buffer size of NTuple: " << totsize
617  << " Bytes." << endmsg;
618 
619  char* buf = new char[totsize];
620  char* bufpos = buf;
621 
622  ntup->setBuffer(buf);
623 
624  std::list< std::pair<TLeaf*,int> >::const_iterator iitr = itemList.begin();
625  int ts = 0;
626  for (; iitr!= itemList.end(); ++iitr) {
627  TLeaf* leaf = (*iitr).first;
628  int isize = (*iitr).second;
629 
630  log << MSG::VERBOSE << "setting TBranch " << leaf->GetBranch()->GetName()
631  << " buffer at " << (void*) bufpos << endmsg;
632 
633  leaf->GetBranch()->SetAddress((void*)bufpos);
634 
635 // //testing
636 // if (leaf->IsA()->InheritsFrom("TLeafI")) {
637 // for (int ievt=0; ievt<5; ievt++) {
638 // leaf->GetBranch()->GetEvent(ievt);
639 // int *idat = (int*)bufpos;
640 // log << MSG::WARNING << leaf->GetName() << ": " << ievt << " "
641 // << *idat << endmsg;
642 
643 // }
644 // }
645 
646  ts += isize;
647 
648  bufpos += isize;
649  }
650 
651  if (totsize != ts ) {
652  log << MSG::ERROR << "buffer size mismatch: " << ts << " " << totsize
653  << endmsg;
654  }
655 
656  refpObject = ntup;
657 
658  return StatusCode::SUCCESS;
659 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
virtual StatusCode add(INTupleItem *item)=0
Add an item row to the N tuple.
SmartIF< IMessageSvc > & msgSvc() const
Retrieve pointer to message service.
Definition: Converter.cpp:131
NTuple interface class definition.
Definition: INTuple.h:80
NTuple interface class definition.
Definition: INTuple.h:27
virtual StatusCode create(const CLID &typ, const std::string &title, NTuple::Tuple *&refpTuple)=0
Create requested N tuple (Hide constructor)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
Abstract base class which allows the user to interact with the actual N tuple implementation.
Definition: NTuple.h:367
virtual void setBuffer(char *buff)=0
Attach data buffer.
#define min(a, b)
tuple item
print s1,s2
Definition: ana.py:146
SmartIF< INTupleSvc > m_ntupleSvc
Reference to N tuple service.
Definition: RNTupleCnv.h:58
INTupleItem * createNTupleItem(std::string itemName, std::string blockName, std::string indexName, int indexRange, int arraySize, TYP min, TYP max, INTuple *ntup)
Definition: RNTupleCnv.cpp:275
template<class T >
size_t RootHistCnv::RCWNTupleCnv::loadItem ( char *  src,
T *  tar,
size_t  len 
)
inlineprotected

Definition at line 60 of file RCWNTupleCnv.h.

60  {
61  long* s = (long*)src;
62  for ( size_t i = 0; i < len; i++ ) {
63  *(tar++) = T( *(s++));
64  }
65  return sizeof(long)*len;
66  }
string s
Definition: gaudirun.py:244
list i
Definition: ana.py:128
size_t RootHistCnv::RCWNTupleCnv::loadItem ( char *  src,
bool *  tar,
size_t  len 
)
inlineprotected

Definition at line 67 of file RCWNTupleCnv.h.

67  {
68  long* s = (long*)src;
69  for ( size_t i = 0; i < len; i++ ) {
70  *(tar++) = (*(s++)) ? true : false;
71  }
72  return sizeof(long)*len;
73  }
string s
Definition: gaudirun.py:244
list i
Definition: ana.py:128
size_t RootHistCnv::RCWNTupleCnv::loadItem ( char *  src,
float *  target,
size_t  len 
)
inlineprotected

Definition at line 74 of file RCWNTupleCnv.h.

74  {
75  memcpy(target, src, sizeof(float)*len);
76  return sizeof(float)*len;
77  }
size_t RootHistCnv::RCWNTupleCnv::loadItem ( char *  src,
double *  target,
size_t  len 
)
inlineprotected

Definition at line 78 of file RCWNTupleCnv.h.

78  {
79  memcpy(target, src, sizeof(double)*len);
80  return sizeof(double)*len;
81  }
size_t RootHistCnv::RCWNTupleCnv::loadItem ( char *  src,
long *  target,
size_t  len 
)
inlineprotected

Definition at line 82 of file RCWNTupleCnv.h.

82  {
83  memcpy(target, src, sizeof(long)*len);
84  return sizeof(long)*len;
85  }
size_t RootHistCnv::RCWNTupleCnv::loadItem ( char *  src,
unsigned long *  target,
size_t  len 
)
inlineprotected

Definition at line 86 of file RCWNTupleCnv.h.

86  {
87  memcpy(target, src, sizeof(unsigned long)*len);
88  return sizeof(unsigned long)*len;
89  }
StatusCode RootHistCnv::RCWNTupleCnv::readData ( TTree *  rtree,
INTuple pObject,
long  ievt 
)
protectedvirtual

Read N tuple data.

Implements RootHistCnv::RNTupleCnv.

Definition at line 351 of file RCWNTupleCnv.cpp.

355 {
356  MsgStream log(msgSvc(), "RCWNTupleCnv::readData");
357 
358  if (ievt >= rtree->GetEntries()) {
359  log << MSG::ERROR << "no more entries in tree to read. max: "
360  << rtree->GetEntries() << " current: " << ievt
361  << endmsg;
362  return StatusCode::FAILURE;
363  }
364 
365  rtree->GetEvent(ievt);
366 
367  ievt++;
368 
369  INTuple::ItemContainer& cols = ntup->items();
370  char * src = ntup->buffer();
371 
372  // copy data from ntup->buffer() to ntup->items()->buffer()
373 
374  for (INTuple::ItemContainer::iterator i = cols.begin(); i != cols.end(); i++ ) {
375 
376 
377  switch( (*i)->type() ) {
378  case DataTypeInfo::BOOL: // bool
379  src += loadItem(src, (bool*)(*i)->buffer(), (*i)->length());
380  break;
381  case DataTypeInfo::CHAR: // char
382  src += loadItem(src, (char*)(*i)->buffer(), (*i)->length());
383  break;
384  case DataTypeInfo::SHORT: // short
385  src += loadItem(src, (short*)(*i)->buffer(), (*i)->length());
386  break;
387  case DataTypeInfo::INT: // short
388  src += loadItem(src, (int*)(*i)->buffer(), (*i)->length());
389  break;
390  case DataTypeInfo::LONG: // long
391  src += loadItem(src, (long*)(*i)->buffer(), (*i)->length());
392  break;
393  case DataTypeInfo::LONGLONG: // long long
394  src += loadItem(src, (long long*)(*i)->buffer(), (*i)->length());
395  break;
396  case DataTypeInfo::UCHAR: // unsigned char
397  src += loadItem(src, (unsigned char*)(*i)->buffer(), (*i)->length());
398  break;
399  case DataTypeInfo::USHORT: // unsigned short
400  src += loadItem(src, (unsigned short*)(*i)->buffer(), (*i)->length());
401  break;
402  case DataTypeInfo::UINT: // unsigned short
403  src += loadItem(src, (unsigned int*)(*i)->buffer(), (*i)->length());
404  break;
405  case DataTypeInfo::ULONG: // unsigned long
406  src += loadItem(src, (unsigned long*)(*i)->buffer(), (*i)->length());
407  break;
408  case DataTypeInfo::ULONGLONG: // unsigned long long
409  src += loadItem(src, (unsigned long long*)(*i)->buffer(), (*i)->length());
410  break;
411  case DataTypeInfo::FLOAT: // float
412  src += loadItem(src, (float*)(*i)->buffer(), (*i)->length());
413  break;
414  case DataTypeInfo::DOUBLE: // unsigned short
415  src += loadItem(src, (double*)(*i)->buffer(), (*i)->length());
416  break;
417  default:
418  break;
419  }
420 
421  }
422 
423  return StatusCode::SUCCESS;
424 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
std::vector< INTupleItem * > ItemContainer
Definition: INTuple.h:86
SmartIF< IMessageSvc > & msgSvc() const
Retrieve pointer to message service.
Definition: Converter.cpp:131
size_t loadItem(char *src, T *tar, size_t len)
Definition: RCWNTupleCnv.h:60
list i
Definition: ana.py:128
template<class T >
size_t RootHistCnv::RCWNTupleCnv::saveItem ( char *  target,
const T *  src,
size_t  len 
)
inlineprotected

Definition at line 46 of file RCWNTupleCnv.h.

46  {
47  long* tar = (long*)target;
48  for ( size_t i = 0; i < len; i++ ) {
49  *(tar++) = long( *(src++));
50  }
51  return sizeof(long)*len;
52  }
list i
Definition: ana.py:128
template<typename T >
size_t RootHistCnv::RCWNTupleCnv::saveItem ( char *  target,
T *  src,
size_t  len 
)
inlineprotected

Definition at line 54 of file RCWNTupleCnv.h.

54  {
55  memcpy(target, src, sizeof(T)*len);
56  return sizeof(T)*len;
57  }
StatusCode RootHistCnv::RCWNTupleCnv::writeData ( TTree *  rtree,
INTuple pObject 
)
protectedvirtual

Write N tuple data.

Implements RootHistCnv::RNTupleCnv.

Definition at line 292 of file RCWNTupleCnv.cpp.

294 {
295  // Fill the tree;
296  const INTuple::ItemContainer& cols = nt->items();
297  char * tar = nt->buffer();
298  for (INTuple::ItemContainer::const_iterator i = cols.begin(); i != cols.end(); i++ ) {
299  switch( (*i)->type() ) {
300  case DataTypeInfo::BOOL: // bool
301  tar += saveItem(tar, (bool*)(*i)->buffer(), (*i)->length());
302  break;
303  case DataTypeInfo::CHAR: // char
304  tar += saveItem(tar, (char*)(*i)->buffer(), (*i)->length());
305  break;
306  case DataTypeInfo::SHORT: // short
307  tar += saveItem(tar, (short*)(*i)->buffer(), (*i)->length());
308  break;
309  case DataTypeInfo::INT: // int
310  tar += saveItem(tar, (int*)(*i)->buffer(), (*i)->length());
311  break;
312  case DataTypeInfo::LONG: // long
313  tar += saveItem(tar, (long*)(*i)->buffer(), (*i)->length());
314  break;
315  case DataTypeInfo::LONGLONG: // long long
316  tar += saveItem(tar, (long long*)(*i)->buffer(), (*i)->length());
317  break;
318  case DataTypeInfo::UCHAR: // unsigned char
319  tar += saveItem(tar, (unsigned char*)(*i)->buffer(), (*i)->length());
320  break;
321  case DataTypeInfo::USHORT: // unsigned short
322  tar += saveItem(tar, (unsigned short*)(*i)->buffer(), (*i)->length());
323  break;
324  case DataTypeInfo::UINT: // unsigned int
325  tar += saveItem(tar, (unsigned int*)(*i)->buffer(), (*i)->length());
326  break;
327  case DataTypeInfo::ULONG: // unsigned long
328  tar += saveItem(tar, (unsigned long*)(*i)->buffer(), (*i)->length());
329  break;
330  case DataTypeInfo::ULONGLONG: // unsigned long
331  tar += saveItem(tar, (unsigned long long*)(*i)->buffer(), (*i)->length());
332  break;
333  case DataTypeInfo::FLOAT: // float
334  tar += saveItem(tar, (float*)(*i)->buffer(), (*i)->length());
335  break;
336  case DataTypeInfo::DOUBLE: // double
337  tar += saveItem(tar, (double*)(*i)->buffer(), (*i)->length());
338  break;
339  default:
340  break;
341  }
342  }
343 
344  rtree->Fill();
345  nt->reset();
346  return StatusCode::SUCCESS;
347 }
std::vector< INTupleItem * > ItemContainer
Definition: INTuple.h:86
size_t saveItem(char *target, const T *src, size_t len)
Definition: RCWNTupleCnv.h:46
list i
Definition: ana.py:128

The documentation for this class was generated from the following files: