Commit cdbc840e authored by Valentina Fioretti's avatar Valentina Fioretti
Browse files

lock for MT with mongodb

parent 06778afc
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -87,6 +87,7 @@ void CXYZSD::Initialize(G4HCofThisEvent* HCE) {
    
    info_primaryEventID = 0;

    gm.config->readInto(writeToMongoDB, "IO.FILETYPE.MONGODB.WriteToServer");

}

@@ -398,12 +399,14 @@ void CXYZSD::EndOfEvent(G4HCofThisEvent* HCE) {

#ifdef MONGODB
    if(gm.enableWriteMONGODB && gm.enableWriteXYZ) {
        if (!writeToMongoDB) mutex_write.lock();
        if(NbHits > 0) {
            for (G4int i=0; i<NbHits; i++) {
                CXYZHit* hit = (*xyzhitCollection)[i];
                gm.mongodb_xyz->writeData(hit, i);
            }
        }
        if (!writeToMongoDB) mutex_write.unlock();        
    }
#endif
}
+2 −0
Original line number Diff line number Diff line
@@ -51,6 +51,8 @@ public:
    G4String GetVolumeName(int flag, int ndepth, G4Step* aStep);
    int GetMotherID(int flag, int ndepth, G4Step* aStep);
    
    bool writeToMongoDB = true; // true = upload, false = write local file only
    

private:
    CHitsXYZCollection* xyzhitCollection;
+1 −1
Original line number Diff line number Diff line
@@ -44,7 +44,7 @@ public:

    mongocxx::pool pool{uri};
    
    bool writeToMongoDB; // true = upload, false = write local file only
    bool writeToMongoDB = true; // true = upload, false = write local file only
    ofstream bson_local_file;
    string local_bson_filename;