20#include <TObjString.h>
22#include "Framework/Conventions/GBuild.h"
34using 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);
99fName(
"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 ;
766 RgType_t type = reg_iter -> second -> TypeInfo();
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;
809 RgType_t type = reg_iter -> second -> TypeInfo();
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 " ;
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE,...
virtual void Print(ostream &) const =0
virtual bool IsLocked(void) const =0
virtual RgType_t TypeInfo(void) const =0
A templated concrete implementation of the RegistryItemI interface. Provides an arbitrary basic type ...
const T & Data(void) const
A registry. Provides the container for algorithm configuration parameters.
void Append(const Registry &, RgKey pfx="")
append the input registry. Entries already in the registry are not updated
void LinkToGlobalDef(RgKey key)
link its value to a global default (i.e. a 'global' item)
void Merge(const Registry &, RgKey pfx="")
append the input registry. Entries already in the registry are updated
Registry & operator=(const Registry ®)
RgInt GetIntDef(RgKey key, RgInt def_opt, bool set_def=true)
RgIMap fRegistry
'key' -> 'value' map
RgDbl GetDouble(RgKey key) const
void Lock(void)
locks the registry
void Clear(bool force=false)
clear the registry
RegistryItemI * CloneRegistryItem(const RgKey &key) const
Properly clone a registry Item according to its type.
void operator()(RgKey key, int item)
string Name(void) const
get the registry name
RgIMapConstIter SafeFind(RgKey key) const
void UnLockItem(RgKey key)
unlocks the registry item
RgAlg GetAlg(RgKey key) const
bool ItemLocksAreActive(void) const
check if item locks are active
RgStr GetString(RgKey key) const
void LockItem(RgKey key)
locks the registry item
bool IsLocked(void) const
checks registry lock
RgType_t ItemType(RgKey key) const
return item type
bool CanSetItem(RgKey key) const
can I set the specifed item?
void OverrideGlobalDef(RgKey key)
let item override global default (i.e. a 'local' item)
RgKeyList FindKeys(RgKey key_part) const
create list with all keys containing 'key_part'
void AssertExistence(RgKey key0) const
RgBool GetBoolDef(RgKey key, RgBool def_opt, bool set_def=true)
int NEntries(void) const
get number of items
RgH2F GetH2F(RgKey key) const
RgStr GetStringDef(RgKey key, RgStr def_opt, bool set_def=true)
bool DeleteEntry(RgKey key)
delete the spcified item
Registry & operator+=(const Registry ®)
RgAlg GetAlgDef(RgKey key, RgAlg def_opt, bool set_def=true)
bool fIsReadOnly
is read only?
bool Exists(RgKey key) const
item with input key exists?
void SetName(string name)
set the registry name
RgInt GetInt(RgKey key) const
bool ItemIsLocked(RgKey key) const
check item lock
void Init(void)
initialize the registry
bool ItemIsLocal(RgKey key) const
local or global?
void InhibitItemLocks(void)
override individual item locks
RgBool GetBool(RgKey key) const
RgDbl GetDoubleDef(RgKey key, RgDbl def_opt, bool set_def=true)
void Set(RgIMapPair entry)
RgH1F GetH1F(RgKey key) const
void Copy(const Registry &)
copy the input registry
void Get(RgKey key, const RegistryItemI *&item) const
RgTree GetTree(RgKey key) const
void RestoreItemLocks(void)
restore individual item locks
void UnLock(void)
unlocks the registry (doesn't unlock items)
void CopyToFolder(TFolder *folder) const
string fName
registry's name
void Print(ostream &stream) const
print the registry to stream
static string AsString(RgType_t rt)
THE MAIN GENIE PROJECT NAMESPACE
T GetValueOrUseDefault(Registry *r, RgKey key, T def, bool set_def)
vector< RgKey > RgKeyList
void SetRegistryItem(Registry *r, RgKey key, T item)
enum genie::ERgType RgType_t
pair< RgKey, RegistryItemI * > RgIMapPair
map< RgKey, RegistryItemI * >::const_iterator RgIMapConstIter
map< RgKey, RegistryItemI * >::size_type RgIMapSizeType
ostream & operator<<(ostream &stream, const AlgConfigPool &config_pool)
map< RgKey, RegistryItemI * >::iterator RgIMapIter