CMS 3D CMS Logo

InputTagDistributor.h
Go to the documentation of this file.
1 #ifndef InputTagDistributor_H
2 #define InputTagDistributor_H
3 
10 
11 #include <map>
12 #include <iostream>
13 
15  public:
17  std::vector< std::string > inpuTags = pset.getParameterNamesForType<edm::InputTag>();
18  for (std::vector< std::string >::iterator i=inpuTags.begin();i!=inpuTags.end();++i)
20  }
22  std::map<std::string, edm::InputTag>::iterator findMe = inputTags_.find(s);
23  if (findMe!=inputTags_.end())
24  return findMe->second;
25  else{
26  std::stringstream known;
27  for (findMe=inputTags_.begin();findMe!=inputTags_.end();++findMe)
28  known<<findMe->first<<" ---> "<<findMe->second<<"\n";
29  edm::LogError("InputTagDistributor")<<" cannot distribute InputTag: "<<s<<"\n knonw mapping is:\n"<<known.str();
30  }
31  return inputTags_[s];
32  }
33 
34  private:
35  std::map<std::string, edm::InputTag> inputTags_;
36 };
37 
38 
40  private:
42  std::map<std::string, InputTagDistributor*> multipleInstance_;
43 
44  public:
47  };
49 
51  if (multipleInstance_.find(user)!=multipleInstance_.end()){
52  std::cerr<<user<<" InputTagDistributor user already defined."<<std::endl;
53  throw;}
54  else SetInputTagDistributorUniqueInstance_ = new InputTagDistributor(iConfig, iC);
55  multipleInstance_[user] = SetInputTagDistributorUniqueInstance_;
56  return (*SetInputTagDistributorUniqueInstance_);
57  }
58  void preModule(const edm::ModuleDescription& desc){
59  //does a set with the module name, except that it does not throw on non-configured modules
60  std::map<std::string, InputTagDistributor*>::iterator f=multipleInstance_.find(desc.moduleLabel());
61  if (f != multipleInstance_.end()) SetInputTagDistributorUniqueInstance_ = f->second;
62  else{
63  //do not say anything but set it to zero to get a safe crash in get() if ever called
64  SetInputTagDistributorUniqueInstance_=nullptr;}
65  }
66  /* InputTagDistributor & set(std::string & user){
67  std::map<std::string, InputTagDistributor*>::iterator f=multipleInstance_.find(user);
68  if (f == multipleInstance_.end()){
69  std::cerr<<user<<" InputTagDistributor user not defined. but it does not matter."<<std::endl;
70  // throw;}
71  }
72  else {
73  SetInputTagDistributorUniqueInstance_ = f->second;
74  return (*SetInputTagDistributorUniqueInstance_);
75  }
76  }*/
78  if (!SetInputTagDistributorUniqueInstance_){
79  std::cerr<<" SetInputTagDistributorUniqueInstance_ is not valid."<<std::endl;
80  throw;
81  }
82  else{ return (*SetInputTagDistributorUniqueInstance_);}
83  }
84 
86  //if used without setting any InputTag mapping
87  if (multipleInstance_.empty())
88  return pset.getParameter<edm::InputTag>(src);
89 
90  // some mapping was setup
91  InputTagDistributor & which=get();
92  std::map<std::string, InputTagDistributor*>::iterator inverseMap=multipleInstance_.begin();
93  std::map<std::string, InputTagDistributor*>::iterator inverseMap_end=multipleInstance_.end();
94  for (;inverseMap!=inverseMap_end;++inverseMap) if (inverseMap->second==&which) break;
95  LogDebug("InputTagDistributor")<<"typeCode: "<<pset.retrieve(src).typeCode()
96  <<"\n"<<pset.dump()<<"\n"
97  <<"looking for: "<<src
98  <<" by user: "<< inverseMap->first
99  <<std::endl;
101  typeCode+=pset.retrieve(src).typeCode();
102  std::string iTC;iTC+='S';
103  if (typeCode==iTC)
104  return which.inputTag(pset.getParameter<std::string>(src));
105  else
106  return pset.getParameter<edm::InputTag>(src);
107  }
108 };
109 
110 
111 
112 #endif
#define LogDebug(id)
T getParameter(std::string const &) const
Entry const & retrieve(char const *) const
InputTagDistributor * SetInputTagDistributorUniqueInstance_
std::map< std::string, InputTagDistributor * > multipleInstance_
std::string dump(unsigned int indent=0) const
void watchPreModuleConstruction(PreModuleConstruction::slot_type const &iSlot)
std::string const & moduleLabel() const
std::vector< std::string > getParameterNamesForType(bool trackiness=true) const
Definition: ParameterSet.h:169
InputTagDistributor & init(std::string user, const edm::ParameterSet &iConfig, edm::ConsumesCollector &&iC)
void preModule(const edm::ModuleDescription &desc)
TypeCode typeCode(const edm::TypeWithDict &t)
Definition: returnType.cc:44
double f[11][100]
InputTagDistributorService(const edm::ParameterSet &iConfig, edm::ActivityRegistry &r)
const edm::InputTag & inputTag(std::string s)
InputTagDistributor(const edm::ParameterSet &pset, edm::ConsumesCollector &iC)
edm::InputTag retrieve(std::string src, const edm::ParameterSet &pset)
def which(cmd)
Definition: eostools.py:336
char typeCode() const
Definition: Entry.h:176
std::map< std::string, edm::InputTag > inputTags_