00001
00002
00003
00004
00005
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "FWCore/Framework/interface/EDAnalyzer.h"
00022 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00023 #include "FWCore/Framework/interface/MakerMacros.h"
00024
00025
00026 #include <algorithm>
00027 #include "TTree.h"
00028 #include "TFile.h"
00029
00030 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00031
00032
00033 #include <fstream>
00034 #include <iostream>
00035
00036
00037
00038
00039
00040 class Tracker_OldtoNewConverter : public edm::EDAnalyzer {
00041 public:
00042 explicit Tracker_OldtoNewConverter(const edm::ParameterSet&);
00043 ~Tracker_OldtoNewConverter();
00044
00045
00046 private:
00047 virtual void beginJob();
00048 virtual void analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup);
00049 virtual void endJob() ;
00050
00051 void createMap();
00052 void addBranches();
00053
00054
00055
00056 std::string m_conversionType;
00057 std::string m_textFile;
00058 std::string m_inputFile;
00059 std::string m_outputFile;
00060 std::string m_treeName;
00061
00062 std::map< uint32_t, uint32_t > theMap;
00063
00064 TFile* m_inputTFile;
00065 TFile* m_outputTFile;
00066 TTree* m_inputTree;
00067 TTree* m_outputTree;
00068
00069
00070 uint32_t rawid_i, rawid_f;
00071
00072 double x_i, y_i, z_i, a_i, b_i, c_i;
00073 double x_f, y_f, z_f, a_f, b_f, c_f;
00074
00075
00076 };
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089 Tracker_OldtoNewConverter::Tracker_OldtoNewConverter(const edm::ParameterSet& iConfig) :
00090 m_inputTFile(0), m_outputTFile(0), m_inputTree(0), m_outputTree(0),
00091 rawid_i(0), rawid_f(0),
00092 x_i(0.), y_i(0.), z_i(0.), a_i(0.), b_i(0.), c_i(0.),
00093 x_f(0.), y_f(0.), z_f(0.), a_f(0.), b_f(0.), c_f(0.)
00094 {
00095 m_conversionType = iConfig.getUntrackedParameter< std::string > ("conversionType");
00096 m_inputFile = iConfig.getUntrackedParameter< std::string > ("inputFile");
00097 m_outputFile = iConfig.getUntrackedParameter< std::string > ("outputFile");
00098 m_textFile = iConfig.getUntrackedParameter< std::string > ("textFile");
00099 m_treeName = iConfig.getUntrackedParameter< std::string > ("treeName");
00100 }
00101
00102
00103 Tracker_OldtoNewConverter::~Tracker_OldtoNewConverter()
00104 {}
00105
00106
00107
00108
00109
00110
00111
00112 void Tracker_OldtoNewConverter::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00113 {}
00114
00115
00116
00117 void Tracker_OldtoNewConverter::beginJob()
00118 {
00119
00120 m_inputTFile = new TFile(m_inputFile.c_str());
00121 m_outputTFile = new TFile(m_outputFile.c_str(),"RECREATE");
00122
00123 m_inputTree = (TTree*) m_inputTFile->Get(m_treeName.c_str());
00124 m_outputTree = new TTree(m_treeName.c_str(), m_treeName.c_str());
00125
00126 createMap();
00127 addBranches();
00128
00129 uint32_t nEntries = m_inputTree->GetEntries();
00130 uint32_t iter = 0;
00131 for (uint32_t i = 0; i < nEntries; ++i){
00132 m_inputTree->GetEntry(i);
00133 std::map< uint32_t, uint32_t >::const_iterator it = theMap.find(rawid_i);
00134
00135 if (it == theMap.end()){
00136 edm::LogInfo("ERROR") << "Error: couldn't find rawId: " << rawid_i;
00137 iter++;
00138 }
00139 else{
00140 rawid_f = (it)->second;
00141 x_f = x_i;
00142 y_f = y_i;
00143 z_f = z_i;
00144 a_f = a_i;
00145 b_f = b_i;
00146 c_f = c_i;
00147 m_outputTree->Fill();
00148 }
00149
00150 }
00151 edm::LogInfo("errors") << "Couldn't find: " << iter;
00152 m_outputTFile->cd();
00153 m_outputTree->Write();
00154 m_outputTFile->Close();
00155 }
00156
00157
00158
00159 void Tracker_OldtoNewConverter::createMap() {
00160
00161 std::ifstream myfile( m_textFile.c_str() );
00162 if (!myfile.is_open())
00163 throw cms::Exception("FileAccess") << "Unable to open input text file";
00164
00165 uint32_t oldid;
00166 uint32_t newid;
00167
00168 uint32_t ctr = 0;
00169 while( !myfile.eof() && myfile.good() ){
00170
00171 myfile >> oldid >> newid;
00172
00173
00174 std::pair< uint32_t, uint32_t > pairType;
00175 if (m_conversionType == "OldtoNew") {pairType.first = oldid; pairType.second = newid;}
00176 if (m_conversionType == "NewtoOld") {pairType.first = newid; pairType.second = oldid;}
00177
00178
00179 theMap.insert( pairType );
00180
00181 if (myfile.fail()) break;
00182
00183 ctr++;
00184 }
00185 edm::LogInfo("Check") << ctr << " alignables read.";
00186 }
00187
00188 void Tracker_OldtoNewConverter::addBranches(){
00189
00190 m_inputTree->SetBranchAddress("rawid", &rawid_i);
00191 m_inputTree->SetBranchAddress("x", &x_i);
00192 m_inputTree->SetBranchAddress("y", &y_i);
00193 m_inputTree->SetBranchAddress("z", &z_i);
00194 m_inputTree->SetBranchAddress("alpha", &a_i);
00195 m_inputTree->SetBranchAddress("beta", &b_i);
00196 m_inputTree->SetBranchAddress("gamma", &c_i);
00197
00198 m_outputTree->Branch("rawid", &rawid_f, "rawid/I");
00199 m_outputTree->Branch("x", &x_f, "x/D");
00200 m_outputTree->Branch("y", &y_f, "y/D");
00201 m_outputTree->Branch("z", &z_f, "z/D");
00202 m_outputTree->Branch("alpha", &a_f, "alpha/D");
00203 m_outputTree->Branch("beta", &b_f, "beta/D");
00204 m_outputTree->Branch("gamma", &c_f, "gamma/D");
00205
00206 }
00207
00208
00209
00210 void Tracker_OldtoNewConverter::endJob() {
00211 }
00212
00213
00214
00215
00216 DEFINE_FWK_MODULE(Tracker_OldtoNewConverter);