CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Tracker_OldtoNewConverter.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Tracker_OldtoNewConverter.cc
4 // Class: Tracker_OldtoNewConverter
5 //
13 //
14 // Original Author: Nhan Tran
15 // Created: Mon Jul 16m 16:56:34 CDT 2007
16 // $Id: Tracker_OldtoNewConverter.cc,v 1.1 2008/02/27 17:35:48 ebutz Exp $
17 //
18 //
19 
20 // system include files
24 
25 
26 #include <algorithm>
27 #include "TTree.h"
28 #include "TFile.h"
29 
31 
32 
33 #include <fstream>
34 #include <iostream>
35 
36 //
37 // class decleration
38 //
39 
41 public:
44 
45 
46 private:
47  virtual void beginJob();
48  virtual void analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup);
49  virtual void endJob() ;
50 
51  void createMap();
52  void addBranches();
53 
54  // ----------member data ---------------------------
55 
56  std::string m_conversionType;
57  std::string m_textFile;
58  std::string m_inputFile;
59  std::string m_outputFile;
60  std::string m_treeName;
61 
62  std::map< uint32_t, uint32_t > theMap;
63 
64  TFile* m_inputTFile;
65  TFile* m_outputTFile;
66  TTree* m_inputTree;
67  TTree* m_outputTree;
68 
69 
70  uint32_t rawid_i, rawid_f;
71  //int rawid_i, rawid_f;
72  double x_i, y_i, z_i, a_i, b_i, c_i;
73  double x_f, y_f, z_f, a_f, b_f, c_f;
74 
75 
76 };
77 
78 //
79 // constants, enums and typedefs
80 //
81 
82 //
83 // static data member definitions
84 //
85 
86 //
87 // constructors and destructor
88 //
90 {
91  m_conversionType = iConfig.getUntrackedParameter< std::string > ("conversionType");
92  m_inputFile = iConfig.getUntrackedParameter< std::string > ("inputFile");
93  m_outputFile = iConfig.getUntrackedParameter< std::string > ("outputFile");
94  m_textFile = iConfig.getUntrackedParameter< std::string > ("textFile");
95  m_treeName = iConfig.getUntrackedParameter< std::string > ("treeName");
96 }
97 
98 
100 {}
101 
102 
103 //
104 // member functions
105 //
106 
107 // ------------ method called to for each event ------------
109 {}
110 
111 
112 // ------------ method called once each job just before starting event loop ------------
114 {
115 
116  m_inputTFile = new TFile(m_inputFile.c_str());
117  m_outputTFile = new TFile(m_outputFile.c_str(),"RECREATE");
118 
119  m_inputTree = (TTree*) m_inputTFile->Get(m_treeName.c_str());
120  m_outputTree = new TTree(m_treeName.c_str(), m_treeName.c_str());
121 
122  createMap();
123  addBranches();
124 
125  uint32_t nEntries = m_inputTree->GetEntries();
126  uint32_t iter = 0;
127  for (uint32_t i = 0; i < nEntries; ++i){
128  m_inputTree->GetEntry(i);
129  std::map< uint32_t, uint32_t >::const_iterator it = theMap.find(rawid_i);
130 
131  if (it == theMap.end()){
132  edm::LogInfo("ERROR") << "Error: couldn't find rawId: " << rawid_i;
133  iter++;
134  }
135  else{
136  rawid_f = (it)->second;
137  x_f = x_i;
138  y_f = y_i;
139  z_f = z_i;
140  a_f = a_i;
141  b_f = b_i;
142  c_f = c_i;
143  m_outputTree->Fill();
144  }
145 
146  }
147  edm::LogInfo("errors") << "Couldn't find: " << iter;
148  m_outputTFile->cd();
149  m_outputTree->Write();
150  m_outputTFile->Close();
151 }
152 
153 
154 
156 
157  std::ifstream myfile( m_textFile.c_str() );
158  if (!myfile.is_open())
159  throw cms::Exception("FileAccess") << "Unable to open input text file";
160 
161  uint32_t oldid;
162  uint32_t newid;
163 
164  uint32_t ctr = 0;
165  while( !myfile.eof() && myfile.good() ){
166 
167  myfile >> oldid >> newid;
168 
169  //depends on conversion type: OldtoNew or NewtoOld
170  std::pair< uint32_t, uint32_t > pairType;
171  if (m_conversionType == "OldtoNew") {pairType.first = oldid; pairType.second = newid;}
172  if (m_conversionType == "NewtoOld") {pairType.first = newid; pairType.second = oldid;}
173 
174 
175  theMap.insert( pairType );
176 
177  if (myfile.fail()) break;
178 
179  ctr++;
180  }
181  edm::LogInfo("Check") << ctr << " alignables read.";
182 }
183 
185 
186  m_inputTree->SetBranchAddress("rawid", &rawid_i);
187  m_inputTree->SetBranchAddress("x", &x_i);
188  m_inputTree->SetBranchAddress("y", &y_i);
189  m_inputTree->SetBranchAddress("z", &z_i);
190  m_inputTree->SetBranchAddress("alpha", &a_i);
191  m_inputTree->SetBranchAddress("beta", &b_i);
192  m_inputTree->SetBranchAddress("gamma", &c_i);
193 
194  m_outputTree->Branch("rawid", &rawid_f, "rawid/I");
195  m_outputTree->Branch("x", &x_f, "x/D");
196  m_outputTree->Branch("y", &y_f, "y/D");
197  m_outputTree->Branch("z", &z_f, "z/D");
198  m_outputTree->Branch("alpha", &a_f, "alpha/D");
199  m_outputTree->Branch("beta", &b_f, "beta/D");
200  m_outputTree->Branch("gamma", &c_f, "gamma/D");
201 
202 }
203 
204 
205 // ------------ method called once each job just after ending the event loop ------------
207 }
208 
209 
210 
211 //define this as a plug-in
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
U second(std::pair< T, U > const &p)
int iEvent
Definition: GenABIO.cc:243
Tracker_OldtoNewConverter(const edm::ParameterSet &)
std::map< uint32_t, uint32_t > theMap
virtual void analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup)