Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 14:30:22

0001 #include "SimMuon/Neutron/src/RootNeutronWriter.h"
0002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0003 
0004 using namespace std;
0005 #include <iostream>
0006 RootNeutronWriter::RootNeutronWriter(const string& fileName) { theFile = new TFile(fileName.c_str(), "update"); }
0007 
0008 RootNeutronWriter::~RootNeutronWriter() {
0009   for (std::map<int, RootChamberWriter>::iterator mapItr = theChamberWriters.begin(); mapItr != theChamberWriters.end();
0010        ++mapItr) {
0011     mapItr->second.tree()->Print();
0012     // the tree will remember which file it's from
0013     theFile = mapItr->second.tree()->GetCurrentFile();
0014   }
0015   theFile->Write();
0016   //  theFile->Close();
0017 }
0018 
0019 void RootNeutronWriter::initialize(int chamberType) {
0020   ostringstream treeName;
0021   treeName << "ChamberType" << chamberType;
0022   theChamberWriters[chamberType] = RootChamberWriter(treeName.str());
0023 }
0024 
0025 RootChamberWriter& RootNeutronWriter::chamberWriter(int chamberType) {
0026   std::map<int, RootChamberWriter>::iterator mapItr = theChamberWriters.find(chamberType);
0027   if (mapItr != theChamberWriters.end()) {
0028     return mapItr->second;
0029   } else {
0030     throw cms::Exception("NeutronWriter") << "It's dangerous to create ROOT chamber "
0031                                           << "writers during processing.  The global file may change";
0032 
0033     // make a new one
0034     initialize(chamberType);
0035     return theChamberWriters[chamberType];
0036   }
0037 }
0038 
0039 void RootNeutronWriter::writeCluster(int chamberType, const edm::PSimHitContainer& hits) {
0040   std::cout << "ROOTNEUTRONWRITER " << chamberType << " HITS SIZE " << hits.size() << std::endl;
0041   chamberWriter(chamberType).write(hits);
0042 }