CMS 3D CMS Logo

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