Changeset 3392 in Sophya for trunk/SophyaLib/HiStats/ntuple.cc
- Timestamp:
- Nov 22, 2007, 7:25:40 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/HiStats/ntuple.cc
r3236 r3392 5 5 #include "perrors.h" 6 6 #include "ntuple.h" 7 #include "thsafeop.h" 7 8 8 9 namespace SOPHYA { … … 17 18 Simple NTuple class (a Table or 2-D data set) with double or 18 19 single precision floating point value columns. 20 \warning 21 Thread safe fill operation can be activated using the method SetThreadSafe() 22 Default mode is NON thread-safe fill. 19 23 \sa SOPHYA::ObjFileIO<NTuple> 20 24 … … 65 69 mFgDouble = true; 66 70 mInfo = NULL; 71 mThS = NULL; 67 72 } 68 73 … … 89 94 mVarD = NULL; 90 95 mInfo = NULL; 96 mThS = NULL; 91 97 if (nvar <= 0) throw ParmError("NTuple::NTuple(nvar<=0) "); 92 98 mNVar = nvar; … … 126 132 mVarD = NULL; 127 133 mInfo = NULL; 134 mThS = NULL; 128 135 int nvar = noms.size(); 129 136 if (nvar <= 0) throw ParmError("NTuple::NTuple(nvar<=0) "); … … 150 157 } 151 158 152 //! Copy constructor - Copies the table definition and associated data 159 /*! 160 Copy constructor - Copies the table definition and associated data, 161 as well as the tread safety state 162 */ 153 163 // cmv 8/10/99 154 164 //++ … … 158 168 //-- 159 169 : mNVar(0), mNEnt(0), mBlk(0), mNBlk(0) 160 , mVar(NULL), mVarD(NULL), mInfo(NULL)170 , mVar(NULL), mVarD(NULL), mInfo(NULL),mThS(NULL) 161 171 { 162 172 if(NT.mNVar<=0) return; // cas ou NT est cree par defaut … … 185 195 186 196 if(NT.mInfo!=NULL) {mInfo = new DVList; *mInfo = *(NT.mInfo);} 187 197 mThS = NULL; 198 if(NT.mThS!=NULL) SetThreadSafe(true); 188 199 return; 189 200 } 190 201 191 /* --Methode-- 192 //! Constructor with table initialized from a PPF file 193 //++ 194 NTuple::NTuple(char *flnm) 195 // 196 // Createur lecture fichier ppersist. 197 //-- 198 { 199 mNVar = mNEnt = mBlk = mNBlk = 0; 200 mVar = NULL; 201 mVarD = NULL; 202 mNames = NULL; 203 mInfo = NULL; 204 PInPersist s(flnm); 205 ObjFileIO<NTuple> fiont(this); 206 fiont.Read(s); 207 } 202 203 /* --Methode-- */ 204 NTuple::~NTuple() 205 { 206 Clean(); 207 } 208 /* --Methode-- */ 209 /*! 210 \brief Activate or deactivate thread-safe \b Fill() operations 211 If fg==true, create an ThSafeOp object in order to insure atomic Fill() 212 operations. if fg==false, the ThSafeOp object (mThS) of the target NTuple 213 is destroyed. 214 \warning The default Fill() operation mode for NTuples is NOT thread-safe. 215 Please note also that the thread-safety state is NOt saved to PPF (or FITS) streams. 208 216 */ 209 210 /* --Methode-- */ 211 NTuple::~NTuple() 212 { 213 Clean(); 217 void NTuple::SetThreadSafe(bool fg) 218 { 219 if (fg) { 220 if (mThS) return; 221 else mThS = new ThSafeOp(); 222 } 223 else { 224 if (mThS) delete mThS; 225 mThS = NULL; 226 } 214 227 } 215 228 … … 221 234 if (mVarD) delete[] mVarD; 222 235 if (mInfo) delete mInfo; 236 if (mThS) delete mThS; 223 237 int i; 224 238 if(mNBlk>0) { … … 232 246 mVarD = NULL; 233 247 mInfo = NULL; 248 mThS = NULL; 234 249 return; 235 250 } … … 283 298 //-- 284 299 { 300 if (mThS) mThS->lock(); // Thread-safe operation 285 301 int numb = mNEnt/mBlk; 286 302 if (numb >= mNBlk) { … … 302 318 else memcpy((mPtr[numb]+offb*mNVar), x, mNVar*sizeof(r_4)); 303 319 mNEnt++; 320 if (mThS) mThS->unlock(); // Thread-safe operation 304 321 return; 305 322 } … … 316 333 //-- 317 334 { 335 if (mThS) mThS->lock(); // Thread-safe operation 318 336 int numb = mNEnt/mBlk; 319 337 if (numb >= mNBlk) { … … 337 355 338 356 mNEnt++; 357 if (mThS) mThS->unlock(); // Thread-safe operation 339 358 return; 340 359 }
Note:
See TracChangeset
for help on using the changeset viewer.