1 #ifndef __JROOT__JMANAGER__
2 #define __JROOT__JMANAGER__
28 namespace JPP {
using namespace JROOT; }
43 template<
class JKey_t,
class JValue_t>
46 public std::map<JKey_t, JPointer<JValue_t>>
86 if (
string(this->
get()->GetName()).find(
wc) == string::npos) {
109 const std::string& name,
111 std::ios::fmtflags format = std::ios::fmtflags()) :
124 this->
get()->SetName(name.c_str());
126 if (
string(this->
get()->GetName()).find(
wc) == string::npos) {
154 this->
set((JValue_t*) manager.
get()->Clone());
168 for (
typename map_type::iterator i = this->begin(); i != this->end(); ++i) {
187 typename map_type::iterator i = this->find(key);
189 if (i == this->end()) {
191 string buffer = this->
get()->GetName();
192 string::size_type ipos = buffer.find(
wc);
200 buffer.replace(ipos, 1, os.str());
202 JValue_t* p = (JValue_t*) this->
get()->Clone(buffer.c_str());
208 this->insert(make_pair(key,p));
227 static JManager Read(TDirectory& in,
const char*
const master,
const char wildcard)
234 TString buffer = master;
236 const Ssiz_t pos = buffer.Index(wildcard);
238 const TString
a = buffer(0, pos);
239 const TString b = buffer(pos+1, buffer.Length());
241 buffer.ReplaceAll(
"[",
"\\[");
242 buffer.ReplaceAll(
"]",
"\\]");
244 buffer.ReplaceAll(wildcard,
".*");
246 const TRegexp regexp(buffer);
248 TIter iter(in.GetListOfKeys());
250 for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
252 const TString tag(key->GetName());
256 if (tag.Index(regexp) != -1) {
258 JValue_t* p =
dynamic_cast<JValue_t*
>(key->ReadObj());
264 string buffer = p->GetName();
266 if (
a.Length() != 0) { buffer.replace(buffer.find(
a),
a.Length(),
""); }
267 if (b.Length() != 0) { buffer.replace(buffer.find(b), b.Length(),
""); }
271 istringstream(buffer) >> key;
273 manager.insert(make_pair(key, p));
304 void Write(TDirectory& out,
const bool wm =
false)
306 for (
typename map_type::iterator i = this->begin(); i != this->end(); ++i) {
307 out.WriteTObject(i->second);
311 out.WriteTObject(this->
get());
322 void Write(
const char* file_name,
const bool wm =
false)
324 TFile out(file_name,
"RECREATE");
326 this->
Write(out, wm) ;
393 template<
class JKey_t,
class JValue_t>
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
bool is_valid() const
Check validity of pointer.
Template implementation of class that holds pointer to object(s).
virtual JClass_t * get() const override
Get pointer.
virtual void set(JClass_t *p) override
Set pointer.
virtual void reset() override
Reset pointer.
Auxiliary class to manage set of compatible ROOT objects (e.g. histograms) using unique keys.
JManager(const JManager &manager)
Copy constructor.
static void detach(TH1 *p)
Implementation for detaching of object pointed to from ROOT I/O.
void Read(TDirectory &in)
Read objects from file.
JPointer< JValue_t > ptr_type
static JManager Read(TDirectory &in, const char *const master, const char wildcard)
Read objects from file into manager.
JManager(JValue_t *master, char wildcard='%', JFormat_t format=JFormat_t())
Constructor.
friend TFile & operator>>(TFile &file, JManager &object)
Read manager from file.
JValue_t * operator[](JKey_t key)
Get pointer to object for given key.
std::map< JKey_t, ptr_type > map_type
friend TFile & operator<<(TFile &file, JManager &object)
Write manager to file.
JManager()
Default constructor.
void Write(TDirectory &out, const bool wm=false)
Write objects to file.
JManager(JValue_t *master, const std::string &name, char wildcard='%', std::ios::fmtflags format=std::ios::fmtflags())
Constructor.
void Write(const char *file_name, const bool wm=false)
Write objects to file.
void clear()
Clear client objects.
static void detach(...)
Fall back for detaching object pointed to from ROOT I/O.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary classes and methods for ROOT I/O.
void resetObject(JManager< JKey_t, JValue_t > *object, const bool reset=false)
Reset JManager object.