Hello,
I have a c++ class that derives from TObject. I want to write it out to a branch in a file, but when I produce it I do so as a vector<unique_ptr<MyClass>> (the cluList below), and to complicate matters it contains a vector<unique_ptr<TObject>> (the hitVector below) as a member variable.
I am running in the ATLAS Athena framework, and everything appears fine when looping over the events, but the job crashes at the end (when releasing the memory) and the branch is not produced in the output root file. I suspect I as the unique_ptrs are going out of scope I am not allowed to output the variable.
Is there a correct way to do this? Or (as I suspect) should I not even be trying to to do this?
Cheers,
Al
/*
Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
*/
#ifndef HTTCLUSTER_H
#define HTTCLUSTER_H
#include <TObject.h>
#include <vector>
#include <map>
#include <iostream>
#include <sstream>
#include <memory>
#include "TrigHTTObjects/HTTRawHit.h"
// Extra helpers for clustering raw hits
// Switching to unique pointers to mitigate memory issues.
typedef std::vector<std::unique_ptr<HTTRawHit>> hitVector;
typedef std::map<unsigned int, hitVector> hitsByModuleMap;
class HTTCluster : public TObject {
public:
HTTCluster();
hitVector hitlist; // list of hits that make the cluster
HTTRawHit clusterEquiv; // hit equivalent to the cluster
HTTRawHit seed; // hit equivalent to the cluster
bool isSafe; // confirmed by ganged pattern recognition
bool isKilled; // ganged pattern recognition suggest to remove this cluster
virtual ~HTTCluster();
ClassDef(HTTCluster, 1);
};
typedef std::vector<std::unique_ptr<HTTCluster>> cluList;
typedef std::map<unsigned int, cluList> clustersByModuleMap;
#endif // HTTCLUSTER_H
Hello,
I had indeed missed the #pragma for the map, and had accidentally left the vector entry as a standard pointer.
Adding these I now shift the error to the moment it tries to write to the file. A bit of the seg…