1 #ifndef __JGIZMO__JMANAGER__
2 #define __JGIZMO__JMANAGER__
26 namespace JPP {
using namespace JGIZMO; }
41 template<
class JKey_t,
class JValue_t>
44 public std::map<JKey_t, JPointer<JValue_t>>
71 std::ios::fmtflags format = std::ios::fmtflags()) :
84 if (
string(this->
get()->GetName()).find(
wc) == string::npos) {
85 THROW(
JException,
"Invalid wildcard <" << this->
get()->GetName() <<
"> '" <<
wc <<
"'");
106 std::ios::fmtflags format,
107 const std::string&
name) :
120 this->
get()->SetName(name.c_str());
122 if (
string(this->
get()->GetName()).find(
wc) == string::npos) {
123 THROW(
JException,
"Invalid wildcard <" << this->
get()->GetName() <<
"> '" <<
wc <<
"'");
148 this->
set((JValue_t*) manager.
get()->Clone());
160 for (
typename map_type::iterator i = this->begin(); i != this->end(); ++i) {
179 typename map_type::iterator i = this->find(key);
181 if (i == this->end()) {
183 string buffer = this->
get()->GetName();
184 string::size_type ipos = buffer.find(
wc);
192 buffer.replace(ipos, 1, os.str());
194 JValue_t* p = (JValue_t*) this->
get()->Clone(buffer.c_str());
198 this->insert(make_pair(key,p));
217 static JManager Read(TDirectory&
in,
const char*
const master,
const char wildcard)
226 const Ssiz_t pos = buffer.Index(wildcard);
228 const TString
a = buffer(0, pos);
229 const TString b = buffer(pos+1, buffer.Length());
231 buffer.ReplaceAll(
"[",
"\\[");
232 buffer.ReplaceAll(
"]",
"\\]");
234 buffer.ReplaceAll(wildcard,
".*");
236 const TRegexp regexp(buffer);
238 TIter iter(in.GetListOfKeys());
240 for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
242 const TString tag(key->GetName());
246 if (tag.Index(regexp) != -1) {
248 JValue_t* p =
dynamic_cast<JValue_t*
>(key->ReadObj());
254 string buffer = p->GetName();
256 if (
a.Length() != 0) { buffer.replace(buffer.find(
a),
a.Length(),
""); }
257 if (b.Length() != 0) { buffer.replace(buffer.find(b), b.Length(),
""); }
261 istringstream(buffer) >> key;
263 manager.insert(make_pair(key, p));
294 void Write(TDirectory& out,
const bool wm =
false)
296 for (
typename map_type::iterator i = this->begin(); i != this->end(); ++i) {
297 out.WriteTObject(i->second);
301 out.WriteTObject(this->
get());
312 void Write(
const char* file_name,
const bool wm =
false)
314 TFile out(file_name,
"RECREATE");
316 this->
Write(out, wm) ;
364 template<
class JKey_t,
class JValue_t>
friend TFile & operator<<(TFile &file, JManager &object)
Write manager to file.
void clear()
Clear client objects.
void Read(TDirectory &in)
Read objects from file.
static JManager Read(TDirectory &in, const char *const master, const char wildcard)
Read objects from file into manager.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
esac print_variable DETECTOR INPUT_FILE OUTPUT_FILE CDF for TYPE in
JManager(JValue_t *master, char wildcard= '%', std::ios::fmtflags format=std::ios::fmtflags())
Constructor.
then echo Test string reversed by master(hit< return > to continue)." JProcess -c "JEcho" -rC fi if (( 1 ))
JManager(JValue_t *master, char wildcard, std::ios::fmtflags format, const std::string &name)
Constructor.
JManager()
Default constructor.
friend TFile & operator>>(TFile &file, JManager &object)
Read manager from file.
fi JEventTimesliceWriter a
bool is_valid() const
Check validity of pointer.
Auxiliary class to manage set of compatible ROOT objects (e.g.
virtual void reset()
Reset pointer.
std::map< JKey_t, ptr_type > map_type
void Write(TDirectory &out, const bool wm=false)
Write objects to file.
Template implementation of class that holds pointer to object(s).
JManager(const JManager &manager)
Copy constructor.
virtual JClass_t * get() const
Get pointer.
JValue_t * operator[](JKey_t key)
Get pointer to object for given key.
bool resetObject(JManager< JKey_t, JValue_t > *object, const bool reset=false)
Reset JManager object.
JPointer< JValue_t > ptr_type
void Write(const char *file_name, const bool wm=false)
Write objects to file.
bool resetObject(TH1 *object, const bool reset=false)
Reset TH1 object.
virtual void set(JClass_t *p)
Set pointer.