CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/SimMuon/Neutron/src/RootNeutronWriter.cc

Go to the documentation of this file.
00001 #include "SimMuon/Neutron/src/RootNeutronWriter.h"
00002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00003 
00004 using namespace std;
00005 #include <iostream>
00006 RootNeutronWriter::RootNeutronWriter(const string & fileName) 
00007 {
00008   theFile = new TFile(fileName.c_str(),"update");
00009 }
00010 
00011 
00012 RootNeutronWriter::~RootNeutronWriter() 
00013 {
00014   for(std::map<int, RootChamberWriter>::iterator mapItr = theChamberWriters.begin();
00015       mapItr != theChamberWriters.end(); ++mapItr)
00016   {
00017     mapItr->second.tree()->Print();
00018     // the tree will remember which file it's from
00019     theFile = mapItr->second.tree()->GetCurrentFile();
00020   }
00021   theFile->Write();
00022 //  theFile->Close();
00023 }
00024 
00025 
00026 void RootNeutronWriter::initialize(int chamberType)
00027 {
00028     ostringstream treeName;
00029     treeName << "ChamberType" << chamberType;
00030     theChamberWriters[chamberType] = RootChamberWriter(treeName.str());
00031 }
00032 
00033 RootChamberWriter & RootNeutronWriter::chamberWriter(int chamberType)
00034 {
00035   std::map<int, RootChamberWriter>::iterator mapItr = theChamberWriters.find(chamberType);
00036   if(mapItr != theChamberWriters.end())
00037   {
00038     return mapItr->second;
00039   }
00040   else
00041   {
00042     throw cms::Exception("NeutronWriter") << "It's dangerous to create ROOT chamber "
00043       << "writers during processing.  The global file may change";
00044       
00045     // make a new one
00046     initialize(chamberType);
00047     return theChamberWriters[chamberType];
00048   }
00049 }
00050 
00051 
00052 void RootNeutronWriter::writeCluster(int chamberType, const edm::PSimHitContainer & hits) 
00053 {
00054 std::cout << "ROOTNEUTRONWRITER " << chamberType << " HITS SIZE " << hits.size() <<std::endl;
00055   chamberWriter(chamberType).write(hits);
00056 }
00057