1 #ifndef __JROOT__JMANAGER__
2 #define __JROOT__JMANAGER__
27 namespace JPP {
using namespace JROOT; }
42 template<
class JKey_t,
class JValue_t>
45 public std::map<JKey_t, JPointer<JValue_t>>
85 if (
string(this->
get()->GetName()).find(
wc) == string::npos) {
86 THROW(
JException,
"Invalid wildcard <" << this->
get()->GetName() <<
"> '" <<
wc <<
"'");
106 const std::string&
name,
108 std::ios::fmtflags format = std::ios::fmtflags()) :
121 this->
get()->SetName(name.c_str());
123 if (
string(this->
get()->GetName()).find(
wc) == string::npos) {
124 THROW(
JException,
"Invalid wildcard <" << this->
get()->GetName() <<
"> '" <<
wc <<
"'");
149 this->
set((JValue_t*) manager.
get()->Clone());
161 for (
typename map_type::iterator i = this->begin(); i != this->end(); ++i) {
180 typename map_type::iterator i = this->find(key);
182 if (i == this->end()) {
184 string buffer = this->
get()->GetName();
185 string::size_type ipos = buffer.find(
wc);
193 buffer.replace(ipos, 1, os.str());
195 JValue_t* p = (JValue_t*) this->
get()->Clone(buffer.c_str());
199 this->insert(make_pair(key,p));
218 static JManager Read(TDirectory&
in,
const char*
const master,
const char wildcard)
227 const Ssiz_t pos = buffer.Index(wildcard);
229 const TString
a = buffer(0, pos);
230 const TString b = buffer(pos+1, buffer.Length());
232 buffer.ReplaceAll(
"[",
"\\[");
233 buffer.ReplaceAll(
"]",
"\\]");
235 buffer.ReplaceAll(wildcard,
".*");
237 const TRegexp regexp(buffer);
239 TIter iter(in.GetListOfKeys());
241 for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
243 const TString tag(key->GetName());
247 if (tag.Index(regexp) != -1) {
249 JValue_t* p =
dynamic_cast<JValue_t*
>(key->ReadObj());
255 string buffer = p->GetName();
257 if (
a.Length() != 0) { buffer.replace(buffer.find(
a),
a.Length(),
""); }
258 if (b.Length() != 0) { buffer.replace(buffer.find(b), b.Length(),
""); }
262 istringstream(buffer) >> key;
264 manager.insert(make_pair(key, p));
295 void Write(TDirectory& out,
const bool wm =
false)
297 for (
typename map_type::iterator i = this->begin(); i != this->end(); ++i) {
298 out.WriteTObject(i->second);
302 out.WriteTObject(this->
get());
313 void Write(
const char* file_name,
const bool wm =
false)
315 TFile out(file_name,
"RECREATE");
317 this->
Write(out, wm) ;
365 template<
class JKey_t,
class JValue_t>
void clear()
Clear client objects.
JManager(JValue_t *master, char wildcard= '%', JFormat_t format=JFormat_t())
Constructor.
JPointer< JValue_t > ptr_type
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
then echo Test string reversed by master(hit< return > to continue)." JProcess -c "JEcho" -rC fi if (( 1 ))
void Write(const char *file_name, const bool wm=false)
Write objects to file.
std::map< JKey_t, ptr_type > map_type
JManager(JValue_t *master, const std::string &name, char wildcard= '%', std::ios::fmtflags format=std::ios::fmtflags())
Constructor.
bool is_valid() const
Check validity of pointer.
bool resetObject(JManager< JKey_t, JValue_t > *object, const bool reset=false)
Reset JManager object.
Auxiliary class to manage set of compatible ROOT objects (e.g. histograms) using unique keys...
static JManager Read(TDirectory &in, const char *const master, const char wildcard)
Read objects from file into manager.
JManager(const JManager &manager)
Copy constructor.
Template implementation of class that holds pointer to object(s).
void Write(TDirectory &out, const bool wm=false)
Write objects to file.
void Read(TDirectory &in)
Read objects from file.
then $JPP_DIR software JCalibrate JCalibrateToT a
JValue_t * operator[](JKey_t key)
Get pointer to object for given key.
JManager()
Default constructor.
friend TFile & operator>>(TFile &file, JManager &object)
Read manager from file.
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY source JAcoustics sh $DETECTOR_ID typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
virtual void set(JClass_t *p) override
Set pointer.
virtual JClass_t * get() const override
Get pointer.
friend TFile & operator<<(TFile &file, JManager &object)
Write manager to file.
virtual void reset() override
Reset pointer.