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 // 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 edm::TypeID& iType,
178  const char* iLabel,
179  const void*& iData) const
180 {
181  cms::Exception* returnValue = nullptr;
182 
183  std::pair<TBranch*,void*>& branch = m_branches[std::make_pair(iType,iLabel)];
184  if(0==branch.first){
185  branch.second=0;
186  if(!edm::hasDictionary(iType.typeInfo())){
187  returnValue = new cms::Exception("UnknownType");
188  (*returnValue)<<"The type "
189  <<iType.typeInfo().name()<<" was requested from Record "<<name()
190  <<" but the type has no known dictionary";
191  return returnValue;
192  }
193  //build branch name
194  std::string branchName = fwlite::format_type_to_mangled(iType.className())+"__"+iLabel;
195  branch.first = m_tree->FindBranch(branchName.c_str());
196 
197  if(0==branch.first){
198  returnValue = new cms::Exception("NoDataAvailable");
199  (*returnValue)<<"The data of type "
200  <<iType.className()
201  <<" with label '"<<iLabel<<"' for Record "<<name()<<" is not in this file.";
202  return returnValue;
203  }
204  //We need GetExpectedType to work in order to delete objects
205  TClass* cls;
206  EDataType dt;
207  if(0!=branch.first->GetExpectedType(cls,dt)) {
208  returnValue = new cms::Exception("UnknownType");
209  (*returnValue)<<"The type "
210  <<iType.typeInfo().name()<<" was requested from Record "<<name()
211  <<" but the TBranch does not know what Type it holds.";
212  return returnValue;
213  }
214 
215  branch.first->SetAutoDelete(kFALSE);
216  }
217  if(m_entry<0) {
218  returnValue = new cms::Exception("NoValidIOV");
219  (*returnValue) <<" The Record "
220  <<name()<<" was asked to get data for a 'time' for which it has no data";
221  return returnValue;
222  }
223  if(0!=branch.second) {
224  iData=branch.second;
225  return nullptr;
226  }
227 
228  assert(0==branch.second);
229  branch.first->SetAddress(&branch.second);
230  iData = branch.second;
231  branch.first->GetEntry(m_entry);
232  return returnValue;
233 }
234 
235 std::vector<std::pair<std::string,std::string> >
237 {
238  std::vector<std::pair<std::string,std::string> > returnValue;
239 
240  TObjArray* branches = m_tree->GetListOfBranches();
241  TIter next( branches );
242  while (TObject* obj = next()) {
243  TBranch* branch = static_cast<TBranch*> (obj);
244  const char* name = branch->GetName();
245  if (0!=strcmp(name, "ESRecordAuxiliary") ) {
246  //The type and label are separated by a double underscore so we need to find that
247  size_t len = strlen(name);
248  const char* cIndex = name+len;
250  while (name != --cIndex) {
251  if(*cIndex == '_') {
252  if( *(cIndex-1)=='_') {
253  label = std::string(cIndex+1);
254  break;
255  }
256  }
257  }
258  std::string type(name, cIndex-name-1);
260  returnValue.push_back(std::make_pair(type,label));
261  }
262  }
263  return returnValue;
264 }
265 
266 //
267 // static member functions
268 //
RunNumber_t run() const
Definition: EventID.h:39
type
Definition: HCALResponse.h:21
float dt
Definition: AMPTWrapper.h:126
static Timestamp invalidTimestamp()
Definition: Timestamp.h:101
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
assert(m_qm.get())
const IOVSyncValue & startSyncValue() const
Definition: Record.cc:166
IOVSyncValue m_start
Definition: Record.h:79
const std::type_info & typeInfo() const
Definition: TypeIDBase.h:58
long m_entry
Definition: Record.h:78
TTree * m_tree
Definition: Record.h:76
std::map< IOVSyncValue, unsigned int > StartIOVtoEntryMap
Definition: Record.cc:31
int iEvent
Definition: GenABIO.cc:230
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:236
std::string m_name
Definition: Record.h:75
double b
Definition: hdecay.h:120
std::map< std::pair< edm::TypeID, std::string >, std::pair< TBranch *, void * > > m_branches
Definition: Record.h:82
std::string const & className() const
Definition: TypeID.cc:46
bool get(HANDLE &, const char *iLabel="") const
Definition: Record.h:87
bool hasDictionary(std::type_info const &)
std::map< IOVSyncValue, unsigned int > m_startIOVtoEntry
Definition: Record.h:77
static const IOVSyncValue & invalidIOVSyncValue()
Definition: IOVSyncValue.cc:87
void resetCaches()
Definition: Record.cc:139
IOVSyncValue m_end
Definition: Record.h:80
virtual ~Record()
Definition: Record.cc:69
const edm::Timestamp & timestamp() const
const IOVSyncValue & endSyncValue() const
Definition: Record.cc:170