CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Record.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: FWLite
4 // Class : Record
5 //
6 // Implementation:
7 // [Notes on implementation]
8 //
9 // Original Author:
10 // Created: Thu Dec 10 15:58:33 CST 2009
11 //
12 
13 // system include files
14 #include <cassert>
15 #include "TTree.h"
16 #include "Reflex/Type.h"
17 // user include files
22 
23 
24 //
25 // constants, enums and typedefs
26 //
27 using namespace fwlite;
28 //
29 // static data member definitions
30 //
31 typedef std::map<IOVSyncValue,unsigned int> StartIOVtoEntryMap;
32 
33 //
34 // constructors and destructor
35 //
36 Record::Record(const char* iName, TTree* iTree):
37 m_name(iName), m_tree(iTree), m_entry(-1),
38 m_start(IOVSyncValue::invalidIOVSyncValue()),
39 m_end(IOVSyncValue::invalidIOVSyncValue())
40 {
41  //read the start iovs and get them in order
44  TBranch* auxBranch = m_tree->FindBranch("ESRecordAuxiliary");
45  auxBranch->SetAddress(&pAux);
47  for(unsigned int index=0; index < m_tree->GetEntries();++index){
48  auxBranch->GetEntry(index);
50  if(aux.eventID().run() != 0) {
51  temp = IOVSyncValue(aux.eventID(),aux.timestamp());
52  } else {
53  temp = IOVSyncValue(aux.timestamp());
54  }
55  } else {
56  temp=IOVSyncValue(aux.eventID());
57  assert(aux.eventID().run()!=0);
58  }
59 
61  }
62 }
63 
64 // Record::Record(const Record& rhs)
65 // {
66 // // do actual copying here;
67 // }
68 
70 {
71  resetCaches();
72 }
73 
74 //
75 // assignment operators
76 //
77 // const Record& Record::operator=(const Record& rhs)
78 // {
79 // //An exception safe implementation is
80 // Record temp(rhs);
81 // swap(rhs);
82 //
83 // return *this;
84 // }
85 
86 //
87 // member functions
88 //
89 void
91 {
92 
94  if(iTime != edm::Timestamp::invalidTimestamp()){
95  if(iEvent.run() != 0) {
96  temp = IOVSyncValue(iEvent,iTime);
97  } else {
98  temp = IOVSyncValue(iTime);
99  }
100  } else {
101  temp=IOVSyncValue(iEvent);
102  assert(iEvent.run()!=0);
103  }
104 
105  //already synched
107  (m_start <=temp ) &&
109  (temp <m_end))) {
110  return;
111  }
112  std::pair<StartIOVtoEntryMap::iterator, StartIOVtoEntryMap::iterator> range =
113  m_startIOVtoEntry.equal_range(temp);
114  if(range.first!=range.second){
115  //happens to be the start of the IOV
116  m_start = range.first->first;
117  m_entry = range.first->second;
118  } else {
119  if(range.first!=m_startIOVtoEntry.begin()){
120  //we have overshot
121  --range.first;
122  m_start = range.first->first;
123  m_entry = range.first->second;
124  } else {
125  //off the beginning
127  m_entry = -1;
128  }
129  }
130  if(range.second==m_startIOVtoEntry.end()){
132  } else {
133  m_end = range.second->first;
134  }
135  resetCaches();
136 }
137 
138 void
140 {
141  for(auto&b : m_branches){
142  TClass* cls=0;
143  EDataType dt;
144  if(0==b.second.first or 0==b.second.second) continue;
145  if(0==b.second.first->GetExpectedType(cls,dt)) {
146  cls->Destructor(b.second.second);
147  b.second.second=0;
148  }
149  }
150  for(auto&b : m_branches){
151  if(0==b.second.first) continue;
152  assert(b.second.second==0);
153  }
154 }
155 
156 //
157 // const member functions
158 //
159 const std::string&
161 {
162  return m_name;
163 }
164 
165 const IOVSyncValue&
167  return m_start;
168 }
169 const IOVSyncValue&
171 {
172  return m_end;
173 }
174 
175 
177 Record::get(const TypeID& iType,
178  const char* iLabel,
179  const void*& iData) const
180 {
181  cms::Exception* returnValue = 0;
182 
183  std::pair<TBranch*,void*>& branch = m_branches[std::make_pair(iType,iLabel)];
184  if(0==branch.first){
185  branch.second=0;
186  using namespace ROOT::Reflex;
187  Type t = Type::ByTypeInfo(iType.typeInfo());
188  if(t == Type()){
189  returnValue = new cms::Exception("UnknownType");
190  (*returnValue)<<"The type "
191  <<iType.typeInfo().name()<<" was requested from Record "<<name()
192  <<" but the type has no known dictionary";
193  return returnValue;
194  }
195  //build branch name
196  std::string branchName = fwlite::format_type_to_mangled(t.Name(ROOT::Reflex::SCOPED|ROOT::Reflex::FINAL))+"__"+iLabel;
197  branch.first = m_tree->FindBranch(branchName.c_str());
198 
199  if(0==branch.first){
200  returnValue = new cms::Exception("NoDataAvailable");
201  (*returnValue)<<"The data of type "
202  <<t.Name(ROOT::Reflex::SCOPED|ROOT::Reflex::FINAL)
203  <<" with label '"<<iLabel<<"' for Record "<<name()<<" is not in this file.";
204  return returnValue;
205  }
206  //We need GetExpectedType to work in order to delete objects
207  TClass* cls;
208  EDataType dt;
209  if(0!=branch.first->GetExpectedType(cls,dt)) {
210  returnValue = new cms::Exception("UnknownType");
211  (*returnValue)<<"The type "
212  <<iType.typeInfo().name()<<" was requested from Record "<<name()
213  <<" but the TBranch does not know what Type it holds.";
214  return returnValue;
215  }
216 
217  branch.first->SetAutoDelete(kFALSE);
218  }
219  if(m_entry<0) {
220  returnValue = new cms::Exception("NoValidIOV");
221  (*returnValue) <<" The Record "
222  <<name()<<" was asked to get data for a 'time' for which it has no data";
223  return returnValue;
224  }
225  if(0!=branch.second) {
226  iData=branch.second;
227  return nullptr;
228  }
229 
230  assert(0==branch.second);
231  branch.first->SetAddress(&branch.second);
232  iData = branch.second;
233  branch.first->GetEntry(m_entry);
234  return returnValue;
235 }
236 
237 std::vector<std::pair<std::string,std::string> >
239 {
240  std::vector<std::pair<std::string,std::string> > returnValue;
241 
242  TObjArray* branches = m_tree->GetListOfBranches();
243  TIter next( branches );
244  while (TObject* obj = next()) {
245  TBranch* branch = static_cast<TBranch*> (obj);
246  const char* name = branch->GetName();
247  if (0!=strcmp(name, "ESRecordAuxiliary") ) {
248  //The type and label are separated by a double underscore so we need to find that
249  size_t len = strlen(name);
250  const char* cIndex = name+len;
251  std::string label;
252  while (name != --cIndex) {
253  if(*cIndex == '_') {
254  if( *(cIndex-1)=='_') {
255  label = std::string(cIndex+1);
256  break;
257  }
258  }
259  }
260  std::string type(name, cIndex-name-1);
262  returnValue.push_back(std::make_pair(type,label));
263  }
264  }
265  return returnValue;
266 }
267 
268 //
269 // static member functions
270 //
RunNumber_t run() const
Definition: EventID.h:42
type
Definition: HCALResponse.h:22
float dt
Definition: AMPTWrapper.h:126
Record(const char *iName, TTree *)
Definition: Record.cc:36
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventIDconst &, edm::Timestampconst & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
const edm::EventID & eventID() const
const IOVSyncValue & startSyncValue() const
Definition: Record.cc:166
IOVSyncValue m_start
Definition: Record.h:86
const std::type_info & typeInfo() const
Definition: TypeIDBase.h:54
long m_entry
Definition: Record.h:85
TTree * m_tree
Definition: Record.h:83
std::map< IOVSyncValue, unsigned int > StartIOVtoEntryMap
Definition: Record.cc:31
int iEvent
Definition: GenABIO.cc:243
std::string unformat_mangled_to_type(const std::string &)
given a mangled name return the C++ class name
const std::string & name() const
Definition: Record.cc:160
std::string format_type_to_mangled(const std::string &)
given a C++ class name returned a mangled name
void syncTo(const edm::EventID &, const edm::Timestamp &)
Definition: Record.cc:90
std::vector< std::pair< std::string, std::string > > typeAndLabelOfAvailableData() const
Definition: Record.cc:238
static Timestamp const & invalidTimestamp()
Definition: Timestamp.cc:83
std::string m_name
Definition: Record.h:82
double b
Definition: hdecay.h:120
std::map< std::pair< TypeID, std::string >, std::pair< TBranch *, void * > > m_branches
Definition: Record.h:89
bool get(HANDLE &, const char *iLabel="") const
Definition: Record.h:94
std::map< IOVSyncValue, unsigned int > m_startIOVtoEntry
Definition: Record.h:84
static const IOVSyncValue & invalidIOVSyncValue()
Definition: IOVSyncValue.cc:87
void resetCaches()
Definition: Record.cc:139
IOVSyncValue m_end
Definition: Record.h:87
virtual ~Record()
Definition: Record.cc:69
const edm::Timestamp & timestamp() const
const IOVSyncValue & endSyncValue() const
Definition: Record.cc:170