Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

RecJobHistory.cxx

Go to the documentation of this file.
00001 
00002 //
00003 // RecJobHistory
00004 //
00005 // RecJobHistory holds information about the jobs used to create or fill
00006 // a record.
00007 //
00008 // Author:  S. Kasahara   10/07
00009 //
00011 #include <cassert>
00012 #include <iostream>
00013 using namespace std;
00014 
00015 #include "MessageService/MsgService.h"
00016 #include "Record/RecJobRecord.h"
00017 #include "Record/RecJobHistory.h"
00018 
00019 ClassImp(RecJobHistory)
00020 
00021 CVSID("$Id: RecJobHistory.cxx,v 1.6 2009/04/12 00:20:12 schubert Exp $");
00022 
00023 
00024 const UInt_t RecJobHistory::kNJobType = 10; // number of valid job types
00025 
00026 // Definition of methods
00027 // *********************
00028 
00029 //_____________________________________________________________________________
00030 RecJobHistory::RecJobHistory() {
00031   // Default constructor
00032 
00033   MSG("Rec",Msg::kDebug) << "RecJobHistory default ctor @ " << this << endl;
00034   
00035 }
00036 
00037 //_____________________________________________________________________________
00038 RecJobHistory::RecJobHistory(const RecJobHistory& that) : TObject(that) {
00039   // Copy constructor
00040 
00041   MSG("Rec",Msg::kDebug) << "RecJobHistory copy ctor @ " << this << endl;
00042   Append(that);
00043   
00044 }
00045   
00046 //_____________________________________________________________________________
00047 RecJobHistory::~RecJobHistory() {
00048   // Destructor
00049   
00050   MSG("Rec",Msg::kDebug) << "RecJobHistory dtor @ " << this << endl;
00051 
00052   JobRecordMapItr itr; 
00053   for ( itr = fJobRecordMap.begin(); itr != fJobRecordMap.end(); itr++ ) {
00054     RecJobRecord* jobrecord = itr->second;
00055     delete jobrecord;
00056   }
00057   fJobRecordMap.clear();
00058   
00059 }
00060 
00061 //_____________________________________________________________________________
00062 const char* RecJobHistory::JobTypeAsString(JobType_t jobtype) const {
00063   // Purpose: Convert enumerated jobtype to a string.
00064 
00065   switch (jobtype) {
00066 
00067   case kRaw:
00068     return "Raw";
00069   case kGMinos:
00070     return "GMinos";
00071   case kPTSim:
00072     return "PTSim";
00073   case kPhotonTransport:
00074     return "PhotonTransport";
00075   case kCand:
00076     return "Cand";
00077   case kNtpMC:
00078     return "NtpMC";
00079   case kNtpTH:
00080     return "NtpTH";
00081   case kNtpSR:
00082     return "NtpSR";
00083   case kNtpSt:
00084     return "NtpSt";
00085   case kUnknownJobType:
00086     return "UnknownJobType";
00087   default:
00088     MSG("Rec",Msg::kWarning)
00089       << "RecJobHistory::JobTypeAsString called with unknown JobType_t "
00090       << (int)jobtype << ". Fix method. Abort." << endl;
00091     abort();
00092   } // end of switch
00093 
00094 }
00095 
00096 //_____________________________________________________________________________
00097 const RecJobRecord* RecJobHistory::GetJobRecord(JobType_t jobtype) const {
00098   // Get ptr to job record by enumerated job type.
00099   // Return null if not found.
00100 
00101   std::string jobtypestr = JobTypeAsString(jobtype);
00102   if ( jobtypestr == "UnknownJobType" ) return 0;
00103 
00104   return GetJobRecord(jobtypestr.c_str());
00105 }
00106 
00107 //_____________________________________________________________________________
00108 const RecJobRecord* RecJobHistory::GetJobRecord(const char* jobtypestr) const {
00109   // Get job record by character string job type.
00110   // Return null if not found.
00111 
00112   JobRecordMapConstItr citr = fJobRecordMap.find(jobtypestr);
00113   if ( citr != fJobRecordMap.end() ) return citr->second;
00114   else return 0;
00115   
00116 }
00117 
00118 //_____________________________________________________________________________
00119 std::ostream& RecJobHistory::Print(std::ostream& os) const {
00120   //  Purpose:  Print history on ostream.  Job records are printed in
00121   //            sequential order by timestamp.
00122 
00123   std::map<const RecJobRecord*,std::string,compareJobRecord> recmapbytime;
00124   JobRecordMapConstItr citr;
00125   for ( citr = fJobRecordMap.begin(); citr != fJobRecordMap.end(); citr++ ) {
00126     recmapbytime.insert(make_pair(citr->second,citr->first));
00127   }
00128   
00129   os << "RecJobHistory:";
00130   if ( recmapbytime.empty() ) os << " <<empty>>" << endl;
00131   else  os << endl;
00132 
00133   std::map<const RecJobRecord*,std::string,compareJobRecord>::const_iterator 
00134                                                                        tcitr; 
00135   for ( tcitr = recmapbytime.begin(); tcitr != recmapbytime.end(); tcitr++ ) {
00136     os << tcitr->second << "\t" << *(tcitr->first) << endl;
00137   }
00138 
00139   return os;
00140 
00141 }
00142 
00143 //_____________________________________________________________________________
00144 void  RecJobHistory::Print(Option_t* /* option */) const {
00145   //  Purpose:  Print header in form supported by TObject::Print.
00146 
00147   Print(std::cout);
00148 
00149   return;
00150 
00151 }
00152 
00153 //_____________________________________________________________________________
00154 bool RecJobHistory::Append(const RecJobHistory& that) {
00155   // Append the contents of that's history to this.
00156   
00157   JobRecordMapConstItr citr; 
00158   const JobRecordMap& thatJobRecordMap = that.GetJobRecordMap();
00159   bool allpass = true;
00160   for ( citr = thatJobRecordMap.begin(); citr != thatJobRecordMap.end(); 
00161                                                                 citr++ ) {
00162     allpass &= CreateJobRecord((citr->first).c_str(),*(citr->second));
00163   }
00164 
00165   return allpass;
00166 
00167 }
00168 
00169 //_____________________________________________________________________________
00170 bool RecJobHistory::CreateJobRecord(JobType_t jobtype) {
00171   // Create job record from current job environment and insert it in the 
00172   // fJobRecordMap with the associated jobtype string as key.  
00173   // Return true if successful, or false if jobtype is unknown.
00174 
00175   return CreateJobRecord(JobTypeAsString(jobtype));
00176 
00177 }
00178 
00179 //_____________________________________________________________________________
00180 bool RecJobHistory::CreateJobRecord(const char* jobtypestr) {
00181   // Create job record from current job environment and insert it in 
00182   // the fJobRecordMap with the specified jobtypestr as key.  Return true
00183   // if successful, or false if jobtypestr is "UnknownJobType".
00184 
00185   RecJobRecord* jobrec = new RecJobRecord();
00186   bool isOk = AdoptJobRecord(jobtypestr,jobrec);
00187   if ( !isOk ) delete jobrec;
00188   return isOk;
00189   
00190 }
00191 
00192 //_____________________________________________________________________________
00193 bool RecJobHistory::CreateJobRecord(JobType_t jobtype, const char* prodname, 
00194                                     const char* codename,const char* hostname,
00195                                     const VldTimeStamp& timestamp) {
00196   // Create job record from arguments and insert it in the 
00197   // fJobRecordMap with the associated jobtype string as key.  
00198   // Return true if successful, or false if jobtype is unknown.
00199 
00200   return CreateJobRecord(JobTypeAsString(jobtype),prodname,codename,
00201                          hostname,timestamp);
00202   
00203 }
00204 
00205 //_____________________________________________________________________________
00206 bool RecJobHistory::CreateJobRecord(const char* jobtypestr,
00207                                     const char* prodname, const char* codename,
00208                                     const char* hostname,
00209                                     const VldTimeStamp& timestamp) {
00210   // Create job record from arguments and insert it in 
00211   // the fJobRecordMap with the specified jobtypestr as key.  Return true
00212   // if successful or false if jobtypestr is "UnknownJobType".
00213 
00214   RecJobRecord* jobrec = new RecJobRecord(prodname,codename,hostname,
00215                                           timestamp);
00216   bool isOk = AdoptJobRecord(jobtypestr,jobrec);
00217   if ( !isOk ) delete jobrec;
00218   return isOk;
00219   
00220 }
00221   
00222 //_____________________________________________________________________________
00223 bool RecJobHistory::CreateJobRecord(JobType_t jobtype,
00224                                     const RecJobRecord& jobrec_tocopy) {
00225   // Create job record as copy from the input jobrec_tocopy and insert it 
00226   // in the fJobRecordMap with the associated jobtype string as key.  
00227   // Return true if successful, or false if jobtype is unknown.
00228 
00229   return CreateJobRecord(JobTypeAsString(jobtype),jobrec_tocopy);
00230 
00231 }
00232 
00233 //_____________________________________________________________________________
00234 bool RecJobHistory::CreateJobRecord(const char* jobtypestr,
00235                                     const RecJobRecord& jobrec_tocopy) {
00236   // Create job record from the input jobrec_tocopy and insert it in 
00237   // the fJobRecordMap with the specified jobtypestr as key.  Return true
00238   // if successful, or false if jobtypestr is "UnknownJobType".
00239 
00240   RecJobRecord* jobrec = new RecJobRecord(jobrec_tocopy);
00241   bool isOk = AdoptJobRecord(jobtypestr,jobrec);
00242   if ( !isOk ) delete jobrec;
00243   return isOk;
00244   
00245 }
00246 
00247 //_____________________________________________________________________________
00248 bool RecJobHistory::AdoptJobRecord(const char* jobtypestr,
00249                                    RecJobRecord* jobrec) {
00250   // Insert job ptr to map with the specified jobtypestr as key.
00251   // If entry already exists, user will be warned and then entry
00252   // will be overrriden with new record.
00253   // Return true if success.  Return false if jobtypestr is "UnknownJobType"
00254   // and no insertion will be made in this case.
00255 
00256   if ( std::string(jobtypestr) == "UnknownJobType" ) {
00257     MSG("Rec",Msg::kWarning) << "RecJobHistory::CreateJobRecord "
00258                              << "received Unknown jobtypestr " << jobtypestr 
00259                              << ". Ignored." << endl;
00260     return false;
00261   }
00262 
00263   JobRecordMapItr itr = fJobRecordMap.find(jobtypestr);
00264   
00265   if ( itr != fJobRecordMap.end() ) {
00266     // Found record map entry of same job type.  Check to see if
00267     // it is an equivalent record, otherwise Print warning.
00268     if ( *(itr->second) != *jobrec ) {
00269       MSG("Rec",Msg::kWarning) << "RecJobHistory::CreateJobRecord "
00270                                << "Found existing entry of requested type "
00271                                << jobtypestr << ". Replaced." 
00272                                << endl;
00273     }
00274     delete (itr->second); // delete old record
00275     itr->second = jobrec; // insert new
00276   }
00277   else {
00278     fJobRecordMap.insert(make_pair(jobtypestr,jobrec));
00279   }
00280   
00281   return true;
00282   
00283 }
00284 
00285 //_____________________________________________________________________________
00286 ReleaseType::Release_t RecJobHistory::GetProdReleaseType(
00287                                                   UInt_t jobtypemask) const {
00288   // Get OR of production release types associated with job records selected
00289   // as specified in the input jobtypemask.  jobtypemask corresponds
00290   // to a bit mask of OR'ed EJobTypes. 
00291   // The default is to return the OR of production release types corresponding 
00292   // to records of type kCand or kGMinos.
00293   // Specifying jobtypemask = EJobType::kUnknownJobType requests the OR of all 
00294   // record release types in the job history.
00295   // Returns ReleaseType::kUnknown if unknown. 
00296 
00297   ReleaseType::Release_t release = ReleaseType::kUnknown;
00298   
00299   if ( kUnknownJobType == jobtypemask ) {
00300     // Loop over all records in the history and construct OR of release types
00301     JobRecordMapConstItr citr;
00302     for ( citr = fJobRecordMap.begin(); citr != fJobRecordMap.end(); citr++ ) {
00303       ReleaseType::Release_t recrelease = citr->second->GetProdReleaseType();
00304       if ( recrelease != ReleaseType::kUnknown ) {
00305         if ( release != ReleaseType::kUnknown ) release |= recrelease;
00306         else release = recrelease;
00307       }
00308     }
00309     return release;
00310   }
00311   
00312   // Otherwise, seek records of jobtype matching those specified in jobtypemask
00313   for ( UInt_t it = 0; it < kNJobType-1; it++ ) {
00314     UInt_t jobbit = 1 << it;
00315     if ( jobbit & jobtypemask ) {
00316       EJobType jobtype = static_cast<EJobType>(jobbit);
00317       const RecJobRecord* jobrecord = GetJobRecord(jobtype);
00318       if ( jobrecord ) {
00319         ReleaseType::Release_t recrelease = jobrecord->GetProdReleaseType();
00320         if ( recrelease != ReleaseType::kUnknown ) {
00321           if ( release != ReleaseType::kUnknown ) release |= recrelease;
00322           else release = recrelease;
00323         }
00324       }
00325     }
00326   }
00327 
00328   return release;
00329   
00330 }
00331 
00332 
00333 
00334 
00335 

Generated on Mon Feb 15 11:07:30 2010 for loon by  doxygen 1.3.9.1