20 #include <TObjString.h>
22 #include "Framework/Conventions/GBuild.h"
27 using namespace genie;
34 using std::ostringstream;
41 string itemtype =
typeid(item).name();
43 <<
"Set item [" << itemtype <<
"]: key = "
44 << key <<
" --> value = " << item;
67 if(was_locked) r->
UnLock();
73 if(was_locked) r->
Lock();
79 registry.
Print(stream);
92 fIsReadOnly ( isReadOnly ),
93 fInhibitItemLocks ( false )
99 fName(
"uninitialised"),
102 this->
Copy(registry);
112 this->
Set(key, item);
117 this->
Set(key, item);
122 this->
Set(key, item);
128 this->
Set(key,item2);
133 this->
Set(key, item);
182 bool is_local = entry->second->IsLocal();
185 #ifdef __GENIE_LOW_LEVEL_MESG_ENABLED__
187 <<
"*** Was asked to check 'local' flag on non-existing item: ["
198 entry->second->SetLocal(
true);
201 <<
"*** Can't give 'local' status to non-existem item ["
210 entry->second->SetLocal(
false);
213 <<
"*** Can't give 'global' status to non-existem item ["
222 bool is_locked = entry->second->IsLocked();
238 entry->second->Lock();
241 <<
"*** Can't lock non-existem item [" << key <<
"]";
249 entry->second->UnLock();
252 <<
"*** Can't unlock non-existem item [" << key <<
"]";
260 bool locked_registry = this->
IsLocked();
262 bool can_set = !locked_registry && ( !locked_item || !active_item_locks );
269 RgKey key = entry.first;
275 <<
"*** Registry item [" << key <<
"] can not be set";
297 this->
Set(key, item2);
328 item = entry->second;
333 #ifdef __GENIE_LOW_LEVEL_MESG_ENABLED__
334 LOG(
"Registry",
pDEBUG) <<
"Get an RgBool item with key: " << key;
341 #ifdef __GENIE_LOW_LEVEL_MESG_ENABLED__
349 #ifdef __GENIE_LOW_LEVEL_MESG_ENABLED__
350 LOG(
"Registry",
pDEBUG) <<
"Getting an RgInt item with key: " << key;
357 #ifdef __GENIE_LOW_LEVEL_MESG_ENABLED__
365 #ifdef __GENIE_LOW_LEVEL_MESG_ENABLED__
366 LOG(
"Registry",
pDEBUG) <<
"Getting an RgDbl item with key: " << key;
373 #ifdef __GENIE_LOW_LEVEL_MESG_ENABLED__
381 #ifdef __GENIE_LOW_LEVEL_MESG_ENABLED__
382 LOG(
"Registry",
pDEBUG) <<
"Getting an RgStr item with key: " << key;
389 #ifdef __GENIE_LOW_LEVEL_MESG_ENABLED__
397 #ifdef __GENIE_LOW_LEVEL_MESG_ENABLED__
398 LOG(
"Registry",
pDEBUG) <<
"Getting an RgAlg item with key: " << key;
405 #ifdef __GENIE_LOW_LEVEL_MESG_ENABLED__
414 #ifdef __GENIE_LOW_LEVEL_MESG_ENABLED__
415 LOG(
"Registry",
pDEBUG) <<
"Getting an RgH1F item with key: " << key;
424 LOG(
"Registry",
pWARN) <<
"Returned NULL ptr for TH1F param = " << key;
430 #ifdef __GENIE_LOW_LEVEL_MESG_ENABLED__
431 LOG(
"Registry",
pDEBUG) <<
"Getting an RgH2F item with key: " << key;
440 LOG(
"Registry",
pWARN) <<
"Returned NULL ptr for TH2F param = " << key;
446 #ifdef __GENIE_LOW_LEVEL_MESG_ENABLED__
447 LOG(
"Registry",
pDEBUG) <<
"Getting an RgTree item with key: " << key;
456 LOG(
"Registry",
pWARN) <<
"Returned NULL ptr for TTree param = " << key;
463 this->
Get(key, value);
470 this->
Get(key, value);
477 this->
Get(key, value);
484 this->
Get(key, value);
491 this->
Get(key, value);
557 <<
"*** Key: " << key
558 <<
" does not exist in registry: " << this->
Name();
585 return (
const int) reg_size;
593 <<
"*** Registry is locked - Can not change its name";
604 if ( ! this->
Exists(key0) ) {
607 <<
"*** Key: " << key0
608 <<
" does not exist in registry: " << this->
Name();
628 LOG(
"Registry",
pINFO) <<
"Converting Registry to TFolder";
630 folder->SetOwner(
true);
635 reg_iter != this->
fRegistry.end(); reg_iter++) {
638 string key = reg_iter->first;
644 entry <<
"key:" << key <<
";type:" << stype;
647 entry <<
";value: " << this->
GetBool(key);
648 LOG(
"Registry",
pINFO) <<
"entry = " << entry.str();
649 folder->Add(
new TObjString(entry.str().c_str()));
651 else if (type ==
kRgDbl) {
652 entry <<
";value: " << this->
GetDouble(key);
653 LOG(
"Registry",
pINFO) <<
"entry = " << entry.str();
654 folder->Add(
new TObjString(entry.str().c_str()));
656 else if (type ==
kRgInt) {
657 entry <<
";value: " << this->
GetInt(key);
658 LOG(
"Registry",
pINFO) <<
"entry = " << entry.str();
659 folder->Add(
new TObjString(entry.str().c_str()));
661 else if (type ==
kRgStr) {
662 entry <<
";value: " << this->
GetString(key);
663 LOG(
"Registry",
pINFO) <<
"entry = " << entry.str();
664 folder->Add(
new TObjString(entry.str().c_str()));
666 else if (type ==
kRgAlg) {
669 LOG(
"Registry",
pINFO) <<
"entry = " << entry.str();
670 folder->Add(
new TObjString(entry.str().c_str()));
672 }
else if (type ==
kRgH1F) {
673 }
else if (type ==
kRgH2F) {
684 stream <<
"[-] Registry name: [" <<
Name() <<
"]";
686 stream <<
" - Write Status: ";
688 else { stream <<
"[unlocked]"; }
690 stream <<
" - Inhibited Item Locking: ";
692 else { stream <<
"[off]"; }
694 stream <<
" - # entries: " << setfill(
' ') << setw(3) <<
fRegistry.size()
698 for( ; rcit !=
fRegistry.end(); rcit++) {
700 RgKey key = rcit->first;
706 string key_lbl = string(
"> ") + key;
707 string type_lbl = string(
"[") + stype + string(
"] ");
708 #ifdef __GENIE_LOW_LEVEL_MESG_ENABLED__
710 <<
"Printing [" << stype <<
"] item named = " << key;
712 stream <<
" |" << setfill(
'-') << setw(50) << key_lbl
713 << setfill(
' ') << setw(10) << type_lbl;
714 ritem->
Print(stream);
717 LOG(
"Registry",
pERROR) <<
"Null RegistryItemI with key = " << key;
727 <<
"Copying registry " << registry.
Name() <<
" to " << this->
Name();
730 LOG(
"Registry",
pWARN) <<
"Registry is locked. Can't copy input entries!";
748 <<
"Appending registry " << registry.
Name() <<
" to " << this->
Name();
751 LOG(
"Registry",
pWARN) <<
"Registry is locked. Can't copy input entries!";
758 for(reg_iter = registry.
fRegistry.begin();
759 reg_iter != registry.
fRegistry.end(); reg_iter++) {
761 RgKey name = reg_iter->first;
762 RgKey new_name = prefix + name;
764 if (
fRegistry.count( new_name ) > 0 )
continue ;
770 <<
"Copying [" << stype <<
"] item named = "
771 << name <<
" as " << new_name;
777 if ( !
fRegistry.insert(reg_entry).second ) {
781 LOG(
"Registry",
pERROR ) <<
"Failing to insert item " << new_name ;
793 <<
"Appending registry " << registry.
Name() <<
" to " << this->
Name();
796 LOG(
"Registry",
pWARN) <<
"Registry is locked. Can't copy input entries!";
803 for(reg_iter = registry.
fRegistry.begin();
804 reg_iter != registry.
fRegistry.end(); reg_iter++) {
806 RgKey name = reg_iter->first;
807 RgKey new_name = prefix + name;
813 <<
"Copying [" << stype <<
"] item named = "
814 << name <<
" as " << new_name;
845 for( ; reg_iter !=
fRegistry.end(); reg_iter++) {
846 RgKey key = reg_iter->first;
847 if (key.find(key_part) != string::npos) {
848 klist.push_back(key);
869 <<
"Cleaning-up [force unlock = " << ((force)?
"true":
"false")
870 <<
"] registry: " << this->
Name();
873 LOG(
"Registry",
pWARN) <<
"Registry is locked. Can't clear its entries";
879 RgKey name = rit->first;
882 LOG(
"Registry",
pWARN) <<
"Item with key = " << name <<
" is null!";
892 std::map<RgKey, RegistryItemI*>::const_iterator it =
fRegistry.find( key ) ;
895 LOG(
"Registry",
pFATAL) <<
"Item " << key <<
" not found while cloning for registry " <<
Name() ;
916 else if (type ==
kRgH1F) {
919 RgH1F chisto =
new TH1F(*histo);
920 LOG(
"Registry",
pDEBUG) << chisto->GetName();
924 <<
"Null TH1F with key = " << key <<
" - not copied";
926 }
else if (type ==
kRgH2F) {
929 RgH2F chisto =
new TH2F(*histo);
930 LOG(
"Registry",
pDEBUG) << chisto->GetName();
934 <<
"Null TH2F with key = " << key <<
" - not copied";
940 TTree * ctree = tree->CopyTree(
"1");
941 LOG(
"Registry",
pDEBUG) << ctree->GetName();
945 <<
"Null TTree with key = " << key <<
" - not copied";
949 LOG(
"Registry",
pFATAL ) <<
"Item " << key <<
" not cloned because its type is not implemented " ;
bool fIsReadOnly
is read only?
RgDbl GetDoubleDef(RgKey key, RgDbl def_opt, bool set_def=true)
static string AsString(RgType_t rt)
bool IsLocked(void) const
checks registry lock
Registry & operator=(const Registry ®)
T GetValueOrUseDefault(Registry *r, RgKey key, T def, bool set_def)
bool DeleteEntry(RgKey key)
delete the spcified item
void Append(const Registry &, RgKey pfx="")
append the input registry. Entries already in the registry are not updated
RgDbl GetDouble(RgKey key) const
bool ItemLocksAreActive(void) const
check if item locks are active
void InhibitItemLocks(void)
override individual item locks
void Print(ostream &stream) const
print the registry to stream
const T & Data(void) const
RgInt GetInt(RgKey key) const
void LockItem(RgKey key)
locks the registry item
void SetRegistryItem(Registry *r, RgKey key, T item)
string Name(void) const
get the registry name
void Copy(const Registry &)
copy the input registry
RgH1F GetH1F(RgKey key) const
enum genie::ERgType RgType_t
RgType_t ItemType(RgKey key) const
return item type
void Get(RgKey key, const RegistryItemI *&item) const
RgKeyList FindKeys(RgKey key_part) const
create list with all keys containing 'key_part'
static constexpr double second
void Init(void)
initialize the registry
map< RgKey, RegistryItemI * >::const_iterator RgIMapConstIter
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
bool ItemIsLocal(RgKey key) const
local or global?
RgIMap fRegistry
'key' -> 'value' map
RgInt GetIntDef(RgKey key, RgInt def_opt, bool set_def=true)
void Lock(void)
locks the registry
virtual bool IsLocked(void) const =0
void SetName(string name)
set the registry name
void AssertExistence(RgKey key0) const
RgIMapConstIter SafeFind(RgKey key) const
pair< RgKey, RegistryItemI * > RgIMapPair
vector< RgKey > RgKeyList
map< RgKey, RegistryItemI * >::size_type RgIMapSizeType
void UnLock(void)
unlocks the registry (doesn't unlock items)
RgStr GetString(RgKey key) const
virtual void Print(ostream &) const =0
void RestoreItemLocks(void)
restore individual item locks
RgStr GetStringDef(RgKey key, RgStr def_opt, bool set_def=true)
void LinkToGlobalDef(RgKey key)
link its value to a global default (i.e. a 'global' item)
ostream & operator<<(ostream &stream, const AlgConfigPool &config_pool)
A registry. Provides the container for algorithm configuration parameters.
RgBool GetBool(RgKey key) const
map< RgKey, RegistryItemI * >::iterator RgIMapIter
RgTree GetTree(RgKey key) const
A templated concrete implementation of the RegistryItemI interface. Provides an arbitrary basic type ...
void OverrideGlobalDef(RgKey key)
let item override global default (i.e. a 'local' item)
void UnLockItem(RgKey key)
unlocks the registry item
RgH2F GetH2F(RgKey key) const
bool Exists(RgKey key) const
item with input key exists?
virtual RgType_t TypeInfo(void) const =0
string fName
registry's name
RgAlg GetAlgDef(RgKey key, RgAlg def_opt, bool set_def=true)
bool CanSetItem(RgKey key) const
can I set the specifed item?
void Clear(bool force=false)
clear the registry
void CopyToFolder(TFolder *folder) const
void Set(RgIMapPair entry)
Registry & operator+=(const Registry ®)
void Merge(const Registry &, RgKey pfx="")
append the input registry. Entries already in the registry are updated
RgBool GetBoolDef(RgKey key, RgBool def_opt, bool set_def=true)
bool ItemIsLocked(RgKey key) const
check item lock
RegistryItemI * CloneRegistryItem(const RgKey &key) const
Properly clone a registry Item according to its type.
RgAlg GetAlg(RgKey key) const
void operator()(RgKey key, int item)
int NEntries(void) const
get number of items