7676#include " TString.h"
7777#include " TStyle.h"
7878#include " TTree.h"
79+ #include " TKey.h"
7980
8081// custom made printout
8182#define LOGPRINT edm::LogPrint (" SiStripHitEffFromCalibTree" )
@@ -94,7 +95,7 @@ struct hit {
9495class SiStripHitEffFromCalibTree : public ConditionDBWriter <SiStripBadStrip> {
9596public:
9697 explicit SiStripHitEffFromCalibTree (const edm::ParameterSet&);
97- ~SiStripHitEffFromCalibTree () override = default ;
98+ ~SiStripHitEffFromCalibTree () override ;
9899
99100private:
100101 // overridden from ConditionDBWriter
@@ -168,16 +169,16 @@ class SiStripHitEffFromCalibTree : public ConditionDBWriter<SiStripBadStrip> {
168169 // for using events after number of tracks cut
169170 map<pair<unsigned int , unsigned int >, bool > event_used;
170171
171- vector<hit> hits[23 ];
172+ vector<hit> hits[::k_END_OF_LAYERS ];
172173 vector<TH2F*> HotColdMaps;
173- map<unsigned int , pair<unsigned int , unsigned int > > modCounter[23 ];
174+ map<unsigned int , pair<unsigned int , unsigned int > > modCounter[::k_END_OF_LAYERS ];
174175 TrackerMap* tkmap;
175176 TrackerMap* tkmapbad;
176177 TrackerMap* tkmapeff;
177178 TrackerMap* tkmapnum;
178179 TrackerMap* tkmapden;
179- long layerfound[23 ];
180- long layertotal[23 ];
180+ long layerfound[::k_END_OF_LAYERS ];
181+ long layertotal[::k_END_OF_LAYERS ];
181182 map<unsigned int , vector<int > > layerfound_perBx;
182183 map<unsigned int , vector<int > > layertotal_perBx;
183184 vector<TH1F*> layerfound_vsLumi;
@@ -188,10 +189,10 @@ class SiStripHitEffFromCalibTree : public ConditionDBWriter<SiStripBadStrip> {
188189 vector<TH1F*> layertotal_vsCM;
189190 vector<TH1F*> layerfound_vsBX;
190191 vector<TH1F*> layertotal_vsBX;
191- int goodlayertotal[35 ];
192- int goodlayerfound[35 ];
193- int alllayertotal[35 ];
194- int alllayerfound[35 ];
192+ int goodlayertotal[::k_END_OF_LAYS_AND_RINGS ];
193+ int goodlayerfound[::k_END_OF_LAYS_AND_RINGS ];
194+ int alllayertotal[::k_END_OF_LAYS_AND_RINGS ];
195+ int alllayerfound[::k_END_OF_LAYS_AND_RINGS ];
195196 map<unsigned int , double > BadModules;
196197};
197198
@@ -229,6 +230,83 @@ SiStripHitEffFromCalibTree::SiStripHitEffFromCalibTree(const edm::ParameterSet&
229230 nTEClayers = 7 ; // number of rings
230231
231232 quality_ = new SiStripQuality (detInfo_);
233+
234+ layerfound_vsLumi.reserve (::k_END_OF_LAYERS);
235+ layertotal_vsLumi.reserve (::k_END_OF_LAYERS);
236+ layerfound_vsPU.reserve (::k_END_OF_LAYERS);
237+ layertotal_vsPU.reserve (::k_END_OF_LAYERS);
238+ layerfound_vsCM.reserve (::k_END_OF_LAYERS);
239+ layertotal_vsCM.reserve (::k_END_OF_LAYERS);
240+ layerfound_vsBX.reserve (::k_END_OF_LAYERS);
241+ layertotal_vsBX.reserve (::k_END_OF_LAYERS);
242+ }
243+
244+ namespace utils {
245+
246+ void Recursion (TFile* f1, TDirectory* target) {
247+ TString path ((char *)strstr (target->GetPath (), " :" ));
248+ path.Remove (0 , 2 );
249+ f1->cd (path);
250+ TDirectory* temp = gDirectory ;
251+ std::cout << " Checking initial Get Keys Here: " << temp->GetPath () << std::endl;
252+
253+ TIter next (temp->GetListOfKeys ());
254+ TKey* key;
255+ while ((key = (TKey*)next ())) {
256+ printf (" key: %s points to an object of class: %s \n " , key->GetName (), key->GetClassName ());
257+
258+ TObject* obj = key->ReadObj ();
259+ if (obj->IsA ()->InheritsFrom (TDirectory::Class ())) {
260+ std::cout << " Found subdirectory " << obj->GetName () << std::endl;
261+ TDirectory* subdir = (TDirectory*)obj;
262+ std::cout << subdir->GetPath () << std::endl;
263+ Recursion (f1, subdir);
264+ } else if (obj->IsA ()->InheritsFrom (TTree::Class ())) {
265+ std::cout << " object found" << std::endl;
266+ delete obj;
267+ } else {
268+ std::cout << " no new directory:" << std::endl;
269+ }
270+ }
271+ }
272+ } // namespace utils
273+
274+ SiStripHitEffFromCalibTree::~SiStripHitEffFromCalibTree () {
275+ if (quality_)
276+ delete quality_;
277+ if (tkmap)
278+ delete tkmap;
279+ if (tkmapbad)
280+ delete tkmapbad;
281+ if (tkmapeff)
282+ delete tkmapeff;
283+ if (tkmapnum)
284+ delete tkmapnum;
285+ if (tkmapden)
286+ delete tkmapden;
287+
288+ if (fs) {
289+ auto & tFile = fs->file ();
290+ // tFile.Print(); // Print information about the file
291+ edm::LogPrint (" " ) << __PRETTY_FUNCTION__ << " File Name: " << tFile.GetName () << std::endl;
292+ edm::LogPrint (" " ) << __PRETTY_FUNCTION__ << " File Title: " << tFile.GetTitle () << std::endl;
293+ edm::LogPrint (" " ) << __PRETTY_FUNCTION__ << " File Option: " << tFile.GetOption () << std::endl;
294+ edm::LogPrint (" " ) << __PRETTY_FUNCTION__ << " File Writable: " << tFile.IsWritable () << std::endl;
295+ edm::LogPrint (" " ) << __PRETTY_FUNCTION__ << " File IsZombie: " << tFile.IsZombie () << std::endl;
296+ edm::LogPrint (" " ) << __PRETTY_FUNCTION__ << " File has inconsistent hash: " << tFile.HasInconsistentHash ()
297+ << std::endl;
298+
299+ bool debug{false };
300+
301+ if (!tFile.IsZombie () && tFile.IsWritable () && debug) {
302+ // Delete all objects in the file recursively
303+ utils::Recursion (&tFile, &tFile);
304+ edm::LogPrint (" " ) << __PRETTY_FUNCTION__ << " done deleting" << std::endl;
305+ // Write and close the file
306+ tFile.Write (); // Ensure all objects are written
307+ tFile.Close ();
308+ }
309+ }
232310}
233311
234312void SiStripHitEffFromCalibTree::algoAnalyze (const edm::Event& e, const edm::EventSetup& c) {
@@ -272,15 +350,15 @@ void SiStripHitEffFromCalibTree::algoAnalyze(const edm::Event& e, const edm::Eve
272350 instLumiHisto_cutOnTracks = fs->make <TH1F>(" instLumi_cutOnTracks" , " inst. lumi." , 250 , 0 , 25000 );
273351 PUHisto_cutOnTracks = fs->make <TH1F>(" PU_cutOnTracks" , " PU" , 300 , 0 , 300 );
274352
275- for (int l = 0 ; l < 35 ; l++) {
353+ for (int l = 0 ; l < ::k_END_OF_LAYS_AND_RINGS ; l++) {
276354 goodlayertotal[l] = 0 ;
277355 goodlayerfound[l] = 0 ;
278356 alllayertotal[l] = 0 ;
279357 alllayerfound[l] = 0 ;
280358 }
281359
282- TH1F* resolutionPlots[23 ];
283- for (Long_t ilayer = 0 ; ilayer < 23 ; ilayer++) {
360+ TH1F* resolutionPlots[::k_END_OF_LAYERS ];
361+ for (Long_t ilayer = 0 ; ilayer < ::k_END_OF_LAYERS ; ilayer++) {
284362 std::string lyrName = ::layerName (ilayer, showRings_, nTEClayers);
285363
286364 resolutionPlots[ilayer] = fs->make <TH1F>(Form (" resol_layer_%i" , (int )(ilayer)), lyrName.c_str (), 125 , -125 , 125 );
@@ -548,7 +626,7 @@ void SiStripHitEffFromCalibTree::algoAnalyze(const edm::Event& e, const edm::Eve
548626 }
549627 }
550628
551- if (!badquality && layer < 23 ) {
629+ if (!badquality && layer < ::k_END_OF_LAYERS ) {
552630 if (resxsig != 1000.0 )
553631 resolutionPlots[layer]->Fill (stripTrajMid - stripCluster);
554632 else
@@ -610,8 +688,8 @@ void SiStripHitEffFromCalibTree::algoAnalyze(const edm::Event& e, const edm::Eve
610688 }
611689
612690 if (layerfound_perBx.find (bx) == layerfound_perBx.end ()) {
613- layerfound_perBx[bx] = vector<int >(23 , 0 );
614- layertotal_perBx[bx] = vector<int >(23 , 0 );
691+ layerfound_perBx[bx] = vector<int >(::k_END_OF_LAYERS , 0 );
692+ layertotal_perBx[bx] = vector<int >(::k_END_OF_LAYERS , 0 );
615693 }
616694 if (!badflag)
617695 layerfound_perBx[bx][layer]++;
@@ -685,6 +763,9 @@ void SiStripHitEffFromCalibTree::algoAnalyze(const edm::Event& e, const edm::Eve
685763 }
686764 // At this point, both of our maps are loaded with the correct information
687765 }
766+ // once we're done close the bloody file
767+ CalibTreeFile->Close ();
768+ delete CalibTreeFile;
688769 } // go to next CalibTreeFile
689770
690771 makeHotColdMaps ();
0 commit comments